StateController Class Reference

#include <ArmarXCore/statechart/StateController.h>

+ Inheritance diagram for StateController:

Classes

struct  Impl
 

Public Types

using transitionFunction = std::function< void(StateController *state, const StateIceBasePtr &nextState, const StateIceBasePtr &previousState)>
 
using TransitionFunctionMap = std::map< std::string, transitionFunction >
 
- Public Types inherited from StateBase
enum  StatePhase {
  ePreDefined, eStatechartDefinitions, eSubstatesDefinitions, eParametersDefinitions,
  eDefined, eEntering, eEntered, eBreaking,
  eExiting, eExited
}
 enum that specifies the phase in which the state is currently in used to control the usage of state-functions in the correct context More...
 

Public Member Functions

bool __applyMappings (const StateControllerPtr &srcState, const TransitionIceBase &t, const EventPtr &event, TransitionError &error)
 Apply the mappings during a transitions. More...
 
virtual bool __breakActiveSubstate (const EventPtr event)
 
bool __checkExistenceOfTransition (const TransitionIceBase &transition)
 
virtual void __enqueueEvent (const EventPtr event)
 
virtual void __finalize (const EventPtr event)
 Function that gets called, when a state enters a FinalSubstate. Virtual function, so that RemoteStateWrapper can override it. More...
 
bool __findValidTransition (const EventPtr &event, const StateIceBasePtr &sourceState, TransitionIceBase &resultTransition, TransitionError &error) const
 
StateControllerPtr __getParentState () const
 Getter function that automatically casts the parentState member of StateBase into StateControllerPtr. More...
 
virtual unsigned int __getUnbreakableBufferSize () const
 
virtual bool __getUnbreakableBufferStati () const
 Before:Function to get the unbreakable-buffer status of all parent state - recursively. More...
 
virtual void __notifyEventBufferedDueToUnbreakableState (bool eventBuffered=true)
 
void __printTransitionError (const TransitionError &transitionError, const EventPtr &event) const
 
virtual void __processBufferedEvents ()
 Processes buffered events, that could not be processed immediately due to unbreakable substates. More...
 
virtual void __processEvent (const EventPtr event, bool buffered=false)
 Main function to control the statemachine/state. More...
 
virtual void __substatesFinished (const EventPtr ev)
 Function that gets called, when a state enters a FinalSubstate. Virtual function, so that RemoteStateWrapper can override it. More...
 
TransitionError __validateTransition (const TransitionIceBase &transition, const EventPtr event, const StateIceBasePtr &sourceState, const StateIceBasePtr &destinationState) const
 
void __waitForRemoteStates () const
 
virtual bool _baseOnBreak (const EventPtr evt)
 Called by StateControllerprocessEvent()-function or parentstate. Must NOT be called by user. More...
 
virtual void _baseOnEnter ()
 Called by StateControllerprocessEvent()-function or parentstate. More...
 
virtual void _baseOnExit ()
 Called by StateController::processEvent()-function or parentstate. Must NOT be called by user. More...
 
virtual void _baseRun ()
 
virtual void _removeInstalledConditions ()
 This function is implemented in StateUtil and removes all conditions that have been installed in onEnter() or run(). More...
 
virtual void _startRun ()
 
void addProfilerRecursive (Profiler::ProfilerPtr profiler, int recursiveLevels=0)
 addProfilerRecursive recursively adds a new armarx::Profiler::Profiler object as armarx::StateController::localProfiler(the default one does not do anything at all). More...
 
void addTransitionFunction (const TransitionIceBase &t, transitionFunction function)
 
void disableRunFunction ()
 disableRunFunction sets useRunFunction to false and waits (blocking) for the current StateBase::run() function to complete. More...
 
void disableStateReporting (bool disable=true)
 Disables the reporting to profilers for this states during state visits. More...
 
void enter (const StringVariantContainerBaseMap &tempInputParameters=StringVariantContainerBaseMap())
 Function to set the statemachine in the first state and call OnEnter(). More...
 
bool findTransition (const std::string &eventName, const std::string sourceStateName, TransitionIceBase &transition)
 
std::string getTransitionID (const std::string &eventName, const std::string sourceStateName) const
 
std::string getTransitionID (const TransitionIceBase &t) const
 
bool isFinished () const
 
bool isRunningTaskFinished () const
 Checks whether the run() function has already finished. More...
 
bool isRunningTaskStopped () const
 isRunningTaskStopped checks whether the RunningTask, that executes run() is requested to stop. More...
 
void removeProfilerRecursive (Profiler::ProfilerPtr profiler, int recursiveLevels=0)
 
 StateController ()
 
 StateController (const StateController &source)
 
void waitForRunningTaskToFinish () const
 Waits until the run-function has finished. More...
 
void waitForStateToFinish (int timeoutMs=-1) const
 waitForStateToFinish waits until this thread has finished (i.e. More...
 
 ~StateController () override
 
- Public Member Functions inherited from StateBase
void __checkPhase (const std::vector< StatePhase > &allowedTypes, const char *functionName) const
 
void __checkPhase (StatePhase allowedType, const char *functionName) const
 Helper function for checking if a function was called in valid position of the statechart. More...
 
void __checkPhaseMin (StatePhase allowedType, const char *functionName) const
 
void __copyDefaultValuesToInput ()
 
StringVariantContainerBaseMap __getSetInputAndLocalParameters () const
 Combines both maps to one map and returns a new map of only the set parameters. More...
 
virtual bool __hasActiveSubstate ()
 Virtual function to indicate wheter a state has an active substate or not. To be overridden by RemoteState to deligate the call to the real state. More...
 
virtual bool __hasSubstates ()
 Virtual function to indicate wheter a state has substates or not. To be overridden by RemoteState to deligate the call to the real state. More...
 
void __setParentState (StateBase *parentState)
 
void __throwUnknownParameter (const StateParameterMap &paramMap, const std::string &key) const
 
void __updateGlobalStateId ()
 
virtual void __updateGlobalStateIdRecursive ()
 
bool addParameter (StateParameterMap &paramMap, const std::string &key, VariantTypeId type, bool optional, VariantPtr defaultValue=VariantPtr()) const
 
bool addParameterContainer (StateParameterMap &paramMap, const std::string &key, const ContainerType &containerType, bool optional, VariantContainerBasePtr defaultValue=VariantContainerBasePtr()) const
 
void clearSelfPointer ()
 
virtual StateBasePtr clone () const =0
 Pure virtual function to clone of the derived class type. More...
 
virtual StateBasePtr createEmptyCopy () const =0
 
virtual void deepCopy (const StateBase &sourceState, bool reset=true)
 Function to copy the states with all it substates and transitions. More...
 
virtual void defineParameters ()
 Virtual function, in which input/local/output parameters can be specified. More...
 
virtual void defineState ()
 Virtual function, in which this state can be configured. More...
 
virtual void defineSubstates ()
 Virtual function, in which substates, transition and mappings can be added. More...
 
StateBasePtr findSubstateByName (const std::string &substateName)
 Utility function to find a substate of this state by the name. More...
 
template<typename ContextType >
ContextType * getContext () const
 
StatechartContextInterfacegetContext (bool checkNULL=true) const
 
std::string getGlobalHierarchyString () const
 
virtual StateParameterMap getInputParameters ()=0
 Not const because RemoteState implementation gets the current parameters via Ice and sets them. More...
 
std::string getLocalHierarchyString () const
 Function to get a string that contains als parent states and this state. (e.g. "Robot->Functional->Idling") More...
 
Ice::Int getLocalUniqueId () const
 
virtual StateParameterMap & getOutputParameters ()
 
void getParameter (const StateParameterMap &paramMap, const std::string &key, VariantPtr &value) const
 
void getParameterContainer (const StateParameterMap &paramMap, const std::string &key, VariantContainerBasePtr &valueContainer) const
 
const std::string & getStateClassName () const
 
std::string getStateName () const
 getStateName More...
 
StatePhase getStatePhase () const
 
EventPtr getTriggeredEndstateEvent () const
 This function returns the event that was triggered by entering an endstate. More...
 
void inheritInputParameters ()
 
bool init (StatechartContextInterface *context, StatechartManager *manager)
 Function to initialize this state. Must be called in the highest level of the hierarchy - and only there. More...
 
virtual bool isInitialized () const
 Returns the status of this state. Only if a state is initialized, it can be used. More...
 
bool isParameterSet (const StateParameterMap &paramMap, const std::string &key) const
 
virtual void onBreak ()
 Virtual function, in which the behaviour of state is defined, when it is abnormally exited. Can be overridden, but it is optional.
An abnormal exit only occurs in hierarchy-levels greater 1.
When a parent state is left before the substates are finished, the OnBreak()-function is called in the active substate and in all it's active substates.
If this function is not implemented, the normal OnExit()-function is called.
More...
 
virtual void onEnter ()
 Virtual function, in which the behaviour of state is defined, when it is entered.
Can be overridden, but it is optional. More...
 
virtual void onExit ()
 Virtual function, in which the behaviour of state is defined, when it is exited. Can be overridden, but it is optional. More...
 
StateBaseoperator= (const StateBase &source)
 
virtual void refetchSubstates ()
 This functions updates the substates. More...
 
void reset ()
 Function to reset the state: clear name, clear substatesList, clear transition etc. More...
 
virtual void run ()
 Virtual function, that can be reimplemented to calculate complex operations. More...
 
void setContext (StatechartContextInterface *context)
 
void setInitialized (bool enable)
 
void setParameter (StateParameterMap &paramMap, const std::string &key, const Variant &variant)
 
void setParameterContainer (StateParameterMap &paramMap, const std::string &key, const VariantContainerBase &valueContainer)
 
void setParameterContainer (StateParameterMap &paramMap, const std::string &key, const VariantContainerBasePtr &valueContainer)
 
void setStateClassName (std::string className)
 setStateClassName() sets the string, that contains a stringrepresentation of this class. Should not be called usually. The classname gets automatically set in the constructor of the derived class StateTemplate<T>. More...
 
void setStatePhase (StatePhase newPhase)
 
 StateBase ()
 
 StateBase (const StateBase &source)
 
virtual bool waitForInitialization (int timeoutMS=-1) const
 
 ~StateBase () override
 
- Public Member Functions inherited from Logging
SpamFilterDataPtr deactivateSpam (float deactivationDurationSec=10.0f, const std::string &identifier="", bool deactivate=true) const
 disables the logging for the current line for the given amount of seconds. More...
 
MessageTypeT getEffectiveLoggingLevel () const
 
 Logging ()
 
void setLocalMinimumLoggingLevel (MessageTypeT level)
 With setLocalMinimumLoggingLevel the minimum verbosity-level of log-messages can be set. More...
 
void setTag (const LogTag &tag)
 
void setTag (const std::string &tagName)
 
virtual ~Logging ()
 

Public Attributes

std::unique_ptr< Implcimpl
 
- Public Attributes inherited from StateBase
std::unique_ptr< Implimpl
 

Friends

class DynamicRemoteState
 
template<class EventType , class StateType >
class FinalStateBase
 
class RemoteState
 
template<typename ContextType >
class RemoteStateOfferer
 
class State
 
class StatechartContext
 
class StatechartEventDistributor
 
class StatechartManager
 
class StateUtility
 

Additional Inherited Members

- Static Public Member Functions inherited from StateBase
static std::vector< StateBasePtrGetActiveStateLeafs (StateBasePtr toplevelState)
 
- Protected Member Functions inherited from Logging
bool checkLogLevel (MessageTypeT level) const
 
const LogSenderPtrgetLogSender () const
 Retrieve log sender. More...
 
LogSenderPtr loghelper (const char *file, int line, const char *function) const
 
- Protected Attributes inherited from Logging
MessageTypeT minimumLoggingLevel
 
SpamFilterDataPtr spamFilter
 
LogTag tag
 

Detailed Description

The StateController class processes events and controls the statechart flow.

Definition at line 55 of file StateController.h.

Member Typedef Documentation

◆ transitionFunction

using transitionFunction = std::function<void(StateController* state, const StateIceBasePtr& nextState, const StateIceBasePtr& previousState)>

Definition at line 59 of file StateController.h.

◆ TransitionFunctionMap

using TransitionFunctionMap = std::map<std::string, transitionFunction >

Definition at line 60 of file StateController.h.

Constructor & Destructor Documentation

◆ StateController() [1/2]

Definition at line 50 of file StateController.cpp.

◆ StateController() [2/2]

StateController ( const StateController source)

Definition at line 55 of file StateController.cpp.

+ Here is the call graph for this function:

◆ ~StateController()

~StateController ( )
override

Definition at line 68 of file StateController.cpp.

Member Function Documentation

◆ __applyMappings()

bool __applyMappings ( const StateControllerPtr srcState,
const TransitionIceBase &  t,
const EventPtr event,
TransitionError error 
)

Apply the mappings during a transitions.

The order is parent's local, parent's output and then next state's input.

Parameters
srcState
tTransition that is currently executed
eventEvent that led to the transition

Definition at line 211 of file StateController.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __breakActiveSubstate()

bool __breakActiveSubstate ( const EventPtr  event)
virtual

Reimplemented in RemoteState.

Definition at line 559 of file StateController.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __checkExistenceOfTransition()

bool __checkExistenceOfTransition ( const TransitionIceBase &  transition)

Definition at line 631 of file StateController.cpp.

+ Here is the caller graph for this function:

◆ __enqueueEvent()

void __enqueueEvent ( const EventPtr  event)
virtual

Reimplemented in RemoteStateWrapper.

Definition at line 195 of file StateController.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __finalize()

void __finalize ( const EventPtr  event)
virtual

Function that gets called, when a state enters a FinalSubstate. Virtual function, so that RemoteStateWrapper can override it.

Reimplemented in RemoteStateWrapper.

Definition at line 188 of file StateController.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __findValidTransition()

bool __findValidTransition ( const EventPtr event,
const StateIceBasePtr &  sourceState,
TransitionIceBase &  resultTransition,
TransitionError error 
) const

Definition at line 420 of file StateController.cpp.

+ Here is the caller graph for this function:

◆ __getParentState()

StateControllerPtr __getParentState ( ) const

Getter function that automatically casts the parentState member of StateBase into StateControllerPtr.

Exceptions
LocalExceptionif parent state could not be cas
Returns
Pointer to the parent state

Definition at line 540 of file StateController.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __getUnbreakableBufferSize()

unsigned int __getUnbreakableBufferSize ( ) const
virtual

Reimplemented in RemoteStateWrapper.

Definition at line 514 of file StateController.cpp.

+ Here is the caller graph for this function:

◆ __getUnbreakableBufferStati()

bool __getUnbreakableBufferStati ( ) const
virtual

Before:Function to get the unbreakable-buffer status of all parent state - recursively.

  • now: checks the flag for the buffer, that gets set externally
    Returns
    Returns true if no parent has any events in the unbreakable buffer, false otherwise.

Reimplemented in RemoteStateWrapper.

Definition at line 1159 of file StateController.cpp.

+ Here is the caller graph for this function:

◆ __notifyEventBufferedDueToUnbreakableState()

void __notifyEventBufferedDueToUnbreakableState ( bool  eventBuffered = true)
virtual

This virtual function notifies all substates that an event has been buffered due to unbreakable states and that they must not process any further events when they have reached a breakable state.

Reimplemented in RemoteState.

Definition at line 519 of file StateController.cpp.

+ Here is the caller graph for this function:

◆ __printTransitionError()

void __printTransitionError ( const TransitionError transitionError,
const EventPtr event 
) const

Definition at line 271 of file StateController.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __processBufferedEvents()

void __processBufferedEvents ( )
virtual

Processes buffered events, that could not be processed immediately due to unbreakable substates.

Gets called after a transition from a unbreakable substate to a breakable substate after execution of OnEnter() of the breakable state.
It is not called yet, when a transition occurs between 2 unbreakable states.
The calling substate can be of any level below this state in the hierarchy.

Reimplemented in RemoteStateWrapper.

Definition at line 582 of file StateController.cpp.

+ Here is the call graph for this function:

◆ __processEvent()

void __processEvent ( const EventPtr  event,
bool  buffered = false 
)
virtual

Main function to control the statemachine/state.

Determines with Parameter event, the active state and the transitiontable, which transition to choose.
If no transition is found, an eUnexpectedEvent-exception is thrown.

Reimplemented in RemoteStateWrapper.

Definition at line 299 of file StateController.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __substatesFinished()

void __substatesFinished ( const EventPtr  ev)
virtual

Function that gets called, when a state enters a FinalSubstate. Virtual function, so that RemoteStateWrapper can override it.

Definition at line 167 of file StateController.cpp.

+ Here is the call graph for this function:

◆ __validateTransition()

TransitionError __validateTransition ( const TransitionIceBase &  transition,
const EventPtr  event,
const StateIceBasePtr &  sourceState,
const StateIceBasePtr &  destinationState 
) const

Definition at line 461 of file StateController.cpp.

+ Here is the call graph for this function:

◆ __waitForRemoteStates()

void __waitForRemoteStates ( ) const

Definition at line 608 of file StateController.cpp.

◆ _baseOnBreak()

bool _baseOnBreak ( const EventPtr  evt)
virtual

Called by StateControllerprocessEvent()-function or parentstate. Must NOT be called by user.

Calls OnBreak() in this hierarchylevel and all sub levels.

Reimplemented in DynamicRemoteState, and RemoteState.

Definition at line 934 of file StateController.cpp.

+ Here is the call graph for this function:

◆ _baseOnEnter()

void _baseOnEnter ( )
virtual

Called by StateControllerprocessEvent()-function or parentstate.

Must NOT be called by user.

Calls OnEnter() in this hierarchylevel and of every initialstate of all sub levels.

Reimplemented in DynamicRemoteState, and RemoteState.

Definition at line 649 of file StateController.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _baseOnExit()

void _baseOnExit ( )
virtual

Called by StateController::processEvent()-function or parentstate. Must NOT be called by user.

Calls OnExit() in this hierarchylevel and all sub levels.
@relates baseOnExit()

Reimplemented in DynamicRemoteState, and RemoteState.

Definition at line 852 of file StateController.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _baseRun()

void _baseRun ( )
virtual

Definition at line 827 of file StateController.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _removeInstalledConditions()

virtual void _removeInstalledConditions ( )
inlinevirtual

This function is implemented in StateUtil and removes all conditions that have been installed in onEnter() or run().

It is called after onExit()

Definition at line 201 of file StateController.h.

+ Here is the caller graph for this function:

◆ _startRun()

void _startRun ( )
virtual

Definition at line 808 of file StateController.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addProfilerRecursive()

void addProfilerRecursive ( Profiler::ProfilerPtr  profiler,
int  recursiveLevels = 0 
)

addProfilerRecursive recursively adds a new armarx::Profiler::Profiler object as armarx::StateController::localProfiler(the default one does not do anything at all).

recursiveLevels determins how many levels deep this new profiler object should be set:

  • == -1: all reachable substates
  • == 0: only current state
  • > 0: current state + recursiveLevels deep)

