RTC Toolkit 5.1.0
Loading...
Searching...
No Matches
Public Member Functions | List of all members
rtctk::componentFramework::StateMachineEngine Class Reference

#include <rtctk/componentFramework/stateMachineEngine.hpp>

Public Member Functions

 StateMachineEngine ()
 
 ~StateMachineEngine ()
 
void RegisterExitEvent (rad::UniqueEvent exit_event)
 Register an exit event.
 
void RegisterModel (const std::string &name, const std::string &model)
 Register a new state machine model.
 
void AppendModel (const std::string &name, const std::string &model)
 Append state machine model fragment.
 
void RegisterAction (const std::string &id, ActionMethod action)
 Register action.
 
template<class Event >
void RegisterActionStatic (const std::string &id, std::function< void(const Event &)> action)
 Register action for statically known event type.
 
void RegisterGuard (const std::string &id, GuardMethod guard)
 Register guard.
 
template<class Event >
void RegisterGuardStatic (const std::string &id, std::function< bool(const Event &)> guard)
 Register guard for statically known event type.
 
void RegisterActivity (const std::string &id, ActivityMethod activity, SuccessMethod on_success, FailureMethod on_failure)
 Register activity.
 
void RegisterRejectHandler (const std::string &id, RejectMethod reject)
 Register reject handler.
 
template<typename T , typename Ex >
void RegisterRejectHandler ()
 Register default reject handler.
 
void RegisterStateChangeHandler (StateMethod on_statechange)
 Register state changed handler.
 
void PostEvent (rad::SharedEvent s)
 Injects a new event into the state machine engine.
 
std::string GetState ()
 Queries the current state.
 
void Work ()
 Runs the event loop of the state machine.
 
void Stop ()
 Stops execution of the state machine event loop.
 

Constructor & Destructor Documentation

◆ StateMachineEngine()

rtctk::componentFramework::StateMachineEngine::StateMachineEngine ( )

◆ ~StateMachineEngine()

rtctk::componentFramework::StateMachineEngine::~StateMachineEngine ( )

Member Function Documentation

◆ AppendModel()

void rtctk::componentFramework::StateMachineEngine::AppendModel ( const std::string & name,
const std::string & model )

Append state machine model fragment.

Appends a state machine model fragment to the current model. The fragment must be a well-formed SCXML model. The fragment will be superimposed and merged with the existing model.

Parameters
nameName of the model.
modelSCXML model as a string.

◆ GetState()

std::string rtctk::componentFramework::StateMachineEngine::GetState ( )

Queries the current state.

Returns
the current state as a string.

◆ PostEvent()

void rtctk::componentFramework::StateMachineEngine::PostEvent ( rad::SharedEvent s)

Injects a new event into the state machine engine.

Parameters
sEvent to be injected.

◆ RegisterAction()

void rtctk::componentFramework::StateMachineEngine::RegisterAction ( const std::string & id,
ActionMethod action )

Register action.

Usually the provided action method is not supposed to throw, in case it does throw all exceptions will be caught and logged.

Parameters
idSCXML guard id.
actionAction handler.

◆ RegisterActionStatic()

template<class Event >
void rtctk::componentFramework::StateMachineEngine::RegisterActionStatic ( const std::string & id,
std::function< void(const Event &)> action )
inline

Register action for statically known event type.

Precondition
action must be valid.
Template Parameters
Eventevent type.
Parameters
idSCXML action id.
actionAction handler.

◆ RegisterActivity()

void rtctk::componentFramework::StateMachineEngine::RegisterActivity ( const std::string & id,
ActivityMethod activity,
SuccessMethod on_success,
FailureMethod on_failure )

Register activity.

Registers a state machine activity that is executed in a dedicated thread. When the activity terminates gracefully the success handler will be executed, this allows to add subsequent behaviour (e.g. posting a Done event). In case the activity throws an exception the exception is caught, logged and the failure handler is invoked, this allows the addition of behavour after errors (e.g. posting a Error event).

Parameters
idSCXML activity id.
activityActivity handler.
on_successSuccess handler.
on_failureFailure handler.

◆ RegisterExitEvent()

void rtctk::componentFramework::StateMachineEngine::RegisterExitEvent ( rad::UniqueEvent exit_event)

Register an exit event.

Registers an exit event that is used to terminate the state machine engine when signals SIGINT, SIGTERM or SIGHUP are received.

Parameters
exit_eventrad event wrapped in unique_ptr.

◆ RegisterGuard()

void rtctk::componentFramework::StateMachineEngine::RegisterGuard ( const std::string & id,
GuardMethod guard )

Register guard.

Usually the provided guard method is not supposed to throw, in case it does throw all exceptions will be caught and logged. A guard that throws is automatically blocked so that the destination state is not reached. This is equivalent to returning false in the guard method.

Parameters
idSCXML guard id.
guardGuard handler.

◆ RegisterGuardStatic()

template<class Event >
void rtctk::componentFramework::StateMachineEngine::RegisterGuardStatic ( const std::string & id,
std::function< bool(const Event &)> guard )
inline

Register guard for statically known event type.

Precondition
guard must be valid.
Template Parameters
Eventevent type.
Parameters
idSCXML guard id.
guardGuard handler.

◆ RegisterModel()

void rtctk::componentFramework::StateMachineEngine::RegisterModel ( const std::string & name,
const std::string & model )

Register a new state machine model.

Registers a SCXML state machine model to the engine.

Parameters
nameName of the model.
modelSCXML model as a string.

◆ RegisterRejectHandler() [1/2]

template<typename T , typename Ex >
void rtctk::componentFramework::StateMachineEngine::RegisterRejectHandler ( )
inline

Register default reject handler.

Provides a default implementation for reject handlers that responds with with a message that the event was rejected. The default was provided to allow for uniform solutions and little typing.

◆ RegisterRejectHandler() [2/2]

void rtctk::componentFramework::StateMachineEngine::RegisterRejectHandler ( const std::string & id,
RejectMethod reject )

Register reject handler.

Reject handlers can be registered for individual event types and they are called when events are not accepted by the state machine in certain states or when guards evaluate to false.

Parameters
idEvent id.
rejectReject handler.

◆ RegisterStateChangeHandler()

void rtctk::componentFramework::StateMachineEngine::RegisterStateChangeHandler ( StateMethod on_statechange)

Register state changed handler.

The provided method on_statechange will be called every time the state machine changes its state. It will include the actual state the state machine is in now.

Parameters
on_statechangeState change handler.

◆ Stop()

void rtctk::componentFramework::StateMachineEngine::Stop ( )

Stops execution of the state machine event loop.

◆ Work()

void rtctk::componentFramework::StateMachineEngine::Work ( )

Runs the event loop of the state machine.

Does not return until the state machine is stopped.


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