Quantum Leaps / qp Featured

Dependents:   qp_hangman qp_dpp qp_blinky

Embed: (wiki syntax)

« Back to documentation index

QHsm Class Reference

Hierarchical State Machine base class. More...

#include <qp.h>

Public Member Functions

virtual ~QHsm ()
 virtual destructor
void init (QEvt const *const e=static_cast< QEvt const * >(0))
 Performs the second step of HSM initialization by triggering the top-most initial transition.
void dispatch (QEvt const *const e)
 Dispatches an event to a HSM.
bool isIn (QStateHandler const s)
 Tests if a given state is part of the current active state configuratioin.

Protected Types

enum  ReservedHsmSignals { Q_ENTRY_SIG = 1, Q_EXIT_SIG, Q_INIT_SIG }

Protected Member Functions

 QHsm (QStateHandler const initial)
 Protected constructor of a HSM.
QStateHandler state (void) const
 Return the current active state.
QState tran (QStateHandler const target)
 internal helper function to record a state transition
QState super (QStateHandler const superstate)
 internal helper function to record the superstate

Static Protected Member Functions

static QState top (void *const me, QEvt const *const e)
 the top-state.
static QState Q_HANDLED (void)
 Inline function to specify the return of a state-handler when it handles the event.
static QState Q_UNHANDLED (void)
 Macro 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.

Detailed Description

Hierarchical State Machine base class.

QHsm represents a Hierarchical Finite State Machine (HSM). QHsm derives from the QFsm class and extends the capabilities of a basic FSM with state hierarchy.

Note:
QHsm is not intended to be instantiated directly, but rather serves as the base structure for derivation of state machines in the application code.

The following example illustrates how to derive a state machine class from QHsm.

Definition at line 448 of file qp.h.


Member Enumeration Documentation

enum ReservedHsmSignals [protected]
Enumerator:
Q_ENTRY_SIG 

signal for entry actions

Q_EXIT_SIG 

signal for exit actions

Q_INIT_SIG 

signal for nested initial transitions

Definition at line 541 of file qp.h.


Constructor & Destructor Documentation

QP_END_ QP_BEGIN_ ~QHsm (  ) [virtual]

virtual destructor

QHsm::init() implementation.

Definition at line 138 of file qp.cpp.

QHsm ( QStateHandler const   initial ) [protected]

Protected constructor of a HSM.

Performs the first step of HSM initialization by assigning the initial pseudostate to the currently active state of the state machine.

Note:
The constructor is protected to prevent direct instantiating of QHsm objects. This class is intended for subclassing only.
See also:
The QHsm example illustrates how to use the QHsm constructor in the constructor initializer list of the derived state machines.
QFsm::QFsm()

Definition at line 499 of file qp.h.


Member Function Documentation

QP_END_ QP_BEGIN_ void dispatch ( QEvt const *const   e )

Dispatches an event to a HSM.

QHsm::dispatch() implementation.

Processes one event at a time in Run-to-Completion (RTC) fashion. The argument e is a constant pointer the QEvt or a class derived from QEvt.

Note:
Must be called after QHsm::init().
See also:
example for QHsm::init()

Definition at line 198 of file qp.cpp.

void init ( QEvt const *const   e = static_cast<QEvt const *>(0) )

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

Parameters:
econstant pointer QEvt or a class derived from QEvt
Note:
Must be called only ONCE before QHsm::dispatch()

The following example illustrates how to initialize a HSM, and dispatch events to it:

Definition at line 141 of file qp.cpp.

bool isIn ( QStateHandler const   s )

Tests if a given state is part of the current active state configuratioin.

Parameters:
stateis a pointer to the state handler function, e.g., &QCalc::on.
static QState Q_HANDLED ( void   ) [static, protected]

Inline function to specify the return of a state-handler when it handles the event.

Definition at line 522 of file qp.h.

static QState Q_UNHANDLED ( void   ) [static, protected]

Macro 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.

Definition at line 527 of file qp.h.

QStateHandler state ( void   ) const [protected]

Return the current active state.

Definition at line 505 of file qp.h.

QState super ( QStateHandler const   superstate ) [protected]

internal helper function to record the superstate

Definition at line 536 of file qp.h.

QP_END_ QP_BEGIN_ QState top ( void *const  me,
QEvt const *const  e 
) [static, protected]

the top-state.

QHsm::top() implementation.

QHsm::top() is the ultimate root of state hierarchy in all HSMs derived from QHsm. This state handler always returns (QSTATE)0, which means that it "handles" all events.

See also:
Example of the QCalc::on() state handler.

Definition at line 126 of file qp.cpp.

QState tran ( QStateHandler const   target ) [protected]

internal helper function to record a state transition

Definition at line 530 of file qp.h.