问题
I have been looking for a while, but I have not been able to find an answer to this question. I am trying to receive a connection notification for a specific usb device. Here is what I have/know:
I am running the linux kernel version 3.2. I have the id's needed to identify the usb device. I have created a kernel module for reading and writing to the device. The kernel module has been tested and works properly. The kernel module creates /dev/Component#.
I am trying to write a program that is notified of a USB device connection event and thus will not need to loop over the /dev/Component# and check if the file exists. My hope is that there is a signal/notification/event that already exists. I have seen the libusb, but my understanding is that you are really just creating a loop that reads all the devices. I have considered adding a syscall, but recompiling the kernel isn't really an option.
Any help would be greatly appreciated.
Thanks,
SgtSquatlow
回答1:
There is a solution using dbus. First you should install the library libdbus-glib (on Debian / Ubuntu the package is called libdbus-glib-1-dev
) if it is not installed yet. Then you can peak a program here, compile the program like this:
gcc -o dbus-usb dbus-usb.c $(pkg-config --libs --cflags dbus-glib-1)
来源:https://stackoverflow.com/questions/14144781/receiving-notification-event-signal-of-usb-device-insertion-in-c