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
@@ -56,6 +56,8 @@ const struct usbi_os_backend * const usbi_backend = &netbsd_backend;
56
56
  const struct usbi_os_backend * const usbi_backend = &windows_backend;
57
57
  #elif defined(OS_WINCE)
58
58
  const struct usbi_os_backend * const usbi_backend = &wince_backend;
59
+ #elif defined(OS_HAIKU)
60
+ const struct usbi_os_backend * const usbi_backend = &haiku_usb_raw_backend;
59
61
  #else
60
62
  #error "Unsupported OS"
61
63
  #endif
@@ -92,6 +94,10 @@ struct list_head active_contexts_list;
92
94
  * Specification</a> which is available for free download. You can probably
93
95
  * find less verbose introductions by searching the web.
94
96
  *
97
+ * \section API Application Programming Interface (API)
98
+ *
99
+ * See the \ref api page for a complete list of the libusb functions.
100
+ *
95
101
  * \section features Library features
96
102
  *
97
103
  * - All transfer types supported (control/bulk/interrupt/isochronous)
@@ -217,9 +223,6 @@ struct list_head active_contexts_list;
217
223
  * -# If the device is already in the desired configuration, calling
218
224
  * libusb_set_configuration() using the same configuration value will cause
219
225
  * a lightweight device reset. This may not be desirable behaviour.
220
- * -# libusb will be unable to change configuration if the device is in
221
- * another configuration and other programs or drivers have claimed
222
- * interfaces under that configuration.
223
226
  * -# In the case where the desired configuration is already active, libusb
224
227
  * may not even be able to perform a lightweight device reset. For example,
225
228
  * take my USB keyboard with fingerprint reader: I'm interested in driving
@@ -228,12 +231,17 @@ struct list_head active_contexts_list;
228
231
  * Because the kernel has claimed an interface, it is not even possible to
229
232
  * perform the lightweight device reset, so libusb_set_configuration() will
230
233
  * fail. (Luckily the device in question only has a single configuration.)
234
+ * -# libusb will be unable to set a configuration if other programs or
235
+ * drivers have claimed interfaces. In particular, this means that kernel
236
+ * drivers must be detached from all the interfaces before
237
+ * libusb_set_configuration() may succeed.
231
238
  *
232
239
  * One solution to some of the above problems is to consider the currently
233
240
  * active configuration. If the configuration we want is already active, then
234
241
  * we don't have to select any configuration:
235
242
  \code
236
- cfg = libusb_get_configuration(dev);
243
+ cfg = -1;
244
+ libusb_get_configuration(dev, &cfg);
237
245
  if (cfg != desired)
238
246
  libusb_set_configuration(dev, desired);
239
247
  \endcode
@@ -323,6 +331,151 @@ if (cfg != desired)
323
331
  * can infer the context from those objects.
324
332
  */
325
333
 
334
+ /**
335
+ * \page api Application Programming Interface
336
+ *
337
+ * This is the complete list of libusb functions, structures and
338
+ * enumerations in alphabetical order.
339
+ *
340
+ * \section Functions
341
+ * - libusb_alloc_streams()
342
+ * - libusb_alloc_transfer()
343
+ * - libusb_attach_kernel_driver()
344
+ * - libusb_bulk_transfer()
345
+ * - libusb_cancel_transfer()
346
+ * - libusb_claim_interface()
347
+ * - libusb_clear_halt()
348
+ * - libusb_close()
349
+ * - libusb_control_transfer()
350
+ * - libusb_control_transfer_get_data()
351
+ * - libusb_control_transfer_get_setup()
352
+ * - libusb_cpu_to_le16()
353
+ * - libusb_detach_kernel_driver()
354
+ * - libusb_error_name()
355
+ * - libusb_event_handler_active()
356
+ * - libusb_event_handling_ok()
357
+ * - libusb_exit()
358
+ * - libusb_fill_bulk_stream_transfer()
359
+ * - libusb_fill_bulk_transfer()
360
+ * - libusb_fill_control_setup()
361
+ * - libusb_fill_control_transfer()
362
+ * - libusb_fill_interrupt_transfer()
363
+ * - libusb_fill_iso_transfer()
364
+ * - libusb_free_bos_descriptor()
365
+ * - libusb_free_config_descriptor()
366
+ * - libusb_free_container_id_descriptor()
367
+ * - libusb_free_device_list()
368
+ * - libusb_free_ss_endpoint_companion_descriptor()
369
+ * - libusb_free_ss_usb_device_capability_descriptor()
370
+ * - libusb_free_streams()
371
+ * - libusb_free_transfer()
372
+ * - libusb_free_usb_2_0_extension_descriptor()
373
+ * - libusb_get_active_config_descriptor()
374
+ * - libusb_get_bos_descriptor()
375
+ * - libusb_get_bus_number()
376
+ * - libusb_get_config_descriptor()
377
+ * - libusb_get_config_descriptor_by_value()
378
+ * - libusb_get_configuration()
379
+ * - libusb_get_container_id_descriptor()
380
+ * - libusb_get_descriptor()
381
+ * - libusb_get_device()
382
+ * - libusb_get_device_address()
383
+ * - libusb_get_device_descriptor()
384
+ * - libusb_get_device_list()
385
+ * - libusb_get_device_speed()
386
+ * - libusb_get_iso_packet_buffer()
387
+ * - libusb_get_iso_packet_buffer_simple()
388
+ * - libusb_get_max_iso_packet_size()
389
+ * - libusb_get_max_packet_size()
390
+ * - libusb_get_next_timeout()
391
+ * - libusb_get_parent()
392
+ * - libusb_get_port_number()
393
+ * - libusb_get_port_numbers()
394
+ * - libusb_get_ss_endpoint_companion_descriptor()
395
+ * - libusb_get_ss_usb_device_capability_descriptor()
396
+ * - libusb_get_string_descriptor()
397
+ * - libusb_get_string_descriptor_ascii()
398
+ * - libusb_get_usb_2_0_extension_descriptor()
399
+ * - libusb_get_version()
400
+ * - libusb_handle_events()
401
+ * - libusb_handle_events_completed()
402
+ * - libusb_handle_events_locked()
403
+ * - libusb_handle_events_timeout()
404
+ * - libusb_handle_events_timeout_completed()
405
+ * - libusb_has_capability()
406
+ * - libusb_hotplug_deregister_callback()
407
+ * - libusb_hotplug_register_callback()
408
+ * - libusb_init()
409
+ * - libusb_interrupt_transfer()
410
+ * - libusb_kernel_driver_active()
411
+ * - libusb_lock_events()
412
+ * - libusb_lock_event_waiters()
413
+ * - libusb_open()
414
+ * - libusb_open_device_with_vid_pid()
415
+ * - libusb_pollfds_handle_timeouts()
416
+ * - libusb_ref_device()
417
+ * - libusb_release_interface()
418
+ * - libusb_reset_device()
419
+ * - libusb_set_auto_detach_kernel_driver()
420
+ * - libusb_set_configuration()
421
+ * - libusb_set_debug()
422
+ * - libusb_set_interface_alt_setting()
423
+ * - libusb_set_iso_packet_lengths()
424
+ * - libusb_setlocale()
425
+ * - libusb_set_pollfd_notifiers()
426
+ * - libusb_strerror()
427
+ * - libusb_submit_transfer()
428
+ * - libusb_transfer_get_stream_id()
429
+ * - libusb_transfer_set_stream_id()
430
+ * - libusb_try_lock_events()
431
+ * - libusb_unlock_events()
432
+ * - libusb_unlock_event_waiters()
433
+ * - libusb_unref_device()
434
+ * - libusb_wait_for_event()
435
+ *
436
+ * \section Structures
437
+ * - libusb_bos_descriptor
438
+ * - libusb_bos_dev_capability_descriptor
439
+ * - libusb_config_descriptor
440
+ * - libusb_container_id_descriptor
441
+ * - \ref libusb_context
442
+ * - libusb_control_setup
443
+ * - \ref libusb_device
444
+ * - libusb_device_descriptor
445
+ * - \ref libusb_device_handle
446
+ * - libusb_endpoint_descriptor
447
+ * - libusb_interface
448
+ * - libusb_interface_descriptor
449
+ * - libusb_iso_packet_descriptor
450
+ * - libusb_pollfd
451
+ * - libusb_ss_endpoint_companion_descriptor
452
+ * - libusb_ss_usb_device_capability_descriptor
453
+ * - libusb_transfer
454
+ * - libusb_usb_2_0_extension_descriptor
455
+ * - libusb_version
456
+ *
457
+ * \section Enums
458
+ * - \ref libusb_bos_type
459
+ * - \ref libusb_capability
460
+ * - \ref libusb_class_code
461
+ * - \ref libusb_descriptor_type
462
+ * - \ref libusb_endpoint_direction
463
+ * - \ref libusb_error
464
+ * - \ref libusb_iso_sync_type
465
+ * - \ref libusb_iso_usage_type
466
+ * - \ref libusb_log_level
467
+ * - \ref libusb_request_recipient
468
+ * - \ref libusb_request_type
469
+ * - \ref libusb_speed
470
+ * - \ref libusb_ss_usb_device_capability_attributes
471
+ * - \ref libusb_standard_request
472
+ * - \ref libusb_supported_speed
473
+ * - \ref libusb_transfer_flags
474
+ * - \ref libusb_transfer_status
475
+ * - \ref libusb_transfer_type
476
+ * - \ref libusb_usb_2_0_extension_attributes
477
+ */
478
+
326
479
  /**
327
480
  * @defgroup lib Library initialization/deinitialization
328
481
  * This page details how to initialize and deinitialize libusb. Initialization
@@ -533,12 +686,8 @@ struct libusb_device *usbi_alloc_device(struct libusb_context *ctx,
533
686
 
534
687
  void usbi_connect_device(struct libusb_device *dev)
535
688
  {
536
- libusb_hotplug_message message;
537
- ssize_t ret;
689
+ struct libusb_context *ctx = DEVICE_CTX(dev);
538
690
 
539
- memset(&message, 0, sizeof(message));
540
- message.event = LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED;
541
- message.device = dev;
542
691
  dev->attached = 1;
543
692
 
544
693
  usbi_mutex_lock(&dev->ctx->usb_devs_lock);
@@ -546,25 +695,17 @@ void usbi_connect_device(struct libusb_device *dev)
546
695
  usbi_mutex_unlock(&dev->ctx->usb_devs_lock);
547
696
 
548
697
  /* Signal that an event has occurred for this device if we support hotplug AND
549
- * the hotplug pipe is ready. This prevents an event from getting raised during
550
- * initial enumeration. */
551
- if (libusb_has_capability(LIBUSB_CAP_HAS_HOTPLUG) && dev->ctx->hotplug_pipe[1] > 0) {
552
- ret = usbi_write(dev->ctx->hotplug_pipe[1], &message, sizeof(message));
553
- if (sizeof (message) != ret) {
554
- usbi_err(DEVICE_CTX(dev), "error writing hotplug message");
555
- }
698
+ * the hotplug message list is ready. This prevents an event from getting raised
699
+ * during initial enumeration. */
700
+ if (libusb_has_capability(LIBUSB_CAP_HAS_HOTPLUG) && dev->ctx->hotplug_msgs.next) {
701
+ usbi_hotplug_notification(ctx, dev, LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED);
556
702
  }
557
703
  }
558
704
 
559
705
  void usbi_disconnect_device(struct libusb_device *dev)
560
706
  {
561
- libusb_hotplug_message message;
562
- struct libusb_context *ctx = dev->ctx;
563
- ssize_t ret;
707
+ struct libusb_context *ctx = DEVICE_CTX(dev);
564
708
 
565
- memset(&message, 0, sizeof(message));
566
- message.event = LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT;
567
- message.device = dev;
568
709
  usbi_mutex_lock(&dev->lock);
569
710
  dev->attached = 0;
570
711
  usbi_mutex_unlock(&dev->lock);
@@ -574,14 +715,11 @@ void usbi_disconnect_device(struct libusb_device *dev)
574
715
  usbi_mutex_unlock(&ctx->usb_devs_lock);
575
716
 
576
717
  /* Signal that an event has occurred for this device if we support hotplug AND
577
- * the hotplug pipe is ready. This prevents an event from getting raised during
578
- * initial enumeration. libusb_handle_events will take care of dereferencing the
579
- * device. */
580
- if (libusb_has_capability(LIBUSB_CAP_HAS_HOTPLUG) && dev->ctx->hotplug_pipe[1] > 0) {
581
- ret = usbi_write(dev->ctx->hotplug_pipe[1], &message, sizeof(message));
582
- if (sizeof(message) != ret) {
583
- usbi_err(DEVICE_CTX(dev), "error writing hotplug message");
584
- }
718
+ * the hotplug message list is ready. This prevents an event from getting raised
719
+ * during initial enumeration. libusb_handle_events will take care of dereferencing
720
+ * the device. */
721
+ if (libusb_has_capability(LIBUSB_CAP_HAS_HOTPLUG) && dev->ctx->hotplug_msgs.next) {
722
+ usbi_hotplug_notification(ctx, dev, LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT);
585
723
  }
586
724
  }
587
725
 
@@ -1021,47 +1159,41 @@ void API_EXPORTED libusb_unref_device(libusb_device *dev)
1021
1159
  }
