-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.cpp
61 lines (42 loc) · 1.52 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**
* @file main.cpp
* @date 1 Sep 2013
* @author lukasz.forynski
* @brief simple example on how to use monitor.
*/
// you can use PTHREADs if you wish to run the monitor
// in the context of pthread. Define USE_PTHREADS for the project.
// Otherwise, if you won't define
// it - call 'run_from_thread()' method from your own thread.
#include <device_notification.h>
class MyDeviceNotif : public DeviceNotification
{
public:
// default implementation (in base class) only prints out the device path etc,
// but this could be overridden - just implement your own versions of these methods as needed.
virtual void device_arrived(const std::string& device_path, void* lparam)
{
std::cout << "new device : " << device_path << "\n";
}
virtual void device_removed(const std::string& device_path, void* lparam)
{
std::cout << "device removed: " << device_path << "\n";
}
};
int main(int argc, char **argv)
{
MyDeviceNotif notif;
// note, that on unix systems you need to define your udev rules to allow notifications for
// your device. For below example, create file like: /etc/udev/rules.d/99-hid.rules and add line:
// and add line: "KERNEL=="hidraw*", MODE="0666" (if you don't have it already)
notif.init("hidraw");
std::cout << " waiting for new HID devices.. \n";
#ifndef USE_PTHREADS
notif.run_from_thread();
#endif
while(true)
{
// ...
}
return 0;
}