QHsm Class Reference

Hierarchical State Machine base class. More...

#include <qep.h>

List of all members.

Public Member Functions

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.
class QCalc : public QHsm {                // Quantum Calculator state machine
private:
    double  m_operand1;
    double  m_operand2;
    char    m_display[DISP_WIDTH + 1];
    uint8_t m_len;
    uint8_t m_opKey;

public:
    QCalc() : QHsm((QStateHandler)&QCalc::initial) {                   // ctor
    }

protected:
    static QState initial  (QCalc *me, QEvent const *e);
    static QState on       (QCalc *me, QEvent const *e);
    static QState error    (QCalc *me, QEvent const *e);
    static QState ready    (QCalc *me, QEvent const *e);
    static QState result   (QCalc *me, QEvent const *e);
    static QState begin    (QCalc *me, QEvent const *e);
    static QState negated1 (QCalc *me, QEvent const *e);
    static QState operand1 (QCalc *me, QEvent const *e);
    static QState zero1    (QCalc *me, QEvent const *e);
    static QState int1     (QCalc *me, QEvent const *e);
    static QState frac1    (QCalc *me, QEvent const *e);
    static QState opEntered(QCalc *me, QEvent const *e);
    static QState negated2 (QCalc *me, QEvent const *e);
    static QState operand2 (QCalc *me, QEvent const *e);
    static QState zero2    (QCalc *me, QEvent const *e);
    static QState int2     (QCalc *me, QEvent const *e);
    static QState frac2    (QCalc *me, QEvent const *e);
};

Definition at line 136 of file qep.h.


Constructor & Destructor Documentation

QHsm::QHsm ( QStateHandler  initial  )  [inline, 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 185 of file qep.h.


Member Function Documentation

void QHsm::init ( QEvent const *  e = (QEvent *)0  ) 

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

Parameters:
e constant 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:
#include "qep.h"                                     // QEP/C public interface
#include "qcalc.h"                              // QCalc HSM derived from QHsm

static QCalc l_qcalc;                              // an instance of QCalc HSM

int main() {

    l_qcalc.init();                              // trigger initial transition

    for (;;) {                                                   // event loop
        QEvent e;
        . . .
        // wait for the next event and assign it to the event object e
        . . .
        l_qcalc.dispatch(&e);                            // dispatch the event
    }
    return 0;
}

Definition at line 38 of file qhsm_ini.cpp.

References Q_ALLEGE, Q_ASSERT, Q_INIT_SIG, Q_RET_TRAN, QEP_EMPTY_SIG_, QEP_ENTER_, QEP_MAX_NEST_DEPTH_, QEP_TRIG_, QS_BEGIN_, QS_END_, QS_FUN_, QS_INT_LOCK_KEY_, QS_OBJ_, QS_QEP_INIT_TRAN, QS_QEP_STATE_INIT, QS_TIME_, QS::smObj_, and top().

void QHsm::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()

Definition at line 38 of file qhsm_dis.cpp.

References Q_ASSERT, Q_EXIT_SIG, Q_INIT_SIG, Q_RET_HANDLED, Q_RET_IGNORED, Q_RET_SUPER, Q_RET_TRAN, QEP_EMPTY_SIG_, QEP_ENTER_, QEP_EXIT_, QEP_MAX_NEST_DEPTH_, QEP_TRIG_, QS_BEGIN_, QS_END_, QS_FUN_, QS_INT_LOCK_KEY_, QS_OBJ_, QS_QEP_IGNORED, QS_QEP_INTERN_TRAN, QS_QEP_STATE_EXIT, QS_QEP_STATE_INIT, QS_QEP_TRAN, QS_SIG_, QS_TIME_, and QS::smObj_.

uint8_t QHsm::isIn ( QStateHandler  state  ) 

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

Parameters:
state is a pointer to the state handler function, e.g., &QCalc::on.

Definition at line 35 of file qhsm_in.cpp.

References m_state, Q_RET_IGNORED, QEP_EMPTY_SIG_, and QEP_TRIG_.

QState QHsm::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.

References Q_IGNORED.

Referenced by init().


The documentation for this class was generated from the following files:
Generated on Sat Dec 27 21:35:30 2008 for QP/C++ by  doxygen 1.5.4