00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00026 #ifndef _UDEV_CONTROL_H_
00027 #define _UDEV_CONTROL_H_
00028
00029 #include <libudev.h>
00030 #include <stdio.h>
00031 #include <stdlib.h>
00032 #include <sys/types.h>
00033 #include <unistd.h>
00034 #include <string>
00035 #include <vector>
00036 #include <iostream>
00037 #include <map>
00038 #include <signal.h>
00039 #include <string.h>
00040 #include <boost/algorithm/string.hpp>
00041
00042 using namespace std;
00043 using namespace boost;
00044
00053 class class_udev_control
00054 {
00055 private:
00057 struct udev *udev;
00059 struct udev_enumerate *enumerate;
00061 struct udev_list_entry *devices, *dev_list_entry;
00063 struct udev_device *dev;
00065 struct udev_monitor *mon;
00067 int fd;
00069 vector<string> sub_systems;
00071 map<string,string> properties;
00073 map<string,string>::iterator properties_it;
00075 map<string,void (*)(string,string,void*)> actions;
00077 map<string,void*> user_data;
00079 map<string,void (*)(string,string,void*)>::iterator actions_it;
00080
00089 bool FilterProperties(struct udev_device *dev_);
00090
00100 string GetProperty(struct udev_device *dev_,string name);
00101
00102 public:
00109 class_udev_control(string id_);
00110
00116 ~class_udev_control();
00117
00119 string id;
00120
00122 vector<string> device_list;
00123
00131 bool AddSubsystem(string subsystem);
00132
00142 bool AddProperty(string name,string value);
00143
00154 bool RegistryAction(string action,void (*callback)(string action,string node,void*data),void*data);
00155
00162 bool SetUpMonitoring();
00163
00173 bool EnumerateDevices();
00174
00181 bool Monitoring();
00182
00187 uint size()
00188 {
00189 return device_list.size();
00190 }
00191
00196 string GetId()
00197 {
00198 return id;
00199 }
00200
00207 string GetPath(uint i=0)
00208 {
00209 if(i>=size())
00210 return "Not found";
00211
00212 return device_list[i];
00213 }
00214
00215 };
00216
00217 #endif