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
impl FailSafe
Sourcepub const fn new(info: BasicCommissioningInfo) -> Self
pub const fn new(info: BasicCommissioningInfo) -> Self
A disarmed fail-safe.
Sourcepub const fn info(&self) -> BasicCommissioningInfo
pub const fn info(&self) -> BasicCommissioningInfo
The BasicCommissioningInfo attribute.
The Breadcrumb attribute (§11.10.6.1).
Writes the Breadcrumb. Its content “is unspecified and its value is not otherwise
used by the functioning of any cluster”.
Sourcepub fn is_armed(&self, now: Instant) -> bool
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.
Sourcepub fn armed(&self, now: Instant) -> Option<Armed>
pub fn armed(&self, now: Instant) -> Option<Armed>
The armed context, if one is live as of now.
Sourcepub fn next_deadline(&self) -> Option<Instant>
pub fn next_deadline(&self) -> Option<Instant>
When the next expiry is due, whichever timer is sooner.
Sourcepub fn arm(
&mut self,
expiry_length_seconds: u16,
breadcrumb: u64,
accessing_fabric: Option<FabricIndex>,
now: Instant,
window_open_over_case: bool,
) -> ArmResult
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.
Sourcepub fn record(
&mut self,
now: Instant,
f: impl FnOnce(&mut Progress),
) -> Result<()>
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.
Sourcepub fn adopt_fabric(&mut self, fabric: FabricIndex, now: Instant) -> Result<()>
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.
Sourcepub fn complete(
&mut self,
over_case: bool,
accessing_fabric: Option<FabricIndex>,
now: Instant,
) -> CompleteResult
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.
Sourcepub fn expire(&mut self, now: Instant) -> Option<Cleanup>
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.