This is automtically set in armarx::StatechartContext::setToplevelState() based on statechart properties.

Parameters
profilerprofiler instance to use in the state for calling armarx::Profiler::Profiler methods
recursiveLevelshow many levels deep the profiler should be set

Definition at line 1033 of file StateController.cpp.

◆ addTransitionFunction()

void addTransitionFunction ( const TransitionIceBase &  t,
StateController::transitionFunction  function 
)

Definition at line 1125 of file StateController.cpp.

+ Here is the call graph for this function:

◆ disableRunFunction()

void disableRunFunction ( )

disableRunFunction sets useRunFunction to false and waits (blocking) for the current StateBase::run() function to complete.

Note
This function needs to be called before the destructor of the state is called. If not called before destructor, the StateBase::run() function might cause a segfault.

Definition at line 1176 of file StateController.cpp.

◆ disableStateReporting()

void disableStateReporting ( bool  disable = true)

Disables the reporting to profilers for this states during state visits.

Definition at line 1120 of file StateController.cpp.

◆ enter()

void enter ( const StringVariantContainerBaseMap &  tempInputParameters = StringVariantContainerBaseMap())

Function to set the statemachine in the first state and call OnEnter().

Should only be called for the outer most state(machine). All initial substates of this state and of it's substates are also entered.

