![]() |
appkit
1.5.1
RoadNarrows Robotics Application Kit
|
Finite State Machine Class. More...
#include <StateMach.h>
Public Types | |
| typedef std::map< int, State * > | StateTblMap_T |
| state table type | |
Public Member Functions | |
| StateMach (int nStateMachId=0, const std::string &strStateMachName="sm") | |
| Default contructor. More... | |
| StateMach (int nStateMachId, const std::string &strStateMachName, int nStartStateId, State *listStates[]) | |
| List contructor. More... | |
| virtual | ~StateMach () |
| Destructor. | |
| int | addStates (State *pState,...) |
| Add a list of states to this state machine. More... | |
| void | addState (State *pState) |
| Add state to this state machine. More... | |
| bool | deleteState (int nStateId) |
| Delete state from this state machine. More... | |
| void | setStartStateId (int nStartStateId) |
| Set state machine's start state id. More... | |
| virtual void | run () |
| Run the state machine from the start. More... | |
| virtual void | startRecording (size_t uLimit=NO_LIMIT) |
| Start recording states ids. More... | |
| virtual void | stopRecording () |
| Stop recording of states ids. More... | |
| virtual void | resumeRecording () |
| Resume recording of states ids. More... | |
| virtual void | eraseRecording () |
| Erase recording of states ids. More... | |
| int | getStateMachId () const |
| Get state machine id. More... | |
| std::string | getStateMachName () const |
| Get state machine name. More... | |
| int | getCurrStateId () const |
| Get the current state id. More... | |
| int | getPrevStateId () const |
| Get the previously recorded state id. More... | |
| virtual void | printStateMach (FILE *fp=stdout, int indent=0) |
| Print out state machine. More... | |
Static Public Attributes | |
| static const size_t | NO_LIMIT = 0 |
| no limit on length of recording | |
Protected Member Functions | |
| void | pushStateId (int nStateid) |
| Push state id onto stack of state ids. More... | |
| int | popStateId () |
| Pop state id from stack of state ids. More... | |
| virtual void | logTransition (int nCurrStateId, int nEventId, int nNextStateId) |
| Log state transition. More... | |
Protected Attributes | |
| int | m_nStateMachId |
| state machine id | |
| std::string | m_strStateMachName |
| state machine name | |
| StateTblMap_T | m_mapStateTbl |
| state table | |
| int | m_nStartStateId |
| starting state id | |
| int | m_nCurrStateId |
| current state id | |
| int | m_nMarkStateId |
| mark state id of last run cycle | |
| std::vector< int > | m_stackStateIds |
| stack of previous state ids | |
| size_t | m_uMaxRecording |
| max recording length | |
| bool | m_bIsRecording |
| is [not] recording work flow | |
Finite State Machine Class.
Definition at line 83 of file StateMach.h.
| rnr::StateMach::StateMach | ( | int | nStateMachId = 0, |
| const std::string & | strStateMachName = "sm" |
||
| ) |
| rnr::StateMach::StateMach | ( | int | nStateMachId, |
| const std::string & | strStateMachName, | ||
| int | nStartStateId, | ||
| State * | listStates[] | ||
| ) |
| void StateMach::addState | ( | State * | pState | ) |
Add state to this state machine.
This state machine owns the state and will automatically delete it when this state machine is deleted.
| pState | Allocated state object. |
Definition at line 151 of file StateMach.cxx.
References rnr::State::getStateId(), rnr::State::getStateName(), m_mapStateTbl, m_nStateMachId, and m_strStateMachName.
Referenced by addStates().
| int StateMach::addStates | ( | State * | pState, |
| ... | |||
| ) |
Add a list of states to this state machine.
This state machine owns all of the states and will automatically delete them when this state machine is deleted.
| pState | First allocated state object. |
| ... | Subsequent allocated state object. Terminate list with NULL. |
Definition at line 134 of file StateMach.cxx.
References addState().
| bool StateMach::deleteState | ( | int | nStateId | ) |
Delete state from this state machine.
| nStateId | State id. |
Definition at line 174 of file StateMach.cxx.
References m_mapStateTbl, m_nStateMachId, and m_strStateMachName.
|
inlinevirtual |
Erase recording of states ids.
The recording start/stop state is not changed.
Definition at line 212 of file StateMach.h.
References m_stackStateIds.
|
inline |
Get the current state id.
Definition at line 242 of file StateMach.h.
References m_nCurrStateId.
|
inline |
Get the previously recorded state id.
State id recording must be enabled. The previous state id never equals the current state id.
Definition at line 258 of file StateMach.h.
References rnr::io::indent(), m_bIsRecording, m_stackStateIds, printStateMach(), and rnr::State::StateIdUndef.
|
inline |
Get state machine id.
Definition at line 222 of file StateMach.h.
References m_nStateMachId.
|
inline |
Get state machine name.
Definition at line 232 of file StateMach.h.
References m_strStateMachName.
|
protectedvirtual |
Log state transition.
| nCurrStateId | Current state id. |
| nEventId | Received event id. |
| nNextStateId | Next (new) state id. |
Definition at line 316 of file StateMach.cxx.
References m_mapStateTbl, m_nStateMachId, and m_strStateMachName.
|
protected |
Pop state id from stack of state ids.
Definition at line 287 of file StateMach.cxx.
References m_bIsRecording, m_stackStateIds, and rnr::State::StateIdUndef.
Referenced by run().
|
virtual |
Print out state machine.
| fp | Output file pointer. |
| indent | Left indentation. |
Definition at line 303 of file StateMach.cxx.
References m_mapStateTbl, m_nStateMachId, and m_strStateMachName.
Referenced by getPrevStateId().
|
protected |
Push state id onto stack of state ids.
The stack preserves the state workflow history.
| nStateId | State id to be pushed. |
Definition at line 265 of file StateMach.cxx.
References m_bIsRecording, m_stackStateIds, m_uMaxRecording, and NO_LIMIT.
Referenced by run().
|
inlinevirtual |
Resume recording of states ids.
The recording is not erased.
Definition at line 202 of file StateMach.h.
References m_bIsRecording.
|
virtual |
Run the state machine from the start.
This function does not return until the terminate state is reached.
Definition at line 192 of file StateMach.cxx.
References rnr::State::actionEnterState(), rnr::State::actionExitState(), rnr::State::dispatchEvent(), LOGTRANSITION, m_mapStateTbl, m_nCurrStateId, m_nMarkStateId, m_nStartStateId, m_nStateMachId, m_strStateMachName, popStateId(), pushStateId(), rnr::State::receiveEvent(), rnr::State::StateIdPrev, rnr::State::StateIdTerminate, and rnr::State::StateIdThis.
Referenced by setStartStateId().
|
inline |
Set state machine's start state id.
| nStartStateId | State id. |
Definition at line 158 of file StateMach.h.
References m_nStartStateId, and run().
|
inlinevirtual |
Start recording states ids.
Any previous recording is erased.
Typical uses for recording states are work flows, in which the previous states may need backtracing, given a previous event.
| uLimit | Limit the length of the recording. |
Definition at line 180 of file StateMach.h.
References m_bIsRecording, m_stackStateIds, and m_uMaxRecording.
|
inlinevirtual |
Stop recording of states ids.
The recording is not erased.
Definition at line 192 of file StateMach.h.
References m_bIsRecording.