yasmine
sxy::state_machine_base Class Referenceabstract

#include <state_machine_base.hpp>

Inheritance diagram for sxy::state_machine_base:
sxy::state_machine_introspection sxy::event_collector sxy::interruptible sxy::SX_FINAL sxy::sync_state_machine

Public Member Functions

 state_machine_base (const std::string &_name, event_processing_callback *const _event_processing_callback=SX_NULLPTR)
 Constructor. More...
 
virtual ~state_machine_base () SX_NOEXCEPT SX_OVERRIDE
 
composite_stateget_root_state () const
 Returns the root state of the state machine. Commonly used to add regions to the root state and to create transitions from and to the root state. More...
 
virtual transitionadd_transition (transition_uptr _transition)
 Add a transition to the state machine. The state machine takes ownership of the transition. More...
 
virtual transitionadd_transition (const event_id _event_id, vertex &_source, vertex &_target, const sxy::transition_kind _kind=transition_kind::EXTERNAL, const constraint_function &_guard=constraint_function(), const behavior_function &_behavior=behavior_function())
 Creates a transition with the given name, kind, event, guard and behavior between the given source and target and adds it to the state machine. More...
 
virtual transitionadd_transition (const event_ids &_event_ids, vertex &_source, vertex &_target, const sxy::transition_kind _kind=transition_kind::EXTERNAL, const constraint_function &_guard=constraint_function(), const behavior_function &_behavior=behavior_function())
 Creates a transition with the given name, kind, event, guard and behavior between the given source and target and adds it to the state machine. More...
 
virtual transitionadd_transition (const event_id _event_id, vertex &_source, vertex &_target, const constraint_function &_guard, const sxy::transition_kind _kind=transition_kind::EXTERNAL)
 Creates a transition with the given name, kind, event, guard between the given source and target and adds it to the state machine. No behavior is provided. More...
 
virtual transitionadd_transition (const event_ids &_event_ids, vertex &_source, vertex &_target, const constraint_function &_guard, const sxy::transition_kind _kind=transition_kind::EXTERNAL)
 Creates a transition with the given name, kind, events, guard between the given source and target and adds it to the state machine. No behavior is provided. More...
 
virtual transitionadd_transition (const event_id _event_id, vertex &_source, vertex &_target, const constraint_function &_guard, const behavior_function &_behavior, const sxy::transition_kind _kind=transition_kind::EXTERNAL)
 Creates a transition with the given name, kind, event, guard and behavior between the given source and target and adds it to the state machine. More...
 
virtual transitionadd_transition (const event_ids &_event_ids, vertex &_source, vertex &_target, const constraint_function &_guard, const behavior_function &_behavior, const sxy::transition_kind _kind=transition_kind::EXTERNAL)
 Creates a transition with the given name, kind, events, guard and behavior between the given source and target and adds it to the state machine. More...
 
virtual transitionadd_transition (const event_id _event_id, vertex &_source, vertex &_target, const behavior_function &_behavior, const sxy::transition_kind _kind=transition_kind::EXTERNAL)
 Creates a transition with the given name, kind, event and behavior between the given source and target and adds it to the state machine. No guard is provided. More...
 
virtual transitionadd_transition (const event_ids &_event_ids, vertex &_source, vertex &_target, const behavior_function &_behavior, const sxy::transition_kind _kind=transition_kind::EXTERNAL)
 Creates a transition with the given name, kind, events and behavior between the given source and target and adds it to the state machine. No guard is provided. More...
 
virtual bool fire_event (const event_sptr &_event)=0
 
bool check (state_machine_defects &_defects) const
 Check the state machine for defects by checking the constraints of each component. More...
 
virtual bool run ()=0
 
virtual void halt ()
 Stops the state machine. It checks for active asynchronous simple states and stops their do behaviors. More...
 
virtual void interrupt ()
 Set the internal flag of the state machine, to interrupt all processes inside the state machine and to stop the state machine. More...
 
virtual bool is_interrupted () const SX_OVERRIDE
 Get the internal flag of the state machine that specify if the run of state machine is interrupted. More...
 
virtual void set_behavior_of_unhandled_event_handler (const behavior_function &_behavior)
 Sets the behavior for handler of unhandled events. More...
 
virtual std::string get_name () const
 Get the name of the state machine. More...
 
- Public Member Functions inherited from sxy::event_collector
 event_collector ()
 
virtual ~event_collector () SX_NOEXCEPT
 
virtual bool push (const event_sptr &_event)=0
 

Protected Member Functions

