pub struct ScenarioStateMachineManager { /* private fields */ }Expand description
Manager for scenario state machines
Handles loading state machines from scenario manifests, validating them, executing state transitions, and managing active state instances.
Implementations§
Source§impl ScenarioStateMachineManager
impl ScenarioStateMachineManager
Sourcepub async fn load_from_manifest(
&self,
manifest: &ScenarioManifest,
) -> Result<()>
pub async fn load_from_manifest( &self, manifest: &ScenarioManifest, ) -> Result<()>
Load state machines from a scenario manifest
Validates and loads all state machines defined in the manifest, along with their visual layouts.
Sourcepub fn validate_state_machine(&self, state_machine: &StateMachine) -> Result<()>
pub fn validate_state_machine(&self, state_machine: &StateMachine) -> Result<()>
Validate a state machine
Checks that:
- Initial state exists in states list
- All transitions reference valid states
- Sub-scenario references are valid
- No circular dependencies in sub-scenarios
Sourcepub async fn get_state_machine(
&self,
resource_type: &str,
) -> Option<StateMachine>
pub async fn get_state_machine( &self, resource_type: &str, ) -> Option<StateMachine>
Get a state machine by resource type
Sourcepub async fn get_visual_layout(
&self,
resource_type: &str,
) -> Option<VisualLayout>
pub async fn get_visual_layout( &self, resource_type: &str, ) -> Option<VisualLayout>
Get visual layout for a state machine
Sourcepub async fn create_instance(
&self,
resource_id: impl Into<String>,
resource_type: impl Into<String>,
) -> Result<()>
pub async fn create_instance( &self, resource_id: impl Into<String>, resource_type: impl Into<String>, ) -> Result<()>
Create a new state instance for a resource
Initializes a new state instance with the initial state from the state machine.
Sourcepub async fn get_current_state(&self, resource_id: &str) -> Option<String>
pub async fn get_current_state(&self, resource_id: &str) -> Option<String>
Get current state of a resource instance
Sourcepub async fn execute_transition(
&self,
resource_id: &str,
to_state: impl Into<String>,
context: Option<HashMap<String, Value>>,
) -> Result<()>
pub async fn execute_transition( &self, resource_id: &str, to_state: impl Into<String>, context: Option<HashMap<String, Value>>, ) -> Result<()>
Execute a state transition
Attempts to transition a resource instance from its current state to a new state. Validates the transition is allowed and evaluates any conditions.
Sourcepub async fn list_instances(&self) -> Vec<StateInstance>
pub async fn list_instances(&self) -> Vec<StateInstance>
Get all state instances
Sourcepub async fn get_instance(&self, resource_id: &str) -> Option<StateInstance>
pub async fn get_instance(&self, resource_id: &str) -> Option<StateInstance>
Get state instance by resource ID
Sourcepub async fn delete_instance(&self, resource_id: &str) -> bool
pub async fn delete_instance(&self, resource_id: &str) -> bool
Delete a state instance
Sourcepub async fn get_next_states(&self, resource_id: &str) -> Result<Vec<String>>
pub async fn get_next_states(&self, resource_id: &str) -> Result<Vec<String>>
Get next possible states for a resource
Returns all states that can be reached from the current state of the resource.
Sourcepub async fn set_visual_layout(&self, resource_type: &str, layout: VisualLayout)
pub async fn set_visual_layout(&self, resource_type: &str, layout: VisualLayout)
Set visual layout for a state machine
Sourcepub async fn delete_state_machine(&self, resource_type: &str) -> bool
pub async fn delete_state_machine(&self, resource_type: &str) -> bool
Delete a state machine by resource type
Removes the state machine and its visual layout. Also removes all instances associated with this resource type.
Sourcepub async fn list_state_machines(&self) -> Vec<(String, StateMachine)>
pub async fn list_state_machines(&self) -> Vec<(String, StateMachine)>
List all state machines
Returns a list of all loaded state machines with their resource types.
Sourcepub async fn export_all(
&self,
) -> (Vec<StateMachine>, HashMap<String, VisualLayout>)
pub async fn export_all( &self, ) -> (Vec<StateMachine>, HashMap<String, VisualLayout>)
Get all state machines and visual layouts for export
Returns all state machines and their associated visual layouts in a format suitable for export.