当前位置:网站首页>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!)
边栏推荐
- 第42讲:Scala中泛型类、泛型函数、泛型在Spark中的广泛应用
- Xms Xmx PermSize MaxPermSize 区别
- 企业如何成功完成云迁移?
- 展厅全息投影所具备的三大应用特点
- SyntaxError: EOL while scanning string literal
- Tutorial on using the one-key upgrade function of the RTSP/Onvif video platform EasyNVR service
- 05 | 后台登录:基于账号密码的登录方式(下)
- 20220729 证券、金融
- Execution order of select, from, join, on where groupby, etc. in MySQL
- 一本通循环结构的程序设计第一章题解(1)
猜你喜欢

OpenHarmony环境搭建报错: ImportError: cannot import name ‘VERSION‘ from ‘hb.__main__‘

How to display an Excel table in the body of an email?

Heshu Group: Make smart cities smarter and make real life better

如何把Excel表格显示到邮件正文里?

SyntaxError: EOL while scanning string literal

C#实现软键盘的制作

ModelCoder状态机:对柴油机工况判断策略进行建模

双击Idea图标打不开——解决办法

监控界的最强王者,没有之一!

一本通循环结构的程序设计第一章题解(1)
随机推荐
机器学习——特征选择
【软考软件评测师】基于规则说明的测试技术上篇
Markdown 1 - 图文音视频等
结合实战,浅析GB/T28181(三)——实况点播
一文读懂Elephant Swap,为何为ePLATO带来如此高的溢价?
[PostgreSQL] - explain SQL analysis introduction
元宇宙的六大支撑技术
Yilian: Activating the Value Potential of Data Elements and Unleashing the Innovation Dividend of SAS SSD
Hand tearing read-write lock performance test
R语言ggplot2可视化时间序列数据(默认时间中断部分前后自动连接起来)、创建时间分组、使用分面图(faceting)可视化时间序列数据
一本通循环结构的程序设计题解(2)
浅析TSINGSEE智能视频分析网关的AI识别技术及应用场景
[PostgreSQL] - 存储结构及缓存shared_buffers
企业如何成功完成云迁移?
物理服务器与虚拟机:主要区别和相似之处
如何将EasyCVR平台RTSP接入的设备数据迁移到EasyNVR中?
【自校正控制】自校正PID
什么是私有云?您应该知道的 6 个优势
每天学一点Scala之 伴生类和伴生对象
R语言ggplot2可视化:使用ggpubr包的ggboxplot函数可视化箱图、width参数自定义箱图中箱体的宽度