bool run (async_event_handler *const _async_event_handler)
 Starts the state machine. More...
 
bool process_event (const event_sptr &_event, async_event_handler *const _async_event_handler)
 

Static Protected Member Functions

static void stop_all_async_states (state &_state)
 

Constructor & Destructor Documentation

◆ state_machine_base()

sxy::state_machine_base::state_machine_base ( const std::string &  _name,
event_processing_callback *const  _event_processing_callback = SX_NULLPTR 
)
explicit

Constructor.

Parameters
_nameName of the state machine.
_event_processing_callbackEvent processing callback interface pointer. It can be a nullptr if no callback interface should be used.

◆ ~state_machine_base()

sxy::state_machine_base::~state_machine_base ( )
virtual

Member Function Documentation

◆ add_transition() [1/9]

transition & sxy::state_machine_base::add_transition ( transition_uptr  _transition)
virtual

Add a transition to the state machine. The state machine takes ownership of the transition.

Parameters
_transitionA transition.
Returns
transition Reference to the added transition.

◆ add_transition() [2/9]

transition & sxy::state_machine_base::add_transition ( const event_id  _event_id,
vertex _source,
vertex _target,
const sxy::transition_kind  _kind = transition_kind::EXTERNAL,
const constraint_function _guard = constraint_function(),
const behavior_function _behavior = behavior_function() 
)
virtual

Creates a transition with the given name, kind, event, guard and behavior between the given source and target and adds it to the state machine.

Parameters
_event_idID of the event for which the transition is enabled.
_sourceThe source vertex.
_targetThe target vertex.
_kindTransition kind. Default is EXTERNAL.
_guardThe guard of the transition. Default is an empty function.
_behaviorThe behavior of the transition. Default is an empty function.
Returns
A reference to the newly created transition.

◆ add_transition() [3/9]

transition & sxy::state_machine_base::add_transition ( const event_ids _event_ids,
vertex _source,
vertex _target,
const sxy::transition_kind  _kind = transition_kind::EXTERNAL,
const constraint_function _guard = constraint_function(),
const behavior_function _behavior = behavior_function() 
)
virtual

Creates a transition with the given name, kind, event, guard and behavior between the given source and target and adds it to the state machine.

Parameters
event_idsList of IDs of the events for which the transition is enabled.
_sourceThe source vertex.
_targetThe target vertex.
_kindTransition kind. Default is EXTERNAL.
_guardThe guard of the transition. Default is an empty function.
_behaviorThe behavior of the transition. Default is an empty function.
Returns
A reference to the newly created transition.

◆ add_transition() [4/9]

transition & sxy::state_machine_base::add_transition ( const event_id  _event_id,
vertex _source,
vertex _target,
const constraint_function _guard,
const sxy::transition_kind  _kind = transition_kind::EXTERNAL 
)
virtual

Creates a transition with the given name, kind, event, guard between the given source and target and adds it to the state machine. No behavior is provided.

Parameters
_event_idID of the event for which the transition is enabled.
_sourceThe source vertex.
_targetThe target vertex.
_guardThe guard of the transition.
_kindTransition kind. Default is EXTERNAL.
Returns
A reference to the newly created transition.

◆ add_transition() [5/9]

transition & sxy::state_machine_base::add_transition ( const event_ids _event_ids,
vertex _source,
vertex _target,
const constraint_function _guard,
const sxy::transition_kind  _kind = transition_kind::EXTERNAL 
)
virtual

Creates a transition with the given name, kind, events, guard between the given source and target and adds it to the state machine. No behavior is provided.

Parameters
_event_idsIDs of the events for which the transition is enabled.
_sourceThe source vertex.
_targetThe target vertex.
_guardThe guard of the transition.
_kindTransition kind. Default is EXTERNAL.
Returns
A reference to the newly created transition.

◆ add_transition() [6/9]

transition & sxy::state_machine_base::add_transition ( const event_id  _event_id,
vertex _source,
vertex _target,
const constraint_function _guard,
const behavior_function _behavior,
const sxy::transition_kind  _kind = transition_kind::EXTERNAL 
)
virtual

Creates a transition with the given name, kind, event, guard and behavior between the given source and target and adds it to the state machine.

Parameters
_event_idID of the event for which the transition is enabled.
_sourceThe source vertex.
_targetThe target vertex.
_guardThe guard of the transition.
_behaviorThe behavior of the transition.
_kindTransition kind. Default is EXTERNAL.
Returns
A reference to the newly created transition.

◆ add_transition() [7/9]

