|
QP/C++
|
Finite State Machine base class. More...
#include <qep.h>
Public Member Functions | |
| virtual | ~QFsm () |
| virtual destructor | |
| void | init (QEvent const *e=(QEvent *) 0) |
| Performs the second step of FSM initialization by triggering the top-most initial transition. | |
| void | dispatch (QEvent const *e) |
| Dispatches an event to a FSM. | |
Protected Member Functions | |
| QFsm (QStateHandler initial) | |
| Protected constructor of a FSM. | |
Protected Attributes | |
| QStateHandler | m_state |
| current active state (state-variable) | |
Finite State Machine base class.
QFsm represents a traditional non-hierarchical Finite State Machine (FSM) without state hierarchy, but with entry/exit actions.
QFsm is also a base structure for the QHsm class.
The following example illustrates how to derive a state machine class from QFsm.
class QBomb : public QFsm { uint8_t m_timeout; // number of seconds till explosion uint8_t m_defuse; // the secret defuse code uint8_t m_code; // the current defuse code entry public: QBomb() : QFsm((QStateHandler)&QBomb::initial) { } protected: static QState initial(QBomb *me, QEvent const *e); static QState setting(QBomb *me, QEvent const *e); static QState timing(QBomb *me, QEvent const *e); static QState blast(QBomb *me, QEvent const *e); };
| QFsm::QFsm | ( | QStateHandler | initial | ) | [inline, protected] |
Protected constructor of a FSM.
Performs the first step of FSM initialization by assigning the initial pseudostate to the currently active state of the state machine.
| void QFsm::dispatch | ( | QEvent const * | e | ) |
Dispatches an event to a FSM.
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 39 of file qfsm_dis.cpp.
References Q_ENTRY_SIG, Q_EXIT_SIG, Q_RET_HANDLED, Q_RET_TRAN, QEP_TRIG_, QS_BEGIN_, QS_CRIT_STAT_, QS_END_, QS_FUN_, QS_OBJ_, QS_QEP_IGNORED, QS_QEP_INTERN_TRAN, QS_QEP_TRAN, QEvent::sig, and QS::smObj_.
Referenced by QEP::getVersion().
Performs the second step of FSM initialization by triggering the top-most initial transition.
The argument e is constant pointer to QEvent or a class derived from QEvent.
The following example illustrates how to initialize a FSM, and dispatch events to it:
#include "qep.h" // QEP/C public interface #include "qbomb.h" // QBomb FSM derived from QFsm static QBomb l_qbomb; // an instance of QBomb FSM int main() { QBombInitEvt ie; ie.defuse = 0x0D; // 1101 binary l_qbomb.init(&ie); // trigger initial transition for (;;) { // event loop QEvent e; . . . // wait for the next event and assign it to the event object e . . . l_qbomb.dispatch(&e); // dispatch the event } return 0; }
Definition at line 45 of file qfsm_ini.cpp.
References Q_ALLEGE, Q_ENTRY_SIG, Q_RET_TRAN, QEP_TRIG_, QS_BEGIN_, QS_CRIT_STAT_, QS_END_, QS_FUN_, QS_OBJ_, QS_QEP_INIT_TRAN, QS_QEP_STATE_INIT, and QS::smObj_.
Referenced by QEP::getVersion().
1.7.5.1