usb 1.7.2-prebuild

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (183) hide show
  1. package/.github/workflows/prebuild.yml +62 -0
  2. package/.gitmodules +3 -0
  3. package/LICENSE +7 -0
  4. package/Readme.md +339 -0
  5. package/binding.gyp +90 -0
  6. package/libusb/.gitattributes +11 -0
  7. package/libusb/.private/README.txt +5 -0
  8. package/libusb/.private/bd.cmd +89 -0
  9. package/libusb/.private/bm.sh +54 -0
  10. package/libusb/.private/bwince.cmd +57 -0
  11. package/libusb/.private/post-rewrite.sh +28 -0
  12. package/libusb/.private/pre-commit.sh +42 -0
  13. package/libusb/.private/wbs.txt +61 -0
  14. package/libusb/.private/wbs_wince.txt +42 -0
  15. package/libusb/AUTHORS +78 -0
  16. package/libusb/COPYING +504 -0
  17. package/libusb/ChangeLog +211 -0
  18. package/libusb/INSTALL +234 -0
  19. package/libusb/INSTALL_WIN.txt +73 -0
  20. package/libusb/Makefile.am +28 -0
  21. package/libusb/NEWS +2 -0
  22. package/libusb/PORTING +94 -0
  23. package/libusb/README +28 -0
  24. package/libusb/README.git +41 -0
  25. package/libusb/TODO +2 -0
  26. package/libusb/Xcode/common.xcconfig +49 -0
  27. package/libusb/Xcode/debug.xcconfig +29 -0
  28. package/libusb/Xcode/libusb.xcconfig +21 -0
  29. package/libusb/Xcode/libusb.xcodeproj/project.pbxproj +1 -0
  30. package/libusb/Xcode/libusb_debug.xcconfig +21 -0
  31. package/libusb/Xcode/libusb_release.xcconfig +21 -0
  32. package/libusb/Xcode/release.xcconfig +30 -0
  33. package/libusb/android/README +114 -0
  34. package/libusb/android/jni/Android.mk +23 -0
  35. package/libusb/android/jni/Application.mk +24 -0
  36. package/libusb/android/jni/examples.mk +134 -0
  37. package/libusb/android/jni/libusb.mk +54 -0
  38. package/libusb/android/jni/tests.mk +56 -0
  39. package/libusb/autogen.sh +8 -0
  40. package/libusb/bootstrap.sh +19 -0
  41. package/libusb/configure.ac +304 -0
  42. package/libusb/doc/Makefile.am +9 -0
  43. package/libusb/doc/doxygen.cfg.in +1288 -0
  44. package/libusb/doc/libusb.png +0 -0
  45. package/libusb/examples/Makefile.am +19 -0
  46. package/libusb/examples/dpfp.c +506 -0
  47. package/libusb/examples/dpfp_threaded.c +544 -0
  48. package/libusb/examples/ezusb.c +831 -0
  49. package/libusb/examples/ezusb.h +120 -0
  50. package/libusb/examples/fxload.c +287 -0
  51. package/libusb/examples/getopt/getopt.c +1060 -0
  52. package/libusb/examples/getopt/getopt.h +180 -0
  53. package/libusb/examples/getopt/getopt1.c +188 -0
  54. package/libusb/examples/hotplugtest.c +104 -0
  55. package/libusb/examples/listdevs.c +71 -0
  56. package/libusb/examples/sam3u_benchmark.c +193 -0
  57. package/libusb/examples/xusb.c +1129 -0
  58. package/libusb/libusb/Makefile.am +75 -0
  59. package/libusb/libusb/core.c +2342 -0
  60. package/libusb/libusb/descriptor.c +1199 -0
  61. package/libusb/libusb/hotplug.c +327 -0
  62. package/libusb/libusb/hotplug.h +82 -0
  63. package/libusb/libusb/io.c +2631 -0
  64. package/libusb/libusb/libusb-1.0.def +166 -0
  65. package/libusb/libusb/libusb-1.0.rc +61 -0
  66. package/libusb/libusb/libusb.h +1998 -0
  67. package/libusb/libusb/libusbi.h +1040 -0
  68. package/libusb/libusb/os/darwin_usb.c +2009 -0
  69. package/libusb/libusb/os/darwin_usb.h +162 -0
  70. package/libusb/libusb/os/linux_netlink.c +369 -0
  71. package/libusb/libusb/os/linux_udev.c +307 -0
  72. package/libusb/libusb/os/linux_usbfs.c +2695 -0
  73. package/libusb/libusb/os/linux_usbfs.h +192 -0
  74. package/libusb/libusb/os/netbsd_usb.c +738 -0
  75. package/libusb/libusb/os/openbsd_usb.c +832 -0
  76. package/libusb/libusb/os/poll_posix.c +51 -0
  77. package/libusb/libusb/os/poll_posix.h +11 -0
  78. package/libusb/libusb/os/poll_windows.c +796 -0
  79. package/libusb/libusb/os/poll_windows.h +131 -0
  80. package/libusb/libusb/os/threads_posix.c +82 -0
  81. package/libusb/libusb/os/threads_posix.h +50 -0
  82. package/libusb/libusb/os/threads_windows.c +212 -0
  83. package/libusb/libusb/os/threads_windows.h +87 -0
  84. package/libusb/libusb/os/wince_usb.c +1032 -0
  85. package/libusb/libusb/os/wince_usb.h +131 -0
  86. package/libusb/libusb/os/windows_common.h +108 -0
  87. package/libusb/libusb/os/windows_usb.c +5347 -0
  88. package/libusb/libusb/os/windows_usb.h +971 -0
  89. package/libusb/libusb/strerror.c +199 -0
  90. package/libusb/libusb/sync.c +307 -0
  91. package/libusb/libusb/version.h +18 -0
  92. package/libusb/libusb/version_nano.h +1 -0
  93. package/libusb/libusb-1.0.pc.in +11 -0
  94. package/libusb/msvc/config.h +50 -0
  95. package/libusb/msvc/ddk_build.cmd +175 -0
  96. package/libusb/msvc/errno.h +102 -0
  97. package/libusb/msvc/fxload_2010.vcxproj +170 -0
  98. package/libusb/msvc/fxload_2010.vcxproj.filters +25 -0
  99. package/libusb/msvc/fxload_2012.vcxproj +174 -0
  100. package/libusb/msvc/fxload_2012.vcxproj.filters +25 -0
  101. package/libusb/msvc/fxload_2013.vcxproj +174 -0
  102. package/libusb/msvc/fxload_sources +23 -0
  103. package/libusb/msvc/getopt_2005.vcproj +288 -0
  104. package/libusb/msvc/getopt_2010.vcxproj +131 -0
  105. package/libusb/msvc/getopt_2010.vcxproj.filters +26 -0
  106. package/libusb/msvc/getopt_2012.vcxproj +136 -0
  107. package/libusb/msvc/getopt_2012.vcxproj.filters +26 -0
  108. package/libusb/msvc/getopt_2013.vcxproj +136 -0
  109. package/libusb/msvc/getopt_sources +20 -0
  110. package/libusb/msvc/hotplugtest_2010.vcxproj +163 -0
  111. package/libusb/msvc/hotplugtest_2010.vcxproj.filters +14 -0
  112. package/libusb/msvc/hotplugtest_2012.vcxproj +167 -0
  113. package/libusb/msvc/hotplugtest_2012.vcxproj.filters +14 -0
  114. package/libusb/msvc/hotplugtest_2013.vcxproj +167 -0
  115. package/libusb/msvc/hotplugtest_sources +20 -0
  116. package/libusb/msvc/inttypes.h +295 -0
  117. package/libusb/msvc/libusb.dsw +71 -0
  118. package/libusb/msvc/libusb_2005.sln +95 -0
  119. package/libusb/msvc/libusb_2010.sln +94 -0
  120. package/libusb/msvc/libusb_2012.sln +94 -0
  121. package/libusb/msvc/libusb_2013.sln +100 -0
  122. package/libusb/msvc/libusb_2015.sln +100 -0
  123. package/libusb/msvc/libusb_dll.dsp +194 -0
  124. package/libusb/msvc/libusb_dll_2005.vcproj +436 -0
  125. package/libusb/msvc/libusb_dll_2010.vcxproj +170 -0
  126. package/libusb/msvc/libusb_dll_2010.vcxproj.filters +81 -0
  127. package/libusb/msvc/libusb_dll_2012.vcxproj +175 -0
  128. package/libusb/msvc/libusb_dll_2012.vcxproj.filters +84 -0
  129. package/libusb/msvc/libusb_dll_2013.vcxproj +175 -0
  130. package/libusb/msvc/libusb_dll_wince.vcproj +1243 -0
  131. package/libusb/msvc/libusb_sources +38 -0
  132. package/libusb/msvc/libusb_static.dsp +174 -0
  133. package/libusb/msvc/libusb_static_2005.vcproj +362 -0
  134. package/libusb/msvc/libusb_static_2010.vcxproj +156 -0
  135. package/libusb/msvc/libusb_static_2010.vcxproj.filters +74 -0
  136. package/libusb/msvc/libusb_static_2012.vcxproj +160 -0
  137. package/libusb/msvc/libusb_static_2012.vcxproj.filters +74 -0
  138. package/libusb/msvc/libusb_static_2013.vcxproj +160 -0
  139. package/libusb/msvc/libusb_static_wince.vcproj +1185 -0
  140. package/libusb/msvc/libusb_wince.sln +246 -0
  141. package/libusb/msvc/listdevs.dsp +103 -0
  142. package/libusb/msvc/listdevs_2005.vcproj +360 -0
  143. package/libusb/msvc/listdevs_2010.vcxproj +165 -0
  144. package/libusb/msvc/listdevs_2010.vcxproj.filters +14 -0
  145. package/libusb/msvc/listdevs_2012.vcxproj +169 -0
  146. package/libusb/msvc/listdevs_2012.vcxproj.filters +14 -0
  147. package/libusb/msvc/listdevs_2013.vcxproj +169 -0
  148. package/libusb/msvc/listdevs_sources +19 -0
  149. package/libusb/msvc/listdevs_wince.vcproj +1120 -0
  150. package/libusb/msvc/missing.c +80 -0
  151. package/libusb/msvc/missing.h +32 -0
  152. package/libusb/msvc/stdint.h +256 -0
  153. package/libusb/msvc/stress_2005.vcproj +390 -0
  154. package/libusb/msvc/stress_2010.vcxproj +167 -0
  155. package/libusb/msvc/stress_2010.vcxproj.filters +25 -0
  156. package/libusb/msvc/stress_2012.vcxproj +171 -0
  157. package/libusb/msvc/stress_2012.vcxproj.filters +25 -0
  158. package/libusb/msvc/stress_2013.vcxproj +171 -0
  159. package/libusb/msvc/stress_wince.vcproj +1128 -0
  160. package/libusb/msvc/xusb.dsp +102 -0
  161. package/libusb/msvc/xusb_2005.vcproj +344 -0
  162. package/libusb/msvc/xusb_2010.vcxproj +163 -0
  163. package/libusb/msvc/xusb_2010.vcxproj.filters +14 -0
  164. package/libusb/msvc/xusb_2012.vcxproj +167 -0
  165. package/libusb/msvc/xusb_2012.vcxproj.filters +14 -0
  166. package/libusb/msvc/xusb_2013.vcxproj +167 -0
  167. package/libusb/msvc/xusb_sources +20 -0
  168. package/libusb/msvc/xusb_wince.vcproj +1120 -0
  169. package/libusb/tests/Makefile.am +6 -0
  170. package/libusb/tests/libusb_testlib.h +107 -0
  171. package/libusb/tests/stress.c +160 -0
  172. package/libusb/tests/testlib.c +281 -0
  173. package/libusb.gypi +136 -0
  174. package/libusb_config/config.h +1 -0
  175. package/package.json +69 -0
  176. package/src/device.cc +412 -0
  177. package/src/helpers.h +64 -0
  178. package/src/node_usb.cc +319 -0
  179. package/src/node_usb.h +120 -0
  180. package/src/transfer.cc +148 -0
  181. package/src/uv_async_queue.h +33 -0
  182. package/test/usb.coffee +191 -0
  183. package/usb.js +524 -0
