libevdevxx 0.5.0
A C++ wrapper for libevdev.
Loading...
Searching...
No Matches
Device Class Reference

Represents a device (real or not). More...

#include <Device.hpp>

Classes

struct  DelayPeriod
 

Public Member Functions

 Device (std::nullptr_t) noexcept
 Construct invalid device.
 
 Device ()
 Default constructor.
 
 Device (int fd)
 Construct form a device file descriptor.
 
 Device (const std::filesystem::path &filename, int flags=O_RDONLY|O_NONBLOCK)
 Construct from a device file path.
 
 ~Device () noexcept
 
void create ()
 Create a new instance, in-place.
 
void create (int fd)
 Construct form a device file descriptor, in-place.
 
void create (const std::filesystem::path &filename, int flags=O_RDONLY|O_NONBLOCK)
 Construct from a device file path, in-place.
 
void destroy () noexcept override
 free all allocated resources and make the instance invalid.
 
 Device (Device &&other) noexcept
 Move constructor.
 
Deviceoperator= (Device &&other) noexcept
 Move assignment.
 
void acquire (libevdev *new_raw, int new_fd) noexcept
 
void acquire (state_type new_state) noexcept
 
state_type release () noexcept
 
void grab ()
 Grab the device through a EVIOCGRAB syscall.
 
void ungrab ()
 Ungrab the device.
 
void set_fd (int fd)
 Set a file descriptor and read the device metadata.
 
void change_fd (int fd)
 Change the file descriptor used internally, without re-reading the actual device.
 
int get_fd () const
 Return the internal file descriptor used to access the device file.
 
void open (const std::filesystem::path &filename, int flags=O_RDONLY|O_NONBLOCK)
 Open a device file and set it for the device.
 
bool is_open () const noexcept
 Check if a file was opened with open().
 
void set_nonblock (bool enable)
 Set the owned file handle's O_NONBLOCK flag.
 
virtual void log (LogLevel priority, const char *file, int line, const char *func, const char *format, std::va_list args) const noexcept
 
std::string get_name () const
 
std::optional< std::string > get_phys () const
 
std::optional< std::string > get_uniq () const
 
std::uint16_t get_product () const noexcept
 
std::uint16_t get_vendor () const noexcept
 
std::uint16_t get_bustype () const noexcept
 
std::uint16_t get_version () const noexcept
 
int get_driver_version () const noexcept
 
bool has (Property prop) const noexcept
 
bool has (Type type) const noexcept
 
bool has (Type type, Code code) const noexcept
 
bool has (const TypeCode &tc) const noexcept
 
int get_abs_min (Code code) const noexcept
 
int get_abs_max (Code code) const noexcept
 
int get_abs_fuzz (Code code) const noexcept
 
int get_abs_flat (Code code) const noexcept
 
int get_abs_res (Code code) const noexcept
 
AbsInfo get_abs_info (Code code) const
 
int get_value (Type type, Code code) const noexcept
 
int get_value (const TypeCode &tc) const noexcept
 
std::optional< int > try_get_value (Type type, Code code) const noexcept
 
std::optional< int > try_get_value (const TypeCode &tc) const noexcept
 
bool get_repeat (int &delay, int &period) const noexcept
 
std::optional< DelayPeriodtry_get_repeat () const noexcept
 
int get_slot (unsigned slot, Code code) const noexcept
 
std::optional< int > try_get_slot (unsigned slot, Code code) const noexcept
 
int get_num_slots () const
 
std::optional< int > try_get_num_slots () const noexcept
 
int get_current_slot () const noexcept
 
void set_name (const std::string &name) noexcept
 
void set_phys (const std::string &phys) noexcept
 
void set_uniq (const std::string &uniq) noexcept
 
void set_product (std::uint16_t pid) noexcept
 
void set_vendor (std::uint16_t vid) noexcept
 
void set_bustype (std::uint16_t bus) noexcept
 
void set_version (std::uint16_t ver) noexcept
 
void enable (Property prop)
 
void disable (Property prop)
 
void set_value (Type type, Code code, int value)
 
void set_value (const TypeCode &tc, int value)
 
void set_slot (unsigned slot, Code code, int value)
 
void set_abs_min (Code code, int val) noexcept
 
void set_abs_max (Code code, int val) noexcept
 
void set_abs_fuzz (Code code, int val) noexcept
 
void set_abs_flat (Code code, int val) noexcept
 
void set_abs_res (Code code, int val) noexcept
 
void set_abs_info (Code code, const AbsInfo &abs) noexcept
 
void enable (Type type)
 
void disable (Type type)
 
void enable (Type type, Code code)
 
void enable (const TypeCode &tc)
 
void enable_abs (Code code, const AbsInfo &info)
 
void enable_rep (Code code, int arg)
 
void disable (Type type, Code code)
 
void disable (const TypeCode &tc)
 
void set_kernel_abs_info (Code code, const AbsInfo &abs)
 
void set_kernel_led_value (Code code, libevdev_led_value value)
 
void set_clock_id (int clockid)
 
Event read (ReadFlag flags=ReadFlag::normal)
 
ReadStatus read (Event &event, ReadFlag flags=ReadFlag::normal) noexcept
 
bool has_pending ()
 
std::vector< Propertyget_properties () const
 
std::vector< Typeget_types () const
 
std::vector< Codeget_codes (Type type) const
 
std::vector< Codeget_codes (Type type, Code max) const
 
void enable_key (Code code)
 
void enable_rel (Code code)
 
void enable_abs (Code code)
 
- Public Member Functions inherited from basic_wrapper< libevdev * >
constexpr basic_wrapper () noexcept=default
 
constexpr basic_wrapper (libevdev *src) noexcept
 
constexpr basic_wrapper (basic_wrapper &&other) noexcept
 Move constructor.
 
basic_wrapperoperator= (basic_wrapper &&other) noexcept
 Move assignment.
 
bool is_valid () const noexcept
 
 operator bool () const noexcept
 
raw_type data () noexcept
 
const raw_type data () const noexcept
 
void acquire (state_type new_state) noexcept
 
state_type release () noexcept
 
constexpr basic_wrapper () noexcept=default
 
constexpr basic_wrapper (libevdev *src) noexcept
 
constexpr basic_wrapper (basic_wrapper &&other) noexcept
 Move constructor.
 
basic_wrapperoperator= (basic_wrapper &&other) noexcept
 Move assignment.
 
bool is_valid () const noexcept
 
 operator bool () const noexcept
 
raw_type data () noexcept
 
const raw_type data () const noexcept
 
void acquire (state_type new_state) noexcept
 
state_type release () noexcept
 

Protected Types

enum class  LogLevel { none = -1 , error = LIBEVDEV_LOG_ERROR , info = LIBEVDEV_LOG_INFO , debug = LIBEVDEV_LOG_DEBUG }
 Helper enum to use the logging functions. More...
 

Protected Member Functions

 Device (LogLevel priority)
 Constructor to enable logging.
 
 Device (LogLevel priority, int fd)
 Constructor to enable logging, and a non-owning device file descriptor.
 
 Device (LogLevel priority, const std::filesystem::path &filename, int flags=O_RDONLY|O_NONBLOCK)
 Constructor to enable logging and a device filename.
 
void create (LogLevel priority)
 Constructor to enable logging, in-place.
 
void create (LogLevel priority, int fd)
 Constructor to enable logging, and a non-owning device file descriptor, in-place.
 
void create (LogLevel priority, const std::filesystem::path &filename, int flags=O_RDONLY|O_NONBLOCK)
 Constructor to enable logging and a device filename, in-place.
 
- Protected Member Functions inherited from basic_wrapper< libevdev * >
 ~basic_wrapper () noexcept=default
 
 ~basic_wrapper () noexcept=default
 

Additional Inherited Members

- Public Types inherited from basic_wrapper< libevdev * >
using raw_type
 
using state_type
 
- Static Public Attributes inherited from basic_wrapper< libevdev * >
static constexpr raw_type invalid_value
 
static constexpr raw_type invalid_value
 
- Protected Attributes inherited from basic_wrapper< libevdev * >
libevdev * raw
 
libevdev * raw
 

Detailed Description

Represents a device (real or not).

In order to use the logging function, the log() method must be overridden in a derived class, and a protected constructor (that takes a Device::LogLevel argument) must be called explicitly.


Class Documentation

◆ evdev::Device::DelayPeriod

struct evdev::Device::DelayPeriod
Class Members
int delay
int period

Member Enumeration Documentation

◆ LogLevel

enum class LogLevel
strongprotected

Helper enum to use the logging functions.

Enumerator
none 

Invalid level.

error 

Error level.

info 

Information level.

debug 

Debug level.

Constructor & Destructor Documentation

◆ Device() [1/8]

Device ( LogLevel priority)
protected

Constructor to enable logging.

Parameters
priorityThe priority level; the log() method will only be called when the message has this priority or above.
See also
log()

◆ Device() [2/8]

Device ( LogLevel priority,
int fd )
protected

Constructor to enable logging, and a non-owning device file descriptor.

Parameters
priorityThe priority level; the log() method will only be called when the message has this priority or above.
fdFile descriptor fot the device file (from /dev/input/event*) that will be used for I/O. Ownership is not taken over this, so the file will not be closed on destruction.
See also
log()

◆ Device() [3/8]

Device ( LogLevel priority,
const std::filesystem::path & filename,
int flags = O_RDONLY|O_NONBLOCK )
protected

Constructor to enable logging and a device filename.

Parameters
priorityThe priority level; the log() method will only be called when the message has this priority or above.
filenamePath to to an evdev device (from /dev/input/event*) that will be open by this device.
flagsFlags used in the open system call.
See also
log()

◆ Device() [4/8]

Device ( std::nullptr_t )
noexcept

Construct invalid device.

In an invalid state, most operations are not allowed. You can safely destroy, move and check for validity.

◆ Device() [5/8]

Device ( )

Default constructor.

No device file is associated with this device. For this to have any use, the user must later do either:

  • call open() to open a device file.
  • call set_fd() to supply a device file descriptor.
  • pass it to a Uinput object, that will turn it into a virtual device.
See also
open()
set_fd()
Uinput

◆ Device() [6/8]

Device ( int fd)

Construct form a device file descriptor.

The file descriptor is not owned: it won't be closed during destruction.

See also
set_fd()

◆ Device() [7/8]

Device ( const std::filesystem::path & filename,
int flags = O_RDONLY|O_NONBLOCK )

Construct from a device file path.

◆ ~Device()

~Device ( )
noexcept

◆ Device() [8/8]

Device ( Device && other)
noexcept

Move constructor.

Member Function Documentation

◆ acquire() [1/2]

void acquire ( libevdev * new_raw,
int new_fd )
noexcept

◆ acquire() [2/2]

void acquire ( state_type new_state)
noexcept

◆ change_fd()

void change_fd ( int fd)

Change the file descriptor used internally, without re-reading the actual device.

This is only useful if you need to close and reopen the file descriptor.

◆ create() [1/6]

void create ( )

Create a new instance, in-place.

No device file is associated with this device. For this to have any use, the user must later do either:

  • call open() to open a device file.
  • call set_fd() to supply a device file descriptor.
  • pass it to a Uinput object, that will turn it into a virtual device.
See also
open()
set_fd()
Uinput

◆ create() [2/6]

void create ( const std::filesystem::path & filename,
int flags = O_RDONLY|O_NONBLOCK )

Construct from a device file path, in-place.

◆ create() [3/6]

void create ( int fd)

Construct form a device file descriptor, in-place.

The file descriptor is not owned: it won't be closed during destruction.

See also
set_fd()

◆ create() [4/6]

void create ( LogLevel priority)
protected

