QP/C++  7.4.0-rc.3
Real-Time Embedded Framework
Loading...
Searching...
No Matches
QP::QMsm Class Reference

Hierarchical State Machine class (QMsm-style state machine implementation strategy) More...

#include "qp.hpp"

Inheritance diagram for QP::QMsm:
QP::QAsm

Public Member Functions

void init (void const *const e, std::uint_fast8_t const qsId) override
 
void init (std::uint_fast8_t const qsId) override
 
void dispatch (QEvt const *const e, std::uint_fast8_t const qsId) override
 
QStateHandler getStateHandler () noexcept override
 
bool isIn (QStateHandler const state) noexcept override
 
bool isInState (QMState const *const stateObj) const noexcept
 
QMState const * childStateObj (QMState const *const parent) const noexcept
 
QMState const * topQMState () const noexcept
 
- Public Member Functions inherited from QP::QAsm
virtual ~QAsm () noexcept
 
QStateHandler state () const noexcept
 
QMState const * stateObj () const noexcept
 

Protected Member Functions

 QMsm (QStateHandler const initial) noexcept
 
- Protected Member Functions inherited from QP::QAsm
 QAsm () noexcept
 
QState tran (QStateHandler const target) noexcept
 
QState tran_hist (QStateHandler const hist) noexcept
 
QState super (QStateHandler const superstate) noexcept
 
QState qm_tran (void const *const tatbl) noexcept
 
QState qm_tran_init (void const *const tatbl) noexcept
 
QState qm_tran_hist (QMState const *const hist, void const *const tatbl) noexcept
 
QState qm_tran_ep (void const *const tatbl) noexcept
 
QState qm_tran_xp (QActionHandler const xp, void const *const tatbl) noexcept
 
QState qm_entry (QMState const *const s) noexcept
 
QState qm_exit (QMState const *const s) noexcept
 
QState qm_sm_exit (QMState const *const s) noexcept
 
QState qm_super_sub (QMState const *const s) noexcept
 

Private Member Functions

QState execTatbl_ (QMTranActTable const *const tatbl, std::uint_fast8_t const qsId)
 
void exitToTranSource_ (QMState const *const cs, QMState const *const ts, std::uint_fast8_t const qsId)
 
QState enterHistory_ (QMState const *const hist, std::uint_fast8_t const qsId)
 

Additional Inherited Members

- Public Types inherited from QP::QAsm
enum  QStateRet : QState {
  Q_RET_SUPER , Q_RET_SUPER_SUB , Q_RET_UNHANDLED , Q_RET_HANDLED ,
  Q_RET_IGNORED , Q_RET_ENTRY , Q_RET_EXIT , Q_RET_NULL ,
  Q_RET_TRAN , Q_RET_TRAN_INIT , Q_RET_TRAN_EP , Q_RET_TRAN_HIST ,
  Q_RET_TRAN_XP
}
 
enum  ReservedSig : QSignal { Q_EMPTY_SIG , Q_ENTRY_SIG , Q_EXIT_SIG , Q_INIT_SIG }
 Reserved signals by the QP-framework. More...
 
- Static Public Member Functions inherited from QP::QAsm
static QState top (void *const me, QEvt const *const e) noexcept
 
- Protected Attributes inherited from QP::QAsm
QAsmAttr m_state
 
QAsmAttr m_temp
 

Detailed Description

Hierarchical State Machine class (QMsm-style state machine implementation strategy)

Details

QMsm (QM State Machine) provides a more efficient state machine implementation strategy than QP::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
QP::QMsm is not intended to be instantiated directly, but rather serves as the abstract base class for derivation of state machines in the application code.
Backward Traceability
Usage

The following example illustrates how to derive a state machine class from QP::QMsm.

class ToasterOven : public QP::QMsm { // <== inherits QP::QMsm
public:
ToasterOven();
public:
// ctor
ToasterOven() : QMsm(Q_STATE_CAST(&ToasterOven::initial)) {...}
protected:
QM_STATE_DECL( initial);
QM_STATE_DECL( doorClosed);
QM_ACTION_DECL(doorClosed_e);
QM_ACTION_DECL(doorClosed_x);
QM_ACTION_DECL(doorClosed_i);
. . .
}; // class ToastOven
Hierarchical State Machine class (QMsm-style state machine implementation strategy)
Definition qp.hpp:420
#define Q_STATE_CAST(handler_)
Definition qp.hpp:488
#define QM_STATE_DECL(state_)
Definition qp.hpp:492
#define QM_ACTION_DECL(action_)
Definition qp.hpp:504

Definition at line 420 of file qp.hpp.

Constructor & Destructor Documentation

◆ QMsm()

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

Constructor of QP::QMsm

Details

Performs the first step of QMsm 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.
Usage

The following example illustrates how to invoke QMsm() constructor in the "constructor" of a derived state machine:

void Calc::Calc()
: QMsm(Q_STATE_CAST(&Calc::initial)); // <===
. . .
{
. . .
}

Definition at line 97 of file qep_msm.cpp.

Member Function Documentation

◆ init() [1/2]

void QP::QMsm::init ( void const *const e,
std::uint_fast8_t const qsId )
overridevirtual

