#include <qep.h>
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) | |
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.
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.
| 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.
Performs the second step of HSM initialization by triggering the top-most initial transition.
#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.
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.
| 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_.
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 35 of file qhsm_top.cpp.
References Q_IGNORED.
Referenced by init().
1.5.4