DUDS
Distributed Update of Data from Something
duds::os::linux::EvdevInput Class Reference

Handles getting input from a specific input device using libevdev. More...

#include <EvdevInput.hpp>

Inheritance diagram for duds::os::linux::EvdevInput:
Collaboration diagram for duds::os::linux::EvdevInput:

Public Member Functions

 EvdevInput ()
 Constructs an EvdevInput object without opening a device file. More...
 
 EvdevInput (const std::string &path)
 Creates a EvdevInput object that will read input from the given device file. More...
 
 EvdevInput (EvdevInput &&old)
 Move constructor. More...
 
 ~EvdevInput ()
 Destructor. More...
 
const input_absinfo * absInfo (unsigned int absEc) const
 Provides information about a specified absolute axis. More...
 
boost::signals2::connection connect (const InputHandlersSptr &ihs)
 Connect the given InputHandlers to the end of the input event signal. More...
 
boost::signals2::connection connect (const InputSignal::slot_type &slot, boost::signals2::connect_position at=boost::signals2::at_back)
 Make a connection to the input event signal. More...
 
boost::signals2::connection connect (const InputSignal::group_type &group, const InputSignal::slot_type &slot, boost::signals2::connect_position at=boost::signals2::at_back)
 Make a connection to the input event signal. More...
 
boost::signals2::connection connectExtended (const InputSignal::extended_slot_type &slot, boost::signals2::connect_position at=boost::signals2::at_back)
 Make a connection to the input event signal. More...
 
boost::signals2::connection connectExtended (const InputSignal::group_type &group, const InputSignal::extended_slot_type &slot, boost::signals2::connect_position at=boost::signals2::at_back)
 Make a connection to the input event signal. More...
 
void disconnect (const InputSignal::group_type &group)
 Disconnect a group from the input event signal. More...
 
template<typename Slot >
void disconnect (const Slot &slotFunc)
 Disconnect a slot from the input event signal. More...
 
void disconnectAll ()
 Disconnects all slots from the input event signal. More...
 
bool eventsAvailable () const
 Returns true if there are events awaiting processing on this device. More...
 
bool grab ()
 Attempts to gain exclusive access to the input device. More...
 
bool hasEvent (EventTypeCode etc) const
 Returns true if the input device can produce events of the given type and code. More...
 
bool hasEventCode (unsigned int et, unsigned int ec) const
 Returns true if the input device can produce events of the given type and code. More...
 
bool hasEventType (unsigned int et) const
 Returns true if the input device can produce events of the given type. More...
 
bool hasMultitouchSlots () const
 True if the input device has at least one multitouch slot. More...
 
InputHandlersSptr makeConnectedHandlers ()
 Makes a new InputHandlers object, connects it to the input event signal for this device, and retruns the object. More...
 
std::string name () const
 Reports the name of the device using libevdev_get_name(). More...
 
int numMultitouchSlots () const
 Returns the number of slots supported by a multitouch input device. More...
 
void open (const std::string &path)
 Opens the given input device file. More...
 
EvdevInputoperator= (EvdevInput &&old) noexcept
 Move assignment. More...
 
void respond (Poller *, int)
 Same as calling respondToNextEvent(); used with Poller. More...
 
void respondToNextEvent ()
 Responds to the next input event on the device. More...
 
void usePoller (Poller &p)
 Registers this object with the given Poller so that Poller::wait() will invoke respondToNextEvent(). More...
 
int value (EventTypeCode etc) const
 Returns the current input value for the given event. More...
 
int value (unsigned int et, unsigned int ec) const
 Returns the current input value for the given event. More...
 

Static Public Member Functions

static std::shared_ptr< EvdevInputmake (const std::string &path)
 Creates a EvdevInput object managed by a std::shared_ptr. More...
 

Private Attributes

InputSignal defReceiver
 Handles all input events. More...
 
libevdev * dev = nullptr
 The object provided by libevdev that is needed to work with the input device. More...
 
int fd
 The file descriptor to the input device file. More...
 

Detailed Description

Handles getting input from a specific input device using libevdev.

A single InputSignal processes all input events from the device. If InputSignals for specific events are needed, use InputHandlers. These objects can be connected with custom code, or with connect(const InputHandlersSptr &). An InputHandlers object may be used with multiple EvdevInput objects.

