-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Receiving notifications despite a filter #157
Comments
I can't reproduce you problem. What linux distro do you use? use rusb::{Context, Device, HotplugBuilder, UsbContext};
struct HotPlugHandler;
impl<T: UsbContext> rusb::Hotplug<T> for HotPlugHandler {
fn device_arrived(&mut self, device: Device<T>) {
println!("device arrived {:?}", device);
}
fn device_left(&mut self, device: Device<T>) {
println!("device left {:?}", device);
}
}
impl Drop for HotPlugHandler {
fn drop(&mut self) {
println!("HotPlugHandler dropped");
}
}
fn main() -> rusb::Result<()> {
if rusb::has_hotplug() {
let context = Context::new()?;
let mut reg: Option<rusb::Registration<Context>> = Some(
HotplugBuilder::new()
.enumerate(true)
.vendor_id(0x18d1)
.product_id(0x4ee7)
.register(&context, Box::new(HotPlugHandler {}))?,
);
loop {
context.handle_events(None).unwrap();
}
Ok(())
} else {
eprint!("libusb hotplug api unsupported");
Ok(())
}
} |
I tested this on MacOS Venture (13.0.1) as well as Ubuntu 22.10. Please change the code in the loop to look like this and you may see what I'm complaining about:
You should see There are operations that should not be performed in the callbacks and it would be natural to wait for a device in the loop and then perform any necessary operations once the device was attached or detached. |
This is expected behavioral. |
I set up a vid/pid filter expecting
ctx.handle_events
not to return unless a notification for my device of choice is received.I receive
connect/disconnect
notifications for any device that's attached or detached, though.Is there a bug in the code or am I supposed to manually figure out if my device was attached or detached, like I'm doing below?
In other words, how do I wait for my device to appear or disappear without polling for it?
The text was updated successfully, but these errors were encountered: