-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexample2.cpp
More file actions
42 lines (35 loc) · 1.17 KB
/
example2.cpp
File metadata and controls
42 lines (35 loc) · 1.17 KB
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
#include <asio.hpp>
#include <iostream>
#include <udev++.hpp>
using namespace std::chrono_literals;
int main(int argc, char* argv[])
{
asio::io_context io;
udev::monitor monitor{io};
monitor.match_device("block");
monitor.enable();
monitor.on_device_added([&](udev::device dev)
{
if (dev.devtype() == "partition" && dev.property("ID_BUS") == "usb")
{
std::cout << "USB drive plugged in"
<< "\n syspath: " << dev.syspath()
<< "\n devnode: " << dev.devnode()
<< "\n filesys: " << dev.property("ID_FS_TYPE")
<< "\n sysname: " << dev.sysname()
<< "\n sysnum : " << dev.sysnum ();
std::cout << std::endl;
}
});
monitor.on_device_removed([&](udev::device dev)
{
if (dev.devtype() == "partition" && dev.property("ID_BUS") == "usb")
{
std::cout << "USB drive unplugged, devnode: " << dev.devnode();
std::cout << std::endl;
}
});
while (io.run_one_for(30s));
std::cout << "Nothing seems to be happening - exiting" << std::endl;
return 0;
}