Linux Face / QPFramework
Embed: (wiki syntax)

« Back to documentation index

QHsm Class Reference

Hierarchical State Machine base class. More...

#include <qep.h>

Public Member Functions

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

Protected Member Functions

 QHsm (QStateHandler initial)
 Protected constructor of a HSM.

Static Protected Member Functions

static QState top (QHsm *me, QEvent const *e)
 the top-state.

Protected Attributes

QStateHandler m_state
 current active state (state-variable)

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 138 of file qep.h.


Constructor & Destructor Documentation

virtual ~QHsm (  ) [virtual]

virtual destructor

QHsm ( QStateHandler  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 189 of file qep.h.


Member Function Documentation

void dispatch ( QEvent const *  e )

Dispatches an event to a HSM.

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

Note:
Must be called after QHsm::init().
See also:
example for QHsm::init()
void init ( QEvent const *  e = (QEvent *)0 )

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

Parameters:
econstant pointer QEvent or a class derived from QEvent
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 41 of file qhsm_ini.cpp.

uint8_t isIn ( QStateHandler  state )

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.

Definition at line 35 of file qhsm_in.cpp.

QState top ( QHsm me,
QEvent const *  e 
) [static, protected]

the top-state.

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 35 of file qhsm_top.cpp.


Field Documentation

QStateHandler m_state [protected]

current active state (state-variable)

Definition at line 140 of file qep.h.