libusb 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +8 -2
  3. data/Gemfile +2 -0
  4. data/History.md +12 -0
  5. data/README.md +25 -14
  6. data/Rakefile +64 -109
  7. data/appveyor.yml +23 -0
  8. data/ext/extconf.rb +10 -12
  9. data/ext/libusb_recipe.rb +29 -0
  10. data/lib/libusb/call.rb +14 -11
  11. data/lib/libusb/compat.rb +9 -9
  12. data/lib/libusb/context.rb +16 -1
  13. data/lib/libusb/dependencies.rb +7 -0
  14. data/lib/libusb/dev_handle.rb +13 -3
  15. data/lib/libusb/eventmachine.rb +4 -4
  16. data/lib/libusb/transfer.rb +71 -10
  17. data/lib/libusb/version_gem.rb +1 -1
  18. data/libusb.gemspec +7 -5
  19. data/ports/archives/libusb-1.0.21.tar.bz2 +0 -0
  20. data/test/test_libusb_bulk_stream_transfer.rb +1 -1
  21. data/test/test_libusb_descriptors.rb +4 -4
  22. data/test/test_libusb_event_machine.rb +7 -7
  23. data/test/test_libusb_hotplug.rb +15 -3
  24. data/test/test_libusb_iso_transfer.rb +1 -1
  25. data/test/test_libusb_mass_storage.rb +19 -19
  26. data/test/test_libusb_mass_storage2.rb +1 -1
  27. data/test/test_libusb_structs.rb +13 -0
  28. data/test/test_libusb_threads.rb +2 -2
  29. data/wireshark-usb-sniffer.png +0 -0
  30. metadata +32 -156
  31. checksums.yaml.gz.sig +0 -0
  32. data.tar.gz.sig +0 -0
  33. data/ext/libusb-1.0.20/AUTHORS +0 -89
  34. data/ext/libusb-1.0.20/COPYING +0 -504
  35. data/ext/libusb-1.0.20/ChangeLog +0 -227
  36. data/ext/libusb-1.0.20/INSTALL +0 -234
  37. data/ext/libusb-1.0.20/Makefile.am +0 -28
  38. data/ext/libusb-1.0.20/Makefile.in +0 -897
  39. data/ext/libusb-1.0.20/NEWS +0 -2
  40. data/ext/libusb-1.0.20/PORTING +0 -94
  41. data/ext/libusb-1.0.20/README +0 -29
  42. data/ext/libusb-1.0.20/TODO +0 -2
  43. data/ext/libusb-1.0.20/Xcode/common.xcconfig +0 -49
  44. data/ext/libusb-1.0.20/Xcode/config.h +0 -28
  45. data/ext/libusb-1.0.20/Xcode/debug.xcconfig +0 -29
  46. data/ext/libusb-1.0.20/Xcode/libusb.xcconfig +0 -21
  47. data/ext/libusb-1.0.20/Xcode/libusb.xcodeproj/project.pbxproj +0 -865
  48. data/ext/libusb-1.0.20/Xcode/libusb_debug.xcconfig +0 -21
  49. data/ext/libusb-1.0.20/Xcode/libusb_release.xcconfig +0 -21
  50. data/ext/libusb-1.0.20/Xcode/release.xcconfig +0 -30
  51. data/ext/libusb-1.0.20/aclocal.m4 +0 -1193
  52. data/ext/libusb-1.0.20/android/README +0 -114
  53. data/ext/libusb-1.0.20/android/config.h +0 -81
  54. data/ext/libusb-1.0.20/android/jni/Android.mk +0 -23
  55. data/ext/libusb-1.0.20/android/jni/Application.mk +0 -24
  56. data/ext/libusb-1.0.20/android/jni/examples.mk +0 -134
  57. data/ext/libusb-1.0.20/android/jni/libusb.mk +0 -54
  58. data/ext/libusb-1.0.20/android/jni/tests.mk +0 -56
  59. data/ext/libusb-1.0.20/compile +0 -347
  60. data/ext/libusb-1.0.20/config.guess +0 -1421
  61. data/ext/libusb-1.0.20/config.h.in +0 -155
  62. data/ext/libusb-1.0.20/config.sub +0 -1807
  63. data/ext/libusb-1.0.20/configure +0 -15466
  64. data/ext/libusb-1.0.20/configure.ac +0 -326
  65. data/ext/libusb-1.0.20/depcomp +0 -791
  66. data/ext/libusb-1.0.20/doc/Makefile.am +0 -9
  67. data/ext/libusb-1.0.20/doc/Makefile.in +0 -456
  68. data/ext/libusb-1.0.20/doc/doxygen.cfg.in +0 -2334
  69. data/ext/libusb-1.0.20/examples/Makefile.am +0 -19
  70. data/ext/libusb-1.0.20/examples/Makefile.in +0 -713
  71. data/ext/libusb-1.0.20/examples/dpfp.c +0 -506
  72. data/ext/libusb-1.0.20/examples/dpfp_threaded.c +0 -549
  73. data/ext/libusb-1.0.20/examples/ezusb.c +0 -831
  74. data/ext/libusb-1.0.20/examples/ezusb.h +0 -120
  75. data/ext/libusb-1.0.20/examples/fxload.c +0 -308
  76. data/ext/libusb-1.0.20/examples/getopt/getopt.c +0 -1060
  77. data/ext/libusb-1.0.20/examples/getopt/getopt.h +0 -180
  78. data/ext/libusb-1.0.20/examples/getopt/getopt1.c +0 -188
  79. data/ext/libusb-1.0.20/examples/hotplugtest.c +0 -122
  80. data/ext/libusb-1.0.20/examples/listdevs.c +0 -71
  81. data/ext/libusb-1.0.20/examples/sam3u_benchmark.c +0 -193
  82. data/ext/libusb-1.0.20/examples/xusb.c +0 -1130
  83. data/ext/libusb-1.0.20/install-sh +0 -501
  84. data/ext/libusb-1.0.20/libusb-1.0.pc.in +0 -11
  85. data/ext/libusb-1.0.20/libusb/Makefile.am +0 -90
  86. data/ext/libusb-1.0.20/libusb/Makefile.in +0 -1053
  87. data/ext/libusb-1.0.20/libusb/core.c +0 -2452
  88. data/ext/libusb-1.0.20/libusb/descriptor.c +0 -1201
  89. data/ext/libusb-1.0.20/libusb/hotplug.c +0 -344
  90. data/ext/libusb-1.0.20/libusb/hotplug.h +0 -90
  91. data/ext/libusb-1.0.20/libusb/io.c +0 -2760
  92. data/ext/libusb-1.0.20/libusb/libusb-1.0.def +0 -168
  93. data/ext/libusb-1.0.20/libusb/libusb-1.0.rc +0 -61
  94. data/ext/libusb-1.0.20/libusb/libusb.h +0 -1999
  95. data/ext/libusb-1.0.20/libusb/libusbi.h +0 -1102
  96. data/ext/libusb-1.0.20/libusb/os/darwin_usb.c +0 -1969
  97. data/ext/libusb-1.0.20/libusb/os/darwin_usb.h +0 -158
  98. data/ext/libusb-1.0.20/libusb/os/haiku/Makefile.am +0 -5
  99. data/ext/libusb-1.0.20/libusb/os/haiku/Makefile.in +0 -810
  100. data/ext/libusb-1.0.20/libusb/os/haiku/aclocal.m4 +0 -1193
  101. data/ext/libusb-1.0.20/libusb/os/haiku/compile +0 -347
  102. data/ext/libusb-1.0.20/libusb/os/haiku/config.guess +0 -1421
  103. data/ext/libusb-1.0.20/libusb/os/haiku/config.sub +0 -1807
  104. data/ext/libusb-1.0.20/libusb/os/haiku/configure +0 -17579
  105. data/ext/libusb-1.0.20/libusb/os/haiku/configure.ac +0 -8
  106. data/ext/libusb-1.0.20/libusb/os/haiku/depcomp +0 -791
  107. data/ext/libusb-1.0.20/libusb/os/haiku/haiku_pollfs.cpp +0 -378
  108. data/ext/libusb-1.0.20/libusb/os/haiku/haiku_usb.h +0 -112
  109. data/ext/libusb-1.0.20/libusb/os/haiku/haiku_usb_backend.cpp +0 -550
  110. data/ext/libusb-1.0.20/libusb/os/haiku/haiku_usb_raw.cpp +0 -255
  111. data/ext/libusb-1.0.20/libusb/os/haiku/haiku_usb_raw.h +0 -180
  112. data/ext/libusb-1.0.20/libusb/os/haiku/install-sh +0 -501
  113. data/ext/libusb-1.0.20/libusb/os/haiku/ltmain.sh +0 -9655
  114. data/ext/libusb-1.0.20/libusb/os/haiku/m4/libtool.m4 +0 -7992
  115. data/ext/libusb-1.0.20/libusb/os/haiku/m4/ltoptions.m4 +0 -384
  116. data/ext/libusb-1.0.20/libusb/os/haiku/m4/ltsugar.m4 +0 -123
  117. data/ext/libusb-1.0.20/libusb/os/haiku/m4/ltversion.m4 +0 -23
  118. data/ext/libusb-1.0.20/libusb/os/haiku/m4/lt~obsolete.m4 +0 -98
  119. data/ext/libusb-1.0.20/libusb/os/haiku/missing +0 -215
  120. data/ext/libusb-1.0.20/libusb/os/linux_netlink.c +0 -369
  121. data/ext/libusb-1.0.20/libusb/os/linux_udev.c +0 -306
  122. data/ext/libusb-1.0.20/libusb/os/linux_usbfs.c +0 -2692
  123. data/ext/libusb-1.0.20/libusb/os/linux_usbfs.h +0 -192
  124. data/ext/libusb-1.0.20/libusb/os/netbsd_usb.c +0 -674
  125. data/ext/libusb-1.0.20/libusb/os/openbsd_usb.c +0 -768
  126. data/ext/libusb-1.0.20/libusb/os/poll_posix.c +0 -53
  127. data/ext/libusb-1.0.20/libusb/os/poll_posix.h +0 -11
  128. data/ext/libusb-1.0.20/libusb/os/poll_windows.c +0 -728
  129. data/ext/libusb-1.0.20/libusb/os/poll_windows.h +0 -131
  130. data/ext/libusb-1.0.20/libusb/os/threads_posix.c +0 -82
  131. data/ext/libusb-1.0.20/libusb/os/threads_posix.h +0 -50
  132. data/ext/libusb-1.0.20/libusb/os/threads_windows.c +0 -214
  133. data/ext/libusb-1.0.20/libusb/os/threads_windows.h +0 -87
  134. data/ext/libusb-1.0.20/libusb/os/wince_usb.c +0 -869
  135. data/ext/libusb-1.0.20/libusb/os/wince_usb.h +0 -131
  136. data/ext/libusb-1.0.20/libusb/os/windows_common.h +0 -108
  137. data/ext/libusb-1.0.20/libusb/os/windows_usb.c +0 -4643
  138. data/ext/libusb-1.0.20/libusb/os/windows_usb.h +0 -973
  139. data/ext/libusb-1.0.20/libusb/strerror.c +0 -202
  140. data/ext/libusb-1.0.20/libusb/sync.c +0 -308
  141. data/ext/libusb-1.0.20/libusb/version.h +0 -18
  142. data/ext/libusb-1.0.20/libusb/version_nano.h +0 -1
  143. data/ext/libusb-1.0.20/ltmain.sh +0 -9655
  144. data/ext/libusb-1.0.20/m4/libtool.m4 +0 -7992
  145. data/ext/libusb-1.0.20/m4/ltoptions.m4 +0 -384
  146. data/ext/libusb-1.0.20/m4/ltsugar.m4 +0 -123
  147. data/ext/libusb-1.0.20/m4/ltversion.m4 +0 -23
  148. data/ext/libusb-1.0.20/m4/lt~obsolete.m4 +0 -98
  149. data/ext/libusb-1.0.20/missing +0 -215
  150. data/ext/libusb-1.0.20/tests/Makefile.am +0 -6
  151. data/ext/libusb-1.0.20/tests/Makefile.in +0 -596
  152. data/ext/libusb-1.0.20/tests/libusb_testlib.h +0 -107
  153. data/ext/libusb-1.0.20/tests/stress.c +0 -160
  154. data/ext/libusb-1.0.20/tests/testlib.c +0 -277
  155. metadata.gz.sig +0 -0