transition & sxy::state_machine_base::add_transition ( const event_ids _event_ids,
vertex _source,
vertex _target,
const constraint_function _guard,
const behavior_function _behavior,
const sxy::transition_kind  _kind = transition_kind::EXTERNAL 
)
virtual

Creates a transition with the given name, kind, events, guard and behavior between the given source and target and adds it to the state machine.

Parameters
_event_idsIDs of the events for which the transition is enabled.
_sourceThe source vertex.
_targetThe target vertex.
_guardThe guard of the transition.
_behaviorThe behavior of the transition.
_kindTransition kind. Default is EXTERNAL.
Returns
A reference to the newly created transition.

◆ add_transition() [8/9]

transition & sxy::state_machine_base::add_transition ( const event_id  _event_id,
vertex _source,
vertex _target,
const behavior_function _behavior,
const sxy::transition_kind  _kind = transition_kind::EXTERNAL 
)
virtual

Creates a transition with the given name, kind, event and behavior between the given source and target and adds it to the state machine. No guard is provided.

Parameters
_event_idID of the event for which the transition is enabled.
_sourceThe source vertex.
_targetThe target vertex.
_behaviorThe behavior of the transition.
_kindTransition kind. Default is EXTERNAL.
Returns
A reference to the newly created transition.

◆ add_transition() [9/9]

transition & sxy::state_machine_base::add_transition ( const event_ids _event_ids,
vertex _source,
vertex _target,
const behavior_function _behavior,
const sxy::transition_kind  _kind = transition_kind::EXTERNAL 
)
virtual

Creates a transition with the given name, kind, events and behavior between the given source and target and adds it to the state machine. No guard is provided.

Parameters
_event_idsIDs of the events for which the transition is enabled.
_sourceThe source vertex.
_targetThe target vertex.
_behaviorThe behavior of the transition.
_kindTransition kind. Default is EXTERNAL.
Returns
A reference to the newly created transition.

◆ check()

bool sxy::state_machine_base::check ( state_machine_defects _defects) const

Check the state machine for defects by checking the constraints of each component.

Parameters
_defectsCollected for all found defects.
Returns
bool true if there are no defects, else false.

◆ fire_event()

virtual bool sxy::state_machine_base::fire_event ( const event_sptr _event)
pure virtual

Implemented in sxy::SX_FINAL, and sxy::sync_state_machine.

◆ get_name()

std::string sxy::state_machine_base::get_name ( ) const
virtual

Get the name of the state machine.

Returns
name of the state machine

◆ get_root_state()

composite_state & sxy::state_machine_base::get_root_state ( ) const

Returns the root state of the state machine. Commonly used to add regions to the root state and to create transitions from and to the root state.

Returns
Reference to the root state of the state machine.

◆ halt()

void sxy::state_machine_base::halt ( )
virtual

Stops the state machine. It checks for active asynchronous simple states and stops their do behaviors.

Reimplemented in sxy::SX_FINAL, and sxy::SX_FINAL.

◆ interrupt()

void sxy::state_machine_base::interrupt ( )
virtual

Set the internal flag of the state machine, to interrupt all processes inside the state machine and to stop the state machine.

◆ is_interrupted()

bool sxy::state_machine_base::is_interrupted ( ) const
virtual

Get the internal flag of the state machine that specify if the run of state machine is interrupted.

Returns
true if the internal flag is set to interrupt the state machine, false otherwise.
See also
interrupt

Implements sxy::interruptible.

◆ process_event()

bool sxy::state_machine_base::process_event ( const event_sptr _event,
async_event_handler *const  _async_event_handler 
)
protected

◆ run() [1/2]

virtual bool sxy::state_machine_base::run ( )
pure virtual

◆ run() [2/2]

bool sxy::state_machine_base::run ( async_event_handler *const  _async_event_handler)
protected

Starts the state machine.

Parameters
_async_event_handlerPointer to an asynchronous event handler. It's used by the asynchronous state machine if it has to process asynchronous errors that occur in the asynchronous behavior of asynchronous simple states.
Returns
bool true if state machine can be started, else false what means that a terminate pseudostate has been reached and the state machine is stopped.

◆ set_behavior_of_unhandled_event_handler()

void sxy::state_machine_base::set_behavior_of_unhandled_event_handler ( const behavior_function _behavior)
virtual

Sets the behavior for handler of unhandled events.

Parameters
_behavior

◆ stop_all_async_states()

void sxy::state_machine_base::stop_all_async_states ( state _state)
staticprotected

The documentation for this class was generated from the following files: