RTC Toolkit  2.0.0
Classes | Public Member Functions | List of all members
rtctk::componentFramework::StateMachineEngine Class Reference

#include <stateMachineEngine.hpp>

Public Member Functions

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

Constructor & Destructor Documentation

◆ StateMachineEngine()

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

◆ ~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 ( std::string const &  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 ( std::string const &  id,
std::function< void(Event const &)>  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 ( std::string const &  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.

◆ RegisterGuard()

void rtctk::componentFramework::StateMachineEngine::RegisterGuard ( std::string const &  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 ( std::string const &  id,
std::function< bool(Event const &)>  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 ( std::string const &  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: