From 5b906d33587dc7694d4c884ae277d30681c8da6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Tue, 3 Aug 2021 13:39:15 +0400 Subject: [PATCH 1/2] Add Context::interrupt_handle_events() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marc-André Lureau --- libusb1-sys/src/lib.rs | 1 + src/context.rs | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/libusb1-sys/src/lib.rs b/libusb1-sys/src/lib.rs index 2f9118d..5350566 100644 --- a/libusb1-sys/src/lib.rs +++ b/libusb1-sys/src/lib.rs @@ -426,6 +426,7 @@ extern "system" { completed: *mut c_int, ) -> c_int; pub fn libusb_handle_events_locked(context: *mut libusb_context, tv: *const timeval) -> c_int; + pub fn libusb_interrupt_event_handler(context: *mut libusb_context); pub fn libusb_try_lock_events(context: *mut libusb_context) -> c_int; pub fn libusb_lock_events(context: *mut libusb_context); diff --git a/src/context.rs b/src/context.rs index c419405..d159145 100644 --- a/src/context.rs +++ b/src/context.rs @@ -190,6 +190,15 @@ pub trait UsbContext: Clone + Sized + Send + Sync { } } + /// Interrupt any active thread that is handling events (for example with + /// [handle_events][`Self::handle_events()`]). + #[doc(alias = "libusb_interrupt_event_handler")] + fn interrupt_handle_events(&self) { + unsafe { + libusb_interrupt_event_handler(self.as_raw()) + } + } + fn next_timeout(&self) -> crate::Result> { let mut tv = timeval { tv_sec: 0, tv_usec: 0 }; let n = unsafe { From 11bca16f1e9850b7fd88006967c33016317f2bb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Wed, 11 Aug 2021 19:25:29 +0400 Subject: [PATCH 2/2] Fix cargo doc warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marc-André Lureau --- src/context.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/context.rs b/src/context.rs index d159145..e7a0a18 100644 --- a/src/context.rs +++ b/src/context.rs @@ -109,13 +109,13 @@ pub trait UsbContext: Clone + Sized + Send + Sync { /// [Hotplug::device_arrived] method is called when a new device is added to /// the bus, and [Hotplug::device_left] is called when it is removed. /// - /// Devices can optionally be filtered by vendor ([vendor_id]) and device id - /// ([device_id]). If [enumerate] is `true`, then devices that are already - /// connected will cause your callback's `device_arrived()` method to be - /// called for them. + /// Devices can optionally be filtered by `vendor_id` and `device_id`. If + /// `enumerate` is `true`, then devices that are already connected will + /// cause your callback's `device_arrived()` method to be called for them. /// /// The callback will remain registered until the returned [Registration] is - /// dropped, which can be done explicitly with [hotplug_unregister_callback]. + /// dropped, which can be done explicitly with + /// [hotplug_unregister_callback][Self::hotplug_unregister_callback()]. #[must_use = "USB hotplug callbacks will be deregistered if the registration is dropped"] fn hotplug_register_callback( &self,