Skip to main content

FailSafe

Struct FailSafe 

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

The fail-safe state machine (§11.10.7.2).

Holds no timer of its own: every method takes the current Instant, so the same code runs against platform::sim’s virtual clock in a test and a real one on a device — which is how the expiry paths get tested at all.

Implementations§

Source§

impl FailSafe

Source

pub const fn new(info: BasicCommissioningInfo) -> Self

A disarmed fail-safe.

Source

pub const fn info(&self) -> BasicCommissioningInfo

The BasicCommissioningInfo attribute.

Source

pub const fn breadcrumb(&self) -> u64

The Breadcrumb attribute (§11.10.6.1).

Source

pub const fn set_breadcrumb(&mut self, value: u64)

Writes the Breadcrumb. Its content “is unspecified and its value is not otherwise used by the functioning of any cluster”.

Source

pub fn is_armed(&self, now: Instant) -> bool

Whether a context is currently armed, as of now.

Expiry is lazy: nothing here runs on a timer, so a caller that never asks never learns. A device drives this from its own timer and from FailSafe::next_deadline.

Source

pub fn armed(&self, now: Instant) -> Option<Armed>

The armed context, if one is live as of now.

Source

pub fn next_deadline(&self) -> Option<Instant>

When the next expiry is due, whichever timer is sooner.

Source

pub fn arm( &mut self, expiry_length_seconds: u16, breadcrumb: u64, accessing_fabric: Option<FabricIndex>, now: Instant, window_open_over_case: bool, ) -> ArmResult

ArmFailSafe (§11.10.7.2).

accessing_fabric is the fabric of the session the command arrived on — None for a PASE session, which is the ordinary case during initial commissioning. window_open_over_case is the one condition that is not about the timer:

If the fail-safe timer is not currently armed, the commissioning window is open, and the command was received over a CASE session … respond with … BusyWithOtherAdmin. This is done to allow commissioners, which use PASE connections, the opportunity to use the failsafe during the relatively short commissioning window.

That is not a conflict between two administrators — it is a priority rule, holding the fail-safe for the commissioner that is mid-flow over PASE.

Source

pub fn record( &mut self, now: Instant, f: impl FnOnce(&mut Progress), ) -> Result<()>

Records that something happened inside the fail-safe period.

Returns ErrorCode::InvalidState when nothing is armed, which is what makes §11.18’s FAILSAFE_REQUIRED reachable: a command that mutates commissioning state outside a fail-safe has nothing to be rolled back by.

Source

pub fn adopt_fabric(&mut self, fabric: FabricIndex, now: Instant) -> Result<()>

Moves the context to the fabric an AddNOC or UpdateNOC just created or changed.

§11.10.7.2: the context’s fabric index is “updated with the Fabric Index associated with an AddNOC or an UpdateNOC command being invoked successfully”. That is what lets CommissioningComplete arrive over CASE on the new fabric and still match.

Source

pub fn complete( &mut self, over_case: bool, accessing_fabric: Option<FabricIndex>, now: Instant, ) -> CompleteResult

CommissioningComplete (§11.10.7.6).

over_case and accessing_fabric describe the session it arrived on. The three refusals are exactly the ones §11.10.7.6 names, and the order matters: a command with no fail-safe at all is NoFailSafe whether or not it came over CASE.

Source

pub fn expire(&mut self, now: Instant) -> Option<Cleanup>

Expires the context and reports §11.10.7.2.2’s cleanup steps.

Call this when FailSafe::next_deadline passes, and on start-up: “If the receiver restarts unexpectedly … the receiver SHALL behave as if the fail-safe timer expired.”

Returns None if nothing was armed.

Trait Implementations§

Source§

impl Clone for FailSafe

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 Copy for FailSafe

Source§

impl Debug for FailSafe

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Eq for FailSafe

Source§

impl PartialEq for FailSafe

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for FailSafe

Auto Trait Implementations§

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> Same for T

Source§

type Output = T

Should always be Self
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.