Skip to main content

RoutingSnapshot

Struct RoutingSnapshot 

Source
pub struct RoutingSnapshot { /* private fields */ }
Expand description

Immutable discovery result, tied to an attachment and active configuration. Keeping a snapshot does not retain the host’s USB claims after Dac::close.

Implementations§

Source§

impl RoutingSnapshot

Source

pub fn hand_back_report(&self) -> Option<RoutingHandBackReport>

None until final retirement completes; remains available after close.

Examples found in repository?
examples/usbip_lifecycle.rs (line 206)
148    fn full_uac3(
149        dac: Dac,
150        fd: i32,
151        caps: &usbdac_core::Capabilities,
152        volatile: bool,
153    ) -> Result<(), Box<dyn std::error::Error>> {
154        use usbdac_core::routing::{
155            ControlKey, Entity, RouteEdit, RouteValue, RoutingHandBackOutcome,
156        };
157        assert_eq!(caps.uac_version, UacVersion::V3);
158        assert_eq!(caps.link_speed, LinkSpeed::High);
159        let key = ControlKey::Selector(Entity {
160            interface: 0,
161            id: 8,
162        });
163        assert_eq!(power(fd)?, 2, "initial power must be D2");
164        let snapshot = dac.routing_discover_powered()?;
165        println!("UAC3_ROUTING snapshot={snapshot:?}");
166        assert_eq!(snapshot.configuration(), 3);
167        assert_eq!(power(fd)?, 2, "discovery must restore D2");
168        assert_eq!(
169            dac.routing_read_powered(&snapshot, key)?,
170            RouteValue::SelectorPin(1)
171        );
172        assert_eq!(power(fd)?, 2, "read must restore D2");
173        let report = dac.routing_apply_powered(
174            &snapshot,
175            &[RouteEdit {
176                key,
177                expected: RouteValue::SelectorPin(1),
178                value: RouteValue::SelectorPin(2),
179            }],
180        )?;
181        assert_eq!(report.changed, vec![key]);
182        let applied = out_of_band("snapshot")?;
183        assert!(
184            applied.contains("selector=[2]"),
185            "fixture selector was not written: {applied}"
186        );
187        assert!(
188            applied.contains(if volatile {
189                "selector_state=1"
190            } else {
191                "selector_state=2"
192            }),
193            "unexpected fixture selector after D2: {applied}"
194        );
195        assert_eq!(power(fd)?, 2, "apply must restore D2");
196        let updated = dac.routing_discover_powered()?;
197        assert_eq!(
198            dac.routing_read_powered(&updated, key)?,
199            RouteValue::SelectorPin(if volatile { 1 } else { 2 }),
200            "selector readback must reflect the fixture's D2 behavior"
201        );
202        assert_eq!(power(fd)?, 2);
203        dac.close()?;
204        assert!(Dac::await_usb_retirement(Duration::from_secs(3)));
205        let hand_back = snapshot
206            .hand_back_report()
207            .ok_or("missing routing hand-back report")?;
208        println!("UAC3_HAND_BACK {hand_back:?}");
209        if !volatile {
210            assert!(
211                hand_back
212                    .controls
213                    .contains(&(key, RoutingHandBackOutcome::Restored)),
214                "selector hand-back was not verified"
215            );
216        }
217        assert_eq!(power(fd)?, 2, "final power must be D2");
218        assert!(
219            out_of_band("snapshot")?.contains("selector_state=1"),
220            "fixture selector was not restored"
221        );
222        assert_eq!(alt(fd)?, 0);
223        for interface in [1, 0] {
224            claim(fd, interface, false)?;
225        }
226        println!("USBIP_LIFECYCLE_PASS mode=full-uac3 selector=restored power=D2 retired=true");
227        Ok(())
228    }
Source

pub fn diagnostics(&self) -> &[RoutingDiagnostic]

Source

pub fn configuration(&self) -> u8

Examples found in repository?
examples/usbip_lifecycle.rs (line 166)
148    fn full_uac3(
149        dac: Dac,
150        fd: i32,
151        caps: &usbdac_core::Capabilities,
152        volatile: bool,
153    ) -> Result<(), Box<dyn std::error::Error>> {
154        use usbdac_core::routing::{
155            ControlKey, Entity, RouteEdit, RouteValue, RoutingHandBackOutcome,
156        };
157        assert_eq!(caps.uac_version, UacVersion::V3);
158        assert_eq!(caps.link_speed, LinkSpeed::High);
159        let key = ControlKey::Selector(Entity {
160            interface: 0,
161            id: 8,
162        });
163        assert_eq!(power(fd)?, 2, "initial power must be D2");
164        let snapshot = dac.routing_discover_powered()?;
165        println!("UAC3_ROUTING snapshot={snapshot:?}");
166        assert_eq!(snapshot.configuration(), 3);
167        assert_eq!(power(fd)?, 2, "discovery must restore D2");
168        assert_eq!(
169            dac.routing_read_powered(&snapshot, key)?,
170            RouteValue::SelectorPin(1)
171        );
172        assert_eq!(power(fd)?, 2, "read must restore D2");
173        let report = dac.routing_apply_powered(
174            &snapshot,
175            &[RouteEdit {
176                key,
177                expected: RouteValue::SelectorPin(1),
178                value: RouteValue::SelectorPin(2),
179            }],
180        )?;
181        assert_eq!(report.changed, vec![key]);
182        let applied = out_of_band("snapshot")?;
183        assert!(
184            applied.contains("selector=[2]"),
185            "fixture selector was not written: {applied}"
186        );
187        assert!(
188            applied.contains(if volatile {
189                "selector_state=1"
190            } else {
191                "selector_state=2"
192            }),
193            "unexpected fixture selector after D2: {applied}"
194        );
195        assert_eq!(power(fd)?, 2, "apply must restore D2");
196        let updated = dac.routing_discover_powered()?;
197        assert_eq!(
198            dac.routing_read_powered(&updated, key)?,
199            RouteValue::SelectorPin(if volatile { 1 } else { 2 }),
200            "selector readback must reflect the fixture's D2 behavior"
201        );
202        assert_eq!(power(fd)?, 2);
203        dac.close()?;
204        assert!(Dac::await_usb_retirement(Duration::from_secs(3)));
205        let hand_back = snapshot
206            .hand_back_report()
207            .ok_or("missing routing hand-back report")?;
208        println!("UAC3_HAND_BACK {hand_back:?}");
209        if !volatile {
210            assert!(
211                hand_back
212                    .controls
213                    .contains(&(key, RoutingHandBackOutcome::Restored)),
214                "selector hand-back was not verified"
215            );
216        }
217        assert_eq!(power(fd)?, 2, "final power must be D2");
218        assert!(
219            out_of_band("snapshot")?.contains("selector_state=1"),
220            "fixture selector was not restored"
221        );
222        assert_eq!(alt(fd)?, 0);
223        for interface in [1, 0] {
224            claim(fd, interface, false)?;
225        }
226        println!("USBIP_LIFECYCLE_PASS mode=full-uac3 selector=restored power=D2 retired=true");
227        Ok(())
228    }
Source

