pub struct AssetWatch { /* private fields */ }Expand description
Subscription handle for one location. One watcher per location;
construct multiple instances if the control program cares about
multiple roles. Hold onto the AssetWatch for the lifetime of the
control program — dropping it leaves the underlying topic
subscribed but discards any queued events.
Implementations§
Source§impl AssetWatch
impl AssetWatch
Sourcepub fn new(location: &str, client: &mut CommandClient) -> Self
pub fn new(location: &str, client: &mut CommandClient) -> Self
Subscribe to ams.asset_updated.<location> and issue the
initial-sync query. Returns the handle the control program
holds for the duration of the run.
client is the CommandClient from TickContext::client. The
subscription persists past this call — CommandClient owns
the buffer.
Sourcepub fn initialised(&self) -> bool
pub fn initialised(&self) -> bool
True once an InitialSync (or InitialSyncEmpty) has been
returned from pump(). Until this flips, subsequent broadcasts
are still surfaced — initial-sync just tells the operator
“you’ve seen the baseline.”
Sourcepub fn is_active(&self) -> bool
pub fn is_active(&self) -> bool
true if the watcher’s latest observation is that an active
asset is registered at this location. The common control-loop
gate: refuse to enter auto when this is false.
Initially false until the first pump() consumes the
initial-sync result. After that it tracks broadcasts in
real time.
Sourcepub fn active_asset_id(&self) -> Option<&str>
pub fn active_asset_id(&self) -> Option<&str>
asset_id currently filling this role, or None when
status is Missing. Useful for logging “running against
LC-2026…” and for the per-cycle trail in TIS records.
Sourcepub fn active_status(&self) -> AssetWatchStatus
pub fn active_status(&self) -> AssetWatchStatus
Finer-grained version of is_active. Use when a control
program needs to distinguish (e.g.) Retired from
OutForService to drive different operator messaging.
Sourcepub fn pump(&mut self, client: &mut CommandClient) -> Vec<AssetUpdate>
pub fn pump(&mut self, client: &mut CommandClient) -> Vec<AssetUpdate>
Per-tick drain. Returns every event since the previous call, in arrival order. Empty when no events are pending.
The first non-empty return (assuming the ams.list_assets
response has arrived) starts with either InitialSync or
InitialSyncEmpty, followed by any broadcasts that landed
before the response did.