QP/C++  5.8.2
QP::QMsm Class Reference

QM State Machine implementation strategy. More...

#include <qep.h>

Inheritance diagram for QP::QMsm:
QP::QHsm

Public Member Functions

virtual void init (QEvt const *const e)
 Performs the second step of SM initialization by triggering the top-most initial transition. More...
 
virtual void init (void)
 
virtual void dispatch (QEvt const *const e)
 Dispatches an event to a HSM. More...
 
bool isInState (QMState const *st) const
 Tests if a given state is part of the active state configuration. More...
 
QMState const * stateObj (void) const
 Return the current active state object (read only)
 
QMState const * childStateObj (QMState const *const parent) const
 Obtain the current active child state of a given parent (read only) More...
 
- Public Member Functions inherited from QP::QHsm
virtual ~QHsm ()
 virtual destructor More...
 
bool isIn (QStateHandler const s)
 Tests if a given state is part of the current active state configuration. More...
 
QStateHandler state (void) const
 Obtain the current state (state handler function) More...
 
QStateHandler childState (QStateHandler const parent)
 Obtain the current active child state of a given parent. More...
 
QState tran_ (QStateHandler const target)
 internal helper function to record a state transition
 
QState tran_hist_ (QStateHandler const hist)
 internal helper function to record a transition to history
 
QState super_ (QStateHandler const superstate)
 internal helper function to record the superstate
 
QState qm_tran_ (QMTranActTable const *const tatbl)
 internal helper function to record a regular state transition
 
QState qm_tran_hist_ (QMState const *const hist, QMTranActTable const *const tatbl)
 Internal helper function to record a regular state transition.
 
QState qm_tran_init_ (QMTranActTable const *const tatbl)
 Internal helper function to record an initial state transition.
 
QState qm_tran_ep_ (QMTranActTable const *const tatbl)
 Internal helper function to record an transition to an entry point to a submachine state.
 
QState qm_tran_xp_ (QActionHandler const xp, QMTranActTable const *const tatbl)
 Internal helper function to record an transition to an exit point from a submachine state.
 
QState qm_entry_ (QMState const *const s)
 Internal helper function to record a state entry.
 
QState qm_exit_ (QMState const *const s)
 Internal helper function to record a state exit.
 
QState qm_super_sub_ (QMState const *const s)
 Internal helper function to call in a QM action-handler when it passes the event to the host submachine state to handle an event.
 

Protected Member Functions

 QMsm (QStateHandler const initial)
 Protected constructor of QMsm. More...
 
- Protected Member Functions inherited from QP::QHsm
 QHsm (QStateHandler const initial)
 Protected constructor of QHsm. More...
 

Friends

class QMActive
 

Additional Inherited Members

- Public Types inherited from QP::QHsm
enum  ReservedHsmSignals { Q_ENTRY_SIG = 1, Q_EXIT_SIG, Q_INIT_SIG }
 
- Static Public Member Functions inherited from QP::QHsm
static QState top (void *const me, QEvt const *const e)
 the top-state. More...
 
static QState Q_HANDLED (void)
 internal helper function to specify the return of a state-handler when it handles the event.
 
static QState Q_UNHANDLED (void)
 internal helper function to specify the return of a state-handler function when it attempts to handle the event but a guard condition evaluates to false and there is no other explicit way of handling the event.
 
static QState QM_HANDLED (void)
 Internal helper function to call in a QM action-handler when it handles an event.
 
static QState QM_UNHANDLED (void)
 Macro to call in a QM action-handler when it does not handle an event due to a guard condition evaluating to false.
 
static QState QM_SUPER (void)
 Internal helper function to call in a QM action-handler when it passes the event to the superstate for processing.
 

Detailed Description

QM State Machine implementation strategy.

Description
QMsm (QM State Machine) provides a more efficient state machine implementation strategy than QHsm, but requires the use of the QM modeling tool, but are the fastest and need the least run-time support (the smallest event-processor taking up the least code space).
Note
QMsm 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 QMsm. Please note that the QMsm member 'super' is defined as the first member of the derived struct.
class Calc : public QMsm { // derived from QMsm
private:
double m_operand;
char m_display[DISP_WIDTH + 1];
uint8_t m_len;
uint8_t m_opKey;
public:
Calc() : QMsm(Q_STATE_CAST(&Calc::initial)) { // ctor
}
protected:
// NOTE: QMsm state machine code is not intended for manual
// coding but rather needs to be generated automatically by
// the QM modeling tool
static QState initial (Calc * const me, QEvt const *e);
static QState on (Calc * const me, QEvt const *e);
static QState error (Calc * const me, QEvt const *e);
static QState ready (Calc * const me, QEvt const *e);
static QState result (Calc * const me, QEvt const *e);
static QState begin (Calc * const me, QEvt const *e);
. . .
};

Definition at line 496 of file qep.h.

Constructor & Destructor Documentation

◆ QMsm()

QP::QMsm::QMsm ( QStateHandler const  initial)
protected

Protected constructor of QMsm.

Description
Performs the first step of initialization by assigning the initial pseudostate to the currently active state of the state machine.
Parameters
[in]initialthe top-most initial transition for the MSM.
Note
The constructor is protected to prevent direct instantiating of the QP::QMsm objects. This class is intended for subclassing only.
See also
The QP::QMsm example illustrates how to use the QMsm constructor in the constructor initializer list of the derived state machines.

Definition at line 84 of file qep_msm.cpp.

Member Function Documentation

◆ childStateObj()

QMState const * QP::QMsm::childStateObj ( QMState const *const  parent) const

Obtain the current active child state of a given parent (read only)

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 QMsm.
Parameters
[in]parentpointer to the state-handler object
Returns
the child of a given parent state, which is an ancestor of the currently active state
Postcondition
the child must be confirmed

Definition at line 513 of file qep_msm.cpp.

◆ dispatch()

void QP::QMsm::dispatch ( QEvt const *const  e)
virtual

Dispatches an event to a HSM.

Description
Dispatches an event for processing to a meta state machine (MSM). The processing of an event represents one run-to-completion (RTC) step.
Parameters
[in]epointer to the event to be dispatched to the MSM
Note
Must be called after QP::QMsm::init().
Precondition
current state must be initialized

Reimplemented from QP::QHsm.

Definition at line 144 of file qep_msm.cpp.

◆ init()

void QP::QMsm::init ( QEvt const *const  e)
virtual

Performs the second step of SM initialization by triggering the top-most initial transition.

Description
Executes the top-most initial transition in a MSM.
Parameters
[in]ea constant pointer to QP::QEvt or a subclass of QP::QEvt
Attention
QP::QMsm::init() must be called exactly once before QP::QMsm::dispatch()
Precondition
the top-most initial transition must be initialized, and the initial transition must not be taken yet.

Reimplemented from QP::QHsm.

Definition at line 101 of file qep_msm.cpp.

◆ isInState()

bool QP::QMsm::isInState ( QMState const *  st) const

Tests if a given state is part of the active state configuration.

Description
Tests if a state machine derived from QMsm is-in a given state.
Note
For a MSM, to "be-in" a state means also to "be-in" a superstate of of the state.
  • [in] st pointer to the QMState object that corresponds to the tested state.
Returns
'true' if the MSM is in the st and 'false' otherwise

Definition at line 485 of file qep_msm.cpp.


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