pub struct Backend { /* private fields */ }Expand description
Backend role for one authorized route. Callers schedule timeouts via Self::cancel.
Implementations§
Source§impl Backend
impl Backend
Sourcepub fn checkpoint(&mut self, now: Clock) -> Result<Vec<u8>, EngineError>
pub fn checkpoint(&mut self, now: Clock) -> Result<Vec<u8>, EngineError>
Checkpoint before publishing a newly registered control and again after its ACK. Store these potentially credential-bearing bytes atomically under exclusive route ownership.
Sourcepub fn restore(self, bytes: &[u8], now: Clock) -> Result<Self, EngineError>
pub fn restore(self, bytes: &[u8], now: Clock) -> Result<Self, EngineError>
Recover using externally provisioned route, source and capacity. Restored commands await the original ACK. A state read can reconcile uncertain equipment while conflicting writes and desired-control replies stay blocked. Explicit cancellation abandons correlation.
Source§impl Backend
impl Backend
Sourcepub fn new(
route: impl Into<String>,
source: impl Into<String>,
capacity: usize,
) -> Self
pub fn new( route: impl Into<String>, source: impl Into<String>, capacity: usize, ) -> Self
capacity bounds outstanding controls and cached meters. A separate slot
permits one state read even while every control slot awaits reconciliation.
Sourcepub fn state(&self) -> Option<&State>
pub fn state(&self) -> Option<&State>
Latest validated observations for this route. The aggregate timestamp is the greatest accepted message timestamp. Individual properties may come from earlier messages.
Sourcepub fn property_observed_at(&self, field: &str) -> Option<i64>
pub fn property_observed_at(&self, field: &str) -> Option<i64>
Device timestamp of the last accepted observation or authoritative clear of a wire field.
For measurements this is the latest time across its inventory and individual sources.
Sourcepub fn meter_observed_at(&self, id: &str) -> Option<i64>
pub fn meter_observed_at(&self, id: &str) -> Option<i64>
Device timestamp of the cached reading for a particular meter, in Unix seconds.
Sourcepub fn cancel(&mut self, id: &str) -> bool
pub fn cancel(&mut self, id: &str) -> bool
Cancel a request after timeout. A later reply cannot update the cache through this ID. Request IDs must be unique across retries and restarts.
Sourcepub fn pending_controls(&self) -> impl Iterator<Item = (&str, &Control)>
pub fn pending_controls(&self) -> impl Iterator<Item = (&str, &Control)>
Outstanding operations whose equipment outcome still needs confirmation. These entries survive checkpoint restore and are never republished by the engine.
Sourcepub fn confirmed_settings(&mut self, now: Clock) -> Result<Control, EngineError>
pub fn confirmed_settings(&mut self, now: Clock) -> Result<Control, EngineError>
Confirmed desired settings, including remaining or expired lifetimes. Both power directions can be represented in memory even where the 1.2.0 reply cannot carry both.
Sourcepub fn send_control(
&mut self,
id: &str,
request: Control,
now: Clock,
) -> Result<Message, EngineError>
pub fn send_control( &mut self, id: &str, request: Control, now: Clock, ) -> Result<Message, EngineError>
Register a standalone control before transmitting. Only one per family may be outstanding.
Sourcepub fn read(
&mut self,
id: &str,
parameters: Vec<String>,
) -> Result<Message, EngineError>
pub fn read( &mut self, id: &str, parameters: Vec<String>, ) -> Result<Message, EngineError>
Register a state read. Empty parameters request a full snapshot.
Sourcepub fn receive(
&mut self,
route: &str,
message: &Message,
reply_id: &str,
now: Clock,
) -> Result<BackendEvent, EngineError>
pub fn receive( &mut self, route: &str, message: &Message, reply_id: &str, now: Clock, ) -> Result<BackendEvent, EngineError>
Consume a verified message received on the provisioned target. reply_id is used on replies.