1022
1160
 
1023
1161
  /*
1024
- * Interrupt the iteration of the event handling thread, so that it picks
1025
- * up the new fd.
1162
+ * Signal the event pipe so that the event handling thread will be
1163
+ * interrupted to process an internal event.
1026
1164
  */
1027
- void usbi_fd_notification(struct libusb_context *ctx)
1165
+ int usbi_signal_event(struct libusb_context *ctx)
1028
1166
  {
1029
1167
  unsigned char dummy = 1;
1030
1168
  ssize_t r;
1031
1169
 
1032
- if (ctx == NULL)
1033
- return;
1034
-
1035
- /* record that we are messing with poll fds */
1036
- usbi_mutex_lock(&ctx->pollfd_modify_lock);
1037
- ctx->pollfd_modify++;
1038
- usbi_mutex_unlock(&ctx->pollfd_modify_lock);
1039
-
1040
- /* write some data on control pipe to interrupt event handlers */
1041
- r = usbi_write(ctx->ctrl_pipe[1], &dummy, sizeof(dummy));
1042
- if (r <= 0) {
1170
+ /* write some data on event pipe to interrupt event handlers */
1171
+ r = usbi_write(ctx->event_pipe[1], &dummy, sizeof(dummy));
1172
+ if (r != sizeof(dummy)) {
1043
1173
  usbi_warn(ctx, "internal signalling write failed");
1044
- usbi_mutex_lock(&ctx->pollfd_modify_lock);
1045
- ctx->pollfd_modify--;
1046
- usbi_mutex_unlock(&ctx->pollfd_modify_lock);
1047
- return;
1174
+ return LIBUSB_ERROR_IO;
1048
1175
  }
1049
1176
 
1050
- /* take event handling lock */
1051
- libusb_lock_events(ctx);
1177
+ return 0;
1178
+ }
1052
1179
 
1053
- /* read the dummy data */
1054
- r = usbi_read(ctx->ctrl_pipe[0], &dummy, sizeof(dummy));
1055
- if (r <= 0)
1056
- usbi_warn(ctx, "internal signalling read failed");
1180
+ /*
1181
+ * Clear the event pipe so that the event handling will no longer be
1182
+ * interrupted.
1183
+ */
1184
+ int usbi_clear_event(struct libusb_context *ctx)
1185
+ {
1186
+ unsigned char dummy;
1187
+ ssize_t r;
1057
1188
 
1058
- /* we're done with modifying poll fds */
1059
- usbi_mutex_lock(&ctx->pollfd_modify_lock);
1060
- ctx->pollfd_modify--;
1061
- usbi_mutex_unlock(&ctx->pollfd_modify_lock);
1189
+ /* read some data on event pipe to clear it */
1190
+ r = usbi_read(ctx->event_pipe[0], &dummy, sizeof(dummy));
1191
+ if (r != sizeof(dummy)) {
1192
+ usbi_warn(ctx, "internal signalling read failed");
1193
+ return LIBUSB_ERROR_IO;
1194
+ }
1062
1195
 
1063
- /* Release event handling lock and wake up event waiters */
1064
- libusb_unlock_events(ctx);
1196
+ return 0;
1065
1197
  }
1066
1198
 
1067
1199
  /** \ingroup dev
@@ -1125,14 +1257,6 @@ int API_EXPORTED libusb_open(libusb_device *dev,
1125
1257
  usbi_mutex_unlock(&ctx->open_devs_lock);
1126
1258
  *handle = _handle;
1127
1259
 
1128
- /* At this point, we want to interrupt any existing event handlers so
1129
- * that they realise the addition of the new device's poll fd. One
1130
- * example when this is desirable is if the user is running a separate
1131
- * dedicated libusb events handling thread, which is running with a long
1132
- * or infinite timeout. We want to interrupt that iteration of the loop,
1133
- * so that it picks up the new fd, and then continues. */
1134
- usbi_fd_notification(ctx);
1135
-
1136
1260
  return 0;
1137
1261
  }
1138
1262
 
@@ -1260,8 +1384,7 @@ static void do_close(struct libusb_context *ctx,
1260
1384
  void API_EXPORTED libusb_close(libusb_device_handle *dev_handle)
1261
1385
  {
1262
1386
  struct libusb_context *ctx;
1263
- unsigned char dummy = 1;
1264
- ssize_t r;
1387
+ int pending_events;
1265
1388
 
1266
1389
  if (!dev_handle)
1267
1390
  return;
@@ -1275,37 +1398,29 @@ void API_EXPORTED libusb_close(libusb_device_handle *dev_handle)
1275
1398
  * thread from doing event handling) because we will be removing a file
1276
1399
  * descriptor from the polling loop. */
1277
1400
 
1278
- /* record that we are messing with poll fds */
1279
- usbi_mutex_lock(&ctx->pollfd_modify_lock);
1280
- ctx->pollfd_modify++;
1281
- usbi_mutex_unlock(&ctx->pollfd_modify_lock);
1282
-
1283
- /* write some data on control pipe to interrupt event handlers */
1284
- r = usbi_write(ctx->ctrl_pipe[1], &dummy, sizeof(dummy));
1285
- if (r <= 0) {
1286
- usbi_warn(ctx, "internal signalling write failed, closing anyway");
1287
- do_close(ctx, dev_handle);
1288
- usbi_mutex_lock(&ctx->pollfd_modify_lock);
1289
- ctx->pollfd_modify--;
1290
- usbi_mutex_unlock(&ctx->pollfd_modify_lock);
1291
- return;
1292
- }
1401
+ /* Record that we are closing a device.
1402
+ * Only signal an event if there are no prior pending events. */
1403
+ usbi_mutex_lock(&ctx->event_data_lock);
1404
+ pending_events = usbi_pending_events(ctx);
1405
+ ctx->device_close++;
1406
+ if (!pending_events)
1407
+ usbi_signal_event(ctx);
1408
+ usbi_mutex_unlock(&ctx->event_data_lock);
1293
1409
 
1294
1410
  /* take event handling lock */
1295
1411
  libusb_lock_events(ctx);
1296
1412
 
1297
- /* read the dummy data */
1298
- r = usbi_read(ctx->ctrl_pipe[0], &dummy, sizeof(dummy));
1299
- if (r <= 0)
1300
- usbi_warn(ctx, "internal signalling read failed, closing anyway");
1301
-
1302
1413
  /* Close the device */
1303
1414
  do_close(ctx, dev_handle);
1304
1415
 
1305
- /* we're done with modifying poll fds */
1306
- usbi_mutex_lock(&ctx->pollfd_modify_lock);
1307
- ctx->pollfd_modify--;
1308
- usbi_mutex_unlock(&ctx->pollfd_modify_lock);
1416
+ /* We're done with closing this device.
1417
+ * Clear the event pipe if there are no further pending events. */
1418
+ usbi_mutex_lock(&ctx->event_data_lock);
1419
+ ctx->device_close--;
1420
+ pending_events = usbi_pending_events(ctx);
1421
+ if (!pending_events)
1422
+ usbi_clear_event(ctx);
1423
+ usbi_mutex_unlock(&ctx->event_data_lock);
1309
1424
 
1310
1425
  /* Release event handling lock and wake up event waiters */
1311
1426
  libusb_unlock_events(ctx);
@@ -1413,7 +1528,8 @@ int API_EXPORTED libusb_get_configuration(libusb_device_handle *dev,
1413
1528
  *
1414
1529
  * \param dev a device handle
1415
1530
  * \param configuration the bConfigurationValue of the configuration you
1416
- * wish to activate, or -1 if you wish to put the device in unconfigured state
1531
+ * wish to activate, or -1 if you wish to put the device in an unconfigured
1532
+ * state
1417
1533
  * \returns 0 on success
1418
1534
  * \returns LIBUSB_ERROR_NOT_FOUND if the requested configuration does not exist
1419
1535
  * \returns LIBUSB_ERROR_BUSY if interfaces are currently claimed
@@ -1907,8 +2023,8 @@ int API_EXPORTED libusb_init(libusb_context **context)
1907
2023
  usbi_dbg("created default context");
1908
2024
  }
1909
2025
 
1910
- usbi_dbg("libusb v%d.%d.%d.%d", libusb_version_internal.major, libusb_version_internal.minor,
1911
- libusb_version_internal.micro, libusb_version_internal.nano);
2026
+ usbi_dbg("libusb v%u.%u.%u.%u%s", libusb_version_internal.major, libusb_version_internal.minor,
2027
+ libusb_version_internal.micro, libusb_version_internal.nano, libusb_version_internal.rc);
1912
2028
 
1913
2029
  usbi_mutex_init(&ctx->usb_devs_lock, NULL);
1914
2030
  usbi_mutex_init(&ctx->open_devs_lock, NULL);
@@ -1946,8 +2062,10 @@ err_backend_exit:
1946
2062
  if (usbi_backend->exit)
1947
2063
  usbi_backend->exit();
1948
2064
  err_free_ctx:
1949
- if (ctx == usbi_default_context)
2065
+ if (ctx == usbi_default_context) {
1950
2066
  usbi_default_context = NULL;
2067
+ default_context_refcnt--;
2068
+ }
1951
2069
 
1952
2070
  usbi_mutex_static_lock(&active_contexts_lock);
1953
2071
  list_del (&ctx->list);
@@ -2191,8 +2309,8 @@ void usbi_log_v(struct libusb_context *ctx, enum libusb_log_level level,
2191
2309
  usbi_gettimeofday(&now, NULL);
2192
2310
  if ((global_debug) && (!has_debug_header_been_displayed)) {
2193
2311
  has_debug_header_been_displayed = 1;
2194
- usbi_log_str(ctx, LIBUSB_LOG_LEVEL_DEBUG, "[timestamp] [threadID] facility level [function call] <message>\n");
2195
- usbi_log_str(ctx, LIBUSB_LOG_LEVEL_DEBUG, "--------------------------------------------------------------------------------\n");
2312
+ usbi_log_str(ctx, LIBUSB_LOG_LEVEL_DEBUG, "[timestamp] [threadID] facility level [function call] <message>" USBI_LOG_LINE_END);
2313
+ usbi_log_str(ctx, LIBUSB_LOG_LEVEL_DEBUG, "--------------------------------------------------------------------------------" USBI_LOG_LINE_END);
2196
2314
  }
2197
2315
  if (now.tv_usec < timestamp_origin.tv_usec) {
2198
2316
  now.tv_sec--;