Receiving notification/event/signal of usb device insertion in c++

我只是一个虾纸丫 提交于 2020-05-27 06:42:45

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!