Parameters
inputparametersDictionary of parameters that should be mapped into the input parameters of this state. Uses '*'=>'*' mapping.

Definition at line 121 of file StateController.cpp.

+ Here is the call graph for this function:

◆ findTransition()

bool findTransition ( const std::string &  eventName,
const std::string  sourceStateName,
TransitionIceBase &  transition 
)

Definition at line 1142 of file StateController.cpp.

◆ getTransitionID() [1/2]

std::string getTransitionID ( const std::string &  eventName,
const std::string  sourceStateName 
) const

Definition at line 1137 of file StateController.cpp.

◆ getTransitionID() [2/2]

std::string getTransitionID ( const TransitionIceBase &  t) const

Definition at line 1131 of file StateController.cpp.

+ Here is the caller graph for this function:

◆ isFinished()

bool isFinished ( ) const

Definition at line 84 of file StateController.cpp.

◆ isRunningTaskFinished()

bool isRunningTaskFinished ( ) const

Checks whether the run() function has already finished.

Returns
true if finished

Definition at line 1102 of file StateController.cpp.

◆ isRunningTaskStopped()

bool isRunningTaskStopped ( ) const

isRunningTaskStopped checks whether the RunningTask, that executes run() is requested to stop.

Check this function periodically in run()

Returns
status of runningtask

