pub struct HotplugHub { /* private fields */ }Expand description
Shared discovery state and subscriptions. On Android feed this from the
host’s registered USB attach/detach receiver and permission result callback,
taking an initial UsbManager.deviceList snapshot after registering. The
host retains responsibility for prompts, configuration, claims and FD life.
Implementations§
Source§impl HotplugHub
impl HotplugHub
Sourcepub fn new() -> Self
pub fn new() -> Self
Examples found in repository?
9fn discovery() {
10 use usbdac_core::{DeviceInfo, HotplugHub, UsbPermission};
11 let hub = HotplugHub::new();
12 let events = hub.subscribe();
13 let attachment = hub.attached(
14 "android-device-name",
15 DeviceInfo::new(1, 2, "DAC"),
16 UsbPermission::Required,
17 );
18 // Pass attachment.id through the host permission request/callback.
19 assert!(hub.permission_changed(attachment.id, UsbPermission::Granted));
20 hub.detached(attachment.id);
21 assert!(!hub.permission_changed(attachment.id, UsbPermission::Granted));
22 drop(events);
23}pub fn snapshot(&self) -> Vec<UsbAttachment>
Sourcepub fn subscribe(&self) -> HotplugSubscription
pub fn subscribe(&self) -> HotplugSubscription
Examples found in repository?
9fn discovery() {
10 use usbdac_core::{DeviceInfo, HotplugHub, UsbPermission};
11 let hub = HotplugHub::new();
12 let events = hub.subscribe();
13 let attachment = hub.attached(
14 "android-device-name",
15 DeviceInfo::new(1, 2, "DAC"),
16 UsbPermission::Required,
17 );
18 // Pass attachment.id through the host permission request/callback.
19 assert!(hub.permission_changed(attachment.id, UsbPermission::Granted));
20 hub.detached(attachment.id);
21 assert!(!hub.permission_changed(attachment.id, UsbPermission::Granted));
22 drop(events);
23}Sourcepub fn attached(
&self,
host_key: impl Into<String>,
info: DeviceInfo,
permission: UsbPermission,
) -> UsbAttachment
pub fn attached( &self, host_key: impl Into<String>, info: DeviceInfo, permission: UsbPermission, ) -> UsbAttachment
Record a host-observed attach. Repeated attach broadcasts are idempotent.
Call permission_changed for an existing attachment’s permission update.
Examples found in repository?
9fn discovery() {
10 use usbdac_core::{DeviceInfo, HotplugHub, UsbPermission};
11 let hub = HotplugHub::new();
12 let events = hub.subscribe();
13 let attachment = hub.attached(
14 "android-device-name",
15 DeviceInfo::new(1, 2, "DAC"),
16 UsbPermission::Required,
17 );
18 // Pass attachment.id through the host permission request/callback.
19 assert!(hub.permission_changed(attachment.id, UsbPermission::Granted));
20 hub.detached(attachment.id);
21 assert!(!hub.permission_changed(attachment.id, UsbPermission::Granted));
22 drop(events);
23}Sourcepub fn reconcile(&self, devices: Vec<(String, DeviceInfo, UsbPermission)>)
pub fn reconcile(&self, devices: Vec<(String, DeviceInfo, UsbPermission)>)
Reconcile a complete, authoritative host snapshot after events may have been missed. Serialize snapshot collection and event delivery in the host. A device which disappeared and returned at the same key entirely between snapshots cannot be distinguished here. Existing keys with the same VID/PID keep their IDs; missing or changed identities are detached.
Sourcepub fn permission_changed(&self, id: u64, permission: UsbPermission) -> bool
pub fn permission_changed(&self, id: u64, permission: UsbPermission) -> bool
Reject delayed results for an unplugged device, including a reused path.
Examples found in repository?
9fn discovery() {
10 use usbdac_core::{DeviceInfo, HotplugHub, UsbPermission};
11 let hub = HotplugHub::new();
12 let events = hub.subscribe();
13 let attachment = hub.attached(
14 "android-device-name",
15 DeviceInfo::new(1, 2, "DAC"),
16 UsbPermission::Required,
17 );
18 // Pass attachment.id through the host permission request/callback.
19 assert!(hub.permission_changed(attachment.id, UsbPermission::Granted));
20 hub.detached(attachment.id);
21 assert!(!hub.permission_changed(attachment.id, UsbPermission::Granted));
22 drop(events);
23}Sourcepub fn detached(&self, id: u64) -> bool
pub fn detached(&self, id: u64) -> bool
Examples found in repository?
9fn discovery() {
10 use usbdac_core::{DeviceInfo, HotplugHub, UsbPermission};
11 let hub = HotplugHub::new();
12 let events = hub.subscribe();
13 let attachment = hub.attached(
14 "android-device-name",
15 DeviceInfo::new(1, 2, "DAC"),
16 UsbPermission::Required,
17 );
18 // Pass attachment.id through the host permission request/callback.
19 assert!(hub.permission_changed(attachment.id, UsbPermission::Granted));
20 hub.detached(attachment.id);
21 assert!(!hub.permission_changed(attachment.id, UsbPermission::Granted));
22 drop(events);
23}