2019-03-28 11:59:31 -04:00

161 lines
5.3 KiB
C++

//$file${.::launcher.cpp} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
//
// Model: start-stop.qm
// File: ${.::launcher.cpp}
//
// This code has been generated by QM 4.5.0 (https://www.state-machine.com/qm).
// DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost.
//
// This program is open source software: you can redistribute it and/or
// modify it under the terms of the GNU General Public License as published
// by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
//
//$endhead${.::launcher.cpp} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#include "qpcpp.h"
#include "worker.h"
#include "bsp.h"
#include <new> // for placement new
//Q_DEFINE_THIS_FILE
static QP::QEvt const *l_workerQueueSto[10];
static StackType_t l_workerStackSto[configMINIMAL_STACK_SIZE];
//$declare${AOs::Launcher} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
//${AOs::Launcher} ...........................................................
class Launcher : public QP::QActive {
public:
static Launcher inst;
Worker * m_worker;
private:
QP::QTimeEvt m_te;
public:
Launcher();
protected:
Q_STATE_DECL(initial);
Q_STATE_DECL(inactive);
Q_STATE_DECL(active);
};
//$enddecl${AOs::Launcher} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//$skip${QP_VERSION} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
// Check for the minimum required QP version
#if (QP_VERSION < 650U) || (QP_VERSION != ((QP_RELEASE^4294967295U) % 0x3E8U))
#error qpcpp version 6.5.0 or higher required
#endif
//$endskip${QP_VERSION} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//$define${AOs::AO_Launcher} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
//${AOs::AO_Launcher} ........................................................
QP::QActive * const AO_Launcher = &Launcher::inst; // opaque pointer
//$enddef${AOs::AO_Launcher} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//$define${AOs::Launcher} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
//${AOs::Launcher} ...........................................................
Launcher Launcher::inst;
//${AOs::Launcher::Launcher} .................................................
Launcher::Launcher()
: QActive(initial),
m_worker(0),
m_te(this, TIMEOUT_SIG, 0U)
{}
//${AOs::Launcher::SM} .......................................................
Q_STATE_DEF(Launcher, initial) {
//${AOs::Launcher::SM::initial}
(void)e; // unused parameter
subscribe(DONE_SIG);
QS_OBJ_DICTIONARY(&Launcher::inst);
QS_OBJ_DICTIONARY(&Launcher::inst.m_te);
QS_SIG_DICTIONARY(DONE_SIG, (void *)0);
QS_SIG_DICTIONARY(TIMEOUT_SIG, (void *)0);
QS_FUN_DICTIONARY(&inactive);
QS_FUN_DICTIONARY(&active);
return tran(&inactive);
}
//${AOs::Launcher::SM::inactive} .............................................
Q_STATE_DEF(Launcher, inactive) {
QP::QState status_;
switch (e->sig) {
//${AOs::Launcher::SM::inactive}
case Q_ENTRY_SIG: {
m_te.armX(BSP::TICKS_PER_SEC / 5U, 0);
status_ = Q_RET_HANDLED;
break;
}
//${AOs::Launcher::SM::inactive}
case Q_EXIT_SIG: {
m_te.disarm();
status_ = Q_RET_HANDLED;
break;
}
//${AOs::Launcher::SM::inactive::TIMEOUT}
case TIMEOUT_SIG: {
status_ = tran(&active);
break;
}
default: {
status_ = super(&top);
break;
}
}
return status_;
}
//${AOs::Launcher::SM::active} ...............................................
Q_STATE_DEF(Launcher, active) {
QP::QState status_;
switch (e->sig) {
//${AOs::Launcher::SM::active}
case Q_ENTRY_SIG: {
// placement new to execute the Worker ctor
m_worker = new (&Worker::inst) Worker;
m_worker->start(
1U, // QP priority of the AO
l_workerQueueSto, // event queue storage
Q_DIM(l_workerQueueSto), // queue length [events]
l_workerStackSto, // stack storage
sizeof(l_workerStackSto), // stack size [bytes]
static_cast<QP::QEvt *>(0)); // initialization event (not used)
status_ = Q_RET_HANDLED;
break;
}
//${AOs::Launcher::SM::active}
case Q_EXIT_SIG: {
m_worker->~Worker(); // explicit destructor call
m_worker = 0;
status_ = Q_RET_HANDLED;
break;
}
//${AOs::Launcher::SM::active::DONE}
case DONE_SIG: {
// arm a timer for at least one tick
m_te.armX(2, 0);
// wait for Worker to stop...
status_ = Q_RET_HANDLED;
break;
}
//${AOs::Launcher::SM::active::TIMEOUT}
case TIMEOUT_SIG: {
status_ = tran(&inactive);
break;
}
default: {
status_ = super(&top);
break;
}
}
return status_;
}
//$enddef${AOs::Launcher} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^