pub fn inventory(&self) -> &RoutingInventory

Source

pub fn selector_values(&self) -> &[RouteChange]

Trait Implementations§

Source§

impl Clone for RoutingSnapshot

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RoutingSnapshot

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for RoutingSnapshot

§

impl !UnwindSafe for RoutingSnapshot

§

impl Forget for RoutingSnapshot

§

impl Freeze for RoutingSnapshot
where *const ArcInner<OwnedUsbFd> is !null: Freeze, PhantomData<ArcInner<OwnedUsbFd>>: Freeze, *const ArcInner<[u8]> is !null: Freeze, PhantomData<ArcInner<[u8]>>: Freeze, *const u8 is !null: Freeze, PhantomData<u8>: Freeze, *const LeafNode<Entity, RoutingUnit> is !null: Freeze, PhantomData<(Owned, LeafOrInternal)>: Freeze, PhantomData<Box<(Entity, RoutingUnit)>>: Freeze, PhantomData<RouteChange>: Freeze, *const LeafNode<(u8, u16), RoutingCluster> is !null: Freeze, PhantomData<Box<((u8, u16), RoutingCluster)>>: Freeze, PhantomData<RoutingDiagnostic>: Freeze, *const ArcInner<Mutex<RawMutex, Option<RoutingHandBackReport>>> is !null: Freeze, PhantomData<ArcInner<Mutex<RawMutex, Option<RoutingHandBackReport>>>>: Freeze,

§

impl Move for RoutingSnapshot

§

impl Send for RoutingSnapshot
where Arc<OwnedUsbFd>: Send, Arc<[u8]>: Send, RawVecInner: Send, NodeRef<Owned, Entity, RoutingUnit, LeafOrInternal>: Send, BoxRaw<(Entity, RoutingUnit)>: Send, NodeRef<Owned, (u8, u16), RoutingCluster, LeafOrInternal>: Send, BoxRaw<((u8, u16), RoutingCluster)>: Send, Arc<Mutex<RawMutex, Option<RoutingHandBackReport>>>: Send,

§

impl Sync for RoutingSnapshot
where Arc<OwnedUsbFd>: Sync, Arc<[u8]>: Sync, RawVecInner: Sync, NodeRef<Owned, Entity, RoutingUnit, LeafOrInternal>: Sync, BoxRaw<(Entity, RoutingUnit)>: Sync, NodeRef<Owned, (u8, u16), RoutingCluster, LeafOrInternal>: Sync, BoxRaw<((u8, u16), RoutingCluster)>: Sync, Arc<Mutex<RawMutex, Option<RoutingHandBackReport>>>: Sync,

§

impl Unpin for RoutingSnapshot
where Arc<OwnedUsbFd>: Unpin, Arc<[u8]>: Unpin, *const u8 is !null: Unpin, *const LeafNode<Entity, RoutingUnit> is !null: Unpin, Box<(Entity, RoutingUnit)>: Unpin, *const LeafNode<(u8, u16), RoutingCluster> is !null: Unpin, Box<((u8, u16), RoutingCluster)>: Unpin, Arc<Mutex<RawMutex, Option<RoutingHandBackReport>>>: Unpin,

§

impl UnsafeUnpin for RoutingSnapshot
where *const ArcInner<OwnedUsbFd> is !null: UnsafeUnpin, PhantomData<ArcInner<OwnedUsbFd>>: UnsafeUnpin, *const ArcInner<[u8]> is !null: UnsafeUnpin, PhantomData<ArcInner<[u8]>>: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin, *const LeafNode<Entity, RoutingUnit> is !null: UnsafeUnpin, PhantomData<(Owned, LeafOrInternal)>: UnsafeUnpin, PhantomData<Box<(Entity, RoutingUnit)>>: UnsafeUnpin, PhantomData<RouteChange>: UnsafeUnpin, *const LeafNode<(u8, u16), RoutingCluster> is !null: UnsafeUnpin, PhantomData<Box<((u8, u16), RoutingCluster)>>: UnsafeUnpin, PhantomData<RoutingDiagnostic>: UnsafeUnpin, *const ArcInner<Mutex<RawMutex, Option<RoutingHandBackReport>>> is !null: UnsafeUnpin, PhantomData<ArcInner<Mutex<RawMutex, Option<RoutingHandBackReport>>>>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.