Hierarchical State Machine class (QHsm-style state machine implementation strategy). More...
#include <qp.h>
Public Member Functions | |
| QStateHandler | QHsm_state (QHsm const *const me) |
| Obtain the current active state from a HSM (read only). | |
| QStateHandler | QHsm_childState (QHsm *const me, QStateHandler const parentHndl) |
| Obtain the current active child state of a given parent in QHsm. | |
Protected Member Functions | |
| void | QHsm_ctor (QHsm *const me, QStateHandler const initial) |
| Constructor of the QHsm base class. | |
| QState | QHsm_top (QHsm const *const me, QEvt const *const e) |
Protected Attributes | |
| QAsm | super |
| Protected Attributes inherited from QAsm | |
| struct QAsmVtable const * | vptr |
| Virtual pointer inherited by all QAsm subclasses (see also SAS_QP_OOA). | |
| union QAsmAttr | state |
| Current state (pointer to the current state-handler function). | |
| union QAsmAttr | temp |
| Temporary storage for target/act-table etc.. | |
Private Member Functions | |
| void | QHsm_init_ (QAsm *const me, void const *const e, uint_fast8_t const qsId) |
| Implementation of the top-most initial transition in QHsm. | |
| void | QHsm_dispatch_ (QAsm *const me, QEvt const *const e, uint_fast8_t const qsId) |
| Implementation of dispatching events to a QHsm. | |
| bool | QHsm_isIn_ (QAsm *const me, QStateHandler const stateHndl) |
| Check if a given state is part of the current active state configuration. | |
| QStateHandler | QHsm_getStateHandler_ (QAsm const *const me) |
| Implementation of getting the state handler in an QHsm subclass. | |
| size_t | QHsm_tran_simple_ (QAsm *const me, QStateHandler *const path, uint_fast8_t const qsId) |
| Implementation of a simple state transition segment. | |
| size_t | QHsm_tran_complex_ (QAsm *const me, QStateHandler *const path, uint_fast8_t const qsId) |
| Implementation of a complex state transition segment. | |
| void | QHsm_enter_target_ (QAsm *const me, QStateHandler *const path, size_t const depth, uint_fast8_t const qsId) |
| Implementation of entry to the target state configuration. | |
Hierarchical State Machine class (QHsm-style state machine implementation strategy).
Details
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.
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.
Backward Traceability
Forward Traceability
|
protected |
Constructor of the QHsm base class.
Details
The constructor initializes the QHsm::state. The constructor is "protected" because it is only intended to be invoked from the subclasses of the abstract base class QAsm.
| [in,out] | me | current instance pointer (see SAS_QP_OOA) |
| [in] | initial | initial pseudostate of the instantiated state machine |
Forward Traceability
|
private |
Implementation of the top-most initial transition in QHsm.
Details
Synchronously executes the top-most initial transition in a state machine.
| [in,out] | me | current instance pointer (see SAS_QP_OOA) |
| [in] | e | pointer to an extra parameter (might be NULL) |
| [in] | qsId | QS-id of this state machine (for QS local filter) |
Forward Traceability
Implementation of dispatching events to a QHsm.
Details
Synchronously dispatches an event for processing to a state machine. The processing of an event represents one run-to-completion (RTC) step.
| [in,out] | me | current instance pointer (see SAS_QP_OOA) |
| [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
|
private |
Check if a given state is part of the current active state configuration.
Details
Please note that for an HSM, to "be in a state" means also to be in a superstate of the state.
| [in] | me | current instance pointer (see SAS_QP_OOA) |
| [in] | stateHndl | pointer to the state-handler function to be tested |
Forward Traceability
|
private |
Implementation of getting the state handler in an QHsm subclass.
| [in,out] | me | current instance pointer (see SAS_QP_OOA) |
| QStateHandler QHsm_state | ( | QHsm const *const | me | ) |
Obtain the current active state from a HSM (read only).
| [in] | me | current instance pointer (see SAS_QP_OOA) |
Forward Traceability
| QStateHandler QHsm_childState | ( | QHsm *const | me, |
| QStateHandler const | parent ) |
Obtain the current active child state of a given parent in QHsm.
Details
Finds the child state of the given parent, such that this child state is an ancestor of the currently active state. The primary purpose of this function is to support **shallow history*transitions in state machines derived from QHsm.
| [in] | me | current instance pointer (see SAS_QP_OOA) |
| [in] | parent | pointer to the state-handler |
Forward Traceability
|
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] | me | current instance pointer (see SAS_QP_OOA) |
| [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 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] | me | current instance pointer (see SAS_QP_OOA) |
| [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] | me | current instance pointer (see SAS_QP_OOA) |
| [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