Virtual function to take the top-most initial transition in the state machine.

Details

Synchronously executes the top-most initial transition in a state machine (must be overridden in the subclasses).

Parameters
[in]epointer to an initialization parameter (might be nullptr)
[in]qsIdQS-id of this state machine (for QS local filter)
Precondition qep_asm:200
  • the virtual pointer must be initialized,
  • the top-most initial transition must be initialized,
  • the initial transition must not be taken yet.

Implements QP::QAsm.

Definition at line 105 of file qep_msm.cpp.

◆ init() [2/2]

void QP::QMsm::init ( std::uint_fast8_t const qsId)
inlineoverridevirtual

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.

Parameters
[in]qsIdQS-id of this state machine (for QS local filter)

Reimplemented from QP::QAsm.

Definition at line 428 of file qp.hpp.

◆ dispatch()

void QP::QMsm::dispatch ( QEvt const *const e,
std::uint_fast8_t const qsId )
overridevirtual

Virtual function to dispatch an event to the state machine.

Details

Synchronously dispatches an event for processing to a state machine (must be overridden in the subclasses). The processing of an event represents one run-to-completion (RTC) step.

Parameters
[in]epointer to the event to be dispatched to the MSM
[in]qsIdQS-id of this state machine (for QS local filter)
Precondition qep_asm:302
  • current state must be initialized
  • check the internal integrity (Software Self-Monitoring (SSM))

Implements QP::QAsm.

Definition at line 166 of file qep_msm.cpp.

◆ getStateHandler()

QStateHandler QP::QMsm::getStateHandler ( )
inlineoverridevirtualnoexcept

Implementation of getting the state handler in a QP::QMsm subclass

Obtain the current active state from a MSM (read only)

Returns
the current active state-handler
Note
This function is used for state history (deep history) in the auto-generated code by the QM modeling tool. Reimplemented from QP::QAsm.

Reimplemented from QP::QAsm.

Definition at line 436 of file qp.hpp.

◆ isIn()

bool QP::QMsm::isIn ( QP::QStateHandler const state)
overridevirtualnoexcept
Details

Check if a given state is part of the current active state configuration in QMsm 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.

See also
QP::QAsm::isIn()
Attention
This function must be called only on a state machine that is in the "stable state configuration". Among others, this means that the state machine cannot call it in the middle of its own transition.
Precondition qep_hsm:602
  • internal integrity check (Software Self-Monitoring (SSM))
Backward Traceability

Reimplemented from QP::QAsm.

Definition at line 376 of file qep_msm.cpp.

◆ isInState()

bool QP::QMsm::isInState ( QMState const *const stateObj) const
noexcept
Deprecated
instead use: QMsm::isIn()
Deprecated
Instead use: QP::QMsm::isIn()
Details

Checks if a state machine derived from QMsm is-in a given state.

Parameters
[in]stateObjpointer to the QMState object that corresponds to the tested state.
Returns
'true' if the MSM "is in" the state and 'false' otherwise

Definition at line 400 of file qep_msm.cpp.

◆ childStateObj()

QMState const * QP::QMsm::childStateObj ( QMState const *const parent) const
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.

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. For the corner case when the currently active state is the given parent state, function returns the parent state.
Postcondition qep_msm:890
  • the child must be found
Note
This function is used in the QM modeling tool for auto-generating code for state history (shallow history)

Definition at line 424 of file qep_msm.cpp.

◆ execTatbl_()

QState QP::QMsm::execTatbl_ ( QMTranActTable const *const tatbl,
std::uint_fast8_t const qsId )
private

Execute transition-action table

Details

Helper function to execute transition sequence in a transition-action table.

Parameters
[in]tatblpointer to the transition-action table
[in]qsIdQS-id of this state machine (for QS local filter)
Returns
status of the last action from the transition-action table.
Precondition qep_msm:400
  • provided state table cannot be NULL
Note
This function is for internal use inside the QEP event processor and should **not* be called directly from the applications.

Definition at line 473 of file qep_msm.cpp.

◆ exitToTranSource_()

void QP::QMsm::exitToTranSource_ ( QMState const *const cs,
QMState const *const ts,
std::uint_fast8_t const qsId )
private

Exit the current state up to the explicit transition source

Details

Static helper function to exit the current state configuration to the transition source, which in a hierarchical state machine might be a superstate of the current state.

Parameters
[in]cspointer to the current state
[in]tspointer to the transition source state
[in]qsIdQS-id of this state machine (for QS local filter)

Definition at line 550 of file qep_msm.cpp.

◆ enterHistory_()

QState QP::QMsm::enterHistory_ ( QMState const *const hist,
std::uint_fast8_t const qsId )
private

Enter history of a composite state

Details

Static helper function to execute the segment of transition to history after entering the composite state and

Parameters
[in]histpointer to the history substate
[in]qsIdQS-id of this state machine (for QS local filter)
Returns
Q_RET_TRAN_INIT, if an initial transition has been executed in the last entered state or Q_RET_NULL if no such transition was taken.

Definition at line 595 of file qep_msm.cpp.

◆ topQMState()

QMState const * QP::QMsm::topQMState ( ) const
noexcept

Definition at line 664 of file qep_msm.cpp.


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