Statifier.StateChart (statifier v1.9.0)

View Source

Represents a running state chart instance.

Contains the parsed document, current configuration, and separate queues for internal and external events as specified by the SCXML specification.

Summary

Functions

Configure logging for the state chart.

Remove and return the next event from internal queue (higher priority). Falls back to external queue if internal queue is empty.

Add an event to the appropriate queue based on its origin.

Get deep history for a parent state.

Get shallow history for a parent state.

Check if there are any events in either queue.

Check if a parent state has recorded history.

Create a new state chart from a document with empty configuration.

Create a new state chart with a specific configuration.

Record history for a parent state before it exits.

Set the current event being processed.

Update the log level for the state chart.

Update the configuration of the state chart.

Update the datamodel of the state chart.

Types

invoke_handler()

@type invoke_handler() :: (String.t(), map(), t() ->
                       {:ok, t()}
                       | {:ok, term(), t()}
                       | {:error, :communication, term()}
                       | {:error, :execution, term()})

t()

@type t() :: %Statifier.StateChart{
  configuration: Statifier.Configuration.t(),
  current_event: Statifier.Event.t() | nil,
  datamodel: Statifier.Datamodel.t(),
  document: Statifier.Document.t(),
  external_queue: [Statifier.Event.t()],
  history_tracker: Statifier.HistoryTracker.t(),
  internal_queue: [Statifier.Event.t()],
  invoke_handlers: %{required(String.t()) => invoke_handler()},
  log_adapter: struct() | nil,
  log_level: atom(),
  logs: [map()]
}

Functions

configure_logging(state_chart, adapter, level \\ :info)

@spec configure_logging(t(), struct(), atom()) :: t()

Configure logging for the state chart.

Parameters

  • state_chart - StateChart to configure
  • adapter - Logging adapter instance
  • level - Minimum log level (optional, defaults to :info)

Examples

adapter = %Statifier.Logging.TestAdapter{max_entries: 100}
state_chart = StateChart.configure_logging(state_chart, adapter, :debug)

dequeue_event(state_chart)

@spec dequeue_event(t()) :: {Statifier.Event.t() | nil, t()}

Remove and return the next event from internal queue (higher priority). Falls back to external queue if internal queue is empty.

enqueue_event(state_chart, event)

@spec enqueue_event(t(), Statifier.Event.t()) :: t()

Add an event to the appropriate queue based on its origin.

get_deep_history(state_chart, parent_state_id)

@spec get_deep_history(t(), String.t()) :: MapSet.t(String.t())

Get deep history for a parent state.

Returns all atomic descendant states that were active when the parent was last exited.

get_shallow_history(state_chart, parent_state_id)

@spec get_shallow_history(t(), String.t()) :: MapSet.t(String.t())

Get shallow history for a parent state.

Returns the immediate children that were active when the parent was last exited.

has_events?(state_chart)

@spec has_events?(t()) :: boolean()

Check if there are any events in either queue.

has_history?(state_chart, parent_state_id)

@spec has_history?(t(), String.t()) :: boolean()

Check if a parent state has recorded history.

new(document)

@spec new(Statifier.Document.t()) :: t()

Create a new state chart from a document with empty configuration.

new(document, configuration)

Create a new state chart with a specific configuration.

record_history(state_chart, parent_state_id)

@spec record_history(t(), String.t()) :: t()

Record history for a parent state before it exits.

Uses the current active state configuration and the document to determine which states to record for shallow and deep history.

set_current_event(state_chart, event)

@spec set_current_event(t(), Statifier.Event.t() | nil) :: t()

Set the current event being processed.

set_log_level(state_chart, level)

@spec set_log_level(t(), atom()) :: t()

Update the log level for the state chart.

update_configuration(state_chart, configuration)

@spec update_configuration(t(), Statifier.Configuration.t()) :: t()

Update the configuration of the state chart.

update_datamodel(state_chart, datamodel)

@spec update_datamodel(t(), Statifier.Datamodel.t()) :: t()

Update the datamodel of the state chart.