1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef DEVICE_UDEV_LINUX_UDEV_H_
6 #define DEVICE_UDEV_LINUX_UDEV_H_
14 #if !defined(USE_UDEV)
15 #error "USE_UDEV not defined"
18 // Adapted from libudev.h.
19 #define udev_list_entry_foreach(list_entry, first_entry) \
20 for (list_entry = first_entry; list_entry != NULL; \
21 list_entry = ::device::udev_list_entry_get_next(list_entry))
23 // Forward declarations of opaque structs.
26 struct udev_enumerate
;
27 struct udev_list_entry
;
32 const char* udev_device_get_action(udev_device
* udev_device
);
33 const char* udev_device_get_devnode(udev_device
* udev_device
);
34 udev_device
* udev_device_get_parent(udev_device
* udev_device
);
35 udev_device
* udev_device_get_parent_with_subsystem_devtype(
36 udev_device
* udev_device
,
37 const char* subsystem
,
39 const char* udev_device_get_property_value(udev_device
* udev_device
,
41 const char* udev_device_get_subsystem(udev_device
* udev_device
);
42 const char* udev_device_get_sysattr_value(udev_device
* udev_device
,
44 const char* udev_device_get_sysname(udev_device
* udev_device
);
45 const char* udev_device_get_syspath(udev_device
* udev_device
);
46 udev_device
* udev_device_new_from_devnum(udev
* udev
, char type
, dev_t devnum
);
47 udev_device
* udev_device_new_from_subsystem_sysname(
49 const char* subsystem
,
51 udev_device
* udev_device_new_from_syspath(udev
* udev
, const char* syspath
);
52 void udev_device_unref(udev_device
* udev_device
);
53 int udev_enumerate_add_match_subsystem(udev_enumerate
* udev_enumerate
,
54 const char* subsystem
);
55 udev_list_entry
* udev_enumerate_get_list_entry(udev_enumerate
* udev_enumerate
);
56 udev_enumerate
* udev_enumerate_new(udev
* udev
);
57 int udev_enumerate_scan_devices(udev_enumerate
* udev_enumerate
);
58 void udev_enumerate_unref(udev_enumerate
* udev_enumerate
);
59 udev_list_entry
* udev_list_entry_get_next(udev_list_entry
* list_entry
);
60 const char* udev_list_entry_get_name(udev_list_entry
* list_entry
);
61 int udev_monitor_enable_receiving(udev_monitor
* udev_monitor
);
62 int udev_monitor_filter_add_match_subsystem_devtype(udev_monitor
* udev_monitor
,
63 const char* subsystem
,
65 int udev_monitor_get_fd(udev_monitor
* udev_monitor
);
66 udev_monitor
* udev_monitor_new_from_netlink(udev
* udev
, const char* name
);
67 udev_device
* udev_monitor_receive_device(udev_monitor
* udev_monitor
);
68 void udev_monitor_unref(udev_monitor
* udev_monitor
);
72 void (*log_fn
)(struct udev
* udev
, int priority
, const char* file
, int line
,
73 const char* fn
, const char* format
, va_list args
));
74 void udev_set_log_priority(struct udev
* udev
, int priority
);
75 void udev_unref(udev
* udev
);
77 // Calls udev_device_get_property_value() and replaces missing values with
79 std::string
UdevDeviceGetPropertyValue(udev_device
* udev_device
,
82 // Calls udev_device_get_sysattr_value() and replaces missing values with
84 std::string
UdevDeviceGetSysattrValue(udev_device
* udev_device
,
87 // Decodes udev-encoded string. Useful for decoding "*_ENC" udev properties.
88 std::string
UdevDecodeString(const std::string
& encoded
);
92 #endif // DEVICE_UDEV_LINUX_UDEV_H_