|
QP/C++
|
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) | |
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.
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); };
| 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.
| 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.
Definition at line 42 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_CRIT_STAT_, QS_END_, QS_FUN_, QS_OBJ_, QS_QEP_DISPATCH, QS_QEP_IGNORED, QS_QEP_INTERN_TRAN, QS_QEP_STATE_EXIT, QS_QEP_STATE_INIT, QS_QEP_TRAN, and QS::smObj_.
Referenced by QEP::getVersion().
Performs the second step of HSM initialization by triggering the top-most initial transition.
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 45 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_CRIT_STAT_, QS_END_, QS_FUN_, QS_OBJ_, QS_QEP_INIT_TRAN, QS_QEP_STATE_INIT, QS::smObj_, and top().
Referenced by QEP::getVersion().
| uint8_t QHsm::isIn | ( | QStateHandler | state | ) |
Tests if a given state is part of the current active state configuratioin.
| state | is a pointer to the state handler function, e.g., &QCalc::on. |
Definition at line 39 of file qhsm_in.cpp.
References Q_RET_IGNORED, QEP_EMPTY_SIG_, and QEP_TRIG_.
Referenced by QEP::getVersion().
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.
Definition at line 39 of file qhsm_top.cpp.
References Q_IGNORED.
Referenced by QEP::getVersion(), and init().
1.7.5.1