QP/C++
qep.h
Go to the documentation of this file.
00001 
00002 // Product: QEP/C++ platform-independent public interface
00003 // Last Updated for Version: 4.2.00
00004 // Date of the Last Update:  Jul 05, 2011
00005 //
00006 //                    Q u a n t u m     L e a P s
00007 //                    ---------------------------
00008 //                    innovating embedded systems
00009 //
00010 // Copyright (C) 2002-2011 Quantum Leaps, LLC. All rights reserved.
00011 //
00012 // This software may be distributed and modified under the terms of the GNU
00013 // General Public License version 2 (GPL) as published by the Free Software
00014 // Foundation and appearing in the file GPL.TXT included in the packaging of
00015 // this file. Please note that GPL Section 2[b] requires that all works based
00016 // on this software must also be made publicly available under the terms of
00017 // the GPL ("Copyleft").
00018 //
00019 // Alternatively, this software may be distributed and modified under the
00020 // terms of Quantum Leaps commercial licenses, which expressly supersede
00021 // the GPL and are specifically designed for licensees interested in
00022 // retaining the proprietary status of their code.
00023 //
00024 // Contact information:
00025 // Quantum Leaps Web site:  http://www.quantum-leaps.com
00026 // e-mail:                  info@quantum-leaps.com
00028 #ifndef qep_h
00029 #define qep_h
00030 
00037 
00038 #include "qevent.h"           // QEP event processor needs the QEvent facility
00039 
00040 #ifdef Q_USE_NAMESPACE
00041 namespace QP {
00042 #endif
00043 
00046 class QEP {
00047 public:
00053     static char const Q_ROM * Q_ROM_VAR getVersion(void);
00054 };
00055 
00057 
00059 typedef uint8_t QState;
00060 
00062 typedef QState (*QStateHandler)(void *me, QEvent const *e);
00063 
00064 
00080 class QFsm {
00081 protected:
00082     QStateHandler m_state;          
00083 
00084 public:
00086     virtual ~QFsm();
00087 
00099     void init(QEvent const *e = (QEvent *)0);
00100 
00110     void dispatch(QEvent const *e);
00111 
00112 protected:
00113 
00125     QFsm(QStateHandler initial) : m_state(initial) {}
00126 };
00127 
00142 class QHsm {
00143 protected:
00144     QStateHandler m_state;          
00145 
00146 public:
00148     virtual ~QHsm();
00149 
00159     void init(QEvent const *e = (QEvent *)0);
00160 
00170     void dispatch(QEvent const *e);
00171 
00177     uint8_t isIn(QStateHandler state);
00178 
00179 protected:
00180 
00193     QHsm(QStateHandler initial) : m_state(initial) {}
00194 
00202     static QState top(QHsm *me, QEvent const *e);
00203 };
00204 
00207 #define Q_RET_IGNORED       ((QState)1)
00208 
00215 #define Q_IGNORED()         (Q_RET_IGNORED)
00216 
00219 #define Q_RET_HANDLED       ((QState)0)
00220 
00228 #define Q_HANDLED()         (Q_RET_HANDLED)
00229 
00232 #define Q_RET_TRAN          ((QState)2)
00233 
00238 //lint -e960 -e1924 ignore MISRA Rule 42 (comma operator) and C-style cast
00239 #define Q_TRAN(target_)  \
00240     (me->m_state = (QStateHandler)(target_), Q_RET_TRAN)
00241 
00244 #define Q_RET_SUPER         ((QState)3)
00245 
00249 //lint -e960 -e1924 ignore MISRA Rule 42 (comma operator) and C-style cast
00250 #define Q_SUPER(super_)  \
00251     (me->m_state = (QStateHandler)(super_),  Q_RET_SUPER)
00252 
00253 
00256 enum QReservedSignals {
00257     Q_ENTRY_SIG = 1,                             
00258     Q_EXIT_SIG,                                   
00259     Q_INIT_SIG,                     
00260     Q_USER_SIG                              
00261 };
00262 
00263 #ifdef Q_USE_NAMESPACE
00264 }                                                              // namespace QP
00265 #endif
00266 
00268 // QS software tracing integration, only if enabled
00269 #ifdef Q_SPY                                   // QS software tracing enabled?
00270     #ifndef qs_h
00271     #include "qs_port.h"                                    // include QS port
00272     #endif                                                             // qs_h
00273 
00274     #if (Q_SIGNAL_SIZE == 1)
00275 
00279         #define QS_SIG_(sig_)       QS::u8_(sig_)
00280     #elif (Q_SIGNAL_SIZE == 2)
00281         #define QS_SIG_(sig_)       QS::u16_(sig_)
00282     #elif (Q_SIGNAL_SIZE == 4)
00283         #define QS_SIG_(sig_)       QS::u32_(sig_)
00284     #endif
00285 
00286 #else
00287     #ifndef qs_dummy_h
00288     #include "qs_dummy.h"                   // disable the QS software tracing
00289     #endif
00290 #endif                                                                // Q_SPY
00291 
00292 #endif                                                                // qep_h