OLD | NEW |
(Empty) | |
| 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..1b51ce44f4973c39b906d472b2a0cab5
1f987d3c 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> |
| 14 |
| 15 +extern "C" { |
| 16 #include "libusb.h" |
| 17 #include "libusbi.h" |
| 18 #include "linux_usbfs.h" |
| 19 +} |
| 20 + |
| 21 +#include "device/udev_linux/udev.h" |
| 22 |
| 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; |
| 27 |
| 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; |
| 34 } |
| 35 |
| 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; |
| 41 } |
| 42 |
| 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 \"u
sb\" subsystem"); |
| 47 goto err_free_monitor; |
| 48 } |
| 49 |
| 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; |
| 54 } |
| 55 |
| 56 - udev_monitor_fd = udev_monitor_get_fd(udev_monitor); |
| 57 + udev_monitor_fd = device::udev_monitor_get_fd(udev_monitor); |
| 58 |
| 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; |
| 74 } |
| 75 @@ -141,12 +144,12 @@ int linux_udev_stop_event_monitor(void) |
| 76 pthread_join(linux_event_thread, NULL); |
| 77 |
| 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; |
| 83 |
| 84 /* Clean up the udev context */ |
| 85 - udev_unref(udev_ctx); |
| 86 + device::udev_unref(udev_ctx); |
| 87 udev_ctx = NULL; |
| 88 |
| 89 /* close and reset control pipe */ |
| 90 @@ -183,7 +186,7 @@ static void *linux_udev_event_thread_main(void *arg) |
| 91 } |
| 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_moni
tor); |
| 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, in
t detached, |
| 100 uint8_t *devaddr, const char **sys_name) { |
| 101 const char *dev_node; |
| 102 |
| 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; |
| 107 } |
| 108 |
| 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; |
| 113 } |
| 114 @@ -223,7 +226,7 @@ static void udev_hotplug_event(struct udev_device* udev_dev) |
| 115 int r; |
| 116 |
| 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; |
| 122 } |
| 123 @@ -246,7 +249,7 @@ static void udev_hotplug_event(struct udev_device* udev_dev) |
| 124 } |
| 125 } while (0); |
| 126 |
| 127 - udev_device_unref(udev_dev); |
| 128 + device::udev_device_unref(udev_dev); |
| 129 } |
| 130 |
| 131 int linux_udev_scan_devices(struct libusb_context *ctx) |
| 132 @@ -259,33 +262,33 @@ int linux_udev_scan_devices(struct libusb_context *ctx) |
| 133 |
| 134 assert(udev_ctx != NULL); |
| 135 |
| 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; |
| 141 } |
| 142 |
| 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); |
| 149 |
| 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; |
| 154 |
| 155 - udev_dev = udev_device_new_from_syspath(udev_ctx, path); |
| 156 + udev_dev = device::udev_device_new_from_syspath(udev_ctx, path); |
| 157 |
| 158 r = udev_device_info(ctx, 0, udev_dev, &busnum, &devaddr, &sys_n
ame); |
| 159 if (r) { |
| 160 - udev_device_unref(udev_dev); |
| 161 + device::udev_device_unref(udev_dev); |
| 162 continue; |
| 163 } |
| 164 |
| 165 linux_enumerate_device(ctx, busnum, devaddr, sys_name); |
| 166 - udev_device_unref(udev_dev); |
| 167 + device::udev_device_unref(udev_dev); |
| 168 } |
| 169 |
| 170 - udev_enumerate_unref(enumerator); |
| 171 + device::udev_enumerate_unref(enumerator); |
| 172 |
| 173 return LIBUSB_SUCCESS; |
| 174 } |
| 175 @@ -296,7 +299,7 @@ void linux_udev_hotplug_poll(void) |
| 176 |
| 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..eedeaaf3654f22ecaac9fd1332d32b28
55450bce 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; |
| 191 |
| 192 #if defined(HAVE_LIBUDEV) |
| 193 + |
| 194 +#ifdef __cplusplus |
| 195 +extern "C" { |
| 196 +#endif |
| 197 + |
| 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); |
| 202 + |
| 203 +#ifdef __cplusplus |
| 204 +} |
| 205 +#endif |
| 206 + |
| 207 #else |
| 208 int linux_netlink_start_event_monitor(void); |
| 209 int linux_netlink_stop_event_monitor(void); |
OLD | NEW |