[Session restore] Rename group name Enabled to Restore.
[chromium-blink-merge.git] / third_party / libusb / linux-udev.patch
blob93249c04d12723a584f7792c1231c709474d7a00
1 Index: third_party/libusb/src/libusb/os/linux_udev.cc
2 diff --git a/third_party/libusb/src/libusb/os/linux_udev.c b/third_party/libusb/src/libusb/os/linux_udev.cc
3 similarity index 83%
4 rename from third_party/libusb/src/libusb/os/linux_udev.c
5 rename to third_party/libusb/src/libusb/os/linux_udev.cc
6 index 99ac943410557de1a5cdd54082932db972040c2c..1b51ce44f4973c39b906d472b2a0cab51f987d3c 100644
7 --- a/third_party/libusb/src/libusb/os/linux_udev.c
8 +++ b/third_party/libusb/src/libusb/os/linux_udev.cc
9 @@ -37,11 +37,14 @@
10 #include <sys/utsname.h>
11 #include <sys/socket.h>
12 #include <unistd.h>
13 -#include <libudev.h>
15 +extern "C" {
16 #include "libusb.h"
17 #include "libusbi.h"
18 #include "linux_usbfs.h"
21 +#include "device/udev_linux/udev.h"
23 /* udev context */
24 static struct udev *udev_ctx = NULL;
25 @@ -58,30 +61,30 @@ int linux_udev_start_event_monitor(void)
26 int r;
28 assert(udev_ctx == NULL);
29 - udev_ctx = udev_new();
30 + udev_ctx = device::udev_new();
31 if (!udev_ctx) {
32 usbi_err(NULL, "could not create udev context");
33 return LIBUSB_ERROR_OTHER;
36 - udev_monitor = udev_monitor_new_from_netlink(udev_ctx, "udev");
37 + udev_monitor = device::udev_monitor_new_from_netlink(udev_ctx, "udev");
38 if (!udev_monitor) {
39 usbi_err(NULL, "could not initialize udev monitor");
40 goto err_free_ctx;
43 - r = udev_monitor_filter_add_match_subsystem_devtype(udev_monitor, "usb", 0);
44 + r = device::udev_monitor_filter_add_match_subsystem_devtype(udev_monitor, "usb", 0);
45 if (r) {
46 usbi_err(NULL, "could not initialize udev monitor filter for \"usb\" subsystem");
47 goto err_free_monitor;
50 - if (udev_monitor_enable_receiving(udev_monitor)) {
51 + if (device::udev_monitor_enable_receiving(udev_monitor)) {
52 usbi_err(NULL, "failed to enable the udev monitor");
53 goto err_free_monitor;
56 - udev_monitor_fd = udev_monitor_get_fd(udev_monitor);
57 + udev_monitor_fd = device::udev_monitor_get_fd(udev_monitor);
59 /* Some older versions of udev are not non-blocking by default,
60 * so make sure this is set */
61 @@ -114,11 +117,11 @@ err_close_pipe:
62 close(udev_control_pipe[0]);
63 close(udev_control_pipe[1]);
64 err_free_monitor:
65 - udev_monitor_unref(udev_monitor);
66 + device::udev_monitor_unref(udev_monitor);
67 udev_monitor = NULL;
68 udev_monitor_fd = -1;
69 err_free_ctx:
70 - udev_unref(udev_ctx);
71 + device::udev_unref(udev_ctx);
72 udev_ctx = NULL;
73 return LIBUSB_ERROR_OTHER;
75 @@ -141,12 +144,12 @@ int linux_udev_stop_event_monitor(void)
76 pthread_join(linux_event_thread, NULL);
78 /* Release the udev monitor */
79 - udev_monitor_unref(udev_monitor);
80 + device::udev_monitor_unref(udev_monitor);
81 udev_monitor = NULL;
82 udev_monitor_fd = -1;
84 /* Clean up the udev context */
85 - udev_unref(udev_ctx);
86 + device::udev_unref(udev_ctx);
87 udev_ctx = NULL;
89 /* close and reset control pipe */
90 @@ -183,7 +186,7 @@ static void *linux_udev_event_thread_main(void *arg)
92 if (fds[1].revents & POLLIN) {
93 usbi_mutex_static_lock(&linux_hotplug_lock);
94 - udev_dev = udev_monitor_receive_device(udev_monitor);
95 + udev_dev = device::udev_monitor_receive_device(udev_monitor);
96 if (udev_dev)
97 udev_hotplug_event(udev_dev);
98 usbi_mutex_static_unlock(&linux_hotplug_lock);
99 @@ -200,12 +203,12 @@ static int udev_device_info(struct libusb_context *ctx, int detached,
100 uint8_t *devaddr, const char **sys_name) {
101 const char *dev_node;
103 - dev_node = udev_device_get_devnode(udev_dev);
104 + dev_node = device::udev_device_get_devnode(udev_dev);
105 if (!dev_node) {
106 return LIBUSB_ERROR_OTHER;
109 - *sys_name = udev_device_get_sysname(udev_dev);
110 + *sys_name = device::udev_device_get_sysname(udev_dev);
111 if (!*sys_name) {
112 return LIBUSB_ERROR_OTHER;
114 @@ -223,7 +226,7 @@ static void udev_hotplug_event(struct udev_device* udev_dev)
115 int r;
117 do {
118 - udev_action = udev_device_get_action(udev_dev);
119 + udev_action = device::udev_device_get_action(udev_dev);
120 if (!udev_action) {
121 break;
123 @@ -246,7 +249,7 @@ static void udev_hotplug_event(struct udev_device* udev_dev)
125 } while (0);
127 - udev_device_unref(udev_dev);
128 + device::udev_device_unref(udev_dev);
131 int linux_udev_scan_devices(struct libusb_context *ctx)
132 @@ -259,33 +262,33 @@ int linux_udev_scan_devices(struct libusb_context *ctx)
134 assert(udev_ctx != NULL);
136 - enumerator = udev_enumerate_new(udev_ctx);
137 + enumerator = device::udev_enumerate_new(udev_ctx);
138 if (NULL == enumerator) {
139 usbi_err(ctx, "error creating udev enumerator");
140 return LIBUSB_ERROR_OTHER;
143 - udev_enumerate_add_match_subsystem(enumerator, "usb");
144 - udev_enumerate_scan_devices(enumerator);
145 - devices = udev_enumerate_get_list_entry(enumerator);
146 + device::udev_enumerate_add_match_subsystem(enumerator, "usb");
147 + device::udev_enumerate_scan_devices(enumerator);
148 + devices = device::udev_enumerate_get_list_entry(enumerator);
150 udev_list_entry_foreach(entry, devices) {
151 - const char *path = udev_list_entry_get_name(entry);
152 + const char *path = device::udev_list_entry_get_name(entry);
153 uint8_t busnum = 0, devaddr = 0;
155 - udev_dev = udev_device_new_from_syspath(udev_ctx, path);
156 + udev_dev = device::udev_device_new_from_syspath(udev_ctx, path);
158 r = udev_device_info(ctx, 0, udev_dev, &busnum, &devaddr, &sys_name);
159 if (r) {
160 - udev_device_unref(udev_dev);
161 + device::udev_device_unref(udev_dev);
162 continue;
165 linux_enumerate_device(ctx, busnum, devaddr, sys_name);
166 - udev_device_unref(udev_dev);
167 + device::udev_device_unref(udev_dev);
170 - udev_enumerate_unref(enumerator);
171 + device::udev_enumerate_unref(enumerator);
173 return LIBUSB_SUCCESS;
175 @@ -296,7 +299,7 @@ void linux_udev_hotplug_poll(void)
177 usbi_mutex_static_lock(&linux_hotplug_lock);
178 do {
179 - udev_dev = udev_monitor_receive_device(udev_monitor);
180 + udev_dev = device::udev_monitor_receive_device(udev_monitor);
181 if (udev_dev) {
182 usbi_dbg("Handling hotplug event from hotplug_poll");
183 udev_hotplug_event(udev_dev);
184 Index: third_party/libusb/src/libusb/os/linux_usbfs.h
185 diff --git a/third_party/libusb/src/libusb/os/linux_usbfs.h b/third_party/libusb/src/libusb/os/linux_usbfs.h
186 index 1f5b191f4a745937efe52695d7dbaa949a15df08..eedeaaf3654f22ecaac9fd1332d32b2855450bce 100644
187 --- a/third_party/libusb/src/libusb/os/linux_usbfs.h
188 +++ b/third_party/libusb/src/libusb/os/linux_usbfs.h
189 @@ -159,10 +159,20 @@ struct usbfs_disconnect_claim {
190 extern usbi_mutex_static_t linux_hotplug_lock;
192 #if defined(HAVE_LIBUDEV)
194 +#ifdef __cplusplus
195 +extern "C" {
196 +#endif
198 int linux_udev_start_event_monitor(void);
199 int linux_udev_stop_event_monitor(void);
200 int linux_udev_scan_devices(struct libusb_context *ctx);
201 void linux_udev_hotplug_poll(void);
203 +#ifdef __cplusplus
205 +#endif
207 #else
208 int linux_netlink_start_event_monitor(void);
209 int linux_netlink_stop_event_monitor(void);