Definition at line 1091 of file StateController.cpp.

+ Here is the caller graph for this function:

◆ removeProfilerRecursive()

void removeProfilerRecursive ( Profiler::ProfilerPtr  profiler,
int  recursiveLevels = 0 
)

Definition at line 1061 of file StateController.cpp.

◆ waitForRunningTaskToFinish()

void waitForRunningTaskToFinish ( ) const

Waits until the run-function has finished.

This might be useful to do in onBreak() or onEnter()

See also
onEnter(), onBreak(), onRun()

Definition at line 1111 of file StateController.cpp.

◆ waitForStateToFinish()

void waitForStateToFinish ( int  timeoutMs = -1) const

waitForStateToFinish waits until this thread has finished (i.e.

a FinalSubState has been reached).

This function can only be called in a toplevelstate (a state with no parent state).

Parameters
timeOutMs
See also
isFinished()

Definition at line 91 of file StateController.cpp.

+ Here is the call graph for this function:

Friends And Related Function Documentation

◆ DynamicRemoteState

friend class DynamicRemoteState
friend

Definition at line 258 of file StateController.h.

◆ FinalStateBase

friend class FinalStateBase
friend

Definition at line 255 of file StateController.h.

◆ RemoteState

friend class RemoteState
friend

Definition at line 257 of file StateController.h.

◆ RemoteStateOfferer

friend class RemoteStateOfferer
friend

Definition at line 256 of file StateController.h.

◆ State

friend class State
friend

Definition at line 253 of file StateController.h.

◆ StatechartContext

friend class StatechartContext
friend

Definition at line 261 of file StateController.h.

◆ StatechartEventDistributor

friend class StatechartEventDistributor
friend

Definition at line 259 of file StateController.h.

◆ StatechartManager

friend class StatechartManager
friend

Definition at line 260 of file StateController.h.

◆ StateUtility

friend class StateUtility
friend

Definition at line 254 of file StateController.h.

Member Data Documentation

◆ cimpl

std::unique_ptr<Impl> cimpl

Definition at line 173 of file StateController.h.


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