Hierarchical State Machine base class.
More...
#include <qep.hpp>
Hierarchical State Machine base class.
- Description
- QHsm represents a Hierarchical State Machine (HSM) with full support for hierarchical nesting of states, entry/exit actions, and initial transitions in any composite state. QHsm inherits QMsm without adding new attributes, so it takes the same amount of RAM as QMsm.
QHsm is also the base class for the QMsm state machine, which provides a superior efficiency, but requries the use of the QM modeling tool to generate code.
- Note
- QHsm is not intended to be instantiated directly, but rather serves as the base class for derivation of state machines in the application code.
- Usage
- The following example illustrates how to derive a state machine class from QHsm.
class Calc :
public QHsm {
private:
double m_operand1;
double m_operand2;
char m_display[DISP_WIDTH + 1];
public:
Calc()
}
protected:
. . .
};
unsigned char uint8_t
exact-width 8-bit unsigned int
QHsm(QStateHandler const initial) noexcept
Protected constructor of QHsm.
#define Q_STATE_DECL(state_)
Macro to generate a declaration of a state-handler, state-caller and a state-object for a given state...
Definition at line 269 of file qep.hpp.
◆ ReservedHsmSignals
Enumerator |
---|
Q_ENTRY_SIG | signal for entry actions
|
Q_EXIT_SIG | signal for exit actions
|
Q_INIT_SIG | signal for nested initial transitions
|
Definition at line 371 of file qep.hpp.
◆ ~QHsm()
virtual destructor
- Description
- Virtual destructor of the QHsm state machine and any of its subclasses.
Definition at line 126 of file qep_hsm.cpp.
◆ QHsm()
|
explicitprotectednoexcept |
Protected constructor of QHsm.
- Description
- Performs the first step of HSM initialization by assigning the initial pseudostate to the currently active state of the state machine.
- Parameters
-
[in] | initial | pointer to the top-most initial state-handler function in the derived state machine |
Definition at line 117 of file qep_hsm.cpp.
◆ init() [1/2]
executes the top-most initial transition in QP::QHsm
- Description
- Executes the top-most initial transition in a HSM.
- Parameters
-
[in] | e | pointer to an extra parameter (might be NULL) |
[in] | qs_id | QS-id of this state machine (for QS local filter) |
- Note
- Must be called exactly once before the QP::QHsm::dispatch().
- Precondition
- ctor must have been executed and initial tran NOT taken
Reimplemented in QMActive, QMsm, QXThread, QActiveDummy, and QTicker.
Definition at line 139 of file qep_hsm.cpp.
◆ init() [2/2]
◆ dispatch()
Dispatches an event to QHsm.
- Description
- Dispatches an event for processing to a hierarchical state machine (HSM). The processing of an event represents one run-to-completion (RTC) step.
- Parameters
-
[in] | e | pointer to the event to be dispatched to the HSM |
[in] | qs_id | QS-id of this state machine (for QS local filter) |
- Note
- This state machine must be initialized by calling QP::QHsm::init() exactly once before calling QP::QHsm::dispatch().
- Precondition
- the current state must be initialized and the state configuration must be stable
Reimplemented in QMActive, QMsm, QXThread, QActiveDummy, and QTicker.
Definition at line 242 of file qep_hsm.cpp.
◆ isIn()
Tests if a given state is part of the current active state configuration.
- Description
- Tests if a state machine derived from QHsm is-in a given state.
- Note
- For a HSM, to "be in a state" means also to be in a superstate of of the state.
- Parameters
-
[in] | s | pointer to the state-handler function to be tested |
- Returns
- 'true' if the HSM is in the
state
and 'false' otherwise
- Precondition
- state configuration must be stable
Definition at line 557 of file qep_hsm.cpp.
◆ state()
Obtain the current state (state handler function)
- Note
- used in the QM code generation
Definition at line 296 of file qep.hpp.
◆ childState()
Obtain the current active child state of a given parent.
- Note
- used in the QM code generation
- Description
- Finds the child state of the given
parent
, such that this child state is an ancestor of the currently active state. The main purpose of this function is to support shallow history transitions in state machines derived from QHsm.
- Parameters
-
[in] | parent | pointer to the state-handler function |
- Returns
- the child of a given
parent
state, which is an ancestor of the currently active state
- Note
- this function is designed to be called during state transitions, so it does not necessarily start in a stable state configuration. However, the function establishes stable state configuration upon exit.
- Postcondition
- the child must be confirmed
Definition at line 600 of file qep_hsm.cpp.
◆ top()
QState top |
( |
void *const |
me, |
|
|
QEvt const *const |
e |
|
) |
| |
|
staticnoexcept |
the top-state.
- Description
- The QP::QHsm::top() state handler is the ultimate root of state hierarchy in all HSMs derived from QP::QHsm.
- Parameters
-
[in] | me | pointer to the HSM instance |
[in] | e | pointer to the event to be dispatched to the HSM |
- Returns
- Always returns Q_RET_IGNORED, which means that the top state ignores all events.
- Note
- The arguments to this state handler are not used. They are provided for conformance with the state-handler function signature QP::QStateHandler.
Definition at line 224 of file qep_hsm.cpp.
◆ tran()
Helper function to specify a state transition.
Definition at line 354 of file qep.hpp.
◆ tran_hist()
Helper function to specify a transition to history.
Definition at line 360 of file qep.hpp.
◆ super()
Helper function to specify the superstate of a given state.
Definition at line 366 of file qep.hpp.
◆ qm_tran()
QState qm_tran |
( |
void const *const |
tatbl | ) |
|
|
inlineprotectednoexcept |
Helper function to specify a regular state transition in a QM state-handler.
Definition at line 380 of file qep.hpp.
◆ qm_tran_hist()
QState qm_tran_hist |
( |
QMState const *const |
hist, |
|
|
void const *const |
tatbl |
|
) |
| |
|
inlineprotectednoexcept |
Helper function to specifiy a transition to history in a QM state-handler.
Definition at line 387 of file qep.hpp.
◆ qm_tran_init()
QState qm_tran_init |
( |
void const *const |
tatbl | ) |
|
|
inlineprotectednoexcept |
Helper function to specify an initial state transition in a QM state-handler.
Definition at line 397 of file qep.hpp.
◆ qm_tran_ep()
QState qm_tran_ep |
( |
void const *const |
tatbl | ) |
|
|
inlineprotectednoexcept |
Helper function to specify a transition to an entry point to a submachine state in a QM state-handler.
Definition at line 404 of file qep.hpp.
◆ qm_tran_xp()
Helper function to specify a transition to an exit point from a submachine state in a QM state-handler.
Definition at line 411 of file qep.hpp.
◆ qm_entry()
Helper function to specify a state entry in a QM state-handler.
Definition at line 421 of file qep.hpp.
◆ qm_exit()
Helper function to specify a state exit in a QM state-handler.
Definition at line 427 of file qep.hpp.
◆ getStateHandler()
◆ qm_sm_exit()
Helper function to specify a submachine exit in a QM state-handler.
Definition at line 449 of file qep.hpp.
◆ qm_super_sub()
Helper function to call in a QM state-handler when it passes the event to the host submachine state to handle an event.
Definition at line 456 of file qep.hpp.
◆ hsm_tran()
internal helper function to take a transition in QP::QHsm
- Description
- helper function to execute transition sequence in a hierarchical state machine (HSM).
- Parameters
-
[in,out] | path | array of pointers to state-handler functions to execute the entry actions |
[in] | qs_id | QS-id of this state machine (for QS local filter) |
- Returns
- the depth of the entry path stored in the
path
parameter. /
Definition at line 404 of file qep_hsm.cpp.
◆ QMsm
◆ QActive
◆ QMActive
◆ QF
◆ QS
◆ QXK
◆ QXThread
◆ QXMutex
◆ QXSemaphore
◆ QActiveDummy
◆ m_state
current active state (state-variable)
Definition at line 270 of file qep.hpp.
◆ m_temp
temporary: transition chain, target state, etc.
Definition at line 271 of file qep.hpp.
◆ Q_RET_SUPER
event passed to the superstate to handle
Definition at line 314 of file qep.hpp.
◆ Q_RET_SUPER_SUB
event passed to submachine superstate
Definition at line 317 of file qep.hpp.
◆ Q_RET_UNHANDLED
event unhandled due to a guard evaluating to 'false'
Definition at line 320 of file qep.hpp.
◆ Q_RET_HANDLED
event handled (internal transition)
Definition at line 323 of file qep.hpp.
◆ Q_RET_IGNORED
event silently ignored (bubbled up to top)
Definition at line 326 of file qep.hpp.
◆ Q_RET_ENTRY
state entry action executed
Definition at line 329 of file qep.hpp.
◆ Q_RET_EXIT
state exit action executed
Definition at line 332 of file qep.hpp.
◆ Q_RET_NULL
return value without any effect
Definition at line 335 of file qep.hpp.
◆ Q_RET_TRAN
regular transition taken
Definition at line 338 of file qep.hpp.
◆ Q_RET_TRAN_INIT
initial transition taken
Definition at line 341 of file qep.hpp.
◆ Q_RET_TRAN_EP
entry-point transition into a submachine
Definition at line 344 of file qep.hpp.
◆ Q_RET_TRAN_HIST
transition to history of a given state
Definition at line 347 of file qep.hpp.
◆ Q_RET_TRAN_XP
exit-point transition out of a submachine
Definition at line 350 of file qep.hpp.
◆ MAX_NEST_DEPTH_
< maximum nesting depth of states in HSM
Definition at line 463 of file qep.hpp.
The documentation for this class was generated from the following files: