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

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

#include <Device.hpp>

Public Member Functions

 Device ()
 Default constructor.
 
 Device (int filedes)
 Construct form a device file descriptor. The file descriptor is not owned.
 
 Device (const std::filesystem::path &filename, int flags=O_RDONLY|O_NONBLOCK)
 Construct from a device file path.
 
virtual ~Device () noexcept
 
::libevdev * data () noexcept
 Access the internal ::libevdev object.
 
const ::libevdev * data () const noexcept
 Access the internal ::libevdev object, const version.
 
void grab ()
 Grab the device through a EVIOCGRAB syscall.
 
void ungrab ()
 Ungrab the device.
 
void 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 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)
 
bool is_open () const noexcept
 
void close () noexcept
 
void nonblock (bool enable)
 
virtual void log (LogPriority p, const char *file, int line, const char *func, const char *format, std::va_list args) const
 
std::string name () const
 
std::optional< std::string > phys () const
 
std::optional< std::string > uniq () const
 
std::uint16_t product () const noexcept
 
std::uint16_t vendor () const noexcept
 
std::uint16_t bustype () const noexcept
 
std::uint16_t version () const noexcept
 
int 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 abs_min (Code code) const noexcept
 
int abs_max (Code code) const noexcept
 
int abs_fuzz (Code code) const noexcept
 
int abs_flat (Code code) const noexcept
 
int abs_res (Code code) const noexcept
 
AbsInfo abs_info (Code code) const
 
int get (Type type, Code code) const noexcept
 
int get (const TypeCode &tc) const noexcept
 
std::optional< int > fetch (Type type, Code code) const noexcept
 
std::optional< int > fetch (const TypeCode &tc) const noexcept
 
bool get_repeat (int &delay, int &period) const noexcept
 
int get_slot (unsigned slot, Code code) const noexcept
 
std::optional< int > fetch_slot (unsigned slot, Code code) const noexcept
 
std::optional< int > num_slots () const noexcept
 
int current_slot () const noexcept
 
void name (const std::string &n)
 
void phys (const std::string &phys)
 
void uniq (const std::string &uniq)
 
void product (std::uint16_t pid)
 
void vendor (std::uint16_t vid)
 
void bustype (std::uint16_t bus)
 
void version (std::uint16_t ver)
 
void enable (Property prop)
 
void disable (Property prop)
 
void set (Type type, Code code, int value)
 
void set (const TypeCode &tc, int value)
 
void set_slot (unsigned slot, Code code, int value)
 
void abs_min (Code code, int val)
 
void abs_max (Code code, int val)
 
void abs_fuzz (Code code, int val)
 
void abs_flat (Code code, int val)
 
void abs_res (Code code, int val)
 
void abs_info (Code code, const AbsInfo &abs)
 
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 kernel_abs_info (Code code, const AbsInfo &abs)
 
void 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 pending ()
 
std::vector< Propertyproperties () const
 
std::vector< Typetypes () const
 
std::vector< Codecodes (Type type) const
 
std::vector< Codecodes (Type type, Code max) const
 
void enable_key (Code code)
 
void enable_rel (Code code)
 
void enable_abs (Code code)
 

Protected Member Functions

 Device (LogPriority priority)
 Constructor to enable logging.
 
 Device (LogPriority priority, int filedes)
 Constructor to enable logging, and a non-owning device file descriptor.
 
 Device (LogPriority priority, const std::filesystem::path &filename, int flags=O_RDONLY|O_NONBLOCK)
 Constructor to enable logging and a device filename.
 

Detailed Description

Represents a device (real of not).

In order to use the logging function, the log() method must be overridden in a derived class, and a protected constructors (that take a LogPriority argument) must be called explicitly.

Constructor & Destructor Documentation

◆ Device() [1/6]

Device ( LogPriority  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/6]

Device ( LogPriority  priority,
int  filedes 
)
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.
filedesFile 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/6]

Device ( LogPriority  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/6]

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 fd() to supply a device file descriptor.
  • pass it to a Uinput object, that will turn it into a virtual device.
See also
open(), fd(int), Uinput

◆ Device() [5/6]

Device ( int  filedes)

Construct form a device file descriptor. The file descriptor is not owned.

See also
fd(int)

◆ Device() [6/6]

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

Construct from a device file path.

◆ ~Device()

virtual ~Device ( )
virtualnoexcept

Member Function Documentation

◆ abs_flat() [1/2]

int abs_flat ( Code  code) const
noexcept

◆ abs_flat() [2/2]

void abs_flat ( Code  code,
int  val 
)

◆ abs_fuzz() [1/2]

int abs_fuzz ( Code  code) const
noexcept

◆ abs_fuzz() [2/2]

void abs_fuzz ( Code  code,
int  val 
)

◆ abs_info() [1/2]

AbsInfo abs_info ( Code  code) const

◆ abs_info() [2/2]

void abs_info ( Code  code,
const AbsInfo abs 
)

◆ abs_max() [1/2]

int abs_max ( Code  code) const
noexcept

◆ abs_max() [2/2]

void abs_max ( Code  code,
int  val 
)

◆ abs_min() [1/2]

int abs_min ( Code  code) const
noexcept

◆ abs_min() [2/2]

void abs_min ( Code  code,
int  val 
)

◆ abs_res() [1/2]

int abs_res ( Code  code) const
noexcept

◆ abs_res() [2/2]

void abs_res ( Code  code,
int  val 
)

◆ bustype() [1/2]

std::uint16_t bustype ( ) const
noexcept

◆ bustype() [2/2]

void bustype ( std::uint16_t  bus)

◆ 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.

◆ close()

void close ( )
noexcept

◆ codes() [1/2]

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

◆ codes() [2/2]

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

◆ current_slot()

int current_slot ( ) const
noexcept

◆ data() [1/2]

const ::libevdev * data ( ) const
noexcept

Access the internal ::libevdev object, const version.

◆ data() [2/2]

::libevdev * data ( )
noexcept

Access the internal ::libevdev object.

◆ 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 
)

◆ driver_version()

int driver_version ( ) const
noexcept

◆ 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 
)

◆ fd() [1/2]

int fd ( ) const

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

◆ fd() [2/2]

void fd ( int  fd)

Set a file descriptor and read the device metadata.

You can only call this function once.

◆ fetch() [1/2]

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

◆ fetch() [2/2]

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

◆ fetch_slot()

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

◆ get() [1/2]

int get ( const TypeCode tc) const
noexcept

◆ get() [2/2]

int get ( Type  type,
Code  code 
) const
noexcept

◆ get_repeat()

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

◆ get_slot()

int get_slot ( unsigned  slot,
Code  code 
) 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

◆ is_open()

bool is_open ( ) const
noexcept

◆ kernel_abs_info()

void kernel_abs_info ( Code  code,
const AbsInfo abs 
)

◆ kernel_led_value()

void kernel_led_value ( Code  code,
::libevdev_led_value  value 
)

◆ log()

virtual void log ( LogPriority  p,
const char *  file,
int  line,
const char *  func,
const char *  format,
std::va_list  args 
) const
virtual

◆ name() [1/2]

std::string name ( ) const

◆ name() [2/2]

void name ( const std::string &  n)

◆ nonblock()

void nonblock ( bool  enable)

◆ num_slots()

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

◆ open()

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

◆ pending()

bool pending ( )

◆ phys() [1/2]

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

◆ phys() [2/2]

void phys ( const std::string &  phys)

◆ product() [1/2]

std::uint16_t product ( ) const
noexcept

◆ product() [2/2]

void product ( std::uint16_t  pid)

◆ properties()

std::vector< Property > properties ( ) const

◆ read() [1/2]

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

◆ read() [2/2]

Event read ( ReadFlag  flags = ReadFlag::normal)

◆ set() [1/2]

void set ( const TypeCode tc,
int  value 
)

◆ set() [2/2]

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

◆ set_clock_id()

void set_clock_id ( int  clockid)

◆ set_slot()

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

◆ types()

std::vector< Type > types ( ) const

◆ ungrab()

void ungrab ( )

Ungrab the device.

Exceptions
std::system_error
See also
Grabber

◆ uniq() [1/2]

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

◆ uniq() [2/2]

void uniq ( const std::string &  uniq)

◆ vendor() [1/2]

std::uint16_t vendor ( ) const
noexcept

◆ vendor() [2/2]

void vendor ( std::uint16_t  vid)

◆ version() [1/2]

std::uint16_t version ( ) const
noexcept

◆ version() [2/2]

void version ( std::uint16_t  ver)

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