@@ -1,180 +0,0 @@
1
- /* Declarations for getopt.
2
- Copyright (C) 1989-1994, 1996-1999, 2001 Free Software Foundation, Inc.
3
- This file is part of the GNU C Library.
4
-
5
- The GNU C 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
- The GNU C 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 the GNU C Library; if not, write to the Free
17
- Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18
- 02111-1307 USA. */
19
-
20
- #ifndef _GETOPT_H
21
-
22
- #ifndef __need_getopt
23
- # define _GETOPT_H 1
24
- #endif
25
-
26
- /* If __GNU_LIBRARY__ is not already defined, either we are being used
27
- standalone, or this is the first header included in the source file.
28
- If we are being used with glibc, we need to include <features.h>, but
29
- that does not exist if we are standalone. So: if __GNU_LIBRARY__ is
30
- not defined, include <ctype.h>, which will pull in <features.h> for us
31
- if it's from glibc. (Why ctype.h? It's guaranteed to exist and it
32
- doesn't flood the namespace with stuff the way some other headers do.) */
33
- #if !defined __GNU_LIBRARY__
34
- # include <ctype.h>
35
- #endif
36
-
37
- #ifdef __cplusplus
38
- extern "C" {
39
- #endif
40
-
41
- /* For communication from `getopt' to the caller.
42
- When `getopt' finds an option that takes an argument,
43
- the argument value is returned here.
44
- Also, when `ordering' is RETURN_IN_ORDER,
45
- each non-option ARGV-element is returned here. */
46
-
47
- extern char *optarg;
48
-
49
- /* Index in ARGV of the next element to be scanned.
50
- This is used for communication to and from the caller
51
- and for communication between successive calls to `getopt'.
52
-
53
- On entry to `getopt', zero means this is the first call; initialize.
54
-
55
- When `getopt' returns -1, this is the index of the first of the
56
- non-option elements that the caller should itself scan.
57
-
58
- Otherwise, `optind' communicates from one call to the next
59
- how much of ARGV has been scanned so far. */
60
-
61
- extern int optind;
62
-
63
- /* Callers store zero here to inhibit the error message `getopt' prints
64
- for unrecognized options. */
65
-
66
- extern int opterr;
67
-
68
- /* Set to an option character which was unrecognized. */
69
-
70
- extern int optopt;
71
-
72
- #ifndef __need_getopt
73
- /* Describe the long-named options requested by the application.
74
- The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
75
- of `struct option' terminated by an element containing a name which is
76
- zero.
77
-
78
- The field `has_arg' is:
79
- no_argument (or 0) if the option does not take an argument,
80
- required_argument (or 1) if the option requires an argument,
81
- optional_argument (or 2) if the option takes an optional argument.
82
-
83
- If the field `flag' is not NULL, it points to a variable that is set
84
- to the value given in the field `val' when the option is found, but
85
- left unchanged if the option is not found.
86
-
87
- To have a long-named option do something other than set an `int' to
88
- a compiled-in constant, such as set a value from `optarg', set the
89
- option's `flag' field to zero and its `val' field to a nonzero
90
- value (the equivalent single-letter option character, if there is
91
- one). For long options that have a zero `flag' field, `getopt'
92
- returns the contents of the `val' field. */
93
-
94
- struct option
95
- {
96
- # if (defined __STDC__ && __STDC__) || defined __cplusplus
97
- const char *name;
98
- # else
99
- char *name;
100
- # endif
101
- /* has_arg can't be an enum because some compilers complain about
102
- type mismatches in all the code that assumes it is an int. */
103
- int has_arg;
104
- int *flag;
105
- int val;
106
- };
107
-
108
- /* Names for the values of the `has_arg' field of `struct option'. */
109
-
110
- # define no_argument 0
111
- # define required_argument 1
112
- # define optional_argument 2
113
- #endif /* need getopt */
114
-
115
-
116
- /* Get definitions and prototypes for functions to process the
117
- arguments in ARGV (ARGC of them, minus the program name) for
118
- options given in OPTS.
119
-
120
- Return the option character from OPTS just read. Return -1 when
121
- there are no more options. For unrecognized options, or options
122
- missing arguments, `optopt' is set to the option letter, and '?' is
123
- returned.
124
-
125
- The OPTS string is a list of characters which are recognized option
126
- letters, optionally followed by colons, specifying that that letter
127
- takes an argument, to be placed in `optarg'.
128
-
129
- If a letter in OPTS is followed by two colons, its argument is
130
- optional. This behavior is specific to the GNU `getopt'.
131
-
132
- The argument `--' causes premature termination of argument
133
- scanning, explicitly telling `getopt' that there are no more
134
- options.
135
-
136
- If OPTS begins with `--', then non-option arguments are treated as
137
- arguments to the option '\0'. This behavior is specific to the GNU
138
- `getopt'. */
139
-
140
- #if (defined __STDC__ && __STDC__) || defined __cplusplus
141
- # ifdef __GNU_LIBRARY__
142
- /* Many other libraries have conflicting prototypes for getopt, with
143
- differences in the consts, in stdlib.h. To avoid compilation
144
- errors, only prototype getopt for the GNU C library. */
145
- extern int getopt (int __argc, char *const *__argv, const char *__shortopts);
146
- # else /* not __GNU_LIBRARY__ */
147
- extern int getopt ();
148
- # endif /* __GNU_LIBRARY__ */
149
-
150
- # ifndef __need_getopt
151
- extern int getopt_long (int __argc, char *const *__argv, const char *__shortopts,
152
- const struct option *__longopts, int *__longind);
153
- extern int getopt_long_only (int __argc, char *const *__argv,
154
- const char *__shortopts,
155
- const struct option *__longopts, int *__longind);
156
-
157
- /* Internal only. Users should not call this directly. */
158
- extern int _getopt_internal (int __argc, char *const *__argv,
159
- const char *__shortopts,
160
- const struct option *__longopts, int *__longind,
161
- int __long_only);
162
- # endif
163
- #else /* not __STDC__ */
164
- extern int getopt ();
165
- # ifndef __need_getopt
166
- extern int getopt_long ();
167
- extern int getopt_long_only ();
168
-
169
- extern int _getopt_internal ();
170
- # endif
171
- #endif /* __STDC__ */
172
-
173
- #ifdef __cplusplus
174
- }
175
- #endif
176
-
177
- /* Make sure we later can get all the definitions and declarations. */
178
- #undef __need_getopt
179
-
180
- #endif /* getopt.h */
@@ -1,188 +0,0 @@
1
- /* getopt_long and getopt_long_only entry points for GNU getopt.
2
- Copyright (C) 1987,88,89,90,91,92,93,94,96,97,98
3
- Free Software Foundation, Inc.
4
- This file is part of the GNU C Library.
5
-
6
- The GNU C 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
- The GNU C 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 the GNU C Library; if not, write to the Free
18
- Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19
- 02111-1307 USA. */
20
-
21
- #ifdef HAVE_CONFIG_H
22
- #include <config.h>
23
- #endif
24
-
25
- #include "getopt.h"
26
-
27
- #if !defined __STDC__ || !__STDC__
28
- /* This is a separate conditional since some stdc systems
29
- reject `defined (const)'. */
30
- #ifndef const
31
- #define const
32
- #endif
33
- #endif
34
-
35
- #include <stdio.h>
36
-
37
- /* Comment out all this code if we are using the GNU C Library, and are not
38
- actually compiling the library itself. This code is part of the GNU C
39
- Library, but also included in many other GNU distributions. Compiling
40
- and linking in this code is a waste when using the GNU C library
41
- (especially if it is a shared library). Rather than having every GNU
42
- program understand `configure --with-gnu-libc' and omit the object files,
43
- it is simpler to just do this in the source for each such file. */
44
-
45
- #define GETOPT_INTERFACE_VERSION 2
46
- #if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2
47
- #include <gnu-versions.h>
48
- #if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION
49
- #define ELIDE_CODE
50
- #endif
51
- #endif
52
-
53
- #ifndef ELIDE_CODE
54
-
55
-
56
- /* This needs to come after some library #include
57
- to get __GNU_LIBRARY__ defined. */
58
- #ifdef __GNU_LIBRARY__
59
- #include <stdlib.h>
60
- #endif
61
-
62
- #ifndef NULL
63
- #define NULL 0
64
- #endif
65
-
66
- int
67
- getopt_long (argc, argv, options, long_options, opt_index)
68
- int argc;
69
- char *const *argv;
70
- const char *options;
71
- const struct option *long_options;
72
- int *opt_index;
73
- {
74
- return _getopt_internal (argc, argv, options, long_options, opt_index, 0);
75
- }
76
-
77
- /* Like getopt_long, but '-' as well as '--' can indicate a long option.
78
- If an option that starts with '-' (not '--') doesn't match a long option,
79
- but does match a short option, it is parsed as a short option
80
- instead. */
81
-
82
- int
83
- getopt_long_only (argc, argv, options, long_options, opt_index)
84
- int argc;
85
- char *const *argv;
86
- const char *options;
87
- const struct option *long_options;
88
- int *opt_index;
89
- {
90
- return _getopt_internal (argc, argv, options, long_options, opt_index, 1);
91
- }
92
-
93
-
94
- #endif /* Not ELIDE_CODE. */
95
-
96
- #ifdef TEST
97
-
98
- #include <stdio.h>
99
-
100
- int
101
- main (argc, argv)
102
- int argc;
103
- char **argv;
104
- {
105
- int c;
106
- int digit_optind = 0;
107
-
108
- while (1)
109
- {
110
- int this_option_optind = optind ? optind : 1;
111
- int option_index = 0;
112
- static struct option long_options[] =
113
- {
114
- {"add", 1, 0, 0},
115
- {"append", 0, 0, 0},
116
- {"delete", 1, 0, 0},
117
- {"verbose", 0, 0, 0},
118
- {"create", 0, 0, 0},
119
- {"file", 1, 0, 0},
120
- {0, 0, 0, 0}
121
- };
122
-
123
- c = getopt_long (argc, argv, "abc:d:0123456789",
124
- long_options, &option_index);
125
- if (c == -1)
126
- break;
127
-
128
- switch (c)
129
- {
130
- case 0:
131
- printf ("option %s", long_options[option_index].name);
132
- if (optarg)
133
- printf (" with arg %s", optarg);
134
- printf ("\n");
135
- break;
136
-
137
- case '0':
138
- case '1':
139
- case '2':
140
- case '3':
141
- case '4':
142
- case '5':
143
- case '6':
144
- case '7':
145
- case '8':
146
- case '9':
147
- if (digit_optind != 0 && digit_optind != this_option_optind)
148
- printf ("digits occur in two different argv-elements.\n");
149
- digit_optind = this_option_optind;
150
- printf ("option %c\n", c);
151
- break;
152
-
153
- case 'a':
154
- printf ("option a\n");
155
- break;
156
-
157
- case 'b':
158
- printf ("option b\n");
159
- break;
160
-
161
- case 'c':
162
- printf ("option c with value `%s'\n", optarg);
163
- break;
164
-
165
- case 'd':
166
- printf ("option d with value `%s'\n", optarg);
167
- break;
168
-
169
- case '?':
170
- break;
171
-
172
- default:
173
- printf ("?? getopt returned character code 0%o ??\n", c);
174
- }
175
- }
176
-
177
- if (optind < argc)
178
- {
179
- printf ("non-option ARGV-elements: ");
180
- while (optind < argc)
181
- printf ("%s ", argv[optind++]);
182
- printf ("\n");
183
- }
184
-
185
- exit (0);
186
- }
187
-
188
- #endif /* TEST */
@@ -1,122 +0,0 @@
1
- /* -*- Mode: C; indent-tabs-mode:t ; c-basic-offset:8 -*- */
2
- /*
3
- * libusb example program for hotplug API
4
- * Copyright © 2012-2013 Nathan Hjelm <hjelmn@mac.ccom>
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 <stdlib.h>
22
- #include <stdio.h>
23
-
24
- #include "libusb.h"
25
-
26
- int done = 0;
27
- libusb_device_handle *handle = NULL;
28
-
29
- static int LIBUSB_CALL hotplug_callback(libusb_context *ctx, libusb_device *dev, libusb_hotplug_event event, void *user_data)
30
- {
31
- struct libusb_device_descriptor desc;
32
- int rc;
33
-
34
- rc = libusb_get_device_descriptor(dev, &desc);
35
- if (LIBUSB_SUCCESS != rc) {
36
- fprintf (stderr, "Error getting device descriptor\n");
37
- }
38
-
39
- printf ("Device attached: %04x:%04x\n", desc.idVendor, desc.idProduct);
40
-
41
- if (handle) {
42
- libusb_close (handle);
43
- handle = NULL;
44
- }
45
-
46
- rc = libusb_open (dev, &handle);
47
- if (LIBUSB_SUCCESS != rc) {
48
- fprintf (stderr, "Error opening device\n");
49
- }
50
-
51
- done++;
52
-
53
- return 0;
54
- }
55
-
56
- static int LIBUSB_CALL hotplug_callback_detach(libusb_context *ctx, libusb_device *dev, libusb_hotplug_event event, void *user_data)
57
- {
58
- printf ("Device detached\n");
59
-
60
- if (handle) {
61
- libusb_close (handle);
62
- handle = NULL;
63
- }
64
-
65
- done++;
66
-
67
- return 0;
68
- }
69
-
70
- int main(int argc, char *argv[])
71
- {
72
- libusb_hotplug_callback_handle hp[2];
73
- int product_id, vendor_id, class_id;
74
- int rc;
75
-
76
- vendor_id = (argc > 1) ? strtol (argv[1], NULL, 0) : 0x045a;
77
- product_id = (argc > 2) ? strtol (argv[2], NULL, 0) : 0x5005;
78
- class_id = (argc > 3) ? strtol (argv[3], NULL, 0) : LIBUSB_HOTPLUG_MATCH_ANY;
79
-
80
- rc = libusb_init (NULL);
81
- if (rc < 0)
82
- {
83
- printf("failed to initialise libusb: %s\n", libusb_error_name(rc));
84
- return EXIT_FAILURE;
85
- }
86
-
87
- if (!libusb_has_capability (LIBUSB_CAP_HAS_HOTPLUG)) {
88
- printf ("Hotplug capabilites are not supported on this platform\n");
89
- libusb_exit (NULL);
90
- return EXIT_FAILURE;
91
- }
92
-
93
- rc = libusb_hotplug_register_callback (NULL, LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED, 0, vendor_id,
94
- product_id, class_id, hotplug_callback, NULL, &hp[0]);
95
- if (LIBUSB_SUCCESS != rc) {
96
- fprintf (stderr, "Error registering callback 0\n");
97
- libusb_exit (NULL);
98
- return EXIT_FAILURE;
99
- }
100
-
101
- rc = libusb_hotplug_register_callback (NULL, LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT, 0, vendor_id,
102
- product_id,class_id, hotplug_callback_detach, NULL, &hp[1]);
103
- if (LIBUSB_SUCCESS != rc) {
104
- fprintf (stderr, "Error registering callback 1\n");
105
- libusb_exit (NULL);
106
- return EXIT_FAILURE;
107
- }
108
-
109
- while (done < 2) {
110
- rc = libusb_handle_events (NULL);
111
- if (rc < 0)
112
- printf("libusb_handle_events() failed: %s\n", libusb_error_name(rc));
113
- }
114
-
115
- if (handle) {
116
- libusb_close (handle);
117
- }
118
-
119
- libusb_exit (NULL);
120
-
121
- return EXIT_SUCCESS;
122
- }