This class simplifies the implementation of the udev library. More...
#include <udev_control.h>
Public Member Functions | |
bool | AddProperty (string name, string value) |
Add a property pair to the list of properties. | |
bool | AddSubsystem (string subsystem) |
Add subsystem to the properties. | |
class_udev_control (string id_) | |
Constructor. | |
bool | EnumerateDevices () |
Enumerate devices. | |
string | GetId () |
Get id of the class. | |
string | GetPath (uint i=0) |
Get the path to the device. | |
bool | Monitoring () |
Monitor device. | |
bool | RegistryAction (string action, void(*callback)(string action, string node, void *data), void *data) |
Registry and action handler. | |
bool | SetUpMonitoring () |
Configure monitoring. | |
uint | size () |
Get the size of the device list. | |
~class_udev_control () | |
Destructor. | |
Public Attributes | |
vector< string > | device_list |
List of all devices that pass the filter. | |
string | id |
Id of the class. | |
Private Member Functions | |
bool | FilterProperties (struct udev_device *dev_) |
Filter properties. | |
string | GetProperty (struct udev_device *dev_, string name) |
Get device property. | |
Private Attributes | |
map< string, void(*)(string, string, void *)> | actions |
Map of pairs of actions strings and corresponding handler function. | |
map< string, void(*)(string, string, void *)>::iterator | actions_it |
Map iterator for the actions handler map. | |
struct udev_device * | dev |
Device auxiliary variable. | |
struct udev_list_entry * | dev_list_entry |
struct udev_list_entry * | devices |
List entries. | |
struct udev_enumerate * | enumerate |
Enumerator auxiliary variable. | |
int | fd |
File descriptor used in the monitoring. | |
struct udev_monitor * | mon |
Udev monitor. | |
map< string, string > | properties |
Map of all properties added. | |
map< string, string >::iterator | properties_it |
Properties map iterator. | |
vector< string > | sub_systems |
Subsystem vector, these will be used to prefilter the devices. | |
struct udev * | udev |
Auxiliary variable. | |
map< string, void * > | user_data |
Map of pairs of actions strings and user data parameters. |
This class simplifies the implementation of the udev library.
Each instance can only handle one device with a variable size set of rules.
Rules are added with the AddSubsystem()
and AddProperty()
functions.
The paths to the devices that correspond to the rules are saved in the device_list
variable and are accessible via the GetPath()
function.
Definition at line 53 of file udev_control.h.
class_udev_control::class_udev_control | ( | string | id_ | ) |
Constructor.
The constructor initializes the udev main object. And sets the class id.
id_ | id of this class |
Definition at line 28 of file udev_control.cpp.
class_udev_control::~class_udev_control | ( | ) |
bool class_udev_control::AddProperty | ( | string | name, | |
string | value | |||
) |
Add a property pair to the list of properties.
This function adds a property name/value pair to the list of all properties that will be used to filter the devices.
name | name of the property to add | |
value | value of the property |
Definition at line 54 of file udev_control.cpp.
bool class_udev_control::AddSubsystem | ( | string | subsystem | ) |
Add subsystem to the properties.
This functions adds a subsystem to the filter pairs.
subsystem | value of the subsytem |
Definition at line 65 of file udev_control.cpp.
bool class_udev_control::EnumerateDevices | ( | ) |
Enumerate devices.
Enumerate all devices that pass the filter of properties and subsystems.
This is the function that filters devices and makes them available in the list.
Multiple devices with the same set of rules are ordered by minor
number (this is a property that all devices share).
Definition at line 152 of file udev_control.cpp.
bool class_udev_control::FilterProperties | ( | struct udev_device * | dev_ | ) | [private] |
Filter properties.
This function filters the devices using the properties added.
dev_ | device to filter |
Definition at line 112 of file udev_control.cpp.
string class_udev_control::GetId | ( | ) | [inline] |
string class_udev_control::GetPath | ( | uint | i = 0 |
) | [inline] |
Get the path to the device.
This function returns the path
Definition at line 207 of file udev_control.h.
string class_udev_control::GetProperty | ( | struct udev_device * | dev_, | |
string | name | |||
) | [private] |
Get device property.
This function reads a device property by its name.
dev_ | device to use | |
name | name of the property |
Definition at line 102 of file udev_control.cpp.
bool class_udev_control::Monitoring | ( | ) |
Monitor device.
This function monitors the device
Definition at line 216 of file udev_control.cpp.
bool class_udev_control::RegistryAction | ( | string | action, | |
void(*)(string action, string node, void *data) | callback, | |||
void * | data | |||
) |
Registry and action handler.
This functions allows the user to set handler for specific actions on the devices
(remove, add, modify, etc..).
action | name of the action | |
callback | handler function | |
data | data to be sent to the handler |
Definition at line 47 of file udev_control.cpp.
bool class_udev_control::SetUpMonitoring | ( | ) |
Configure monitoring.
Configure the monitoring, must be called before calling Monitoring()
.
Definition at line 72 of file udev_control.cpp.
uint class_udev_control::size | ( | ) | [inline] |
Get the size of the device list.
Definition at line 187 of file udev_control.h.
map<string,void (*)(string,string,void*)> class_udev_control::actions [private] |
Map of pairs of actions strings and corresponding handler function.
Definition at line 75 of file udev_control.h.
map<string,void (*)(string,string,void*)>::iterator class_udev_control::actions_it [private] |
Map iterator for the actions handler map.
Definition at line 79 of file udev_control.h.
struct udev_device* class_udev_control::dev [private] |
Device auxiliary variable.
Definition at line 63 of file udev_control.h.
struct udev_list_entry * class_udev_control::dev_list_entry [private] |
Definition at line 61 of file udev_control.h.
vector<string> class_udev_control::device_list |
List of all devices that pass the filter.
Definition at line 122 of file udev_control.h.
struct udev_list_entry* class_udev_control::devices [private] |
List entries.
Definition at line 61 of file udev_control.h.
struct udev_enumerate* class_udev_control::enumerate [private] |
Enumerator auxiliary variable.
Definition at line 59 of file udev_control.h.
int class_udev_control::fd [private] |
File descriptor used in the monitoring.
Definition at line 67 of file udev_control.h.
string class_udev_control::id |
Id of the class.
Definition at line 119 of file udev_control.h.
struct udev_monitor* class_udev_control::mon [private] |
Udev monitor.
Definition at line 65 of file udev_control.h.
map<string,string> class_udev_control::properties [private] |
Map of all properties added.
Definition at line 71 of file udev_control.h.
map<string,string>::iterator class_udev_control::properties_it [private] |
Properties map iterator.
Definition at line 73 of file udev_control.h.
vector<string> class_udev_control::sub_systems [private] |
Subsystem vector, these will be used to prefilter the devices.
Definition at line 69 of file udev_control.h.
struct udev* class_udev_control::udev [private] |
Auxiliary variable.
Definition at line 57 of file udev_control.h.
map<string,void*> class_udev_control::user_data [private] |
Map of pairs of actions strings and user data parameters.
Definition at line 77 of file udev_control.h.