Roll src/third_party/WebKit 73b5774:da0ca61 (svn 201762:201763)
[chromium-blink-merge.git] / device / udev_linux / udev.h
blobc40603d3beafe959583b03c55d228fd3a13a9921
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_
8 #include <stdarg.h>
9 #include <sys/types.h>
10 #include <sys/stat.h>
12 #include <string>
14 #if !defined(USE_UDEV)
15 #error "USE_UDEV not defined"
16 #endif
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.
24 struct udev;
25 struct udev_device;
26 struct udev_enumerate;
27 struct udev_list_entry;
28 struct udev_monitor;
30 namespace device {
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,
38 const char* devtype);
39 const char* udev_device_get_property_value(udev_device* udev_device,
40 const char* key);
41 const char* udev_device_get_subsystem(udev_device* udev_device);
42 const char* udev_device_get_sysattr_value(udev_device* udev_device,
43 const char* sysattr);
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(
48 udev* udev,
49 const char* subsystem,
50 const char* sysname);
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,
64 const char* devtype);
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);
69 udev* udev_new();
70 void udev_set_log_fn(
71 struct udev* udev,
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
78 // the empty string.
79 std::string UdevDeviceGetPropertyValue(udev_device* udev_device,
80 const char* key);
82 // Calls udev_device_get_sysattr_value() and replaces missing values with
83 // the empty string.
84 std::string UdevDeviceGetSysattrValue(udev_device* udev_device,
85 const char* key);
87 // Decodes udev-encoded string. Useful for decoding "*_ENC" udev properties.
88 std::string UdevDecodeString(const std::string& encoded);
90 } // namespace device
92 #endif // DEVICE_UDEV_LINUX_UDEV_H_