libusb 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/.travis.yml +1 -0
  5. data/History.md +8 -0
  6. data/README.md +5 -15
  7. data/Rakefile +8 -1
  8. data/ext/extconf.rb +49 -12
  9. data/ext/{libusb-1.0.19 → libusb-1.0.20}/AUTHORS +12 -1
  10. data/ext/{libusb-1.0.19 → libusb-1.0.20}/COPYING +0 -0
  11. data/ext/{libusb-1.0.19 → libusb-1.0.20}/ChangeLog +18 -2
  12. data/ext/{libusb-1.0.19 → libusb-1.0.20}/INSTALL +0 -0
  13. data/ext/{libusb-1.0.19 → libusb-1.0.20}/Makefile.am +0 -0
  14. data/ext/{libusb-1.0.19 → libusb-1.0.20}/Makefile.in +31 -18
  15. data/ext/{libusb-1.0.19 → libusb-1.0.20}/NEWS +0 -0
  16. data/ext/{libusb-1.0.19 → libusb-1.0.20}/PORTING +0 -0
  17. data/ext/{libusb-1.0.19 → libusb-1.0.20}/README +5 -3
  18. data/ext/{libusb-1.0.19 → libusb-1.0.20}/TODO +0 -0
  19. data/ext/{libusb-1.0.19 → libusb-1.0.20}/Xcode/common.xcconfig +0 -0
  20. data/ext/{libusb-1.0.19 → libusb-1.0.20}/Xcode/config.h +0 -0
  21. data/ext/{libusb-1.0.19 → libusb-1.0.20}/Xcode/debug.xcconfig +0 -0
  22. data/ext/{libusb-1.0.19 → libusb-1.0.20}/Xcode/libusb.xcconfig +0 -0
  23. data/ext/libusb-1.0.20/Xcode/libusb.xcodeproj/project.pbxproj +865 -0
  24. data/ext/{libusb-1.0.19 → libusb-1.0.20}/Xcode/libusb_debug.xcconfig +0 -0
  25. data/ext/{libusb-1.0.19 → libusb-1.0.20}/Xcode/libusb_release.xcconfig +0 -0
  26. data/ext/{libusb-1.0.19 → libusb-1.0.20}/Xcode/release.xcconfig +0 -0
  27. data/ext/{libusb-1.0.19 → libusb-1.0.20}/aclocal.m4 +35 -32
  28. data/ext/{libusb-1.0.19 → libusb-1.0.20}/android/README +0 -0
  29. data/ext/{libusb-1.0.19 → libusb-1.0.20}/android/config.h +0 -0
  30. data/ext/{libusb-1.0.19 → libusb-1.0.20}/android/jni/Android.mk +0 -0
  31. data/ext/{libusb-1.0.19 → libusb-1.0.20}/android/jni/Application.mk +0 -0
  32. data/ext/{libusb-1.0.19 → libusb-1.0.20}/android/jni/examples.mk +0 -0
  33. data/ext/{libusb-1.0.19 → libusb-1.0.20}/android/jni/libusb.mk +0 -0
  34. data/ext/{libusb-1.0.19 → libusb-1.0.20}/android/jni/tests.mk +0 -0
  35. data/ext/{libusb-1.0.19 → libusb-1.0.20}/compile +1 -1
  36. data/ext/{libusb-1.0.19 → libusb-1.0.20}/config.guess +13 -160
  37. data/ext/{libusb-1.0.19 → libusb-1.0.20}/config.h.in +6 -0
  38. data/ext/{libusb-1.0.19 → libusb-1.0.20}/config.sub +26 -12
  39. data/ext/{libusb-1.0.19 → libusb-1.0.20}/configure +244 -20
  40. data/ext/{libusb-1.0.19 → libusb-1.0.20}/configure.ac +27 -4
  41. data/ext/{libusb-1.0.19 → libusb-1.0.20}/depcomp +1 -1
  42. data/ext/{libusb-1.0.19 → libusb-1.0.20}/doc/Makefile.am +0 -0
  43. data/ext/{libusb-1.0.19 → libusb-1.0.20}/doc/Makefile.in +19 -6
  44. data/ext/libusb-1.0.20/doc/doxygen.cfg.in +2334 -0
  45. data/ext/{libusb-1.0.19 → libusb-1.0.20}/examples/Makefile.am +0 -0
  46. data/ext/{libusb-1.0.19 → libusb-1.0.20}/examples/Makefile.in +19 -6
  47. data/ext/{libusb-1.0.19 → libusb-1.0.20}/examples/dpfp.c +0 -0
  48. data/ext/{libusb-1.0.19 → libusb-1.0.20}/examples/dpfp_threaded.c +15 -10
  49. data/ext/{libusb-1.0.19 → libusb-1.0.20}/examples/ezusb.c +0 -0
  50. data/ext/{libusb-1.0.19 → libusb-1.0.20}/examples/ezusb.h +0 -0
  51. data/ext/{libusb-1.0.19 → libusb-1.0.20}/examples/fxload.c +28 -7
  52. data/ext/{libusb-1.0.19 → libusb-1.0.20}/examples/getopt/getopt.c +0 -0
  53. data/ext/{libusb-1.0.19 → libusb-1.0.20}/examples/getopt/getopt.h +0 -0
  54. data/ext/{libusb-1.0.19 → libusb-1.0.20}/examples/getopt/getopt1.c +0 -0
  55. data/ext/{libusb-1.0.19 → libusb-1.0.20}/examples/hotplugtest.c +21 -3
  56. data/ext/{libusb-1.0.19 → libusb-1.0.20}/examples/listdevs.c +0 -0
  57. data/ext/{libusb-1.0.19 → libusb-1.0.20}/examples/sam3u_benchmark.c +0 -0
  58. data/ext/{libusb-1.0.19 → libusb-1.0.20}/examples/xusb.c +2 -1
  59. data/ext/{libusb-1.0.19 → libusb-1.0.20}/install-sh +170 -196
  60. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb-1.0.pc.in +0 -0
  61. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/Makefile.am +15 -0
  62. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/Makefile.in +192 -53
  63. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/core.c +218 -100
  64. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/descriptor.c +3 -1
  65. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/hotplug.c +26 -9
  66. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/hotplug.h +8 -0
  67. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/io.c +432 -290
  68. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/libusb-1.0.def +2 -0
  69. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/libusb-1.0.rc +0 -0
  70. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/libusb.h +11 -10
  71. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/libusbi.h +106 -29
  72. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/darwin_usb.c +27 -67
  73. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/darwin_usb.h +3 -7
  74. data/ext/libusb-1.0.20/libusb/os/haiku/Makefile.am +5 -0
  75. data/ext/libusb-1.0.20/libusb/os/haiku/Makefile.in +810 -0
  76. data/ext/libusb-1.0.20/libusb/os/haiku/aclocal.m4 +1193 -0
  77. data/ext/libusb-1.0.20/libusb/os/haiku/compile +347 -0
  78. data/ext/libusb-1.0.20/libusb/os/haiku/config.guess +1421 -0
  79. data/ext/libusb-1.0.20/libusb/os/haiku/config.sub +1807 -0
  80. data/ext/libusb-1.0.20/libusb/os/haiku/configure +17579 -0
  81. data/ext/libusb-1.0.20/libusb/os/haiku/configure.ac +8 -0
  82. data/ext/libusb-1.0.20/libusb/os/haiku/depcomp +791 -0
  83. data/ext/libusb-1.0.20/libusb/os/haiku/haiku_pollfs.cpp +378 -0
  84. data/ext/libusb-1.0.20/libusb/os/haiku/haiku_usb.h +112 -0
  85. data/ext/libusb-1.0.20/libusb/os/haiku/haiku_usb_backend.cpp +550 -0
  86. data/ext/libusb-1.0.20/libusb/os/haiku/haiku_usb_raw.cpp +255 -0
  87. data/ext/libusb-1.0.20/libusb/os/haiku/haiku_usb_raw.h +180 -0
  88. data/ext/libusb-1.0.20/libusb/os/haiku/install-sh +501 -0
  89. data/ext/{libusb-1.0.19 → libusb-1.0.20/libusb/os/haiku}/ltmain.sh +0 -0
  90. data/ext/{libusb-1.0.19 → libusb-1.0.20/libusb/os/haiku}/m4/libtool.m4 +0 -0
  91. data/ext/{libusb-1.0.19 → libusb-1.0.20/libusb/os/haiku}/m4/ltoptions.m4 +0 -0
  92. data/ext/{libusb-1.0.19 → libusb-1.0.20/libusb/os/haiku}/m4/ltsugar.m4 +0 -0
  93. data/ext/{libusb-1.0.19 → libusb-1.0.20/libusb/os/haiku}/m4/ltversion.m4 +0 -0
  94. data/ext/{libusb-1.0.19 → libusb-1.0.20/libusb/os/haiku}/m4/lt~obsolete.m4 +0 -0
  95. data/ext/{libusb-1.0.19 → libusb-1.0.20/libusb/os/haiku}/missing +1 -1
  96. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/linux_netlink.c +4 -4
  97. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/linux_udev.c +1 -2
  98. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/linux_usbfs.c +46 -49
  99. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/linux_usbfs.h +1 -1
  100. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/netbsd_usb.c +9 -73
  101. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/openbsd_usb.c +9 -73
  102. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/poll_posix.c +2 -0
  103. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/poll_posix.h +0 -0
  104. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/poll_windows.c +3 -1
  105. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/poll_windows.h +0 -0
  106. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/threads_posix.c +3 -3
  107. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/threads_posix.h +0 -0
  108. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/threads_windows.c +3 -1
  109. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/threads_windows.h +0 -0
  110. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/wince_usb.c +87 -250
  111. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/wince_usb.h +0 -0
  112. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/windows_common.h +1 -1
  113. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/windows_usb.c +267 -181
  114. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/windows_usb.h +22 -7
  115. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/strerror.c +5 -2
  116. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/sync.c +2 -1
  117. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/version.h +1 -1
  118. data/ext/libusb-1.0.20/libusb/version_nano.h +1 -0
  119. data/ext/libusb-1.0.20/ltmain.sh +9655 -0
  120. data/ext/libusb-1.0.20/m4/libtool.m4 +7992 -0
  121. data/ext/libusb-1.0.20/m4/ltoptions.m4 +384 -0
  122. data/ext/libusb-1.0.20/m4/ltsugar.m4 +123 -0
  123. data/ext/libusb-1.0.20/m4/ltversion.m4 +23 -0
  124. data/ext/libusb-1.0.20/m4/lt~obsolete.m4 +98 -0
  125. data/ext/libusb-1.0.20/missing +215 -0
  126. data/ext/{libusb-1.0.19 → libusb-1.0.20}/tests/Makefile.am +0 -0
  127. data/ext/{libusb-1.0.19 → libusb-1.0.20}/tests/Makefile.in +19 -6
  128. data/ext/{libusb-1.0.19 → libusb-1.0.20}/tests/libusb_testlib.h +0 -0
  129. data/ext/{libusb-1.0.19 → libusb-1.0.20}/tests/stress.c +0 -0
  130. data/ext/{libusb-1.0.19 → libusb-1.0.20}/tests/testlib.c +0 -0
  131. data/lib/libusb.rb +1 -0
  132. data/lib/libusb/call.rb +1 -0
  133. data/lib/libusb/context.rb +5 -2
  134. data/lib/libusb/stdio.rb +25 -0
  135. data/lib/libusb/version_gem.rb +1 -1
  136. data/libusb.gemspec +2 -1
  137. metadata +152 -115
  138. metadata.gz.sig +0 -0
  139. data/ext/libusb-1.0.19/Xcode/libusb.xcodeproj/project.pbxproj +0 -1
  140. data/ext/libusb-1.0.19/doc/doxygen.cfg.in +0 -1288
  141. data/ext/libusb-1.0.19/libusb/version_nano.h +0 -1
