当前位置:网站首页>libudev manual
libudev manual
2022-07-30 13:22:00 【Ruo_Xiao】
First, initialization
First call udev_new to create a udev library context.The udev library context adopts the reference counting mechanism. The default reference count of the created context is 1. Use udev_ref and udev_unref to increase or decrease the reference count. If the reference count is 0, the internal resources are released.
Second, enumerate devices
Use udev_enumerate_new to create an enumerator that scans the system for connected devices.Use udev_enumerate_ref and udev_enumerate_unref to increase or decrease the citation count.
Use the udev_enumerate_add_match / nomatch_xxx series of functions to add enumeration filters and filter keyWords are represented by characters, such as "block" devices.
Use the udev_enumerate_scan_xxx series of functions to scan the /sys directory for all devices that match the filter.The data structure after scanning is a linked list, use udev_enumerate_get_list_entry to get the first node of the linked list, use udev_list_entry_foreach Traverse the entire linked list.
3. Monitoring device plugging and unplugging udev's equipment plugging and unplugging is implemented based on netlink.
Use udev_monitor_new_from_netlink to create a new monitor, the second parameter of the function is the name of the event source, optional "kernel" or "udev".Event notifications based on "kernel" are earlier than "udev", but the related device nodes may not be created, so the design of general applications should be monitored based on "udev".
Use udev_monitor_filter_add_match_subsystem_devtype to add a udev event filter based on device type, eg: "block" devices.
Use udev_monitor_enable_receiving to start the monitoring process.For monitoring, you can use udev_monitor_get_fd to get a file descriptor, and based on the returned fd, you can perform the poll operation to simplify program design.
After the plug event arrives, you can use udev_monitor_receive_device to get the device mapping that generated the event.Calling udev_device_get_action can get a string: "add" or "remove", and "change", "online", "offline", etc., but the last threeIt is unknown under what circumstances it will occur.
Fourth, get device information
Use udev_list_entry_get_name to get the sys path of a device node, based on this path use udev_device_new_from_syspath can create a map of udev devices, which can be used to get device properties.To get device properties use udev_device_get_properties_list_entry to return a linked list that stores all property information of the device, use udev_list_entry_foreach Traverse the list and use udev_list_entry_get_name and udev_list_entry_get_value to get the name and value of the attribute.
Reprinted: libudev instruction manual_coroutinesBlog - CSDN Blog_libudev
(SAW: Game Over!)
边栏推荐
- 【23考研】408代码题参考模板——顺序表
- TaskDispatcher源码解析
- WinForm枚举容器中的控件,实现控件统一事件处理机制
- Why is Prometheus a monitoring artifact sufficient to replace Zabbix?
- How to solve the problem that the page does not display the channel configuration after the EasyNVR is updated to (V5.3.0)?
- Markdown 3 - 流程图表
- R语言时间序列数据算术运算:使用log函数将时间序列数据的数值对数化(平方、开平方、指数化等函数类似使用)
- Anaconda\Scripts\pip-script.py is not present ? 解决方案
- 腰部外骨骼机器人线性自抗扰控制器参数优化
- 【河北工业大学】考研初试复试资料分享
猜你喜欢
随机推荐
R语言ggpubr包的ggboxplot函数可视化分组箱图、自定义移除可视化图像的特定对象(移除可视化图像轴坐标轴的刻度线标签文本、both x and y axis ticks labels)
DeFi 巨头进军 NFT 领域 用户怎么看?
自从外包干了四年,基本废了...
Mysql batch insert transaction unique key repeated processing
CV-Model【2】:MobileNet v1
ENVI图像处理(6):NDVI和植被指数
Anaconda\Scripts\pip-script.py is not present ? 解决方案
【微信小程序】一文带你搞懂小程序的页面配置和网络数据请求
dbaplus丛书丨《MySQL DBA工作笔记》限量签名版来了!
no matching host key type found. Their offer: ssh-rsa
Greenplum 6.0有哪些不可错过的硬核升级与应用?
【语音识别】基于GMM-HMM的语音识别系统
[BJDCTF2020]Cookie is so stable-1|SSTI injection
R语言使用方差分析ANOVA比较回归模型的差异、anova函数比较两个模型并报告它们是否存在显著差异(两个模型的数据相同,一个模型使用的预测特征包含另外一个模型的特征)
一文读懂Elephant Swap,为何为ePLATO带来如此高的溢价?
Markdown 1 - 图文音视频等
第42讲:Scala中泛型类、泛型函数、泛型在Spark中的广泛应用
常见的云计算安全问题以及如何解决
R语言ggplot2可视化:使用ggpubr包的ggmaplot函数可视化MA图(MA-plot)、设置label.select参数自定义在图中显示标签的基因类型(自定义显示的标签列表)
Tutorial on using the one-key upgrade function of the RTSP/Onvif video platform EasyNVR service









