Hierarchical State Machine class (QHsm-style state machine implementation strategy). More...
#include <qp.hpp>
Public Member Functions | |
| void | init (void const *const e, std::uint_fast8_t const qsId) override |
| Virtual override to take the top-most initial transition in QHsm. | |
| void | dispatch (QEvt const *const e, std::uint_fast8_t const qsId) override |
| Virtual override to dispatch an event to QHsm. | |
| bool | isIn (QStateHandler const stateHndl) noexcept override |
| Check whether the HSM is in a given state. | |
| QStateHandler | getStateHandler () const noexcept override |
| Virtual method for getting the current state handler. | |
| QStateHandler | childState (QStateHandler const parentHndl) noexcept |
| Obtain the current active child state of a given parent in QP::QMsm. | |
| virtual void | init (std::uint_fast8_t const qsId) |
| Virtual function to take the top-most initial transition in the state machine (overloaded). | |
| Public Member Functions inherited from QP::QAsm | |
| virtual | ~QAsm ()=default |
| Virtual destructor of the QP::QAsm abstract base class. | |
| QStateHandler | state () const noexcept |
| QMState const * | stateObj () const noexcept |
Protected Member Functions | |
| QHsm (QStateHandler const initial) noexcept | |
| Protected Member Functions inherited from QP::QAsm | |
| QAsm () noexcept | |
| Constructor of the QP::QAsm base class. | |
| QState | tran (QStateHandler const target) noexcept |
| Internal helper function to take a state transition in sublclasses of QP::QAsm. | |
| QState | tran_hist (QStateHandler const hist) noexcept |
| Internal helper function to take a state transition to history in sublclasses of QP::QAsm. | |
| QState | super (QStateHandler const superstate) noexcept |
| Internal helper function to indicate superstate of a given state in sublclasses of QP::QAsm. | |
| QState | qm_tran (void const *const tatbl) noexcept |
| Internal helper function to take a state transition in QP::QMsm. | |
| QState | qm_tran_init (void const *const tatbl) noexcept |
| QState | qm_tran_hist (QMState const *const hist, void const *const tatbl) noexcept |
| Internal helper function to take a state transition to history in QP::QMsm. | |
| QState | qm_entry (QMState const *const s) noexcept |
| Internal helper function to execute state entry actions in QP::QMsm. | |
| QState | qm_exit (QMState const *const s) noexcept |
| Internal helper function to execute state exit actions in QP::QMsm. | |
Private Member Functions | |
| std::size_t | tran_simple_ (std::array< QStateHandler, MAX_NEST_DEPTH_ > &path, std::uint_fast8_t const qsId) |
| Implementation of a simple state transition segment. | |
| std::size_t | tran_complex_ (std::array< QStateHandler, MAX_NEST_DEPTH_ > &path, std::uint_fast8_t const qsId) |
| Implementation of a complex state transition segment. | |
| void | enter_target_ (std::array< QStateHandler, MAX_NEST_DEPTH_ > &path, std::size_t const depth, std::uint_fast8_t const qsId) |
| Implementation of entry to the target state configuration. | |
| std::size_t | tran_simple_ (std::array< QStateHandler, MAX_NEST_DEPTH_ > &path, std::uint_fast8_t const qsId) |
| std::size_t | tran_complex_ (std::array< QStateHandler, MAX_NEST_DEPTH_ > &path, std::uint_fast8_t const qsId) |
| void | enter_target_ (std::array< QStateHandler, MAX_NEST_DEPTH_ > &path, std::size_t const depth, std::uint_fast8_t const qsId) |
Static Private Attributes | |
| static constexpr std::size_t | MAX_NEST_DEPTH_ {6U} |
Friends | |
| class | QS |
Additional Inherited Members | |
| Static Public Member Functions inherited from QP::QAsm | |
| static constexpr QState | Q_HANDLED () |
| static constexpr QState | Q_UNHANDLED () |
| static constexpr QState | QM_HANDLED () |
| static constexpr QState | QM_UNHANDLED () |
| static constexpr QState | QM_SUPER () |
| static QState | top (void *const me, QEvt const *const e) noexcept |
| Top state handler that ignores all events. | |
| Public Attributes inherited from QP::QAsm | |
| QAsmAttr | m_state |
| Current state (pointer to the current state-handler function). | |
| QAsmAttr | m_temp |
| Temporary storage for target/act-table etc. | |
| Static Public Attributes inherited from QP::QAsm | |
| static constexpr QState | Q_RET_SUPER {0U} |
| static constexpr QState | Q_RET_UNHANDLED {1U} |
| static constexpr QState | Q_RET_HANDLED {2U} |
| static constexpr QState | Q_RET_TRAN {3U} |
| static constexpr QState | Q_RET_TRAN_HIST {4U} |
| static constexpr QState | Q_RET_IGNORED {5U} |
| static constexpr QState | Q_RET_ENTRY {6U} |
| static constexpr QState | Q_RET_EXIT {7U} |
| static constexpr QState | Q_RET_TRAN_INIT {8U} |
| static constexpr QSignal | Q_EMPTY_SIG {0U} |
| static constexpr QSignal | Q_ENTRY_SIG {1U} |
| static constexpr QSignal | Q_EXIT_SIG {2U} |
| static constexpr QSignal | Q_INIT_SIG {3U} |
| static constexpr QMState const * | QM_STATE_NULL { nullptr } |
| static constexpr QActionHandler const | Q_ACTION_NULL { nullptr } |
Hierarchical State Machine class (QHsm-style state machine implementation strategy).
Details
QP::QHsm represents a Hierarchical State Machine (HSM) with full support for hierarchical nesting of states, entry/exit actions, initial transitions, and transitions to history in any composite state. This class is designed for ease of manual coding of HSMs in C++, but it is also supported by the QM modeling tool.
Backward Traceability
Usage
The following example illustrates how to derive a state machine class from QHsm. Please note that the QHsm member super is defined as the FIRST member of the derived class.
|
explicitprotectednoexcept |
Definition at line 142 of file qep_hsm.cpp.
|
overridevirtual |
Virtual override to take the top-most initial transition in QHsm.
Details
Synchronously executes the top-most initial transition in QHsm-type state machine.
| [in] | e | pointer to the initialization parameter |
| [in] | qsId | QS-id of this state machine (for QS local filter) |
Implements QP::QAsm.
Definition at line 150 of file qep_hsm.cpp.
|
overridevirtual |
Virtual override to dispatch an event to QHsm.
Details
Synchronously dispatches an event for processing to a QHsm-type state machine.
| [in] | e | pointer to the event to be dispatched to the MSM |
| [in] | qsId | QS-id of this state machine (for QS local filter) |
Backward Traceability
Forward Traceability
Implements QP::QAsm.
Definition at line 225 of file qep_hsm.cpp.
|
overridevirtualnoexcept |
Check whether the HSM is in a given state.
Details
Check if a given state is part of the current active state configuration in ::QHsm subclasses. Please note that in a hierarchical state machine, to "be in a state" means also to be in a superstate of of the state.
Backward Traceability
Implements QP::QAsm.
Definition at line 549 of file qep_hsm.cpp.
|
overridevirtualnoexcept |
Virtual method for getting the current state handler.
Details
This virtual call applies to all subclasses of QP::QAsm, such as: QP::QHsm, QP::QMsm, QP::QActive, and QP::QMActive.
Backward Traceability
Usage
The following example illustrates how to obtain the current state handler of an Active Object:
Implements QP::QAsm.
Definition at line 610 of file qep_hsm.cpp.
|
noexcept |
Obtain the current active child state of a given parent in QP::QMsm.
Details
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 QMsm.
| [in] | parent | pointer to the state-handler |
Definition at line 579 of file qep_hsm.cpp.
|
private |
Implementation of a simple state transition segment.
Details
Determines the type of a simple transition (A-D, see Figure SDS-SM-STRAN). If the simple transition type is found, the function exits the source states to the LCA, otherwise the function returns 2.
| [in,out] | path | array containing the target state-handler in path[0], and source state-handler in path[2]. Upon return, path[] contains the sequence of state handlers to be entered in QHsm::enter_target_() |
| [in] | qsId | QS-id of this state machine (for QS local filter) |
Backward Traceability
Forward Traceability
|
private |
Implementation of a complex state transition segment.
Details
Determines the type of a complex transition (E-H, see Figure SDS-SM-CTRAN). Next, the function exits the source states to the LCA.
| [in,out] | path | array containing the target state-handler in path[0], and source state-handler in path[2]. Upon return, path[] contains the sequence of state handlers to be entered in QHsm::QHsm_enter_target_() |
| [in] | qsId | QS-id of this state machine (for QS local filter) |
Backward Traceability
Forward Traceability
|
private |
Implementation of entry to the target state configuration.
Details
This function performs entry to the target state configuration by following the nested initial transition. This process can be recursive, which the function implements by iteration.
| [in,out] | path[] | contains the sequence of state handlers to be entered. It is also reused for entry-path for initial transition. |
| [in] | depth | the initial number of nesting levels in the path[] array. |
| [in] | qsId | QS-id of this state machine (for QS local filter) |
Backward Traceability
Forward Traceability
|
private |
Definition at line 328 of file qep_hsm.cpp.
|
private |
Definition at line 395 of file qep_hsm.cpp.
|
private |
Definition at line 484 of file qep_hsm.cpp.
|
virtual |
Virtual function to take the top-most initial transition in the state machine (overloaded).
Details
Synchronously executes the top-most initial transition in a state machine. This overloaded version takes no initialization parameter.
| [in] | qsId | QS-id of this state machine (for QS local filter) |
Reimplemented from QP::QAsm.
Definition at line 218 of file qf_act.cpp.
|
staticconstexprprivate |