This class is not thread-safe, but this should not be an issue.

If used with Poller, this object must be managed by a std::shared_ptr.

Author
Jeff Jackowski
Examples:
evdevin.cpp.

Definition at line 29 of file EvdevInput.hpp.

Constructor & Destructor Documentation

◆ EvdevInput() [1/3]

duds::os::linux::EvdevInput::EvdevInput ( )

Constructs an EvdevInput object without opening a device file.

Before input events can be handled, open() must be called.

Definition at line 22 of file EvdevInput.cpp.

◆ EvdevInput() [2/3]

duds::os::linux::EvdevInput::EvdevInput ( const std::string &  path)

Creates a EvdevInput object that will read input from the given device file.

Parameters
pathThe device file. This is normally some variation of "/dev/input/event[0-9]+". Read-only access will be requested.
Exceptions
EvdevFileOpenErrorThe device file could not be opened.
EvdevInitErrorThe attempt to initialize libevdev failed. An error code will be added to the exception in a boost::errinfo_errno attribute.

Definition at line 24 of file EvdevInput.cpp.

◆ EvdevInput() [3/3]

duds::os::linux::EvdevInput::EvdevInput ( EvdevInput &&  old)

Move constructor.

Postcondition
The InputSignal, used to handle input events, within old will no longer be usable until after it is move-assigned.

Definition at line 50 of file EvdevInput.cpp.

◆ ~EvdevInput()

duds::os::linux::EvdevInput::~EvdevInput ( )

Destructor.

Definition at line 58 of file EvdevInput.cpp.

Referenced by make().

Member Function Documentation

◆ absInfo()

const input_absinfo * duds::os::linux::EvdevInput::absInfo ( unsigned int  absEc) const

Provides information about a specified absolute axis.

Parameters
absEcThe event code for the axis to query. It must be for an event of type EV_ABS.
Returns
A non-null pointer to the data.
Exceptions
EvdevUnsupportedEventThe requested event lacks the information; either isn't an axis, or the axis is not provided by the input device.

Definition at line 137 of file EvdevInput.cpp.

Referenced by value().

◆ connect() [1/3]

boost::signals2::connection duds::os::linux::EvdevInput::connect ( const InputHandlersSptr ihs)

Connect the given InputHandlers to the end of the input event signal.

Postcondition
When the last reference to the InputHandlers object is lost, it will be automaticlly removed from the event signal.
Parameters
ihsThe InputHandlers object that should process events from this input device.

Definition at line 147 of file EvdevInput.cpp.

Referenced by makeConnectedHandlers(), and value().

◆ connect() [2/3]

boost::signals2::connection duds::os::linux::EvdevInput::connect ( const InputSignal::slot_type &  slot,
boost::signals2::connect_position  at = boost::signals2::at_back 
)
inline

Make a connection to the input event signal.

See the Boost reference documentation for more details, or the tutorial for an overview of the whole boost::singals2 system.

Definition at line 230 of file EvdevInput.hpp.

◆ connect() [3/3]

boost::signals2::connection duds::os::linux::EvdevInput::connect ( const InputSignal::group_type &  group,
const InputSignal::slot_type &  slot,
boost::signals2::connect_position  at = boost::signals2::at_back 
)
inline

Make a connection to the input event signal.

See the Boost reference documentation for more details, or the tutorial for an overview of the whole boost::singals2 system.

Definition at line 242 of file EvdevInput.hpp.

◆ connectExtended() [1/2]

boost::signals2::connection duds::os::linux::EvdevInput::connectExtended ( const InputSignal::extended_slot_type &  slot,
boost::signals2::connect_position  at = boost::signals2::at_back 
)
inline

Make a connection to the input event signal.

See the Boost reference documentation for more details, or the tutorial for an overview of the whole boost::singals2 system.

Definition at line 255 of file EvdevInput.hpp.

◆ connectExtended() [2/2]

boost::signals2::connection duds::os::linux::EvdevInput::connectExtended ( const InputSignal::group_type &  group,
const InputSignal::extended_slot_type &  slot,
boost::signals2::connect_position  at = boost::signals2::at_back 
)
inline

