QP/C++  7.3.3
Real-Time Embedded Framework
Loading...
Searching...
No Matches
QP::QHsm Class Reference

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

#include "qp.hpp"

Inheritance diagram for QP::QHsm:
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
 
bool isIn (QStateHandler const state) noexcept override
 
QStateHandler childState (QStateHandler const parent) noexcept
 
QStateHandler getStateHandler () noexcept override
 
- Public Member Functions inherited from QP::QAsm
virtual void init (void const *const e, std::uint_fast8_t const qsId)=0
 
virtual void init (std::uint_fast8_t const qsId)
 
virtual void dispatch (QEvt const *const e, std::uint_fast8_t const qsId)=0
 
virtual bool isIn (QStateHandler const state) noexcept
 
QStateHandler state () const noexcept
 
QMState const * stateObj () const noexcept
 
virtual QStateHandler getStateHandler () noexcept
 

Static Public Attributes

static constexpr std::int_fast8_t MAX_NEST_DEPTH_ {6}
 

Protected Member Functions

 QHsm (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

std::int_fast8_t hsm_tran (QStateHandler(&path)[MAX_NEST_DEPTH_], 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 (QHsm-style state machine implementation strategy)

Description
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.
Note
QP::QHsm is not intended to be instantiated directly, but rather serves as the abstract base class for derivation of state machines in the QP application.
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.
// Calculator class with a state machine...
class Calc : public QP::QHsm { // <== inherit QP::QHsm
public:
static Calc inst;
private:
double m_op1;
double m_op2;
uint8_t m_oper1;
uint8_t m_oper2;
public:
// ctor
Calc() : : QHsm(Q_STATE_CAST(&Calc::initial)) {...}
protected:
Q_STATE_DECL(initial);
Q_STATE_DECL(ready);
Q_STATE_DECL(begin);
. . .
}; // class Calc
Hierarchical State Machine class (QHsm-style state machine implementation strategy)
Definition qp.hpp:392
#define Q_STATE_CAST(handler_)
Definition qp.hpp:493
#define Q_STATE_DECL(state_)
Definition qp.hpp:473

Definition at line 392 of file qp.hpp.

Constructor & Destructor Documentation

◆ QHsm()

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

Definition at line 119 of file qep_hsm.cpp.

Member Function Documentation

◆ init() [1/2]

void QP::QHsm::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.

Description
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 127 of file qep_hsm.cpp.

◆ init() [2/2]

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

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

Description
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 403 of file qp.hpp.

◆ dispatch()

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

Virtual function to dispatch an event to the state machine.

Description
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 249 of file qep_hsm.cpp.

◆ isIn()

QP::QHsm::isIn ( QP::QStateHandler const  state)
overridevirtualnoexcept
Description
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.
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))
Traceability

Reimplemented from QP::QAsm.

Definition at line 452 of file qep_hsm.cpp.

◆ childState()

QP::QHsm::childState ( QP::QStateHandler const  parent)
noexcept

Obtain the current active child state of a given parent in QP::QMsm

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
Returns
the child of a given parent state-handler, 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_hsm:890
  • the child must be found
Note
This function is used in QM for auto-generating code for state history (shallow history)

Definition at line 488 of file qep_hsm.cpp.

◆ getStateHandler()

QStateHandler QP::QHsm::getStateHandler ( )
inlineoverridevirtualnoexcept

Get the current state (handler) in the state machine

Reimplemented from QP::QAsm.

Definition at line 413 of file qp.hpp.

◆ hsm_tran()

QP::QHsm::hsm_tran ( QStateHandler(&)  path[MAX_NEST_DEPTH_],
std::uint_fast8_t const  qsId 
)
private

Internal implementation of the transition given the path to the target.

Parameters
[in]patharray of handler function pointers leading to the target

Definition at line 520 of file qep_hsm.cpp.

Member Data Documentation

◆ MAX_NEST_DEPTH_

constexpr std::int_fast8_t QP::QHsm::MAX_NEST_DEPTH_ {6}
staticconstexpr

Definition at line 394 of file qp.hpp.


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