ui: ozone: add missing files to GN build
[chromium-blink-merge.git] / device / udev_linux / udev.cc
blob6055fb9db0dcdadb50250cf1347ee3ee7a499ebd
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 #include "device/udev_linux/udev.h"
7 #include "base/strings/string_util.h"
8 #include "device/udev_linux/udev_loader.h"
10 namespace device {
12 namespace {
14 std::string StringOrEmptyIfNull(const char* value) {
15 return value ? value : std::string();
18 } // namespace
20 const char* udev_device_get_action(udev_device* udev_device) {
21 return UdevLoader::Get()->udev_device_get_action(udev_device);
24 const char* udev_device_get_devnode(udev_device* udev_device) {
25 return UdevLoader::Get()->udev_device_get_devnode(udev_device);
28 udev_device* udev_device_get_parent(udev_device* udev_device) {
29 return UdevLoader::Get()->udev_device_get_parent(udev_device);
32 udev_device* udev_device_get_parent_with_subsystem_devtype(
33 udev_device* udev_device,
34 const char* subsystem,
35 const char* devtype) {
36 return UdevLoader::Get()->udev_device_get_parent_with_subsystem_devtype(
37 udev_device, subsystem, devtype);
40 const char* udev_device_get_property_value(udev_device* udev_device,
41 const char* key) {
42 return UdevLoader::Get()->udev_device_get_property_value(udev_device, key);
45 const char* udev_device_get_subsystem(udev_device* udev_device) {
46 return UdevLoader::Get()->udev_device_get_subsystem(udev_device);
49 const char* udev_device_get_sysattr_value(udev_device* udev_device,
50 const char* sysattr) {
51 return UdevLoader::Get()->udev_device_get_sysattr_value(udev_device, sysattr);
54 const char* udev_device_get_sysname(udev_device* udev_device) {
55 return UdevLoader::Get()->udev_device_get_sysname(udev_device);
58 const char* udev_device_get_syspath(udev_device* udev_device) {
59 return UdevLoader::Get()->udev_device_get_syspath(udev_device);
62 udev_device* udev_device_new_from_devnum(udev* udev, char type, dev_t devnum) {
63 return UdevLoader::Get()->udev_device_new_from_devnum(udev, type, devnum);
66 udev_device* udev_device_new_from_subsystem_sysname(
67 udev* udev,
68 const char* subsystem,
69 const char* sysname) {
70 return UdevLoader::Get()->udev_device_new_from_subsystem_sysname(
71 udev, subsystem, sysname);
74 udev_device* udev_device_new_from_syspath(udev* udev, const char* syspath) {
75 return UdevLoader::Get()->udev_device_new_from_syspath(udev, syspath);
78 void udev_device_unref(udev_device* udev_device) {
79 UdevLoader::Get()->udev_device_unref(udev_device);
82 int udev_enumerate_add_match_subsystem(udev_enumerate* udev_enumerate,
83 const char* subsystem) {
84 return UdevLoader::Get()->udev_enumerate_add_match_subsystem(udev_enumerate,
85 subsystem);
88 udev_list_entry* udev_enumerate_get_list_entry(udev_enumerate* udev_enumerate) {
89 return UdevLoader::Get()->udev_enumerate_get_list_entry(udev_enumerate);
92 udev_enumerate* udev_enumerate_new(udev* udev) {
93 return UdevLoader::Get()->udev_enumerate_new(udev);
96 int udev_enumerate_scan_devices(udev_enumerate* udev_enumerate) {
97 return UdevLoader::Get()->udev_enumerate_scan_devices(udev_enumerate);
100 void udev_enumerate_unref(udev_enumerate* udev_enumerate) {
101 UdevLoader::Get()->udev_enumerate_unref(udev_enumerate);
104 udev_list_entry* udev_list_entry_get_next(udev_list_entry* list_entry) {
105 return UdevLoader::Get()->udev_list_entry_get_next(list_entry);
108 const char* udev_list_entry_get_name(udev_list_entry* list_entry) {
109 return UdevLoader::Get()->udev_list_entry_get_name(list_entry);
112 int udev_monitor_enable_receiving(udev_monitor* udev_monitor) {
113 return UdevLoader::Get()->udev_monitor_enable_receiving(udev_monitor);
116 int udev_monitor_filter_add_match_subsystem_devtype(udev_monitor* udev_monitor,
117 const char* subsystem,
118 const char* devtype) {
119 return UdevLoader::Get()->udev_monitor_filter_add_match_subsystem_devtype(
120 udev_monitor, subsystem, devtype);
123 int udev_monitor_get_fd(udev_monitor* udev_monitor) {
124 return UdevLoader::Get()->udev_monitor_get_fd(udev_monitor);
127 udev_monitor* udev_monitor_new_from_netlink(udev* udev, const char* name) {
128 return UdevLoader::Get()->udev_monitor_new_from_netlink(udev, name);
131 udev_device* udev_monitor_receive_device(udev_monitor* udev_monitor) {
132 return UdevLoader::Get()->udev_monitor_receive_device(udev_monitor);
135 void udev_monitor_unref(udev_monitor* udev_monitor) {
136 UdevLoader::Get()->udev_monitor_unref(udev_monitor);
139 udev* udev_new() {
140 return UdevLoader::Get()->udev_new();
143 void udev_set_log_fn(
144 struct udev* udev,
145 void (*log_fn)(struct udev* udev, int priority, const char* file, int line,
146 const char* fn, const char* format, va_list args)) {
147 return UdevLoader::Get()->udev_set_log_fn(udev, log_fn);
150 void udev_set_log_priority(struct udev* udev, int priority) {
151 return UdevLoader::Get()->udev_set_log_priority(udev, priority);
154 void udev_unref(udev* udev) {
155 UdevLoader::Get()->udev_unref(udev);
158 std::string UdevDeviceGetPropertyValue(udev_device* udev_device,
159 const char* key) {
160 return StringOrEmptyIfNull(udev_device_get_property_value(udev_device, key));
163 std::string UdevDeviceGetSysattrValue(udev_device* udev_device,
164 const char* key) {
165 return StringOrEmptyIfNull(udev_device_get_sysattr_value(udev_device, key));
168 std::string UdevDecodeString(const std::string& encoded) {
169 std::string decoded;
170 const size_t size = encoded.size();
171 for (size_t i = 0; i < size; ++i) {
172 char c = encoded[i];
173 if ((i + 3 < size) && c == '\\' && encoded[i + 1] == 'x') {
174 c = (base::HexDigitToInt(encoded[i + 2]) << 4) +
175 base::HexDigitToInt(encoded[i + 3]);
176 i += 3;
178 decoded.push_back(c);
180 return decoded;
183 } // namespace device