udev_control.h
Go to the documentation of this file.
1 // This file is part of the tcp/ip client library.
2 //
3 // Copyright (C) 2011 LAR - Laboratory for Automation and Robotics, ATLAS Project
4 // Department of Mechanical Engineering
5 // University of Aveiro
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2.1
10 // of the License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 // 02110-1301, USA.
21 
26 #ifndef _UDEV_CONTROL_H_
27 #define _UDEV_CONTROL_H_
28 
29 #include <libudev.h>
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <sys/types.h>
33 #include <unistd.h>
34 #include <string>
35 #include <vector>
36 #include <iostream>
37 #include <map>
38 #include <signal.h>
39 #include <string.h>
40 #include <boost/algorithm/string.hpp>
41 
42 using namespace std;
43 using namespace boost;
44 
54 {
55  private:
57  struct udev *udev;
59  struct udev_enumerate *enumerate;
61  struct udev_list_entry *devices, *dev_list_entry;
63  struct udev_device *dev;
65  struct udev_monitor *mon;
67  int fd;
69  vector<string> sub_systems;
71  map<string,string> properties;
73  map<string,string>::iterator properties_it;
75  map<string,void (*)(string,string,void*)> actions;
77  map<string,void*> user_data;
79  map<string,void (*)(string,string,void*)>::iterator actions_it;
80 
89  bool FilterProperties(struct udev_device *dev_);
90 
100  string GetProperty(struct udev_device *dev_,string name);
101 
102  public:
109  class_udev_control(string id_);
110 
117 
119  string id;
120 
122  vector<string> device_list;
123 
131  bool AddSubsystem(string subsystem);
132 
142  bool AddProperty(string name,string value);
143 
154  bool RegistryAction(string action,void (*callback)(string action,string node,void*data),void*data);
155 
162  bool SetUpMonitoring();
163 
173  bool EnumerateDevices();
174 
181  bool Monitoring();
182 
187  uint size()
188  {
189  return device_list.size();
190  }
191 
196  string GetId()
197  {
198  return id;
199  }
200 
207  string GetPath(uint i=0)
208  {
209  if(i>=size())
210  return "Not found";
211 
212  return device_list[i];
213  }
214 
215 };
216 
217 #endif
struct udev_list_entry * devices
List entries.
Definition: udev_control.h:61
vector< string > device_list
List of all devices that pass the filter.
Definition: udev_control.h:122
struct udev * udev
Auxiliary variable.
Definition: udev_control.h:57
map< string, string > properties
Map of all properties added.
Definition: udev_control.h:71
struct udev_monitor * mon
Udev monitor.
Definition: udev_control.h:65
map< string, void(*)(string, string, void *)>::iterator actions_it
Map iterator for the actions handler map.
Definition: udev_control.h:79
string GetPath(uint i=0)
Get the path to the device.
Definition: udev_control.h:207
string GetId()
Get id of the class.
Definition: udev_control.h:196
map< string, void * > user_data
Map of pairs of actions strings and user data parameters.
Definition: udev_control.h:77
map< string, string >::iterator properties_it
Properties map iterator.
Definition: udev_control.h:73
vector< string > sub_systems
Subsystem vector, these will be used to prefilter the devices.
Definition: udev_control.h:69
map< string, void(*)(string, string, void *)> actions
Map of pairs of actions strings and corresponding handler function.
Definition: udev_control.h:75
int fd
File descriptor used in the monitoring.
Definition: udev_control.h:67
struct udev_enumerate * enumerate
Enumerator auxiliary variable.
Definition: udev_control.h:59
uint size()
Get the size of the device list.
Definition: udev_control.h:187
struct udev_device * dev
Device auxiliary variable.
Definition: udev_control.h:63
string id
Id of the class.
Definition: udev_control.h:119
This class simplifies the implementation of the udev library.
Definition: udev_control.h:53


device_mapper
Author(s): Jorge Almeida
autogenerated on Mon Mar 2 2015 01:31:36