在C ++中接收USB设备插入的通知/事件/信号 [英] Receiving notification/event/signal of usb device insertion in c++
问题描述
我已经寻找了一段时间,但无法找到该问题的答案.我正在尝试接收特定USB设备的连接通知.这是我所知道的:
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:
我正在运行Linux内核版本3.2.我需要识别USB设备的ID.我已经创建了用于读取和写入设备的内核模块.内核模块已经过测试,可以正常工作.内核模块创建/dev/Component#.
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#.
我正在尝试编写一个通知USB设备连接事件的程序,因此不需要遍历/dev/Component#并检查文件是否存在.我的希望是已经存在一个信号/通知/事件.我已经看过libusb,但是我的理解是您实际上只是在创建一个读取所有设备的循环.我已经考虑过添加系统调用,但是重新编译内核并不是真正的选择.
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.
任何帮助将不胜感激.
谢谢
SgtSquatlow
SgtSquatlow
推荐答案
有一种使用dbus的解决方案.首先,应该安装libdbus-glib库(在Debian/Ubuntu上,该软件包称为 libdbus-glib-1-dev
),如果尚未安装的话.然后,您可以在此处达到峰值,像这样编译程序:
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)
这篇关于在C ++中接收USB设备插入的通知/事件/信号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!