@@ -0,0 +1,378 @@
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
+
68
+ fIsDirectory = true;
69
+
70
+ while (directory.GetNextEntry(&entry) >= B_OK) {
71
+ if (entry.GetRef(ref) < B_OK)
72
+ continue;
73
+
74
+ WatchedEntry* child = new(std::nothrow) WatchedEntry(fMessenger, ref);
75
+ if (child == NULL)
76
+ continue;
77
+ if (child->InitCheck() == false)
78
+ {
79
+ delete child;
80
+ continue;
81
+ }
82
+
83
+
84
+ child->fLink = fEntries;
85
+ fEntries = child;
86
+ }
87
+
88
+ watch_node(&fNode, B_WATCH_DIRECTORY, *fMessenger);
89
+
90
+ } else {
91
+ if (strncmp(ref->name, "raw", 3) == 0)
92
+ return;
93
+
94
+ BPath path, parent_path;
95
+ entry.GetPath(&path);
96
+ fDevice = new(std::nothrow) USBDevice(path.Path());
97
+ if (fDevice != NULL && fDevice->InitCheck() == true) {
98
+ // Add this new device to each active context's device list
99
+ struct libusb_context *ctx;
100
+ unsigned long session_id = (unsigned long)&fDevice;
101
+
102
+ usbi_mutex_lock(&active_contexts_lock);
103
+ list_for_each_entry(ctx, &active_contexts_list, list, struct libusb_context) {
104
+
105
+ struct libusb_device* dev = usbi_get_device_by_session_id(ctx, session_id);
106
+ if (dev) {
107
+ usbi_dbg("using previously allocated device with location %lu", session_id);
108
+ libusb_unref_device(dev);
109
+ continue;
110
+ }
111
+ usbi_dbg("allocating new device with location %lu" ,session_id);
112
+ dev = usbi_alloc_device(ctx, session_id);
113
+ if (!dev) {
114
+ usbi_dbg("device allocation failed");
115
+ continue;
116
+ }
117
+ *((USBDevice**)dev->os_priv) = fDevice;
118
+
119
+ // Calculate pseudo-device-address
120
+ int addr,tmp;
121
+ if (strcmp(path.Leaf(), "hub") == 0)
122
+ {
123
+ tmp=100; //Random Number
124
+ }
125
+ else
126
+ {
127
+ sscanf(path.Leaf(), "%d", &tmp);
128
+ }
129
+ addr = tmp + 1;
130
+ path.GetParent(&parent_path);
131
+ while(strcmp(parent_path.Leaf(),"usb") != 0)
132
+ {
133
+ sscanf(parent_path.Leaf(), "%d", &tmp);
134
+ addr += tmp + 1;
135
+ parent_path.GetParent(&parent_path);
136
+ }
137
+ sscanf(path.Path(), "/dev/bus/usb/%d", &dev->bus_number);
138
+ (dev->device_address) = addr - (dev->bus_number + 1);
139
+
140
+ if(usbi_sanitize_device(dev) < 0)
141
+ {
142
+ usbi_dbg("device sanitization failed");
143
+ libusb_unref_device(dev);
144
+ continue;
145
+ }
146
+ usbi_connect_device(dev);
147
+ }
148
+ usbi_mutex_unlock(&active_contexts_lock);
149
+ } else if (fDevice) {
150
+ delete fDevice;
151
+ fDevice = NULL;
152
+ return;
153
+ }
154
+ }
155
+ fInitCheck = true;
156
+ }
157
+
158
+
159
+ WatchedEntry::~WatchedEntry()
160
+ {
161
+ if (fIsDirectory) {
162
+ watch_node(&fNode, B_STOP_WATCHING, *fMessenger);
163
+
164
+ WatchedEntry* child = fEntries;
165
+ while (child) {
166
+ WatchedEntry *next = child->fLink;
167
+ delete child;
168
+ child = next;
169
+ }
170
+ }
171
+
172
+ if (fDevice) {
173
+ // Remove this device from each active context's device list
174
+ struct libusb_context *ctx;
175
+ struct libusb_device *dev;
176
+ unsigned long session_id = (unsigned long)&fDevice;
177
+
178
+ usbi_mutex_lock(&active_contexts_lock);
179
+ list_for_each_entry(ctx, &active_contexts_list, list, struct libusb_context) {
180
+ dev = usbi_get_device_by_session_id (ctx, session_id);
181
+ if (dev != NULL) {
182
+ usbi_disconnect_device (dev);
183
+ libusb_unref_device(dev);
184
+ } else {
185
+ usbi_dbg("device with location %lu not found", session_id);
186
+ }
187
+ }
188
+ usbi_mutex_static_unlock(&active_contexts_lock);
189
+ delete fDevice;
190
+ }
191
+ }
192
+
193
+
194
+ bool
195
+ WatchedEntry::EntryCreated(entry_ref *ref)
196
+ {
197
+ if (!fIsDirectory)
198
+ return false;
199
+
200
+ if (ref->directory != fNode.node) {
201
+ WatchedEntry* child = fEntries;
202
+ while (child) {
203
+ if (child->EntryCreated(ref))
204
+ return true;
205
+ child = child->fLink;
206
+ }
207
+ return false;
208
+ }
209
+
210
+ WatchedEntry* child = new(std::nothrow) WatchedEntry(fMessenger, ref);
211
+ if (child == NULL)
212
+ return false;
213
+ child->fLink = fEntries;
214
+ fEntries = child;
215
+ return true;
216
+ }
217
+
218
+
219
+ bool
220
+ WatchedEntry::EntryRemoved(ino_t node)
221
+ {
222
+ if (!fIsDirectory)
223
+ return false;
224
+
225
+ WatchedEntry* child = fEntries;
226
+ WatchedEntry* lastChild = NULL;
227
+ while (child) {
228
+ if (child->fNode.node == node) {
229
+ if (lastChild)
230
+ lastChild->fLink = child->fLink;
231
+ else
232
+ fEntries = child->fLink;
233
+ delete child;
234
+ return true;
235
+ }
236
+
237
+ if (child->EntryRemoved(node))
238
+ return true;
239
+
240
+ lastChild = child;
241
+ child = child->fLink;
242
+ }
243
+ return false;
244
+ }
245
+
246
+
247
+ bool
248
+ WatchedEntry::InitCheck()
249
+ {
250
+ return fInitCheck;
251
+ }
252
+
253
+
254
+ RosterLooper::RosterLooper(USBRoster* roster)
255
+ : BLooper("LibusbRoster Looper"),
256
+ fRoster(roster),
257
+ fRoot(NULL),
258
+ fMessenger(NULL),
259
+ fInitCheck(false)
260
+ {
261
+ BEntry entry("/dev/bus/usb");
262
+ if (!entry.Exists()) {
263
+ usbi_err(NULL,"usb_raw not published");
264
+ return;
265
+ }
266
+
267
+ Run();
268
+ fMessenger = new(std::nothrow) BMessenger(this);
269
+ if (fMessenger == NULL)
270
+ {
271
+ usbi_err(NULL,"error creating BMessenger object");
272
+ return;
273
+ }
274
+
275
+ if(Lock()) {
276
+ entry_ref ref;
277
+ entry.GetRef(&ref);
278
+ fRoot = new(std::nothrow) WatchedEntry(fMessenger, &ref);
279
+ Unlock();
280
+ if (fRoot == NULL)
281
+ {
282
+ return;
283
+ }
284
+ if (fRoot->InitCheck() == false)
285
+ {
286
+ delete fRoot;
287
+ return;
288
+ }
289
+ }
290
+ fInitCheck = true;
291
+ }
292
+
293
+
294
+ void
295
+ RosterLooper::Stop()
296
+ {
297
+ Lock();
298
+ delete fRoot;
299
+ delete fMessenger;
300
+ Quit();
301
+ }
302
+
303
+
304
+ void
305
+ RosterLooper::MessageReceived(BMessage *message)
306
+ {
307
+ int32 opcode;
308
+ if (message->FindInt32("opcode", &opcode) < B_OK)
309
+ return;
310
+
311
+ switch (opcode) {
312
+ case B_ENTRY_CREATED: {
313
+ dev_t device;
314
+ ino_t directory;
315
+ const char* name;
316
+ if (message->FindInt32("device", &device) < B_OK
317
+ || message->FindInt64("directory", &directory) < B_OK
318
+ || message->FindString("name", &name) < B_OK)
319
+ break;
320
+
321
+ entry_ref ref(device, directory, name);
322
+ fRoot->EntryCreated(&ref);
323
+ break;
324
+ }
325
+ case B_ENTRY_REMOVED: {
326
+ ino_t node;
327
+ if (message->FindInt64("node", &node) < B_OK)
328
+ break;
329
+ fRoot->EntryRemoved(node);
330
+ break;
331
+ }
332
+ }
333
+ }
334
+
335
+
336
+ bool
337
+ RosterLooper::InitCheck()
338
+ {
339
+ return fInitCheck;
340
+ }
341
+
342
+
343
+ USBRoster::USBRoster()
344
+ : fLooper(NULL)
345
+ {
346
+ }
347
+
348
+
349
+ USBRoster::~USBRoster()
350
+ {
351
+ Stop();
352
+ }
353
+
354
+
355
+ int
356
+ USBRoster::Start()
357
+ {
358
+ if(fLooper)
359
+ return LIBUSB_SUCCESS;
360
+
361
+ fLooper = new(std::nothrow) RosterLooper(this);
362
+ if (fLooper == NULL || ((RosterLooper*)fLooper)->InitCheck() == false)
363
+ return LIBUSB_ERROR_OTHER;
364
+ return LIBUSB_SUCCESS;
365
+ }
366
+
367
+
368
+ void
369
+ USBRoster::Stop()
370
+ {
371
+ if(!fLooper)
372
+ return;
373
+
374
+ ((RosterLooper *)fLooper)->Stop();
375
+ fLooper = NULL;
376
+ }
377
+
378
+
@@ -0,0 +1,112 @@
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(uint32) const;
42
+ const usb_configuration_descriptor* ActiveConfiguration() const;
43
+ uint8 EndpointToIndex(uint8) const;
44
+ uint8 EndpointToInterface(uint8) const;
45
+ int ClaimInterface(int);
46
+ int ReleaseInterface(int);
47
+ int CheckInterfacesFree(int);
48
+ int SetActiveConfiguration(int);
49
+ int 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
+ int 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(int);
69
+ int ReleaseInterface(int);
70
+ int SetConfiguration(int);
71
+ int SetAltSetting(int,int);
72
+ status_t SubmitTransfer(struct usbi_transfer*);
73
+ status_t CancelTransfer(USBTransfer*);
74
+ bool InitCheck();
75
+ private:
76
+ int fRawFD;
77
+ static status_t TransfersThread(void *);
78
+ void TransfersWorker();
79
+ USBDevice* fUSBDevice;
80
+ unsigned int fClaimedInterfaces;
81
+ BList fTransfers;
82
+ BLocker fTransfersLock;
83
+ sem_id fTransfersSem;
84
+ thread_id fTransfersThread;
85
+ bool fInitCheck;
86
+ };
87
+
88
+ class USBTransfer {
89
+ public:
90
+ USBTransfer(struct usbi_transfer*,USBDevice*);
91
+ virtual ~USBTransfer();
92
+ void Do(int);
93
+ struct usbi_transfer* UsbiTransfer();
94
+ void SetCancelled();
95
+ bool IsCancelled();
96
+ private:
97
+ struct usbi_transfer* fUsbiTransfer;
98
+ struct libusb_transfer* fLibusbTransfer;
99
+ USBDevice* fUSBDevice;
100
+ BLocker fStatusLock;
101
+ bool fCancelled;
102
+ };
103
+
104
+ class USBRoster {
105
+ public:
106
+ USBRoster();
107
+ virtual ~USBRoster();
108
+ int Start();
109
+ void Stop();
110
+ private:
111
+ void* fLooper;
112
+ };