blob: 4a6e3ee7a410785e7c807f0268e35e2abee26d27 (
plain)
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
|
#include <stdio.h>
#include <time.h>
#include <libusbhp.h>
static void attach_fn(struct libusbhp_device_t *device, void *user_data)
{
printf("attach\n");
if(device) printf(" (%04x/%04x)\n", device->idVendor, device->idProduct);
}
static void detach_fn(struct libusbhp_device_t *device, void *user_data)
{
printf("detach\n");
if(device) printf(" (%04x/%04x)\n", device->idVendor, device->idProduct);
}
int main(int args, char* argv[])
{
struct libusbhp_t *handle;
int ret = libusbhp_init(&handle);
if(ret != 0) {
printf("Could not initialise handle.\n");
return 1;
}
libusbhp_register_hotplug_listeners(handle, attach_fn, detach_fn, NULL);
// 100ms timeout
struct timeval tv;
tv.tv_sec = 0;
tv.tv_usec = 100000;
while(1) {
int ret = libusbhp_handle_events_timeout(handle, &tv);
if(ret) printf("handle_events failed [%d]...\n", ret);
printf("loop\n");
}
libusbhp_exit(handle);
return 0;
}
|