Skip to main content

StateSetContext

Struct StateSetContext 

Source
pub struct StateSetContext<V: ProgramVars> {
    pub local_vars: V,
    pub ss_id: usize,
    /* private fields */
}
Expand description

Context for a single state set’s execution.

Each state set runs as an independent tokio task with its own local variable snapshot. The main loop evaluates when conditions and performs state transitions.

Fields§

§local_vars: V

Local variable snapshot — updated from channel store at sync points.

§ss_id: usize

State set index.

Implementations§

Source§

impl<V: ProgramVars> StateSetContext<V>

Source

pub fn new( initial_vars: V, ss_id: usize, num_channels: usize, wakeup: Arc<Notify>, store: Arc<ChannelStore>, channels: Arc<Vec<Channel>>, event_flags: Arc<EventFlagSet>, shutdown: Arc<AtomicBool>, ) -> Self

Source

pub fn dirty_flags(&self) -> Arc<Vec<AtomicBool>>

Get a clone of the dirty flags Arc (needed for monitor setup).

Source

pub fn current_state(&self) -> usize

Get the current state index.

Source

pub fn transition_to(&mut self, state: usize)

Signal a transition to a new state. The transition completes after the current when-action finishes.

Source

pub fn has_transition(&self) -> bool

Check if a transition is pending.

Source

pub fn is_shutdown(&self) -> bool

Check if shutdown was requested.

Source

pub fn delay(&mut self, seconds: f64) -> bool

SNL delay(t) — returns true if enough time has elapsed since entering the current state.

If not yet elapsed, registers a wakeup at the remaining time so the state set re-evaluates when the delay expires.

Source

pub async fn pv_get(&mut self, ch_id: usize, comp: CompType) -> PvStat

pvGet: read value from IOC via CA.

  • Default/Sync: synchronous with 5s timeout. Returns PvStat.
  • Async: starts background task. Check with pv_get_complete().
Source

pub async fn pv_put(&mut self, ch_id: usize, comp: CompType) -> PvStat

pvPut: write local var value to IOC via CA.

  • Default: fire-and-forget (start put, don’t wait). Returns PvStat.
  • Sync: synchronous with 5s timeout.
  • Async: starts background task. Check with pv_put_complete().
Source

pub async fn pv_get_complete(&mut self, ch_id: usize) -> bool

Check if async pvGet has completed. If safe mode, copies value from store. Returns true if complete (idempotent — can be called multiple times).

Source

pub async fn pv_put_complete(&mut self, ch_id: usize) -> bool

Check if async pvPut has completed.

Source

pub async fn pv_get_cancel(&mut self, ch_id: usize)

Cancel pending async pvGet.

Source

pub async fn pv_put_cancel(&mut self, ch_id: usize)

Cancel pending async pvPut.

Source

pub fn pv_status(&self, ch_id: usize) -> PvStat

Get the PvStat of the last completed operation on a channel.

Source

pub fn pv_severity(&self, ch_id: usize) -> i16

Get the severity of the last completed operation on a channel.

Source

pub fn pv_message(&self, ch_id: usize) -> Option<&str>

Get the message of the last completed operation on a channel.

Source

pub fn ef_set(&self, ef_id: usize)

Set an event flag.

Source

pub fn ef_test(&mut self, ef_id: usize) -> bool

Test an event flag. If true, also performs selective sync of channels synced to this flag.

Source

pub fn ef_clear(&self, ef_id: usize) -> bool

Clear an event flag.

Source

pub fn ef_test_and_clear(&mut self, ef_id: usize) -> bool

Test and clear an event flag atomically. If was set, also performs selective sync.

Source

pub fn pv_connected(&self, ch_id: usize) -> bool

Check if a specific channel is connected.

Source

pub fn pv_connect_count(&self) -> usize

Count of connected channels.

Source

pub fn pv_channel_count(&self) -> usize

Total channel count.

Source

pub fn sync_dirty_vars(&mut self)

Synchronize all dirty channel values from the store into local_vars. Called once per when-evaluation cycle to maintain snapshot atomicity.

Source

pub fn reset_wakeup(&mut self)

Reset wakeup timer for a new evaluation cycle.

Source

pub async fn wait_for_wakeup(&self)

Wait for the next wakeup event (notification, timeout, or shutdown).

Source

pub fn enter_state(&mut self, state: usize)

Enter a new state: reset time_entered and clear transition.

Source

pub fn should_run_entry(&self) -> bool

Should entry actions run? (prev_state != current_state)

Source

pub fn should_run_exit(&self) -> bool

Should exit actions run? (next_state != current_state)

Source

pub fn take_transition(&mut self) -> Option<usize>

Consume the pending transition, returning the target state.

Source

pub fn wakeup(&self) -> &Arc<Notify>

Get the wakeup Notify (for initial trigger).

Auto Trait Implementations§

§

impl<V> Freeze for StateSetContext<V>
where V: Freeze,

§

impl<V> !RefUnwindSafe for StateSetContext<V>

§

impl<V> Send for StateSetContext<V>

§

impl<V> Sync for StateSetContext<V>

§

impl<V> Unpin for StateSetContext<V>
where V: Unpin,

§

impl<V> UnsafeUnpin for StateSetContext<V>
where V: UnsafeUnpin,

§

impl<V> !UnwindSafe for StateSetContext<V>

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more