1.利用libudev和select模式,启动线程监听usb设备插拔
XN_THREAD_PROC xnUSBUDEVEventsThread(XN_THREAD_PARAM pThreadParam)
{
struct udev *udev;
struct udev_device *dev;
struct udev_monitor *mon;
int fd;
/* Create the udev object */
udev = udev_new();
if (!udev) {
printf("Can't create udev\n");
exit(1);
}
/* This section sets up a monitor which will report events when
devices attached to the system change. Events include "add",
"remove", "change", "online", and "offline".
This section sets up and starts the monitoring. Events are
polled for (and delivered) later on.
It is important that the monitor be set up before the call to
udev_enumerate_scan_devices() so that events (and devices) are
not missed. For example, if enumeration happened first, there
would be no event generated for a device which was attached after
enumeration but before monitoring began.
Note that a filter is added so that we
Linux USB 插拔监听技术

本文介绍了在Linux系统中如何监听USB设备的插入和移除。分别通过libudev库结合select模式启动线程监听,以及使用netlink机制来监控U盘的插拔事件。
最低0.47元/天 解锁文章
1247

被折叠的 条评论
为什么被折叠?



