usb 2.17.0 → 3.0.0-alpha.2

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 (207) hide show
  1. package/LICENSE +18 -4
  2. package/README.md +25 -516
  3. package/dist/index.d.ts +67 -13
  4. package/dist/index.js +333 -64
  5. package/index.d.ts +89 -0
  6. package/index.js +583 -0
  7. package/package.json +53 -33
  8. package/CHANGELOG.md +0 -294
  9. package/binding.gyp +0 -128
  10. package/dist/index.js.map +0 -1
  11. package/dist/usb/bindings.d.ts +0 -266
  12. package/dist/usb/bindings.js +0 -10
  13. package/dist/usb/bindings.js.map +0 -1
  14. package/dist/usb/capability.d.ts +0 -13
  15. package/dist/usb/capability.js +0 -17
  16. package/dist/usb/capability.js.map +0 -1
  17. package/dist/usb/descriptors.d.ts +0 -128
  18. package/dist/usb/descriptors.js +0 -3
  19. package/dist/usb/descriptors.js.map +0 -1
  20. package/dist/usb/device.d.ts +0 -100
  21. package/dist/usb/device.js +0 -297
  22. package/dist/usb/device.js.map +0 -1
  23. package/dist/usb/endpoint.d.ts +0 -94
  24. package/dist/usb/endpoint.js +0 -219
  25. package/dist/usb/endpoint.js.map +0 -1
  26. package/dist/usb/index.d.ts +0 -31
  27. package/dist/usb/index.js +0 -116
  28. package/dist/usb/index.js.map +0 -1
  29. package/dist/usb/interface.d.ts +0 -80
  30. package/dist/usb/interface.js +0 -133
  31. package/dist/usb/interface.js.map +0 -1
  32. package/dist/webusb/index.d.ts +0 -64
  33. package/dist/webusb/index.js +0 -295
  34. package/dist/webusb/index.js.map +0 -1
  35. package/dist/webusb/webusb-device.d.ts +0 -54
  36. package/dist/webusb/webusb-device.js +0 -434
  37. package/dist/webusb/webusb-device.js.map +0 -1
  38. package/libusb/.clang-tidy +0 -34
  39. package/libusb/.codespellrc +0 -3
  40. package/libusb/.private/README.txt +0 -5
  41. package/libusb/.private/appveyor_build.sh +0 -26
  42. package/libusb/.private/bm.sh +0 -54
  43. package/libusb/.private/ci-build.sh +0 -92
  44. package/libusb/.private/ci-container-build.sh +0 -67
  45. package/libusb/.private/post-rewrite.sh +0 -32
  46. package/libusb/.private/pre-commit.sh +0 -52
  47. package/libusb/.private/wbs.txt +0 -43
  48. package/libusb/.travis.yml +0 -58
  49. package/libusb/AUTHORS +0 -231
  50. package/libusb/COPYING +0 -504
  51. package/libusb/ChangeLog +0 -365
  52. package/libusb/HACKING +0 -25
  53. package/libusb/INSTALL_WIN.txt +0 -52
  54. package/libusb/KEYS +0 -123
  55. package/libusb/Makefile.am +0 -50
  56. package/libusb/NEWS +0 -2
  57. package/libusb/PORTING +0 -94
  58. package/libusb/README +0 -29
  59. package/libusb/README.git +0 -41
  60. package/libusb/TODO +0 -2
  61. package/libusb/Xcode/common.xcconfig +0 -92
  62. package/libusb/Xcode/config.h +0 -31
  63. package/libusb/Xcode/debug.xcconfig +0 -32
  64. package/libusb/Xcode/libusb.xcconfig +0 -21
  65. package/libusb/Xcode/libusb.xcodeproj/project.pbxproj +0 -1391
  66. package/libusb/Xcode/libusb_debug.xcconfig +0 -21
  67. package/libusb/Xcode/libusb_release.xcconfig +0 -21
  68. package/libusb/Xcode/release.xcconfig +0 -30
  69. package/libusb/android/README +0 -152
  70. package/libusb/android/config.h +0 -55
  71. package/libusb/android/examples/unrooted_android.c +0 -301
  72. package/libusb/android/examples/unrooted_android.h +0 -36
  73. package/libusb/android/jni/Android.mk +0 -23
  74. package/libusb/android/jni/Application.mk +0 -40
  75. package/libusb/android/jni/examples.mk +0 -168
  76. package/libusb/android/jni/libusb.mk +0 -60
  77. package/libusb/android/jni/tests.mk +0 -45
  78. package/libusb/appveyor.yml +0 -108
  79. package/libusb/autogen.sh +0 -10
  80. package/libusb/bootstrap.sh +0 -10
  81. package/libusb/configure.ac +0 -450
  82. package/libusb/doc/Makefile.in +0 -22
  83. package/libusb/doc/doxygen.cfg.in +0 -2571
  84. package/libusb/doc/libusb.png +0 -0
  85. package/libusb/examples/Makefile.am +0 -12
  86. package/libusb/examples/dpfp.c +0 -711
  87. package/libusb/examples/ezusb.c +0 -846
  88. package/libusb/examples/ezusb.h +0 -109
  89. package/libusb/examples/fxload.c +0 -310
  90. package/libusb/examples/hotplugtest.c +0 -147
  91. package/libusb/examples/listdevs.c +0 -73
  92. package/libusb/examples/sam3u_benchmark.c +0 -228
  93. package/libusb/examples/testlibusb.c +0 -312
  94. package/libusb/examples/xusb.c +0 -1254
  95. package/libusb/libusb/Makefile.am +0 -98
  96. package/libusb/libusb/Makefile.am.extra +0 -26
  97. package/libusb/libusb/core.c +0 -2925
  98. package/libusb/libusb/descriptor.c +0 -1558
  99. package/libusb/libusb/hotplug.c +0 -489
  100. package/libusb/libusb/io.c +0 -2865
  101. package/libusb/libusb/libusb-1.0.def +0 -199
  102. package/libusb/libusb/libusb-1.0.rc +0 -53
  103. package/libusb/libusb/libusb.h +0 -2421
  104. package/libusb/libusb/libusbi.h +0 -1535
  105. package/libusb/libusb/os/darwin_usb.c +0 -2977
  106. package/libusb/libusb/os/darwin_usb.h +0 -156
  107. package/libusb/libusb/os/emscripten_webusb.cpp +0 -875
  108. package/libusb/libusb/os/events_posix.c +0 -340
  109. package/libusb/libusb/os/events_posix.h +0 -62
  110. package/libusb/libusb/os/events_windows.c +0 -214
  111. package/libusb/libusb/os/events_windows.h +0 -46
  112. package/libusb/libusb/os/haiku_pollfs.cpp +0 -372
  113. package/libusb/libusb/os/haiku_usb.h +0 -113
  114. package/libusb/libusb/os/haiku_usb_backend.cpp +0 -532
  115. package/libusb/libusb/os/haiku_usb_raw.cpp +0 -231
  116. package/libusb/libusb/os/haiku_usb_raw.h +0 -188
  117. package/libusb/libusb/os/linux_netlink.c +0 -401
  118. package/libusb/libusb/os/linux_udev.c +0 -321
  119. package/libusb/libusb/os/linux_usbfs.c +0 -2829
  120. package/libusb/libusb/os/linux_usbfs.h +0 -221
  121. package/libusb/libusb/os/netbsd_usb.c +0 -617
  122. package/libusb/libusb/os/null_usb.c +0 -111
  123. package/libusb/libusb/os/openbsd_usb.c +0 -700
  124. package/libusb/libusb/os/sunos_usb.c +0 -1619
  125. package/libusb/libusb/os/sunos_usb.h +0 -79
  126. package/libusb/libusb/os/threads_posix.c +0 -126
  127. package/libusb/libusb/os/threads_posix.h +0 -98
  128. package/libusb/libusb/os/threads_windows.c +0 -40
  129. package/libusb/libusb/os/threads_windows.h +0 -113
  130. package/libusb/libusb/os/windows_common.c +0 -923
  131. package/libusb/libusb/os/windows_common.h +0 -424
  132. package/libusb/libusb/os/windows_usbdk.c +0 -724
  133. package/libusb/libusb/os/windows_usbdk.h +0 -106
  134. package/libusb/libusb/os/windows_winusb.c +0 -4766
  135. package/libusb/libusb/os/windows_winusb.h +0 -787
  136. package/libusb/libusb/strerror.c +0 -223
  137. package/libusb/libusb/sync.c +0 -342
  138. package/libusb/libusb/version.h +0 -18
  139. package/libusb/libusb/version_nano.h +0 -1
  140. package/libusb/libusb-1.0.pc.in +0 -11
  141. package/libusb/msvc/Base.props +0 -60
  142. package/libusb/msvc/Configuration.Application.props +0 -7
  143. package/libusb/msvc/Configuration.Base.props +0 -47
  144. package/libusb/msvc/Configuration.DynamicLibrary.props +0 -21
  145. package/libusb/msvc/Configuration.StaticLibrary.props +0 -7
  146. package/libusb/msvc/ProjectConfigurations.Base.props +0 -69
  147. package/libusb/msvc/build_all.ps1 +0 -17
  148. package/libusb/msvc/config.h +0 -58
  149. package/libusb/msvc/dpfp.vcxproj +0 -33
  150. package/libusb/msvc/dpfp_threaded.vcxproj +0 -38
  151. package/libusb/msvc/fxload.vcxproj +0 -46
  152. package/libusb/msvc/getopt/getopt.c +0 -1060
  153. package/libusb/msvc/getopt/getopt.h +0 -180
  154. package/libusb/msvc/getopt/getopt1.c +0 -188
  155. package/libusb/msvc/getopt.vcxproj +0 -33
  156. package/libusb/msvc/hotplugtest.vcxproj +0 -32
  157. package/libusb/msvc/init_context.vcxproj +0 -35
  158. package/libusb/msvc/libusb.sln +0 -542
  159. package/libusb/msvc/libusb_dll.vcxproj +0 -61
  160. package/libusb/msvc/libusb_static.vcxproj +0 -49
  161. package/libusb/msvc/listdevs.vcxproj +0 -32
  162. package/libusb/msvc/sam3u_benchmark.vcxproj +0 -33
  163. package/libusb/msvc/set_option.vcxproj +0 -35
  164. package/libusb/msvc/stress.vcxproj +0 -35
  165. package/libusb/msvc/stress_mt.vcxproj +0 -33
  166. package/libusb/msvc/testlibusb.vcxproj +0 -32
  167. package/libusb/msvc/xusb.vcxproj +0 -38
  168. package/libusb/tests/Makefile.am +0 -40
  169. package/libusb/tests/init_context.c +0 -153
  170. package/libusb/tests/libusb_testlib.h +0 -76
  171. package/libusb/tests/macos.c +0 -130
  172. package/libusb/tests/set_option.c +0 -253
  173. package/libusb/tests/stress.c +0 -172
  174. package/libusb/tests/stress_mt.c +0 -267
  175. package/libusb/tests/testlib.c +0 -184
  176. package/libusb/tests/umockdev.c +0 -1175
  177. package/libusb/tests/webusb-test-shim/index.js +0 -12
  178. package/libusb/tests/webusb-test-shim/package-lock.json +0 -50
  179. package/libusb/tests/webusb-test-shim/package.json +0 -10
  180. package/libusb.gypi +0 -154
  181. package/libusb_config/config.h +0 -1
  182. package/prebuilds/android-arm/node.napi.armv7.node +0 -0
  183. package/prebuilds/android-arm64/node.napi.armv8.node +0 -0
  184. package/prebuilds/darwin-x64+arm64/node.napi.node +0 -0
  185. package/prebuilds/linux-arm/node.napi.armv6.node +0 -0
  186. package/prebuilds/linux-arm/node.napi.armv7.node +0 -0
  187. package/prebuilds/linux-arm64/node.napi.armv8.node +0 -0
  188. package/prebuilds/linux-ia32/node.napi.node +0 -0
  189. package/prebuilds/linux-x64/node.napi.glibc.node +0 -0
  190. package/prebuilds/linux-x64/node.napi.musl.node +0 -0
  191. package/prebuilds/win32-arm64/node.napi.node +0 -0
  192. package/prebuilds/win32-ia32/node.napi.node +0 -0
  193. package/prebuilds/win32-x64/node.napi.node +0 -0
  194. package/src/device.cc +0 -439
  195. package/src/helpers.h +0 -64
  196. package/src/hotplug/hotplug.h +0 -22
  197. package/src/hotplug/libusb.cc +0 -90
  198. package/src/hotplug/windows.cc +0 -168
  199. package/src/node_usb.cc +0 -314
  200. package/src/node_usb.h +0 -131
  201. package/src/thread_name.cc +0 -79
  202. package/src/thread_name.h +0 -11
  203. package/src/transfer.cc +0 -143
  204. package/src/uv_async_queue.h +0 -41
  205. package/test/usb.coffee +0 -250
  206. package/test/webusb.coffee +0 -227
  207. package/test/worker.cjs +0 -13
