tenderlove-usb 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,22 @@
1
+ 2009-07-28 Daiki Ueno <ueno@unixuser.org>
2
+
3
+ * extconf.rb: check ruby/st.h for ruby 1.9.
4
+
5
+ * usb.c: prefer ruby/st.h over st.h.
6
+
7
+ 2008-04-12 Tanaka Akira <akr@fsij.org>
8
+
9
+ * ruby-usb 0.2 released.
10
+
11
+ 2007-01-21 Tanaka Akira <akr@fsij.org>
12
+
13
+ * usb.c: include st.h.
14
+ fix a compile error on MacOS X reported by Tony Buser.
15
+
16
+ 2007-01-10 Tanaka Akira <akr@fsij.org>
17
+
18
+ * lib/usb.rb (USB.each_device_by_class): new method.
19
+
20
+ 2007-01-10 Tanaka Akira <akr@fsij.org>
21
+
22
+ * ruby-usb 0.1 released.
@@ -0,0 +1,10 @@
1
+ COPYING
2
+ ChangeLog
3
+ Manifest.txt
4
+ README
5
+ Rakefile
6
+ ext/usb/constants.h
7
+ ext/usb/extconf.rb
8
+ ext/usb/usb.c
9
+ lib/usb.rb
10
+ sample/usb-power
data/README ADDED
@@ -0,0 +1,56 @@
1
+ = ruby-usb - libusb binding for Ruby
2
+
3
+ ruby-usb is a libusb binding library for Ruby.
4
+
5
+ == Author
6
+
7
+ Tanaka Akira <akr@fsij.org>
8
+
9
+ == Home Page
10
+
11
+ http://www.a-k-r.org/ruby-usb/
12
+
13
+ == License
14
+
15
+ LGPL
16
+
17
+ == Feature
18
+
19
+ * direct (non-rubyish) binding
20
+ * rubyish interface (work in progress)
21
+
22
+ == Requirements
23
+
24
+ * ruby : http://www.ruby-lang.org/
25
+ * libusb 0.1 : http://libusb.sourceforge.net/
26
+
27
+ == Download
28
+
29
+ * latest release: http://www.a-k-r.org/ruby-usb/ruby-usb-0.2.tar.gz
30
+
31
+ * development version: http://github.com/akr/ruby-usb
32
+
33
+ == Install
34
+
35
+ % gem install usb
36
+
37
+ == Packaging
38
+
39
+ % rake package
40
+
41
+ == Releasing to rubygems.org
42
+
43
+ Make sure to `gem install hoe-git` first.
44
+
45
+ % rake release VERSION=0.3.0
46
+
47
+ == Reference Manual
48
+
49
+ See rdoc/ or
50
+ http://www.a-k-r.org/ruby-usb/rdoc/
51
+
52
+ == See Also
53
+
54
+ * USB.org : http://www.usb.org/
55
+ * AC Power Control through USB : http://www.gniibe.org/ac-power-by-usb/ac-power-control.html
56
+ * How To Control USB Missile Launcher on Linux : http://blog.taragana.com/index.php/archive/how-to-control-usb-missile-launcher-on-linux/
@@ -0,0 +1,29 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+ gem 'rake-compiler', '>= 0.4.1'
6
+ require "rake/extensiontask"
7
+
8
+ Hoe.plugin :git # gem install hoe-git
9
+
10
+ Hoe.spec 'tenderlove-usb' do
11
+ developer 'Tanaka Akira', 'akr@fsij.org'
12
+
13
+ self.history_file = 'ChangeLog'
14
+ self.readme_file = 'README'
15
+ self.testlib = :minitest
16
+
17
+ extra_dev_deps << ['rake-compiler', '>= 0.4.1']
18
+
19
+ self.spec_extras = {
20
+ :extensions => ["ext/usb/extconf.rb"],
21
+ :homepage => 'http://www.a-k-r.org/ruby-usb/'
22
+ }
23
+
24
+ Rake::ExtensionTask.new "usb", spec do |ext|
25
+ ext.lib_dir = File.join(*['lib', ENV['FAT_DIR']].compact)
26
+ end
27
+ end
28
+
29
+ task :test => :compile
@@ -0,0 +1,86 @@
1
+ /*
2
+ constants.h - libusb constants
3
+
4
+ Copyright (C) 2007 Tanaka Akira
5
+
6
+ This library is free software; you can redistribute it and/or
7
+ modify it under the terms of the GNU Lesser General Public
8
+ License as published by the Free Software Foundation; either
9
+ version 2.1 of the License, or (at your option) any later version.
10
+
11
+ This library is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ Lesser General Public License for more details.
15
+
16
+ You should have received a copy of the GNU Lesser General Public
17
+ License along with this library; if not, write to the Free Software
18
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
+ */
20
+
21
+ f(USB_CLASS_PER_INTERFACE)
22
+ f(USB_CLASS_AUDIO)
23
+ f(USB_CLASS_COMM)
24
+ f(USB_CLASS_HID)
25
+ f(USB_CLASS_PRINTER)
26
+ #ifdef USB_CLASS_PTP
27
+ f(USB_CLASS_PTP)
28
+ #endif
29
+ f(USB_CLASS_MASS_STORAGE)
30
+ f(USB_CLASS_HUB)
31
+ f(USB_CLASS_DATA)
32
+ f(USB_CLASS_VENDOR_SPEC)
33
+ f(USB_DT_DEVICE)
34
+ f(USB_DT_CONFIG)
35
+ f(USB_DT_STRING)
36
+ f(USB_DT_INTERFACE)
37
+ f(USB_DT_ENDPOINT)
38
+ f(USB_DT_HID)
39
+ f(USB_DT_REPORT)
40
+ f(USB_DT_PHYSICAL)
41
+ f(USB_DT_HUB)
42
+ f(USB_DT_DEVICE_SIZE)
43
+ f(USB_DT_CONFIG_SIZE)
44
+ f(USB_DT_INTERFACE_SIZE)
45
+ f(USB_DT_ENDPOINT_SIZE)
46
+ f(USB_DT_ENDPOINT_AUDIO_SIZE)
47
+ f(USB_DT_HUB_NONVAR_SIZE)
48
+ f(USB_MAXENDPOINTS)
49
+ f(USB_ENDPOINT_ADDRESS_MASK)
50
+ f(USB_ENDPOINT_DIR_MASK)
51
+ f(USB_ENDPOINT_TYPE_MASK)
52
+ f(USB_ENDPOINT_TYPE_CONTROL)
53
+ f(USB_ENDPOINT_TYPE_ISOCHRONOUS)
54
+ f(USB_ENDPOINT_TYPE_BULK)
55
+ f(USB_ENDPOINT_TYPE_INTERRUPT)
56
+ f(USB_MAXINTERFACES)
57
+ f(USB_MAXALTSETTING)
58
+ f(USB_MAXCONFIG)
59
+ f(USB_REQ_GET_STATUS)
60
+ f(USB_REQ_CLEAR_FEATURE)
61
+ f(USB_REQ_SET_FEATURE)
62
+ f(USB_REQ_SET_ADDRESS)
63
+ f(USB_REQ_GET_DESCRIPTOR)
64
+ f(USB_REQ_SET_DESCRIPTOR)
65
+ f(USB_REQ_GET_CONFIGURATION)
66
+ f(USB_REQ_SET_CONFIGURATION)
67
+ f(USB_REQ_GET_INTERFACE)
68
+ f(USB_REQ_SET_INTERFACE)
69
+ f(USB_REQ_SYNCH_FRAME)
70
+ f(USB_TYPE_STANDARD)
71
+ f(USB_TYPE_CLASS)
72
+ f(USB_TYPE_VENDOR)
73
+ f(USB_TYPE_RESERVED)
74
+ f(USB_RECIP_DEVICE)
75
+ f(USB_RECIP_INTERFACE)
76
+ f(USB_RECIP_ENDPOINT)
77
+ f(USB_RECIP_OTHER)
78
+ f(USB_ENDPOINT_IN)
79
+ f(USB_ENDPOINT_OUT)
80
+ f(USB_ERROR_BEGIN)
81
+ #ifdef LIBUSB_HAS_GET_DRIVER_NP
82
+ f(LIBUSB_HAS_GET_DRIVER_NP)
83
+ #endif
84
+ #ifdef LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP
85
+ f(LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP)
86
+ #endif
@@ -0,0 +1,29 @@
1
+ # Copyright (C) 2006 Tanaka Akira. All rights reserved.
2
+ #
3
+ # Redistribution and use in source and binary forms, with or without
4
+ # modification, are permitted provided that the following conditions
5
+ # are met:
6
+ # 1. Redistributions of source code must retain the above copyright
7
+ # notice, this list of conditions and the following disclaimer.
8
+ # 2. Redistributions in binary form must reproduce the above copyright
9
+ # notice, this list of conditions and the following disclaimer in the
10
+ # documentation and/or other materials provided with the distribution.
11
+ #
12
+ # THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
13
+ # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15
+ # ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
16
+ # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
18
+ # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19
+ # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20
+ # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
21
+ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
22
+ # SUCH DAMAGE.
23
+
24
+ require 'mkmf'
25
+
26
+ have_library("usb", "usb_init")
27
+ have_header("ruby/st.h")
28
+
29
+ create_makefile('usb')
@@ -0,0 +1,935 @@
1
+ /*
2
+ usb.c - libusb interface for Ruby.
3
+
4
+ Copyright (C) 2007 Tanaka Akira
5
+
6
+ This library is free software; you can redistribute it and/or
7
+ modify it under the terms of the GNU Lesser General Public
8
+ License as published by the Free Software Foundation; either
9
+ version 2.1 of the License, or (at your option) any later version.
10
+
11
+ This library is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ Lesser General Public License for more details.
15
+
16
+ You should have received a copy of the GNU Lesser General Public
17
+ License along with this library; if not, write to the Free Software
18
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
+ */
20
+
21
+ #include "ruby.h"
22
+ #ifdef HAVE_RUBY_ST_H
23
+ #include "ruby/st.h"
24
+ #else
25
+ #include "st.h"
26
+ #endif
27
+ #include <usb.h>
28
+ #include <errno.h>
29
+
30
+ #ifndef RSTRING_PTR
31
+ # define RSTRING_PTR(s) (RSTRING(s)->ptr)
32
+ # define RSTRING_LEN(s) (RSTRING(s)->len)
33
+ #endif
34
+
35
+ static VALUE rb_cUSB;
36
+
37
+ static VALUE rusb_dev_handle_new(usb_dev_handle *h);
38
+
39
+ #define define_usb_struct(c_name, ruby_name) \
40
+ static VALUE rb_cUSB_ ## ruby_name; \
41
+ static st_table *c_name ## _objects; \
42
+ typedef struct { struct usb_ ## c_name *ptr; VALUE parent; } rusb_ ## c_name ## _t; \
43
+ static void rusb_ ## c_name ## _free(void *p) { \
44
+ if (p) free(p); \
45
+ } \
46
+ static VALUE rusb_ ## c_name ## _make(struct usb_ ## c_name *p, VALUE parent) \
47
+ { \
48
+ VALUE v; \
49
+ rusb_ ## c_name ## _t *d; \
50
+ if (p == NULL) { return Qnil; } \
51
+ if (st_lookup(c_name ## _objects, (st_data_t)p, (st_data_t *)&v)) \
52
+ return v; \
53
+ d = (rusb_ ## c_name ## _t *)xmalloc(sizeof(*d)); \
54
+ d->ptr = p; \
55
+ d->parent = parent; \
56
+ v = Data_Wrap_Struct(rb_cUSB_ ## ruby_name, 0, rusb_ ## c_name ## _free, d); \
57
+ st_add_direct(c_name ## _objects, (st_data_t)p, (st_data_t)v); \
58
+ return v; \
59
+ } \
60
+ static rusb_ ## c_name ## _t *check_usb_ ## c_name(VALUE v) \
61
+ { \
62
+ Check_Type(v, T_DATA); \
63
+ if (RDATA(v)->dfree != rusb_ ## c_name ## _free) { \
64
+ rb_raise(rb_eTypeError, "wrong argument type %s (expected USB::" #ruby_name ")", \
65
+ rb_class2name(CLASS_OF(v))); \
66
+ } \
67
+ return DATA_PTR(v); \
68
+ } \
69
+ static rusb_ ## c_name ## _t *get_rusb_ ## c_name(VALUE v) \
70
+ { \
71
+ rusb_ ## c_name ## _t *d = check_usb_ ## c_name(v); \
72
+ if (!d) { \
73
+ rb_raise(rb_eArgError, "revoked USB::" #ruby_name); \
74
+ } \
75
+ return d; \
76
+ } \
77
+ static struct usb_ ## c_name *get_usb_ ## c_name(VALUE v) \
78
+ { \
79
+ return get_rusb_ ## c_name(v)->ptr; \
80
+ } \
81
+ static VALUE get_usb_ ## c_name ## _parent(VALUE v) \
82
+ { \
83
+ return get_rusb_ ## c_name(v)->parent; \
84
+ }
85
+
86
+ define_usb_struct(bus, Bus)
87
+ define_usb_struct(device, Device)
88
+ define_usb_struct(config_descriptor, Configuration)
89
+ define_usb_struct(interface, Interface)
90
+ define_usb_struct(interface_descriptor, Setting)
91
+ define_usb_struct(endpoint_descriptor, Endpoint)
92
+
93
+ static int mark_data_i(st_data_t key, st_data_t val, st_data_t arg)
94
+ {
95
+ if (DATA_PTR((VALUE)val))
96
+ rb_gc_mark((VALUE)val);
97
+ return ST_CONTINUE;
98
+ }
99
+
100
+ VALUE rusb_gc_root;
101
+ static void rusb_gc_mark(void *p) {
102
+ st_foreach(bus_objects, mark_data_i, 0);
103
+ st_foreach(device_objects, mark_data_i, 0);
104
+ st_foreach(config_descriptor_objects, mark_data_i, 0);
105
+ st_foreach(interface_objects, mark_data_i, 0);
106
+ st_foreach(interface_descriptor_objects, mark_data_i, 0);
107
+ st_foreach(endpoint_descriptor_objects, mark_data_i, 0);
108
+ }
109
+
110
+ /* -------- USB::Bus -------- */
111
+ static int revoke_data_i(st_data_t key, st_data_t val, st_data_t arg)
112
+ {
113
+ DATA_PTR((VALUE)val) = NULL;
114
+ return ST_DELETE;
115
+ }
116
+
117
+ /* USB.find_busses */
118
+ static VALUE
119
+ rusb_find_busses(VALUE cUSB)
120
+ {
121
+ st_foreach(bus_objects, revoke_data_i, 0);
122
+ st_foreach(device_objects, revoke_data_i, 0);
123
+ st_foreach(config_descriptor_objects, revoke_data_i, 0);
124
+ st_foreach(interface_objects, revoke_data_i, 0);
125
+ st_foreach(interface_descriptor_objects, revoke_data_i, 0);
126
+ st_foreach(endpoint_descriptor_objects, revoke_data_i, 0);
127
+ return INT2NUM(usb_find_busses());
128
+ }
129
+
130
+ /* USB.find_devices */
131
+ static VALUE
132
+ rusb_find_devices(VALUE cUSB)
133
+ {
134
+ return INT2NUM(usb_find_devices());
135
+ }
136
+
137
+ /* USB.first_bus */
138
+ static VALUE
139
+ rusb_first_bus(VALUE cUSB)
140
+ {
141
+ struct usb_bus *bus = usb_get_busses();
142
+ return rusb_bus_make(bus, Qnil);
143
+ }
144
+
145
+ /* USB::Bus#revoked? */
146
+ static VALUE
147
+ rusb_bus_revoked_p(VALUE v)
148
+ {
149
+ return RTEST(!check_usb_bus(v));
150
+ }
151
+
152
+ /* USB::Bus#prev */
153
+ static VALUE rusb_bus_prev(VALUE v) { return rusb_bus_make(get_usb_bus(v)->prev, Qnil); }
154
+
155
+ /* USB::Bus#next */
156
+ static VALUE rusb_bus_next(VALUE v) { return rusb_bus_make(get_usb_bus(v)->next, Qnil); }
157
+
158
+ /* USB::Bus#dirname */
159
+ static VALUE rusb_bus_dirname(VALUE v) { return rb_str_new2(get_usb_bus(v)->dirname); }
160
+
161
+ /* USB::Bus#location */
162
+ static VALUE rusb_bus_location(VALUE v) { return UINT2NUM(get_usb_bus(v)->location); }
163
+
164
+ /* USB::Bus#first_device */
165
+ static VALUE rusb_bus_first_device(VALUE v) { return rusb_device_make(get_usb_bus(v)->devices, v); }
166
+
167
+ /* -------- USB::Device -------- */
168
+
169
+ /* USB::Bus#revoked? */
170
+ static VALUE
171
+ rusb_device_revoked_p(VALUE v)
172
+ {
173
+ return RTEST(!check_usb_device(v));
174
+ }
175
+
176
+ /* USB::Device#prev */
177
+ static VALUE rusb_device_prev(VALUE v) { rusb_device_t *device = get_rusb_device(v); return rusb_device_make(device->ptr->prev, device->parent); }
178
+
179
+ /* USB::Device#next */
180
+ static VALUE rusb_device_next(VALUE v) { rusb_device_t *device = get_rusb_device(v); return rusb_device_make(device->ptr->next, device->parent); }
181
+
182
+ /* USB::Device#filename */
183
+ static VALUE rusb_device_filename(VALUE v) { return rb_str_new2(get_usb_device(v)->filename); }
184
+
185
+ /* USB::Device#bus */
186
+ static VALUE rusb_device_bus(VALUE v) { return rusb_bus_make(get_usb_device(v)->bus, Qnil); }
187
+
188
+ /* USB::Device#devnum */
189
+ static VALUE rusb_device_devnum(VALUE v) { return INT2FIX(get_usb_device(v)->devnum); }
190
+
191
+ /* USB::Device#num_children */
192
+ static VALUE rusb_device_num_children(VALUE v) { return INT2FIX(get_usb_device(v)->num_children); }
193
+
194
+ /* USB::Device#children */
195
+ static VALUE
196
+ rusb_device_children(VALUE vdevice)
197
+ {
198
+ rusb_device_t *d = get_rusb_device(vdevice);
199
+ struct usb_device *device = d->ptr;
200
+ int i;
201
+ VALUE children = rb_ary_new2(device->num_children);
202
+ for (i = 0; i < device->num_children; i++)
203
+ rb_ary_store(children, i, rusb_device_make(device->children[i], d->parent));
204
+ return children;
205
+ }
206
+
207
+ /* USB::Device#descriptor_bLength */
208
+ static VALUE rusb_devdesc_bLength(VALUE v) { return INT2FIX(get_usb_device(v)->descriptor.bLength); }
209
+
210
+ /* USB::Device#descriptor_bDescriptorType */
211
+ static VALUE rusb_devdesc_bDescriptorType(VALUE v) { return INT2FIX(get_usb_device(v)->descriptor.bDescriptorType); }
212
+
213
+ /* USB::Device#descriptor_bcdUSB */
214
+ static VALUE rusb_devdesc_bcdUSB(VALUE v) { return INT2FIX(get_usb_device(v)->descriptor.bcdUSB); }
215
+
216
+ /* USB::Device#descriptor_bDeviceClass */
217
+ static VALUE rusb_devdesc_bDeviceClass(VALUE v) { return INT2FIX(get_usb_device(v)->descriptor.bDeviceClass); }
218
+
219
+ /* USB::Device#descriptor_bDeviceSubClass */
220
+ static VALUE rusb_devdesc_bDeviceSubClass(VALUE v) { return INT2FIX(get_usb_device(v)->descriptor.bDeviceSubClass); }
221
+
222
+ /* USB::Device#descriptor_bDeviceProtocol */
223
+ static VALUE rusb_devdesc_bDeviceProtocol(VALUE v) { return INT2FIX(get_usb_device(v)->descriptor.bDeviceProtocol); }
224
+
225
+ /* USB::Device#descriptor_bMaxPacketSize0 */
226
+ static VALUE rusb_devdesc_bMaxPacketSize0(VALUE v) { return INT2FIX(get_usb_device(v)->descriptor.bMaxPacketSize0); }
227
+
228
+ /* USB::Device#descriptor_idVendor */
229
+ static VALUE rusb_devdesc_idVendor(VALUE v) { return INT2FIX(get_usb_device(v)->descriptor.idVendor); }
230
+
231
+ /* USB::Device#descriptor_idProduct */
232
+ static VALUE rusb_devdesc_idProduct(VALUE v) { return INT2FIX(get_usb_device(v)->descriptor.idProduct); }
233
+
234
+ /* USB::Device#descriptor_bcdDevice */
235
+ static VALUE rusb_devdesc_bcdDevice(VALUE v) { return INT2FIX(get_usb_device(v)->descriptor.bcdDevice); }
236
+
237
+ /* USB::Device#descriptor_iManufacturer */
238
+ static VALUE rusb_devdesc_iManufacturer(VALUE v) { return INT2FIX(get_usb_device(v)->descriptor.iManufacturer); }
239
+
240
+ /* USB::Device#descriptor_iProduct */
241
+ static VALUE rusb_devdesc_iProduct(VALUE v) { return INT2FIX(get_usb_device(v)->descriptor.iProduct); }
242
+
243
+ /* USB::Device#descriptor_iSerialNumber */
244
+ static VALUE rusb_devdesc_iSerialNumber(VALUE v) { return INT2FIX(get_usb_device(v)->descriptor.iSerialNumber); }
245
+
246
+ /* USB::Device#descriptor_bNumConfigurations */
247
+ static VALUE rusb_devdesc_bNumConfigurations(VALUE v) { return INT2FIX(get_usb_device(v)->descriptor.bNumConfigurations); }
248
+
249
+ /* USB::Device#configurations */
250
+ static VALUE
251
+ rusb_device_config(VALUE v)
252
+ {
253
+ struct usb_device *device = get_usb_device(v);
254
+ int i;
255
+ VALUE children = rb_ary_new2(device->descriptor.bNumConfigurations);
256
+ for (i = 0; i < device->descriptor.bNumConfigurations; i++)
257
+ rb_ary_store(children, i, rusb_config_descriptor_make(&device->config[i], v));
258
+ return children;
259
+ }
260
+
261
+ /* USB::Device#usb_open */
262
+ static VALUE
263
+ rusb_device_open(VALUE vdevice)
264
+ {
265
+ struct usb_device *device = get_usb_device(vdevice);
266
+ usb_dev_handle *h = usb_open(device);
267
+ return rusb_dev_handle_new(h);
268
+ }
269
+
270
+ /* -------- USB::Configuration -------- */
271
+
272
+ /* USB::Configuration#revoked? */
273
+ static VALUE
274
+ rusb_config_revoked_p(VALUE v)
275
+ {
276
+ return RTEST(!check_usb_config_descriptor(v));
277
+ }
278
+
279
+ /* USB::Configuration#device */
280
+ static VALUE rusb_config_device(VALUE v) { return get_rusb_config_descriptor(v)->parent; }
281
+
282
+ /* USB::Configuration#bLength */
283
+ static VALUE rusb_config_bLength(VALUE v) { return INT2FIX(get_usb_config_descriptor(v)->bLength); }
284
+
285
+ /* USB::Configuration#bDescriptorType */
286
+ static VALUE rusb_config_bDescriptorType(VALUE v) { return INT2FIX(get_usb_config_descriptor(v)->bDescriptorType); }
287
+
288
+ /* USB::Configuration#wTotalLength */
289
+ static VALUE rusb_config_wTotalLength(VALUE v) { return INT2FIX(get_usb_config_descriptor(v)->wTotalLength); }
290
+
291
+ /* USB::Configuration#bNumInterfaces */
292
+ static VALUE rusb_config_bNumInterfaces(VALUE v) { return INT2FIX(get_usb_config_descriptor(v)->bNumInterfaces); }
293
+
294
+ /* USB::Configuration#bConfigurationValue */
295
+ static VALUE rusb_config_bConfigurationValue(VALUE v) { return INT2FIX(get_usb_config_descriptor(v)->bConfigurationValue); }
296
+
297
+ /* USB::Configuration#iConfiguration */
298
+ static VALUE rusb_config_iConfiguration(VALUE v) { return INT2FIX(get_usb_config_descriptor(v)->iConfiguration); }
299
+
300
+ /* USB::Configuration#bmAttributes */
301
+ static VALUE rusb_config_bmAttributes(VALUE v) { return INT2FIX(get_usb_config_descriptor(v)->bmAttributes); }
302
+
303
+ /* USB::Configuration#bMaxPower */
304
+ static VALUE rusb_config_bMaxPower(VALUE v) { return INT2FIX(get_usb_config_descriptor(v)->MaxPower); }
305
+
306
+ /* USB::Configuration#interfaces */
307
+ static VALUE
308
+ rusb_config_interfaces(VALUE v)
309
+ {
310
+ struct usb_config_descriptor *p = get_usb_config_descriptor(v);
311
+ int i;
312
+ VALUE interface = rb_ary_new2(p->bNumInterfaces);
313
+ for (i = 0; i < p->bNumInterfaces; i++)
314
+ rb_ary_store(interface, i, rusb_interface_make(&p->interface[i], v));
315
+ return interface;
316
+ }
317
+
318
+ /* -------- USB::Interface -------- */
319
+
320
+ /* USB::Interface#revoked? */
321
+ static VALUE
322
+ rusb_interface_revoked_p(VALUE v)
323
+ {
324
+ return RTEST(!check_usb_interface(v));
325
+ }
326
+
327
+ /* USB::Interface#configuration */
328
+ static VALUE rusb_interface_configuration(VALUE v) { return get_rusb_interface(v)->parent; }
329
+
330
+ /* USB::Interface#num_altsetting */
331
+ static VALUE rusb_interface_num_altsetting(VALUE v) { return INT2FIX(get_usb_interface(v)->num_altsetting); }
332
+
333
+ /* USB::Interface#settings */
334
+ static VALUE
335
+ rusb_interface_settings(VALUE v)
336
+ {
337
+ struct usb_interface *p = get_usb_interface(v);
338
+ int i;
339
+ VALUE altsetting = rb_ary_new2(p->num_altsetting);
340
+ for (i = 0; i < p->num_altsetting; i++)
341
+ rb_ary_store(altsetting, i, rusb_interface_descriptor_make(&p->altsetting[i], v));
342
+ return altsetting;
343
+ }
344
+
345
+ /* -------- USB::Setting -------- */
346
+
347
+ /* USB::Setting#revoked? */
348
+ static VALUE
349
+ rusb_setting_revoked_p(VALUE v)
350
+ {
351
+ return RTEST(!check_usb_interface_descriptor(v));
352
+ }
353
+
354
+ /* USB::Interface#interface */
355
+ static VALUE rusb_setting_interface(VALUE v) { return get_rusb_interface_descriptor(v)->parent; }
356
+
357
+ /* USB::Setting#bLength */
358
+ static VALUE rusb_setting_bLength(VALUE v) { return INT2FIX(get_usb_interface_descriptor(v)->bLength); }
359
+
360
+ /* USB::Setting#bDescriptorType */
361
+ static VALUE rusb_setting_bDescriptorType(VALUE v) { return INT2FIX(get_usb_interface_descriptor(v)->bDescriptorType); }
362
+
363
+ /* USB::Setting#bInterfaceNumber */
364
+ static VALUE rusb_setting_bInterfaceNumber(VALUE v) { return INT2FIX(get_usb_interface_descriptor(v)->bInterfaceNumber); }
365
+
366
+ /* USB::Setting#bAlternateSetting */
367
+ static VALUE rusb_setting_bAlternateSetting(VALUE v) { return INT2FIX(get_usb_interface_descriptor(v)->bAlternateSetting); }
368
+
369
+ /* USB::Setting#bNumEndpoints */
370
+ static VALUE rusb_setting_bNumEndpoints(VALUE v) { return INT2FIX(get_usb_interface_descriptor(v)->bNumEndpoints); }
371
+
372
+ /* USB::Setting#bInterfaceClass */
373
+ static VALUE rusb_setting_bInterfaceClass(VALUE v) { return INT2FIX(get_usb_interface_descriptor(v)->bInterfaceClass); }
374
+
375
+ /* USB::Setting#bInterfaceSubClass */
376
+ static VALUE rusb_setting_bInterfaceSubClass(VALUE v) { return INT2FIX(get_usb_interface_descriptor(v)->bInterfaceSubClass); }
377
+
378
+ /* USB::Setting#bInterfaceProtocol */
379
+ static VALUE rusb_setting_bInterfaceProtocol(VALUE v) { return INT2FIX(get_usb_interface_descriptor(v)->bInterfaceProtocol); }
380
+
381
+ /* USB::Setting#iInterface */
382
+ static VALUE rusb_setting_iInterface(VALUE v) { return INT2FIX(get_usb_interface_descriptor(v)->iInterface); }
383
+
384
+ /* USB::Setting#endpoints */
385
+ static VALUE
386
+ rusb_setting_endpoints(VALUE v)
387
+ {
388
+ struct usb_interface_descriptor *p = get_usb_interface_descriptor(v);
389
+ int i;
390
+ VALUE endpoint = rb_ary_new2(p->bNumEndpoints);
391
+ for (i = 0; i < p->bNumEndpoints; i++)
392
+ rb_ary_store(endpoint, i, rusb_endpoint_descriptor_make(&p->endpoint[i], v));
393
+ return endpoint;
394
+ }
395
+
396
+ /* -------- USB::Endpoint -------- */
397
+
398
+ /* USB::Endpoint#revoked? */
399
+ static VALUE
400
+ rusb_endpoint_revoked_p(VALUE v)
401
+ {
402
+ return RTEST(!check_usb_endpoint_descriptor(v));
403
+ }
404
+
405
+ /* USB::Endpoint#setting */
406
+ static VALUE rusb_endpoint_setting(VALUE v) { return get_rusb_endpoint_descriptor(v)->parent; }
407
+
408
+ /* USB::Endpoint#bLength */
409
+ static VALUE rusb_endpoint_bLength(VALUE v) { return INT2FIX(get_usb_endpoint_descriptor(v)->bLength); }
410
+
411
+ /* USB::Endpoint#bDescriptorType */
412
+ static VALUE rusb_endpoint_bDescriptorType(VALUE v) { return INT2FIX(get_usb_endpoint_descriptor(v)->bDescriptorType); }
413
+
414
+ /* USB::Endpoint#bEndpointAddress */
415
+ static VALUE rusb_endpoint_bEndpointAddress(VALUE v) { return INT2FIX(get_usb_endpoint_descriptor(v)->bEndpointAddress); }
416
+
417
+ /* USB::Endpoint#bmAttributes */
418
+ static VALUE rusb_endpoint_bmAttributes(VALUE v) { return INT2FIX(get_usb_endpoint_descriptor(v)->bmAttributes); }
419
+
420
+ /* USB::Endpoint#wMaxPacketSize */
421
+ static VALUE rusb_endpoint_wMaxPacketSize(VALUE v) { return INT2FIX(get_usb_endpoint_descriptor(v)->wMaxPacketSize); }
422
+
423
+ /* USB::Endpoint#bInterval */
424
+ static VALUE rusb_endpoint_bInterval(VALUE v) { return INT2FIX(get_usb_endpoint_descriptor(v)->bInterval); }
425
+
426
+ /* USB::Endpoint#bRefresh */
427
+ static VALUE rusb_endpoint_bRefresh(VALUE v) { return INT2FIX(get_usb_endpoint_descriptor(v)->bRefresh); }
428
+
429
+ /* USB::Endpoint#bSynchAddress */
430
+ static VALUE rusb_endpoint_bSynchAddress(VALUE v) { return INT2FIX(get_usb_endpoint_descriptor(v)->bSynchAddress); }
431
+
432
+ /* -------- USB::DevHandle -------- */
433
+
434
+ static VALUE rb_cUSB_DevHandle;
435
+
436
+ void rusb_devhandle_free(void *_h)
437
+ {
438
+ usb_dev_handle *h = (usb_dev_handle *)_h;
439
+ if (h) usb_close(h);
440
+ }
441
+
442
+ static VALUE
443
+ rusb_dev_handle_new(usb_dev_handle *h)
444
+ {
445
+ return Data_Wrap_Struct(rb_cUSB_DevHandle, 0, rusb_devhandle_free, h);
446
+ }
447
+
448
+ static usb_dev_handle *check_usb_devhandle(VALUE v)
449
+ {
450
+ Check_Type(v, T_DATA);
451
+ if (RDATA(v)->dfree != rusb_devhandle_free) {
452
+ rb_raise(rb_eTypeError, "wrong argument type %s (expected USB::DevHandle)",
453
+ rb_class2name(CLASS_OF(v)));
454
+ }
455
+ return DATA_PTR(v);
456
+ }
457
+
458
+ static usb_dev_handle *get_usb_devhandle(VALUE v)
459
+ {
460
+ usb_dev_handle *p = check_usb_devhandle(v); \
461
+ if (!p) {
462
+ rb_raise(rb_eArgError, "closed USB::DevHandle");
463
+ }
464
+ return p;
465
+ }
466
+
467
+ static int check_usb_error(char *reason, int ret)
468
+ {
469
+ if (ret < 0) {
470
+ errno = -ret;
471
+ rb_sys_fail(reason);
472
+ }
473
+ return ret;
474
+ }
475
+
476
+ /* USB::DevHandle#usb_close */
477
+ static VALUE
478
+ rusb_close(VALUE v)
479
+ {
480
+ usb_dev_handle *p = get_usb_devhandle(v);
481
+ check_usb_error("usb_close", usb_close(p));
482
+ DATA_PTR(v) = NULL;
483
+ return Qnil;
484
+ }
485
+
486
+ /* USB::DevHandle#usb_set_configuration(configuration) */
487
+ static VALUE
488
+ rusb_set_configuration(VALUE v, VALUE configuration)
489
+ {
490
+ usb_dev_handle *p = get_usb_devhandle(v);
491
+ int ret = usb_set_configuration(p, NUM2INT(configuration));
492
+ check_usb_error("usb_set_configuration", ret);
493
+ return Qnil;
494
+ }
495
+
496
+ /* USB::DevHandle#usb_set_altinterface(alternate) */
497
+ static VALUE
498
+ rusb_set_altinterface(VALUE v, VALUE alternate)
499
+ {
500
+ usb_dev_handle *p = get_usb_devhandle(v);
501
+ int ret = usb_set_altinterface(p, NUM2INT(alternate));
502
+ check_usb_error("usb_set_altinterface", ret);
503
+ return Qnil;
504
+ }
505
+
506
+ /* USB::DevHandle#usb_clear_halt(endpoint) */
507
+ static VALUE
508
+ rusb_clear_halt(VALUE v, VALUE ep)
509
+ {
510
+ usb_dev_handle *p = get_usb_devhandle(v);
511
+ int ret = usb_clear_halt(p, NUM2UINT(ep));
512
+ check_usb_error("usb_clear_halt", ret);
513
+ return Qnil;
514
+ }
515
+
516
+ /* USB::DevHandle#usb_reset */
517
+ static VALUE
518
+ rusb_reset(VALUE v)
519
+ {
520
+ usb_dev_handle *p = get_usb_devhandle(v);
521
+ int ret = usb_reset(p);
522
+ check_usb_error("usb_reset", ret);
523
+ /* xxx: call usb_close? */
524
+ return Qnil;
525
+ }
526
+
527
+ /* USB::DevHandle#usb_claim_interface(interface) */
528
+ static VALUE
529
+ rusb_claim_interface(VALUE v, VALUE interface)
530
+ {
531
+ usb_dev_handle *p = get_usb_devhandle(v);
532
+ int ret = usb_claim_interface(p, NUM2INT(interface));
533
+ check_usb_error("usb_claim_interface", ret);
534
+ return Qnil;
535
+ }
536
+
537
+ /* USB::DevHandle#usb_release_interface(interface) */
538
+ static VALUE
539
+ rusb_release_interface(VALUE v, VALUE interface)
540
+ {
541
+ usb_dev_handle *p = get_usb_devhandle(v);
542
+ int ret = usb_release_interface(p, NUM2INT(interface));
543
+ check_usb_error("usb_release_interface", ret);
544
+ return Qnil;
545
+ }
546
+
547
+ /* USB::DevHandle#usb_control_msg(requesttype, request, value, index, bytes, timeout) */
548
+ static VALUE
549
+ rusb_control_msg(
550
+ VALUE v,
551
+ VALUE vrequesttype,
552
+ VALUE vrequest,
553
+ VALUE vvalue,
554
+ VALUE vindex,
555
+ VALUE vbytes,
556
+ VALUE vtimeout)
557
+ {
558
+ usb_dev_handle *p = get_usb_devhandle(v);
559
+ int requesttype = NUM2INT(vrequesttype);
560
+ int request = NUM2INT(vrequest);
561
+ int value = NUM2INT(vvalue);
562
+ int index = NUM2INT(vindex);
563
+ int timeout = NUM2INT(vtimeout);
564
+ char *bytes;
565
+ int size;
566
+ int ret;
567
+ StringValue(vbytes);
568
+ rb_str_modify(vbytes);
569
+ bytes = RSTRING_PTR(vbytes);
570
+ size = RSTRING_LEN(vbytes);
571
+ ret = usb_control_msg(p, requesttype, request, value, index, bytes, size, timeout);
572
+ check_usb_error("usb_control_msg", ret);
573
+ return INT2NUM(ret);
574
+ }
575
+
576
+ /* USB::DevHandle#usb_get_string(index, langid, buf) */
577
+ static VALUE
578
+ rusb_get_string(
579
+ VALUE v,
580
+ VALUE vindex,
581
+ VALUE vlangid,
582
+ VALUE vbuf)
583
+ {
584
+ usb_dev_handle *p = get_usb_devhandle(v);
585
+ int index = NUM2INT(vindex);
586
+ int langid = NUM2INT(vlangid);
587
+ char *buf;
588
+ int buflen;
589
+ int ret;
590
+ StringValue(vbuf);
591
+ rb_str_modify(vbuf);
592
+ buf = RSTRING_PTR(vbuf);
593
+ buflen = RSTRING_LEN(vbuf);
594
+ ret = usb_get_string(p, index, langid, buf, buflen);
595
+ check_usb_error("usb_get_string", ret);
596
+ return INT2NUM(ret);
597
+ }
598
+
599
+ /* USB::DevHandle#usb_get_string_simple(index, buf) */
600
+ static VALUE
601
+ rusb_get_string_simple(
602
+ VALUE v,
603
+ VALUE vindex,
604
+ VALUE vbuf)
605
+ {
606
+ usb_dev_handle *p = get_usb_devhandle(v);
607
+ int index = NUM2INT(vindex);
608
+ char *buf;
609
+ int buflen;
610
+ int ret;
611
+ StringValue(vbuf);
612
+ rb_str_modify(vbuf);
613
+ buf = RSTRING_PTR(vbuf);
614
+ buflen = RSTRING_LEN(vbuf);
615
+ ret = usb_get_string_simple(p, index, buf, buflen);
616
+ check_usb_error("usb_get_string_simple", ret);
617
+ return INT2NUM(ret);
618
+ }
619
+
620
+ /* USB::DevHandle#usb_get_descriptor(type, index, buf) */
621
+ static VALUE
622
+ rusb_get_descriptor(
623
+ VALUE v,
624
+ VALUE vtype,
625
+ VALUE vindex,
626
+ VALUE vbuf)
627
+ {
628
+ usb_dev_handle *p = get_usb_devhandle(v);
629
+ int type = NUM2INT(vtype);
630
+ int index = NUM2INT(vindex);
631
+ char *buf;
632
+ int buflen;
633
+ int ret;
634
+ StringValue(vbuf);
635
+ rb_str_modify(vbuf);
636
+ buf = RSTRING_PTR(vbuf);
637
+ buflen = RSTRING_LEN(vbuf);
638
+ ret = usb_get_descriptor(p, type, index, buf, buflen);
639
+ check_usb_error("usb_get_descriptor", ret);
640
+ return INT2NUM(ret);
641
+ }
642
+
643
+ /* USB::DevHandle#usb_get_descriptor_by_endpoint(endpoint, type, index, buf) */
644
+ static VALUE
645
+ rusb_get_descriptor_by_endpoint(
646
+ VALUE v,
647
+ VALUE vep,
648
+ VALUE vtype,
649
+ VALUE vindex,
650
+ VALUE vbuf)
651
+ {
652
+ usb_dev_handle *p = get_usb_devhandle(v);
653
+ int ep = NUM2INT(vep);
654
+ int type = NUM2INT(vtype);
655
+ int index = NUM2INT(vindex);
656
+ char *buf;
657
+ int buflen;
658
+ int ret;
659
+ StringValue(vbuf);
660
+ rb_str_modify(vbuf);
661
+ buf = RSTRING_PTR(vbuf);
662
+ buflen = RSTRING_LEN(vbuf);
663
+ ret = usb_get_descriptor_by_endpoint(p, ep, type, index, buf, buflen);
664
+ check_usb_error("usb_get_descriptor_by_endpoint", ret);
665
+ return INT2NUM(ret);
666
+ }
667
+
668
+ /* USB::DevHandle#usb_bulk_write(endpoint, bytes, timeout) */
669
+ static VALUE
670
+ rusb_bulk_write(
671
+ VALUE v,
672
+ VALUE vep,
673
+ VALUE vbytes,
674
+ VALUE vtimeout)
675
+ {
676
+ usb_dev_handle *p = get_usb_devhandle(v);
677
+ int ep = NUM2INT(vep);
678
+ int timeout = NUM2INT(vtimeout);
679
+ char *bytes;
680
+ int size;
681
+ int ret;
682
+ StringValue(vbytes);
683
+ bytes = RSTRING_PTR(vbytes);
684
+ size = RSTRING_LEN(vbytes);
685
+ ret = usb_bulk_write(p, ep, bytes, size, timeout);
686
+ check_usb_error("usb_bulk_write", ret);
687
+ return INT2NUM(ret);
688
+ }
689
+
690
+ /* USB::DevHandle#usb_bulk_read(endpoint, bytes, timeout) */
691
+ static VALUE
692
+ rusb_bulk_read(
693
+ VALUE v,
694
+ VALUE vep,
695
+ VALUE vbytes,
696
+ VALUE vtimeout)
697
+ {
698
+ usb_dev_handle *p = get_usb_devhandle(v);
699
+ int ep = NUM2INT(vep);
700
+ int timeout = NUM2INT(vtimeout);
701
+ char *bytes;
702
+ int size;
703
+ int ret;
704
+ StringValue(vbytes);
705
+ rb_str_modify(vbytes);
706
+ bytes = RSTRING_PTR(vbytes);
707
+ size = RSTRING_LEN(vbytes);
708
+ ret = usb_bulk_read(p, ep, bytes, size, timeout);
709
+ check_usb_error("usb_bulk_read", ret);
710
+ return INT2NUM(ret);
711
+ }
712
+
713
+ /* USB::DevHandle#usb_interrupt_write(endpoint, bytes, timeout) */
714
+ static VALUE
715
+ rusb_interrupt_write(
716
+ VALUE v,
717
+ VALUE vep,
718
+ VALUE vbytes,
719
+ VALUE vtimeout)
720
+ {
721
+ usb_dev_handle *p = get_usb_devhandle(v);
722
+ int ep = NUM2INT(vep);
723
+ int timeout = NUM2INT(vtimeout);
724
+ char *bytes;
725
+ int size;
726
+ int ret;
727
+ StringValue(vbytes);
728
+ bytes = RSTRING_PTR(vbytes);
729
+ size = RSTRING_LEN(vbytes);
730
+ ret = usb_interrupt_write(p, ep, bytes, size, timeout);
731
+ check_usb_error("usb_interrupt_write", ret);
732
+ return INT2NUM(ret);
733
+ }
734
+
735
+ /* USB::DevHandle#usb_interrupt_read(endpoint, bytes, timeout) */
736
+ static VALUE
737
+ rusb_interrupt_read(
738
+ VALUE v,
739
+ VALUE vep,
740
+ VALUE vbytes,
741
+ VALUE vtimeout)
742
+ {
743
+ usb_dev_handle *p = get_usb_devhandle(v);
744
+ int ep = NUM2INT(vep);
745
+ int timeout = NUM2INT(vtimeout);
746
+ char *bytes;
747
+ int size;
748
+ int ret;
749
+ StringValue(vbytes);
750
+ rb_str_modify(vbytes);
751
+ bytes = RSTRING_PTR(vbytes);
752
+ size = RSTRING_LEN(vbytes);
753
+ ret = usb_interrupt_read(p, ep, bytes, size, timeout);
754
+ check_usb_error("usb_interrupt_read", ret);
755
+ return INT2NUM(ret);
756
+ }
757
+
758
+ #ifdef LIBUSB_HAS_GET_DRIVER_NP
759
+ /* USB::DevHandle#usb_get_driver_np(interface, name) */
760
+ static VALUE
761
+ rusb_get_driver_np(
762
+ VALUE v,
763
+ VALUE vinterface,
764
+ VALUE vname)
765
+ {
766
+ usb_dev_handle *p = get_usb_devhandle(v);
767
+ int interface = NUM2INT(vinterface);
768
+ char *name;
769
+ int namelen;
770
+ int ret;
771
+ StringValue(vname);
772
+ rb_str_modify(vname);
773
+ name = RSTRING_PTR(vname);
774
+ namelen = RSTRING_LEN(vname);
775
+ ret = usb_get_driver_np(p, interface, name, namelen);
776
+ check_usb_error("usb_get_driver_np", ret);
777
+ return Qnil;
778
+ }
779
+ #endif
780
+
781
+ #ifdef LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP
782
+ /* USB::DevHandle#usb_detach_kernel_driver_np(interface) */
783
+ static VALUE
784
+ rusb_detach_kernel_driver_np(
785
+ VALUE v,
786
+ VALUE vinterface)
787
+ {
788
+ usb_dev_handle *p = get_usb_devhandle(v);
789
+ int interface = NUM2INT(vinterface);
790
+ int ret;
791
+ ret = usb_detach_kernel_driver_np(p, interface);
792
+ check_usb_error("usb_detach_kernel_driver_np", ret);
793
+ return Qnil;
794
+ }
795
+ #endif
796
+
797
+ /* -------- libusb binding initialization -------- */
798
+
799
+ void
800
+ Init_usb()
801
+ {
802
+ rb_cUSB = rb_define_module("USB");
803
+
804
+ #define f(name) rb_define_const(rb_cUSB, #name, INT2NUM(name));
805
+ #include "constants.h"
806
+ #undef f
807
+
808
+ bus_objects = st_init_numtable();
809
+ rb_cUSB_Bus = rb_define_class_under(rb_cUSB, "Bus", rb_cData);
810
+
811
+ device_objects = st_init_numtable();
812
+ rb_cUSB_Device = rb_define_class_under(rb_cUSB, "Device", rb_cData);
813
+
814
+ config_descriptor_objects = st_init_numtable();
815
+ rb_cUSB_Configuration = rb_define_class_under(rb_cUSB, "Configuration", rb_cData);
816
+
817
+ interface_objects = st_init_numtable();
818
+ rb_cUSB_Interface = rb_define_class_under(rb_cUSB, "Interface", rb_cData);
819
+
820
+ interface_descriptor_objects = st_init_numtable();
821
+ rb_cUSB_Setting = rb_define_class_under(rb_cUSB, "Setting", rb_cData);
822
+
823
+ endpoint_descriptor_objects = st_init_numtable();
824
+ rb_cUSB_Endpoint = rb_define_class_under(rb_cUSB, "Endpoint", rb_cData);
825
+
826
+ rb_cUSB_DevHandle = rb_define_class_under(rb_cUSB, "DevHandle", rb_cData);
827
+
828
+ rusb_gc_root = Data_Wrap_Struct(0, rusb_gc_mark, 0, 0); \
829
+ rb_global_variable(&rusb_gc_root);
830
+
831
+ usb_init();
832
+ usb_find_busses(); /* xxx: return value */
833
+ usb_find_devices(); /* xxx: return value */
834
+
835
+ rb_define_module_function(rb_cUSB, "find_busses", rusb_find_busses, 0);
836
+ rb_define_module_function(rb_cUSB, "find_devices", rusb_find_devices, 0);
837
+ rb_define_module_function(rb_cUSB, "first_bus", rusb_first_bus, 0);
838
+
839
+ rb_define_method(rb_cUSB_Bus, "revoked?", rusb_bus_revoked_p, 0);
840
+ rb_define_method(rb_cUSB_Bus, "prev", rusb_bus_prev, 0);
841
+ rb_define_method(rb_cUSB_Bus, "next", rusb_bus_next, 0);
842
+ rb_define_method(rb_cUSB_Bus, "dirname", rusb_bus_dirname, 0);
843
+ rb_define_method(rb_cUSB_Bus, "location", rusb_bus_location, 0);
844
+ rb_define_method(rb_cUSB_Bus, "first_device", rusb_bus_first_device, 0);
845
+
846
+ rb_define_method(rb_cUSB_Device, "revoked?", rusb_device_revoked_p, 0);
847
+ rb_define_method(rb_cUSB_Device, "prev", rusb_device_prev, 0);
848
+ rb_define_method(rb_cUSB_Device, "next", rusb_device_next, 0);
849
+ rb_define_method(rb_cUSB_Device, "filename", rusb_device_filename, 0);
850
+ rb_define_method(rb_cUSB_Device, "bus", rusb_device_bus, 0);
851
+ rb_define_method(rb_cUSB_Device, "devnum", rusb_device_devnum, 0);
852
+ rb_define_method(rb_cUSB_Device, "num_children", rusb_device_num_children, 0);
853
+ rb_define_method(rb_cUSB_Device, "children", rusb_device_children, 0);
854
+ rb_define_method(rb_cUSB_Device, "bLength", rusb_devdesc_bLength, 0);
855
+ rb_define_method(rb_cUSB_Device, "bDescriptorType", rusb_devdesc_bDescriptorType, 0);
856
+ rb_define_method(rb_cUSB_Device, "bcdUSB", rusb_devdesc_bcdUSB, 0);
857
+ rb_define_method(rb_cUSB_Device, "bDeviceClass", rusb_devdesc_bDeviceClass, 0);
858
+ rb_define_method(rb_cUSB_Device, "bDeviceSubClass", rusb_devdesc_bDeviceSubClass, 0);
859
+ rb_define_method(rb_cUSB_Device, "bDeviceProtocol", rusb_devdesc_bDeviceProtocol, 0);
860
+ rb_define_method(rb_cUSB_Device, "bMaxPacketSize0", rusb_devdesc_bMaxPacketSize0, 0);
861
+ rb_define_method(rb_cUSB_Device, "idVendor", rusb_devdesc_idVendor, 0);
862
+ rb_define_method(rb_cUSB_Device, "idProduct", rusb_devdesc_idProduct, 0);
863
+ rb_define_method(rb_cUSB_Device, "bcdDevice", rusb_devdesc_bcdDevice, 0);
864
+ rb_define_method(rb_cUSB_Device, "iManufacturer", rusb_devdesc_iManufacturer, 0);
865
+ rb_define_method(rb_cUSB_Device, "iProduct", rusb_devdesc_iProduct, 0);
866
+ rb_define_method(rb_cUSB_Device, "iSerialNumber", rusb_devdesc_iSerialNumber, 0);
867
+ rb_define_method(rb_cUSB_Device, "bNumConfigurations", rusb_devdesc_bNumConfigurations, 0);
868
+ rb_define_method(rb_cUSB_Device, "configurations", rusb_device_config, 0);
869
+ rb_define_method(rb_cUSB_Device, "usb_open", rusb_device_open, 0);
870
+
871
+ rb_define_method(rb_cUSB_Configuration, "revoked?", rusb_config_revoked_p, 0);
872
+ rb_define_method(rb_cUSB_Configuration, "device", rusb_config_device, 0);
873
+ rb_define_method(rb_cUSB_Configuration, "bLength", rusb_config_bLength, 0);
874
+ rb_define_method(rb_cUSB_Configuration, "bDescriptorType", rusb_config_bDescriptorType, 0);
875
+ rb_define_method(rb_cUSB_Configuration, "wTotalLength", rusb_config_wTotalLength, 0);
876
+ rb_define_method(rb_cUSB_Configuration, "bNumInterfaces", rusb_config_bNumInterfaces, 0);
877
+ rb_define_method(rb_cUSB_Configuration, "bConfigurationValue", rusb_config_bConfigurationValue, 0);
878
+ rb_define_method(rb_cUSB_Configuration, "iConfiguration", rusb_config_iConfiguration, 0);
879
+ rb_define_method(rb_cUSB_Configuration, "bmAttributes", rusb_config_bmAttributes, 0);
880
+ rb_define_method(rb_cUSB_Configuration, "bMaxPower", rusb_config_bMaxPower, 0);
881
+ rb_define_method(rb_cUSB_Configuration, "interfaces", rusb_config_interfaces, 0);
882
+
883
+ rb_define_method(rb_cUSB_Interface, "revoked?", rusb_interface_revoked_p, 0);
884
+ rb_define_method(rb_cUSB_Interface, "configuration", rusb_interface_configuration, 0);
885
+ rb_define_method(rb_cUSB_Interface, "num_altsetting", rusb_interface_num_altsetting, 0);
886
+ rb_define_method(rb_cUSB_Interface, "settings", rusb_interface_settings, 0);
887
+
888
+ rb_define_method(rb_cUSB_Setting, "revoked?", rusb_setting_revoked_p, 0);
889
+ rb_define_method(rb_cUSB_Setting, "interface", rusb_setting_interface, 0);
890
+ rb_define_method(rb_cUSB_Setting, "bLength", rusb_setting_bLength, 0);
891
+ rb_define_method(rb_cUSB_Setting, "bDescriptorType", rusb_setting_bDescriptorType, 0);
892
+ rb_define_method(rb_cUSB_Setting, "bInterfaceNumber", rusb_setting_bInterfaceNumber, 0);
893
+ rb_define_method(rb_cUSB_Setting, "bAlternateSetting", rusb_setting_bAlternateSetting, 0);
894
+ rb_define_method(rb_cUSB_Setting, "bNumEndpoints", rusb_setting_bNumEndpoints, 0);
895
+ rb_define_method(rb_cUSB_Setting, "bInterfaceClass", rusb_setting_bInterfaceClass, 0);
896
+ rb_define_method(rb_cUSB_Setting, "bInterfaceSubClass", rusb_setting_bInterfaceSubClass, 0);
897
+ rb_define_method(rb_cUSB_Setting, "bInterfaceProtocol", rusb_setting_bInterfaceProtocol, 0);
898
+ rb_define_method(rb_cUSB_Setting, "iInterface", rusb_setting_iInterface, 0);
899
+ rb_define_method(rb_cUSB_Setting, "endpoints", rusb_setting_endpoints, 0);
900
+
901
+ rb_define_method(rb_cUSB_Endpoint, "revoked?", rusb_endpoint_revoked_p, 0);
902
+ rb_define_method(rb_cUSB_Endpoint, "setting", rusb_endpoint_setting, 0);
903
+ rb_define_method(rb_cUSB_Endpoint, "bLength", rusb_endpoint_bLength, 0);
904
+ rb_define_method(rb_cUSB_Endpoint, "bDescriptorType", rusb_endpoint_bDescriptorType, 0);
905
+ rb_define_method(rb_cUSB_Endpoint, "bEndpointAddress", rusb_endpoint_bEndpointAddress, 0);
906
+ rb_define_method(rb_cUSB_Endpoint, "bmAttributes", rusb_endpoint_bmAttributes, 0);
907
+ rb_define_method(rb_cUSB_Endpoint, "wMaxPacketSize", rusb_endpoint_wMaxPacketSize, 0);
908
+ rb_define_method(rb_cUSB_Endpoint, "bInterval", rusb_endpoint_bInterval, 0);
909
+ rb_define_method(rb_cUSB_Endpoint, "bRefresh", rusb_endpoint_bRefresh, 0);
910
+ rb_define_method(rb_cUSB_Endpoint, "bSynchAddress", rusb_endpoint_bSynchAddress, 0);
911
+
912
+ rb_define_method(rb_cUSB_DevHandle, "usb_close", rusb_close, 0);
913
+ rb_define_method(rb_cUSB_DevHandle, "usb_set_configuration", rusb_set_configuration, 1);
914
+ rb_define_method(rb_cUSB_DevHandle, "usb_set_altinterface", rusb_set_altinterface, 1);
915
+ rb_define_method(rb_cUSB_DevHandle, "usb_clear_halt", rusb_clear_halt, 1);
916
+ rb_define_method(rb_cUSB_DevHandle, "usb_reset", rusb_reset, 0);
917
+ rb_define_method(rb_cUSB_DevHandle, "usb_claim_interface", rusb_claim_interface, 1);
918
+ rb_define_method(rb_cUSB_DevHandle, "usb_release_interface", rusb_release_interface, 1);
919
+ rb_define_method(rb_cUSB_DevHandle, "usb_control_msg", rusb_control_msg, 6);
920
+ rb_define_method(rb_cUSB_DevHandle, "usb_get_string", rusb_get_string, 3);
921
+ rb_define_method(rb_cUSB_DevHandle, "usb_get_string_simple", rusb_get_string_simple, 2);
922
+ rb_define_method(rb_cUSB_DevHandle, "usb_get_descriptor", rusb_get_descriptor, 3);
923
+ rb_define_method(rb_cUSB_DevHandle, "usb_get_descriptor_by_endpoint", rusb_get_descriptor_by_endpoint, 4);
924
+ rb_define_method(rb_cUSB_DevHandle, "usb_bulk_write", rusb_bulk_write, 3);
925
+ rb_define_method(rb_cUSB_DevHandle, "usb_bulk_read", rusb_bulk_read, 3);
926
+ rb_define_method(rb_cUSB_DevHandle, "usb_interrupt_write", rusb_interrupt_write, 3);
927
+ rb_define_method(rb_cUSB_DevHandle, "usb_interrupt_read", rusb_interrupt_read, 3);
928
+
929
+ #ifdef LIBUSB_HAS_GET_DRIVER_NP
930
+ rb_define_method(rb_cUSB_DevHandle, "usb_get_driver_np", rusb_get_driver_np, 2);
931
+ #endif
932
+ #ifdef LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP
933
+ rb_define_method(rb_cUSB_DevHandle, "usb_detach_kernel_driver_np", rusb_detach_kernel_driver_np, 1);
934
+ #endif
935
+ }