Constructor to enable logging, in-place.

Parameters
priorityThe priority level; the log() method will only be called when the message has this priority or above.
See also
log()

◆ create() [5/6]

void create ( LogLevel priority,
const std::filesystem::path & filename,
int flags = O_RDONLY|O_NONBLOCK )
protected

Constructor to enable logging and a device filename, in-place.

Parameters
priorityThe priority level; the log() method will only be called when the message has this priority or above.
filenamePath to to an evdev device (from /dev/input/event*) that will be open by this device.
flagsFlags used in the open system call.
See also
log()

◆ create() [6/6]

void create ( LogLevel priority,
int fd )
protected

Constructor to enable logging, and a non-owning device file descriptor, in-place.

Parameters
priorityThe priority level; the log() method will only be called when the message has this priority or above.
fdFile descriptor fot the device file (from /dev/input/event*) that will be used for I/O. Ownership is not taken over this, so the file will not be closed on destruction.
See also
log()

◆ destroy()

void destroy ( )
overridevirtualnoexcept

free all allocated resources and make the instance invalid.

The result is the same as if this object was moved from.

Implements basic_wrapper< libevdev * >.

◆ disable() [1/4]

void disable ( const TypeCode & tc)

◆ disable() [2/4]

void disable ( Property prop)

◆ disable() [3/4]

void disable ( Type type)

◆ disable() [4/4]

void disable ( Type type,
Code code )

◆ enable() [1/4]

void enable ( const TypeCode & tc)

◆ enable() [2/4]

void enable ( Property prop)

◆ enable() [3/4]

void enable ( Type type)

◆ enable() [4/4]

void enable ( Type type,
Code code )

◆ enable_abs() [1/2]

void enable_abs ( Code code)

◆ enable_abs() [2/2]

void enable_abs ( Code code,
const AbsInfo & info )

◆ enable_key()

void enable_key ( Code code)

◆ enable_rel()

void enable_rel ( Code code)

◆ enable_rep()

void enable_rep ( Code code,
int arg )

◆ get_abs_flat()

int get_abs_flat ( Code code) const
noexcept

◆ get_abs_fuzz()

int get_abs_fuzz ( Code code) const
noexcept

◆ get_abs_info()

AbsInfo get_abs_info ( Code code) const

◆ get_abs_max()

int get_abs_max ( Code code) const
noexcept

◆ get_abs_min()

int get_abs_min ( Code code) const
noexcept

◆ get_abs_res()

int get_abs_res ( Code code) const
noexcept

◆ get_bustype()

std::uint16_t get_bustype ( ) const
noexcept

◆ get_codes() [1/2]

std::vector< Code > get_codes ( Type type) const

◆ get_codes() [2/2]

std::vector< Code > get_codes ( Type type,
Code max ) const

◆ get_current_slot()

int get_current_slot ( ) const
noexcept

◆ get_driver_version()

int get_driver_version ( ) const
noexcept

◆ get_fd()

int get_fd ( ) const

Return the internal file descriptor used to access the device file.

◆ get_name()

std::string get_name ( ) const

◆ get_num_slots()

int get_num_slots ( ) const

◆ get_phys()

std::optional< std::string > get_phys ( ) const

◆ get_product()

std::uint16_t get_product ( ) const
noexcept

◆ get_properties()

std::vector< Property > get_properties ( ) const

◆ get_repeat()

bool get_repeat ( int & delay,
int & period ) const
noexcept

◆ get_slot()

int get_slot ( unsigned slot,
Code code ) const
noexcept

◆ get_types()

std::vector< Type > get_types ( ) const

◆ get_uniq()

std::optional< std::string > get_uniq ( ) const

◆ get_value() [1/2]

int get_value ( const TypeCode & tc) const
noexcept

◆ get_value() [2/2]

int get_value ( Type type,
Code code ) const
noexcept

◆ get_vendor()

std::uint16_t get_vendor ( ) const
noexcept

◆ get_version()

std::uint16_t get_version ( ) const
noexcept

◆ grab()

void grab ( )

Grab the device through a EVIOCGRAB syscall.

Use Grabber to grab and ungrab with exception-safety.

Exceptions
std::system_error
See also
Grabber

◆ has() [1/4]

bool has ( const TypeCode & tc) const
noexcept

◆ has() [2/4]

bool has ( Property prop) const
noexcept

◆ has() [3/4]

bool has ( Type type) const
noexcept

◆ has() [4/4]

bool has ( Type type,
Code code ) const
noexcept

◆ has_pending()

bool has_pending ( )

◆ is_open()

bool is_open ( ) const
noexcept

Check if a file was opened with open().

◆ log()

virtual void log ( LogLevel priority,
const char * file,
int line,
const char * func,
const char * format,
std::va_list args ) const
virtualnoexcept

◆ open()

void open ( const std::filesystem::path & filename,
int flags = O_RDONLY|O_NONBLOCK )

Open a device file and set it for the device.

This Device instance must have been default-constructed for this to work. The file handle is owned by Device, you don't have to close it explicitly.

◆ operator=()

Device & operator= ( Device && other)
noexcept

Move assignment.

◆ read() [1/2]

ReadStatus read ( Event & event,
ReadFlag flags = ReadFlag::normal )
noexcept

◆ read() [2/2]

Event read ( ReadFlag flags = ReadFlag::normal)

◆ release()

state_type release ( )
noexcept

◆ set_abs_flat()

void set_abs_flat ( Code code,
int val )
noexcept

◆ set_abs_fuzz()

void set_abs_fuzz ( Code code,
int val )
noexcept

◆ set_abs_info()

void set_abs_info ( Code code,
const AbsInfo & abs )
noexcept

◆ set_abs_max()

void set_abs_max ( Code code,
int val )
noexcept

◆ set_abs_min()

void set_abs_min ( Code code,
int val )
noexcept

◆ set_abs_res()

void set_abs_res ( Code code,
int val )
noexcept

◆ set_bustype()

void set_bustype ( std::uint16_t bus)
noexcept

◆ set_clock_id()

void set_clock_id ( int clockid)

◆ set_fd()

void set_fd ( int fd)

Set a file descriptor and read the device metadata.

You can only call this function once.

◆ set_kernel_abs_info()

void set_kernel_abs_info ( Code code,
const AbsInfo & abs )

◆ set_kernel_led_value()

void set_kernel_led_value ( Code code,
libevdev_led_value value )

◆ set_name()

void set_name ( const std::string & name)
noexcept

◆ set_nonblock()

void set_nonblock ( bool enable)

Set the owned file handle's O_NONBLOCK flag.

◆ set_phys()

void set_phys ( const std::string & phys)
noexcept

◆ set_product()

void set_product ( std::uint16_t pid)
noexcept

◆ set_slot()

void set_slot ( unsigned slot,
Code code,
int value )

◆ set_uniq()

void set_uniq ( const std::string & uniq)
noexcept

◆ set_value() [1/2]

void set_value ( const TypeCode & tc,
int value )

◆ set_value() [2/2]

void set_value ( Type type,
Code code,
int value )

◆ set_vendor()

void set_vendor ( std::uint16_t vid)
noexcept

◆ set_version()

void set_version ( std::uint16_t ver)
noexcept

◆ try_get_num_slots()

std::optional< int > try_get_num_slots ( ) const
noexcept

◆ try_get_repeat()

std::optional< DelayPeriod > try_get_repeat ( ) const
noexcept

◆ try_get_slot()

std::optional< int > try_get_slot ( unsigned slot,
Code code ) const
noexcept

◆ try_get_value() [1/2]

std::optional< int > try_get_value ( const TypeCode & tc) const
noexcept

◆ try_get_value() [2/2]

std::optional< int > try_get_value ( Type type,
Code code ) const
noexcept

◆ ungrab()

void ungrab ( )

Ungrab the device.

Exceptions
std::system_error
See also
Grabber

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