Make a connection to the input event signal.

See the Boost reference documentation for more details, or the tutorial for an overview of the whole boost::singals2 system.

Definition at line 267 of file EvdevInput.hpp.

◆ disconnect() [1/2]

void duds::os::linux::EvdevInput::disconnect ( const InputSignal::group_type &  group)
inline

Disconnect a group from the input event signal.

See the Boost reference documentation for more details, or the tutorial for an overview of the whole boost::singals2 system.

Definition at line 280 of file EvdevInput.hpp.

◆ disconnect() [2/2]

template<typename Slot >
void duds::os::linux::EvdevInput::disconnect ( const Slot &  slotFunc)
inline

Disconnect a slot from the input event signal.

See the Boost reference documentation for more details, or the tutorial for an overview of the whole boost::singals2 system.

Definition at line 292 of file EvdevInput.hpp.

◆ disconnectAll()

void duds::os::linux::EvdevInput::disconnectAll ( )
inline

Disconnects all slots from the input event signal.

Definition at line 298 of file EvdevInput.hpp.

◆ eventsAvailable()

bool duds::os::linux::EvdevInput::eventsAvailable ( ) const

Returns true if there are events awaiting processing on this device.

When true, respondToNextEvent() will not block.

Examples:
evdevin.cpp.

Definition at line 106 of file EvdevInput.cpp.

Referenced by value().

◆ grab()

bool duds::os::linux::EvdevInput::grab ( )

Attempts to gain exclusive access to the input device.

Returns
True if exclusive access was granted.

Definition at line 80 of file EvdevInput.cpp.

Referenced by make().

◆ hasEvent()

bool duds::os::linux::EvdevInput::hasEvent ( EventTypeCode  etc) const

Returns true if the input device can produce events of the given type and code.

Parameters
etcThe event type and code to check.
Examples:
evdevin.cpp.

Definition at line 88 of file EvdevInput.cpp.

Referenced by hasEventCode(), and make().

◆ hasEventCode()

bool duds::os::linux::EvdevInput::hasEventCode ( unsigned int  et,
unsigned int  ec 
) const
inline

Returns true if the input device can produce events of the given type and code.

Parameters
etThe event type to check.
ecThe event code to check.

Definition at line 134 of file EvdevInput.hpp.

◆ hasEventType()

bool duds::os::linux::EvdevInput::hasEventType ( unsigned int  et) const

Returns true if the input device can produce events of the given type.

Parameters
etThe event type to check.

Definition at line 84 of file EvdevInput.cpp.

Referenced by make().

◆ hasMultitouchSlots()

bool duds::os::linux::EvdevInput::hasMultitouchSlots ( ) const
inline

True if the input device has at least one multitouch slot.

Definition at line 148 of file EvdevInput.hpp.

◆ make()

static std::shared_ptr<EvdevInput> duds::os::linux::EvdevInput::make ( const std::string &  path)
inlinestatic

Creates a EvdevInput object managed by a std::shared_ptr.

Parameters
pathThe device file. This is normally some variation of "/dev/input/event[0-9]+". Read-only access will be requested.
Exceptions
EvdevFileOpenErrorThe device file could not be opened.
EvdevInitErrorThe attempt to initialize libevdev failed. An error code will be added to the exception in a boost::errinfo_errno attribute.

Definition at line 81 of file EvdevInput.hpp.

◆ makeConnectedHandlers()

InputHandlersSptr duds::os::linux::EvdevInput::makeConnectedHandlers ( )

Makes a new InputHandlers object, connects it to the input event signal for this device, and retruns the object.

Postcondition
When the last reference to the InputHandlers object is lost, it will be automaticlly removed from the event signal.
Examples:
evdevin.cpp.

Definition at line 156 of file EvdevInput.cpp.

Referenced by value().

◆ name()

std::string duds::os::linux::EvdevInput::name ( ) const

Reports the name of the device using libevdev_get_name().

Definition at line 76 of file EvdevInput.cpp.

Referenced by make().

◆ numMultitouchSlots()

int duds::os::linux::EvdevInput::numMultitouchSlots ( ) const

Returns the number of slots supported by a multitouch input device.

Some such devices support 0 slots. If a device has no slot support, the value will be -1.