@@ -1,372 +0,0 @@
1
- /*
2
- * Copyright 2007-2008, Haiku Inc. All rights reserved.
3
- * Distributed under the terms of the MIT License.
4
- *
5
- * Authors:
6
- * Michael Lotz <mmlr@mlotz.ch>
7
- */
8
-
9
- #include "haiku_usb.h"
10
- #include <cstdio>
11
- #include <Directory.h>
12
- #include <Entry.h>
13
- #include <Looper.h>
14
- #include <Messenger.h>
15
- #include <Node.h>
16
- #include <NodeMonitor.h>
17
- #include <Path.h>
18
- #include <cstring>
19
-
20
- class WatchedEntry {
21
- public:
22
- WatchedEntry(BMessenger *, entry_ref *);
23
- ~WatchedEntry();
24
- bool EntryCreated(entry_ref *ref);
25
- bool EntryRemoved(ino_t node);
26
- bool InitCheck();
27
-
28
- private:
29
- BMessenger* fMessenger;
30
- node_ref fNode;
31
- bool fIsDirectory;
32
- USBDevice* fDevice;
33
- WatchedEntry* fEntries;
34
- WatchedEntry* fLink;
35
- bool fInitCheck;
36
- };
37
-
38
-
39
- class RosterLooper : public BLooper {
40
- public:
41
- RosterLooper(USBRoster *);
42
- void Stop();
43
- virtual void MessageReceived(BMessage *);
44
- bool InitCheck();
45
-
46
- private:
47
- USBRoster* fRoster;
48
- WatchedEntry* fRoot;
49
- BMessenger* fMessenger;
50
- bool fInitCheck;
51
- };
52
-
53
-
54
- WatchedEntry::WatchedEntry(BMessenger *messenger, entry_ref *ref)
55
- : fMessenger(messenger),
56
- fIsDirectory(false),
57
- fDevice(NULL),
58
- fEntries(NULL),
59
- fLink(NULL),
60
- fInitCheck(false)
61
- {
62
- BEntry entry(ref);
63
- entry.GetNodeRef(&fNode);
64
-
65
- BDirectory directory;
66
- if (entry.IsDirectory() && directory.SetTo(ref) >= B_OK) {
67
- fIsDirectory = true;
68
-
69
- while (directory.GetNextEntry(&entry) >= B_OK) {
70
- if (entry.GetRef(ref) < B_OK)
71
- continue;
72
-
73
- WatchedEntry *child = new(std::nothrow) WatchedEntry(fMessenger, ref);
74
- if (child == NULL)
75
- continue;
76
- if (child->InitCheck() == false) {
77
- delete child;
78
- continue;
79
- }
80
-
81
- child->fLink = fEntries;
82
- fEntries = child;
83
- }
84
-
85
- watch_node(&fNode, B_WATCH_DIRECTORY, *fMessenger);
86
- }
87
- else {
88
- if (strncmp(ref->name, "raw", 3) == 0)
89
- return;
90
-
91
- BPath path, parent_path;
92
- entry.GetPath(&path);
93
- fDevice = new(std::nothrow) USBDevice(path.Path());
94
- if (fDevice != NULL && fDevice->InitCheck() == true) {
95
- // Add this new device to each active context's device list
96
- struct libusb_context *ctx;
97
- unsigned long session_id = (unsigned long)&fDevice;
98
-
99
- usbi_mutex_lock(&active_contexts_lock);
100
- for_each_context(ctx) {
101
- struct libusb_device *dev = usbi_get_device_by_session_id(ctx, session_id);
102
- if (dev) {
103
- usbi_dbg(NULL, "using previously allocated device with location %lu", session_id);
104
- libusb_unref_device(dev);
105
- continue;
106
- }
107
- usbi_dbg(NULL, "allocating new device with location %lu", session_id);
108
- dev = usbi_alloc_device(ctx, session_id);
109
- if (!dev) {
110
- usbi_dbg(NULL, "device allocation failed");
111
- continue;
112
- }
113
- *((USBDevice **)usbi_get_device_priv(dev)) = fDevice;
114
-
115
- // Calculate pseudo-device-address
116
- int addr, tmp;
117
- if (strcmp(path.Leaf(), "hub") == 0)
118
- tmp = 100; //Random Number
119
- else
120
- sscanf(path.Leaf(), "%d", &tmp);
121
- addr = tmp + 1;
122
- path.GetParent(&parent_path);
123
- while (strcmp(parent_path.Leaf(), "usb") != 0) {
124
- sscanf(parent_path.Leaf(), "%d", &tmp);
125
- addr += tmp + 1;
126
- parent_path.GetParent(&parent_path);
127
- }
128
- sscanf(path.Path(), "/dev/bus/usb/%hhu", &dev->bus_number);
129
- dev->device_address = addr - (dev->bus_number + 1);
130
-
131
- static_assert(sizeof(dev->device_descriptor) == sizeof(usb_device_descriptor),
132
- "mismatch between libusb and OS device descriptor sizes");
133
- memcpy(&dev->device_descriptor, fDevice->Descriptor(), LIBUSB_DT_DEVICE_SIZE);
134
- usbi_localize_device_descriptor(&dev->device_descriptor);
135
-
136
- if (usbi_sanitize_device(dev) < 0) {
137
- usbi_dbg(NULL, "device sanitization failed");
138
- libusb_unref_device(dev);
139
- continue;
140
- }
141
- usbi_connect_device(dev);
142
- }
143
- usbi_mutex_unlock(&active_contexts_lock);
144
- }
145
- else if (fDevice) {
146
- delete fDevice;
147
- fDevice = NULL;
148
- return;
149
- }
150
- }
151
- fInitCheck = true;
152
- }
153
-
154
-
155
- WatchedEntry::~WatchedEntry()
156
- {
157
- if (fIsDirectory) {
158
- watch_node(&fNode, B_STOP_WATCHING, *fMessenger);
159
-
160
- WatchedEntry *child = fEntries;
161
- while (child) {
162
- WatchedEntry *next = child->fLink;
163
- delete child;
164
- child = next;
165
- }
166
- }
167
-
168
- if (fDevice) {
169
- // Remove this device from each active context's device list
170
- struct libusb_context *ctx;
171
- struct libusb_device *dev;
172
- unsigned long session_id = (unsigned long)&fDevice;
173
-
174
- usbi_mutex_lock(&active_contexts_lock);
175
- for_each_context(ctx) {
176
- dev = usbi_get_device_by_session_id(ctx, session_id);
177
- if (dev != NULL) {
178
- usbi_disconnect_device(dev);
179
- libusb_unref_device(dev);
180
- } else {
181
- usbi_dbg(ctx, "device with location %lu not found", session_id);
182
- }
183
- }
184
- usbi_mutex_static_unlock(&active_contexts_lock);
185
- delete fDevice;
186
- }
187
- }
188
-
189
-
190
- bool
191
- WatchedEntry::EntryCreated(entry_ref *ref)
192
- {
193
- if (!fIsDirectory)
194
- return false;
195
-
196
- if (ref->directory != fNode.node) {
197
- WatchedEntry *child = fEntries;
198
- while (child) {
199
- if (child->EntryCreated(ref))
200
- return true;
201
- child = child->fLink;
202
- }
203
- return false;
204
- }
205
-
206
- WatchedEntry *child = new(std::nothrow) WatchedEntry(fMessenger, ref);
207
- if (child == NULL)
208
- return false;
209
- child->fLink = fEntries;
210
- fEntries = child;
211
- return true;
212
- }
213
-
214
-
215
- bool
216
- WatchedEntry::EntryRemoved(ino_t node)
217
- {
218
- if (!fIsDirectory)
219
- return false;
220
-
221
- WatchedEntry *child = fEntries;
222
- WatchedEntry *lastChild = NULL;
223
- while (child) {
224
- if (child->fNode.node == node) {
225
- if (lastChild)
226
- lastChild->fLink = child->fLink;
227
- else
228
- fEntries = child->fLink;
229
- delete child;
230
- return true;
231
- }
232
-
233
- if (child->EntryRemoved(node))
234
- return true;
235
-
236
- lastChild = child;
237
- child = child->fLink;
238
- }
239
- return false;
240
- }
241
-
242
-
243
- bool
244
- WatchedEntry::InitCheck()
245
- {
246
- return fInitCheck;
247
- }
248
-
249
-
250
- RosterLooper::RosterLooper(USBRoster *roster)
251
- : BLooper("LibusbRoster Looper"),
252
- fRoster(roster),
253
- fRoot(NULL),
254
- fMessenger(NULL),
255
- fInitCheck(false)
256
- {
257
- BEntry entry("/dev/bus/usb");
258
- if (!entry.Exists()) {
259
- usbi_err(NULL, "usb_raw not published");
260
- return;
261
- }
262
-
263
- Run();
264
- fMessenger = new(std::nothrow) BMessenger(this);
265
- if (fMessenger == NULL) {
266
- usbi_err(NULL, "error creating BMessenger object");
267
- return;
268
- }
269
-
270
- if (Lock()) {
271
- entry_ref ref;
272
- entry.GetRef(&ref);
273
- fRoot = new(std::nothrow) WatchedEntry(fMessenger, &ref);
274
- Unlock();
275
- if (fRoot == NULL)
276
- return;
277
- if (fRoot->InitCheck() == false) {
278
- delete fRoot;
279
- fRoot = NULL;
280
- return;
281
- }
282
- }
283
- fInitCheck = true;
284
- }
285
-
286
-
287
- void
288
- RosterLooper::Stop()
289
- {
290
- Lock();
291
- delete fRoot;
292
- delete fMessenger;
293
- Quit();
294
- }
295
-
296
-
297
- void
298
- RosterLooper::MessageReceived(BMessage *message)
299
- {
300
- int32 opcode;
301
- if (message->FindInt32("opcode", &opcode) < B_OK)
302
- return;
303
-
304
- switch (opcode) {
305
- case B_ENTRY_CREATED:
306
- {
307
- dev_t device;
308
- ino_t directory;
309
- const char *name;
310
- if (message->FindInt32("device", &device) < B_OK ||
311
- message->FindInt64("directory", &directory) < B_OK ||
312
- message->FindString("name", &name) < B_OK)
313
- break;
314
-
315
- entry_ref ref(device, directory, name);
316
- fRoot->EntryCreated(&ref);
317
- break;
318
- }
319
- case B_ENTRY_REMOVED:
320
- {
321
- ino_t node;
322
- if (message->FindInt64("node", &node) < B_OK)
323
- break;
324
- fRoot->EntryRemoved(node);
325
- break;
326
- }
327
- }
328
- }
329
-
330
-
331
- bool
332
- RosterLooper::InitCheck()
333
- {
334
- return fInitCheck;
335
- }
336
-
337
-
338
- USBRoster::USBRoster()
339
- : fLooper(NULL)
340
- {
341
- }
342
-
343
-
344
- USBRoster::~USBRoster()
345
- {
346
- Stop();
347
- }
348
-
349
-
350
- int
351
- USBRoster::Start()
352
- {
353
- if (fLooper == NULL) {
354
- fLooper = new(std::nothrow) RosterLooper(this);
355
- if (fLooper == NULL || ((RosterLooper *)fLooper)->InitCheck() == false) {
356
- if (fLooper)
357
- fLooper = NULL;
358
- return LIBUSB_ERROR_OTHER;
359
- }
360
- }
361
- return LIBUSB_SUCCESS;
362
- }
363
-
364
-
365
- void
366
- USBRoster::Stop()
367
- {
368
- if (fLooper) {
369
- ((RosterLooper *)fLooper)->Stop();
370
- fLooper = NULL;
371
- }
372
- }
@@ -1,113 +0,0 @@
1
- /*
2
- * Haiku Backend for libusb
3
- * Copyright © 2014 Akshay Jaggi <akshay1994.leo@gmail.com>
4
- *
5
- * This library is free software; you can redistribute it and/or
6
- * modify it under the terms of the GNU Lesser General Public
7
- * License as published by the Free Software Foundation; either
8
- * version 2.1 of the License, or (at your option) any later version.
9
- *
10
- * This library is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
- * Lesser General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU Lesser General Public
16
- * License along with this library; if not, write to the Free Software
17
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
- */
19
-
20
- #include <List.h>
21
- #include <Locker.h>
22
- #include <Autolock.h>
23
- #include <USBKit.h>
24
- #include <map>
25
- #include "libusbi.h"
26
- #include "haiku_usb_raw.h"
27
-
28
- using namespace std;
29
-
30
- class USBDevice;
31
- class USBDeviceHandle;
32
- class USBTransfer;
33
-
34
- class USBDevice {
35
- public:
36
- USBDevice(const char *);
37
- virtual ~USBDevice();
38
- const char* Location() const;
39
- uint8 CountConfigurations() const;
40
- const usb_device_descriptor* Descriptor() const;
41
- const usb_configuration_descriptor* ConfigurationDescriptor(uint8) const;
42
- const usb_configuration_descriptor* ActiveConfiguration() const;
43
- uint8 EndpointToIndex(uint8) const;
44
- uint8 EndpointToInterface(uint8) const;
45
- int ClaimInterface(uint8);
46
- int ReleaseInterface(uint8);
47
- int CheckInterfacesFree(uint8);
48
- void SetActiveConfiguration(uint8);
49
- uint8 ActiveConfigurationIndex() const;
50
- bool InitCheck();
51
- private:
52
- int Initialise();
53
- unsigned int fClaimedInterfaces; // Max Interfaces can be 32. Using a bitmask
54
- usb_device_descriptor fDeviceDescriptor;
55
- unsigned char** fConfigurationDescriptors;
56
- uint8 fActiveConfiguration;
57
- char* fPath;
58
- map<uint8,uint8> fConfigToIndex;
59
- map<uint8,uint8>* fEndpointToIndex;
60
- map<uint8,uint8>* fEndpointToInterface;
61
- bool fInitCheck;
62
- };
63
-
64
- class USBDeviceHandle {
65
- public:
66
- USBDeviceHandle(USBDevice *dev);
67
- virtual ~USBDeviceHandle();
68
- int ClaimInterface(uint8);
69
- int ReleaseInterface(uint8);
70
- int SetConfiguration(uint8);
71
- int SetAltSetting(uint8, uint8);
72
- int ClearHalt(uint8);
73
- status_t SubmitTransfer(struct usbi_transfer *);
74
- status_t CancelTransfer(USBTransfer *);
75
- bool InitCheck();
76
- private:
77
- int fRawFD;
78
- static status_t TransfersThread(void *);
79
- void TransfersWorker();
80
- USBDevice* fUSBDevice;
81
- unsigned int fClaimedInterfaces;
82
- BList fTransfers;
83
- BLocker fTransfersLock;
84
- sem_id fTransfersSem;
85
- thread_id fTransfersThread;
86
- bool fInitCheck;
87
- };
88
-
89
- class USBTransfer {
90
- public:
91
- USBTransfer(struct usbi_transfer *, USBDevice *);
92
- virtual ~USBTransfer();
93
- void Do(int);
94
- struct usbi_transfer* UsbiTransfer();
95
- void SetCancelled();
96
- bool IsCancelled();
97
- private:
98
- struct usbi_transfer* fUsbiTransfer;
99
- struct libusb_transfer* fLibusbTransfer;
100
- USBDevice* fUSBDevice;
101
- BLocker fStatusLock;
102
- bool fCancelled;
103
- };
104
-
105
- class USBRoster {
106
- public:
107
- USBRoster();
108
- virtual ~USBRoster();
109
- int Start();
110
- void Stop();
111
- private:
112
- void* fLooper;
113
- };