@@ -0,0 +1,327 @@
1
+ /* -*- Mode: C; indent-tabs-mode:t ; c-basic-offset:8 -*- */
2
+ /*
3
+ * Hotplug functions for libusb
4
+ * Copyright © 2012-2013 Nathan Hjelm <hjelmn@mac.com>
5
+ * Copyright © 2012-2013 Peter Stuge <peter@stuge.se>
6
+ *
7
+ * This library is free software; you can redistribute it and/or
8
+ * modify it under the terms of the GNU Lesser General Public
9
+ * License as published by the Free Software Foundation; either
10
+ * version 2.1 of the License, or (at your option) any later version.
11
+ *
12
+ * This library is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
+ * Lesser General Public License for more details.
16
+ *
17
+ * You should have received a copy of the GNU Lesser General Public
18
+ * License along with this library; if not, write to the Free Software
19
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
+ */
21
+
22
+ #include <config.h>
23
+
24
+ #include <errno.h>
25
+ #include <stdio.h>
26
+ #include <stdlib.h>
27
+ #include <string.h>
28
+ #ifdef HAVE_SYS_TYPES_H
29
+ #include <sys/types.h>
30
+ #endif
31
+ #include <assert.h>
32
+
33
+ #include "libusbi.h"
34
+ #include "hotplug.h"
35
+
36
+ /**
37
+ * @defgroup hotplug Device hotplug event notification
38
+ * This page details how to use the libusb hotplug interface, where available.
39
+ *
40
+ * Be mindful that not all platforms currently implement hotplug notification and
41
+ * that you should first call on \ref libusb_has_capability() with parameter
42
+ * \ref LIBUSB_CAP_HAS_HOTPLUG to confirm that hotplug support is available.
43
+ *
44
+ * \page hotplug Device hotplug event notification
45
+ *
46
+ * \section intro Introduction
47
+ *
48
+ * Version 1.0.16, \ref LIBUSB_API_VERSION >= 0x01000102, has added support
49
+ * for hotplug events on <b>some</b> platforms (you should test if your platform
50
+ * supports hotplug notification by calling \ref libusb_has_capability() with
51
+ * parameter \ref LIBUSB_CAP_HAS_HOTPLUG).
52
+ *
53
+ * This interface allows you to request notification for the arrival and departure
54
+ * of matching USB devices.
55
+ *
56
+ * To receive hotplug notification you register a callback by calling
57
+ * \ref libusb_hotplug_register_callback(). This function will optionally return
58
+ * a handle that can be passed to \ref libusb_hotplug_deregister_callback().
59
+ *
60
+ * A callback function must return an int (0 or 1) indicating whether the callback is
61
+ * expecting additional events. Returning 0 will rearm the callback and 1 will cause
62
+ * the callback to be deregistered. Note that when callbacks are called from
63
+ * libusb_hotplug_register_callback() because of the \ref LIBUSB_HOTPLUG_ENUMERATE
64
+ * flag, the callback return value is ignored, iow you cannot cause a callback
65
+ * to be deregistered by returning 1 when it is called from
66
+ * libusb_hotplug_register_callback().
67
+ *
68
+ * Callbacks for a particular context are automatically deregistered by libusb_exit().
69
+ *
70
+ * As of 1.0.16 there are two supported hotplug events:
71
+ * - LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED: A device has arrived and is ready to use
72
+ * - LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT: A device has left and is no longer available
73
+ *
74
+ * A hotplug event can listen for either or both of these events.
75
+ *
76
+ * Note: If you receive notification that a device has left and you have any
77
+ * a libusb_device_handles for the device it is up to you to call libusb_close()
78
+ * on each handle to free up any remaining resources associated with the device.
79
+ * Once a device has left any libusb_device_handle associated with the device
80
+ * are invalid and will remain so even if the device comes back.
81
+ *
82
+ * When handling a LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED event it is considered
83
+ * safe to call any libusb function that takes a libusb_device. On the other hand,
84
+ * when handling a LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT event the only safe function
85
+ * is libusb_get_device_descriptor().
86
+ *
87
+ * The following code provides an example of the usage of the hotplug interface:
88
+ \code
89
+ #include <stdio.h>
90
+ #include <stdlib.h>
91
+ #include <libusb.h>
92
+
93
+ static int count = 0;
94
+
95
+ int hotplug_callback(struct libusb_context *ctx, struct libusb_device *dev,
96
+ libusb_hotplug_event event, void *user_data) {
97
+ static libusb_device_handle *handle = NULL;
98
+ struct libusb_device_descriptor desc;
99
+ int rc;
100
+
101
+ (void)libusb_get_device_descriptor(dev, &desc);
102
+
103
+ if (LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED == event) {
104
+ rc = libusb_open(dev, &handle);
105
+ if (LIBUSB_SUCCESS != rc) {
106
+ printf("Could not open USB device\n");
107
+ }
108
+ } else if (LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT == event) {
109
+ if (handle) {
110
+ libusb_close(handle);
111
+ handle = NULL;
112
+ }
113
+ } else {
114
+ printf("Unhandled event %d\n", event);
115
+ }
116
+ count++;
117
+
118
+ return 0;
119
+ }
120
+
121
+ int main (void) {
122
+ libusb_hotplug_callback_handle handle;
123
+ int rc;
124
+
125
+ libusb_init(NULL);
126
+
127
+ rc = libusb_hotplug_register_callback(NULL, LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED |
128
+ LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT, 0, 0x045a, 0x5005,
129
+ LIBUSB_HOTPLUG_MATCH_ANY, hotplug_callback, NULL,
130
+ &handle);
131
+ if (LIBUSB_SUCCESS != rc) {
132
+ printf("Error creating a hotplug callback\n");
133
+ libusb_exit(NULL);
134
+ return EXIT_FAILURE;
135
+ }
136
+
137
+ while (count < 2) {
138
+ libusb_handle_events_completed(NULL, NULL);
139
+ usleep(10000);
140
+ }
141
+
142
+ libusb_hotplug_deregister_callback(NULL, handle);
143
+ libusb_exit(NULL);
144
+
145
+ return 0;
146
+ }
147
+ \endcode
148
+ */
149
+
150
+ static int usbi_hotplug_match_cb (struct libusb_context *ctx,
151
+ struct libusb_device *dev, libusb_hotplug_event event,
152
+ struct libusb_hotplug_callback *hotplug_cb)
153
+ {
154
+ /* Handle lazy deregistration of callback */
155
+ if (hotplug_cb->needs_free) {
156
+ /* Free callback */
157
+ return 1;
158
+ }
159
+
160
+ if (!(hotplug_cb->events & event)) {
161
+ return 0;
162
+ }
163
+
164
+ if (LIBUSB_HOTPLUG_MATCH_ANY != hotplug_cb->vendor_id &&
165
+ hotplug_cb->vendor_id != dev->device_descriptor.idVendor) {
166
+ return 0;
167
+ }
168
+
169
+ if (LIBUSB_HOTPLUG_MATCH_ANY != hotplug_cb->product_id &&
170
+ hotplug_cb->product_id != dev->device_descriptor.idProduct) {
171
+ return 0;
172
+ }
173
+
174
+ if (LIBUSB_HOTPLUG_MATCH_ANY != hotplug_cb->dev_class &&
175
+ hotplug_cb->dev_class != dev->device_descriptor.bDeviceClass) {
176
+ return 0;
177
+ }
178
+
179
+ return hotplug_cb->cb (ctx, dev, event, hotplug_cb->user_data);
180
+ }
181
+
182
+ void usbi_hotplug_match(struct libusb_context *ctx, struct libusb_device *dev,
183
+ libusb_hotplug_event event)
184
+ {
185
+ struct libusb_hotplug_callback *hotplug_cb, *next;
186
+ int ret;
187
+
188
+ usbi_mutex_lock(&ctx->hotplug_cbs_lock);
189
+
190
+ list_for_each_entry_safe(hotplug_cb, next, &ctx->hotplug_cbs, list, struct libusb_hotplug_callback) {
191
+ usbi_mutex_unlock(&ctx->hotplug_cbs_lock);
192
+ ret = usbi_hotplug_match_cb (ctx, dev, event, hotplug_cb);
193
+ usbi_mutex_lock(&ctx->hotplug_cbs_lock);
194
+
195
+ if (ret) {
196
+ list_del(&hotplug_cb->list);
197
+ free(hotplug_cb);
198
+ }
199
+ }
200
+
201
+ usbi_mutex_unlock(&ctx->hotplug_cbs_lock);
202
+
203
+ /* the backend is expected to call the callback for each active transfer */
204
+ }
205
+
206
+ int API_EXPORTED libusb_hotplug_register_callback(libusb_context *ctx,
207
+ libusb_hotplug_event events, libusb_hotplug_flag flags,
208
+ int vendor_id, int product_id, int dev_class,
209
+ libusb_hotplug_callback_fn cb_fn, void *user_data,
210
+ libusb_hotplug_callback_handle *handle)
211
+ {
212
+ libusb_hotplug_callback *new_callback;
213
+ static int handle_id = 1;
214
+
215
+ /* check for hotplug support */
216
+ if (!libusb_has_capability(LIBUSB_CAP_HAS_HOTPLUG)) {
217
+ return LIBUSB_ERROR_NOT_SUPPORTED;
218
+ }
219
+
220
+ /* check for sane values */
221
+ if ((LIBUSB_HOTPLUG_MATCH_ANY != vendor_id && (~0xffff & vendor_id)) ||
222
+ (LIBUSB_HOTPLUG_MATCH_ANY != product_id && (~0xffff & product_id)) ||
223
+ (LIBUSB_HOTPLUG_MATCH_ANY != dev_class && (~0xff & dev_class)) ||
224
+ !cb_fn) {
225
+ return LIBUSB_ERROR_INVALID_PARAM;
226
+ }
227
+
228
+ USBI_GET_CONTEXT(ctx);
229
+
230
+ new_callback = (libusb_hotplug_callback *)calloc(1, sizeof (*new_callback));
231
+ if (!new_callback) {
232
+ return LIBUSB_ERROR_NO_MEM;
233
+ }
234
+
235
+ new_callback->ctx = ctx;
236
+ new_callback->vendor_id = vendor_id;
237
+ new_callback->product_id = product_id;
238
+ new_callback->dev_class = dev_class;
239
+ new_callback->flags = flags;
240
+ new_callback->events = events;
241
+ new_callback->cb = cb_fn;
242
+ new_callback->user_data = user_data;
243
+ new_callback->needs_free = 0;
244
+
245
+ usbi_mutex_lock(&ctx->hotplug_cbs_lock);
246
+
247
+ /* protect the handle by the context hotplug lock. it doesn't matter if the same handle
248
+ * is used for different contexts only that the handle is unique for this context */
249
+ new_callback->handle = handle_id++;
250
+
251
+ list_add(&new_callback->list, &ctx->hotplug_cbs);
252
+
253
+ usbi_mutex_unlock(&ctx->hotplug_cbs_lock);
254
+
255
+
256
+ if (flags & LIBUSB_HOTPLUG_ENUMERATE) {
257
+ int i, len;
258
+ struct libusb_device **devs;
259
+
260
+ len = (int) libusb_get_device_list(ctx, &devs);
261
+ if (len < 0) {
262
+ libusb_hotplug_deregister_callback(ctx,
263
+ new_callback->handle);
264
+ return len;
265
+ }
266
+
267
+ for (i = 0; i < len; i++) {
268
+ usbi_hotplug_match_cb(ctx, devs[i],
269
+ LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED,
270
+ new_callback);
271
+ }
272
+
273
+ libusb_free_device_list(devs, 1);
274
+ }
275
+
276
+
277
+ if (handle) {
278
+ *handle = new_callback->handle;
279
+ }
280
+
281
+ return LIBUSB_SUCCESS;
282
+ }
283
+
284
+ void API_EXPORTED libusb_hotplug_deregister_callback (struct libusb_context *ctx,
285
+ libusb_hotplug_callback_handle handle)
286
+ {
287
+ struct libusb_hotplug_callback *hotplug_cb;
288
+ libusb_hotplug_message message;
289
+ ssize_t ret;
290
+
291
+ /* check for hotplug support */
292
+ if (!libusb_has_capability(LIBUSB_CAP_HAS_HOTPLUG)) {
293
+ return;
294
+ }
295
+
296
+ USBI_GET_CONTEXT(ctx);
297
+
298
+ usbi_mutex_lock(&ctx->hotplug_cbs_lock);
299
+ list_for_each_entry(hotplug_cb, &ctx->hotplug_cbs, list,
300
+ struct libusb_hotplug_callback) {
301
+ if (handle == hotplug_cb->handle) {
302
+ /* Mark this callback for deregistration */
303
+ hotplug_cb->needs_free = 1;
304
+ }
305
+ }
306
+ usbi_mutex_unlock(&ctx->hotplug_cbs_lock);
307
+
308
+ /* wakeup handle_events to do the actual free */
309
+ memset(&message, 0, sizeof(message));
310
+ ret = usbi_write(ctx->hotplug_pipe[1], &message, sizeof(message));
311
+ if (sizeof(message) != ret) {
312
+ usbi_err(ctx, "error writing hotplug message");
313
+ }
314
+ }
315
+
316
+ void usbi_hotplug_deregister_all(struct libusb_context *ctx) {
317
+ struct libusb_hotplug_callback *hotplug_cb, *next;
318
+
319
+ usbi_mutex_lock(&ctx->hotplug_cbs_lock);
320
+ list_for_each_entry_safe(hotplug_cb, next, &ctx->hotplug_cbs, list,
321
+ struct libusb_hotplug_callback) {
322
+ list_del(&hotplug_cb->list);
323
+ free(hotplug_cb);
324
+ }
325
+
326
+ usbi_mutex_unlock(&ctx->hotplug_cbs_lock);
327
+ }
@@ -0,0 +1,82 @@
1
+ /* -*- Mode: C; indent-tabs-mode:t ; c-basic-offset:8 -*- */
2
+ /*
3
+ * Hotplug support for libusb
4
+ * Copyright © 2012-2013 Nathan Hjelm <hjelmn@mac.com>
5
+ * Copyright © 2012-2013 Peter Stuge <peter@stuge.se>
6
+ *
7
+ * This library is free software; you can redistribute it and/or
8
+ * modify it under the terms of the GNU Lesser General Public
9
+ * License as published by the Free Software Foundation; either
10
+ * version 2.1 of the License, or (at your option) any later version.
11
+ *
12
+ * This library is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
+ * Lesser General Public License for more details.
16
+ *
17
+ * You should have received a copy of the GNU Lesser General Public
18
+ * License along with this library; if not, write to the Free Software
19
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
+ */
21
+
22
+ #if !defined(USBI_HOTPLUG_H)
23
+ #define USBI_HOTPLUG_H
24
+
25
+ #ifndef LIBUSBI_H
26
+ #include "libusbi.h"
27
+ #endif
28
+
29
+ /** \ingroup hotplug
30
+ * The hotplug callback structure. The user populates this structure with
31
+ * libusb_hotplug_prepare_callback() and then calls libusb_hotplug_register_callback()
32
+ * to receive notification of hotplug events.
33
+ */
34
+ struct libusb_hotplug_callback {
35
+ /** Context this callback is associated with */
36
+ struct libusb_context *ctx;
37
+
38
+ /** Vendor ID to match or LIBUSB_HOTPLUG_MATCH_ANY */
39
+ int vendor_id;
40
+
41
+ /** Product ID to match or LIBUSB_HOTPLUG_MATCH_ANY */
42
+ int product_id;
43
+
44
+ /** Device class to match or LIBUSB_HOTPLUG_MATCH_ANY */
45
+ int dev_class;
46
+
47
+ /** Hotplug callback flags */
48
+ libusb_hotplug_flag flags;
49
+
50
+ /** Event(s) that will trigger this callback */
51
+ libusb_hotplug_event events;
52
+
53
+ /** Callback function to invoke for matching event/device */
54
+ libusb_hotplug_callback_fn cb;
55
+
56
+ /** Handle for this callback (used to match on deregister) */
57
+ libusb_hotplug_callback_handle handle;
58
+
59
+ /** User data that will be passed to the callback function */
60
+ void *user_data;
61
+
62
+ /** Callback is marked for deletion */
63
+ int needs_free;
64
+
65
+ /** List this callback is registered in (ctx->hotplug_cbs) */
66
+ struct list_head list;
67
+ };
68
+
69
+ typedef struct libusb_hotplug_callback libusb_hotplug_callback;
70
+
71
+ struct libusb_hotplug_message {
72
+ libusb_hotplug_event event;
73
+ struct libusb_device *device;
74
+ };
75
+
76
+ typedef struct libusb_hotplug_message libusb_hotplug_message;
77
+
78
+ void usbi_hotplug_deregister_all(struct libusb_context *ctx);
79
+ void usbi_hotplug_match(struct libusb_context *ctx, struct libusb_device *dev,
80
+ libusb_hotplug_event event);
81
+
82
+ #endif