Note
To check for no slots without checking for the difference between 0 slots and slots not supported, check for less than 1.

Definition at line 92 of file EvdevInput.cpp.

Referenced by hasEventCode(), and hasMultitouchSlots().

◆ open()

void duds::os::linux::EvdevInput::open ( const std::string &  path)

Opens the given input device file.

Precondition
An input device file has not yet been opened by this object.
Parameters
pathThe device file. This is normally some variation of "/dev/input/event[0-9]+". Read-only access will be requested.
Exceptions
EvdevFileOpenErrorThe device file could not be opened.
EvdevFileAlreadyOpenErrorA device file is already open.
EvdevInitErrorThe attempt to initialize libevdev failed. An error code will be added to the exception in a boost::errinfo_errno attribute.
Examples:
evdevin.cpp.

Definition at line 28 of file EvdevInput.cpp.

Referenced by EvdevInput(), and make().

◆ operator=()

EvdevInput & duds::os::linux::EvdevInput::operator= ( EvdevInput &&  old)
noexcept

Move assignment.

Postcondition
The InputSignal, used to handle input events, within old will no longer be usable until after it is move-assigned.

Definition at line 67 of file EvdevInput.cpp.

Referenced by make().

◆ respond()

void duds::os::linux::EvdevInput::respond ( Poller ,
int   
)
virtual

Same as calling respondToNextEvent(); used with Poller.

Implements duds::os::linux::PollResponder.

Definition at line 129 of file EvdevInput.cpp.

Referenced by value().

◆ respondToNextEvent()

void duds::os::linux::EvdevInput::respondToNextEvent ( )

Responds to the next input event on the device.

If there is currently no queued event, this function will block until an event is available. If there are one or more queued events, all queued events will be handled without blocking for more events.

The event processing is in a loop. The next event is read and then provided to the appropriate InputSignal for handling. The InputSignal is invoked directly; it runs on this thread, and no other events are read until the signal has completed. The loop will continue while no error has occured, and there are queued events. The queued event check will include events that have been queued during the time this function is running.

Examples:
evdevin.cpp.

Definition at line 110 of file EvdevInput.cpp.

Referenced by respond(), and value().

◆ usePoller()

void duds::os::linux::EvdevInput::usePoller ( Poller p)

Registers this object with the given Poller so that Poller::wait() will invoke respondToNextEvent().

Precondition
This object is managed by a std::shared_ptr.
Parameters
pThe Poller object.

Definition at line 133 of file EvdevInput.cpp.

Referenced by value().

◆ value() [1/2]

int duds::os::linux::EvdevInput::value ( EventTypeCode  etc) const

Returns the current input value for the given event.

Parameters
etcThe event type and code to check.
Exceptions
EvdevUnsupportedEventThe event is not supplied by the input device.

Definition at line 96 of file EvdevInput.cpp.

Referenced by hasMultitouchSlots(), and value().

◆ value() [2/2]

int duds::os::linux::EvdevInput::value ( unsigned int  et,
unsigned int  ec 
) const
inline

Returns the current input value for the given event.

Parameters
etThe event type to check.
ecThe event code to check.
Exceptions
EvdevUnsupportedEventThe event is not supplied by the input device.

Definition at line 165 of file EvdevInput.hpp.

Member Data Documentation

◆ defReceiver

InputSignal duds::os::linux::EvdevInput::defReceiver
private

Handles all input events.

Definition at line 37 of file EvdevInput.hpp.

Referenced by connect(), operator=(), and respondToNextEvent().

◆ dev

libevdev* duds::os::linux::EvdevInput::dev = nullptr
private

The object provided by libevdev that is needed to work with the input device.

Definition at line 42 of file EvdevInput.hpp.

Referenced by absInfo(), eventsAvailable(), grab(), hasEvent(), hasEventType(), name(), numMultitouchSlots(), open(), operator=(), respondToNextEvent(), value(), and ~EvdevInput().

◆ fd

int duds::os::linux::EvdevInput::fd
private

The file descriptor to the input device file.

Definition at line 46 of file EvdevInput.hpp.

Referenced by open(), operator=(), usePoller(), and ~EvdevInput().


The documentation for this class was generated from the following files: