34 cout<<
"Can't create udev!"<<endl;
90 mon = udev_monitor_new_from_netlink(
udev,
"udev");
93 udev_monitor_filter_add_match_subsystem_devtype(
mon,
sub_systems[i].c_str(),NULL);
95 udev_monitor_enable_receiving(
mon);
98 fd = udev_monitor_get_fd(
mon);
107 value=udev_device_get_property_value(
dev,name.c_str());
114 int num_properties_to_match=
properties.size();
115 int num_properties_match=0;
118 struct udev_list_entry * sysattr_list;
120 sysattr_list=udev_device_get_properties_list_entry(dev_);
122 while(sysattr_list!=NULL)
124 string name=udev_list_entry_get_name(sysattr_list);
125 string value=udev_list_entry_get_value(sysattr_list);
137 num_properties_match++;
139 sysattr_list=udev_list_entry_get_next(sysattr_list);
149 return num_properties_match==num_properties_to_match;
170 string last_minor=
"0";
180 dev = udev_device_new_from_syspath(
udev, path);
188 lpath=udev_device_get_devnode(
dev);
194 vector<string>::iterator it;
199 cout<<
"Added device to local list, ID: "<<
id<<
" Path: "<<lpath<<endl;
206 udev_device_unref(
dev);
246 cout<<
"Monitoring was not configured, please run SetUpMonitoring() before calling Monitoring()"<<endl;
250 ret = select(
fd+1, &fds, NULL, NULL, &tv);
253 if (ret > 0 && FD_ISSET(
fd, &fds))
257 dev = udev_monitor_receive_device(
mon);
269 udev_device_unref(
dev);
272 cout<<
"No Device from receive_device(). An error occured."<<endl;
struct udev_list_entry * devices
List entries.
vector< string > device_list
List of all devices that pass the filter.
struct udev * udev
Auxiliary variable.
map< string, string > properties
Map of all properties added.
bool AddProperty(string name, string value)
Add a property pair to the list of properties.
struct udev_monitor * mon
Udev monitor.
map< string, void(*)(string, string, void *)>::iterator actions_it
Map iterator for the actions handler map.
bool FilterProperties(struct udev_device *dev_)
Filter properties.
struct udev_list_entry * dev_list_entry
string GetProperty(struct udev_device *dev_, string name)
Get device property.
map< string, void * > user_data
Map of pairs of actions strings and user data parameters.
map< string, string >::iterator properties_it
Properties map iterator.
bool RegistryAction(string action, void(*callback)(string action, string node, void *data), void *data)
Registry and action handler.
vector< string > sub_systems
Subsystem vector, these will be used to prefilter the devices.
bool SetUpMonitoring()
Configure monitoring.
map< string, void(*)(string, string, void *)> actions
Map of pairs of actions strings and corresponding handler function.
~class_udev_control()
Destructor.
bool AddSubsystem(string subsystem)
Add subsystem to the properties.
int fd
File descriptor used in the monitoring.
bool Monitoring()
Monitor device.
Class that simplifies the implementation of the udev library.
struct udev_enumerate * enumerate
Enumerator auxiliary variable.
bool EnumerateDevices()
Enumerate devices.
struct udev_device * dev
Device auxiliary variable.
class_udev_control(string id_)
Constructor.