#include<main.h>
-static int detect_usbs();
+static int detect_usb();
static int on_event();
int main(int argc, char **argv) {
- if(detect_usbs()<0) { return EXIT_FAILURE; }
+ if(detect_usb()<0) { return EXIT_FAILURE; }
return EXIT_SUCCESS;
}
-static int detect_usbs() {
+static int detect_usb() {
sd_device_monitor *monitor;
if(sd_device_monitor_new(&monitor)<0) { return -1; }
if(sd_device_monitor_filter_add_match_subsystem_devtype(monitor,"block","disk")!=0) { return -1; }
- if(sd_device_monitor_filter_update(monitor)!=0) { return -1; }
if(sd_device_monitor_start(monitor,&on_event,NULL)!=0) { return -1; }
- while(1) { }
+ if(sd_event_run(sd_device_monitor_get_event(monitor),UINT64_MAX)<0) { return -1; }
return 1;
}
static int on_event(sd_device_monitor *monitor, sd_device *dev, void *userdata) {
- printf("event?\n");
- return -1;
+ const char *name, *bus;
+
+ if(sd_device_get_devname(dev,&name)!=0) { return -1; }
+ if(sd_device_get_property_value(dev,"ID_BUS",&bus)!=0) { return -1; }
+
+ if(strcmp(bus,"usb")!=0) { return -1; }
+
+ printf("dev name: %s\n",name);
+
+ if(sd_device_monitor_stop(monitor)!=0) { return -1; }
+
+ return 0;
}