Start-stop application that demonstrates staring and stopping active objects multiple times during the runtime, as opposed to starting AOs only at the beginning. The only instance of the Launcher AO (Singleton pattern) : QActive(initial), m_worker(0), m_te(this, TIMEOUT_SIG, 0U) (void)e; // unused parameter subscribe(DONE_SIG); QS_OBJ_DICTIONARY(&Launcher::inst); QS_OBJ_DICTIONARY(&Launcher::inst.m_te); QS_SIG_DICTIONARY(DONE_SIG, nullptr); QS_SIG_DICTIONARY(TIMEOUT_SIG, nullptr); m_te.armX(BSP::TICKS_PER_SEC / 5U, 0); m_te.disarm(); // 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] m_worker->~Worker(); // explicit destructor call m_worker = nullptr; // arm a timer for at least one tick m_te.armX(2, 0); // wait for Worker to stop... "Worker" active object that will be started, perform its job, and then stop itself. The only instance of the Worker AO (Singleton pattern) blink down-counter : QActive(&initial), m_te(this, TIMEOUT_SIG, 0U) virtual destructor BSP::led2Off(); (void)e; // unused parameter QS_OBJ_DICTIONARY(&Worker::inst); QS_OBJ_DICTIONARY(&Worker::inst.m_te); m_counter = 5U; // number of blinks m_te.armX(BSP::TICKS_PER_SEC / 5U, BSP::TICKS_PER_SEC / 5U); m_te.disarm(); BSP::ledOn(); BSP::ledOff(); --m_counter; m_counter == 0U BSP::led2On(); static QEvt const doneEvt = { DONE_SIG, 0 }; QF::PUBLISH(&doneEvt, this); stop(); // stop this active object = &Launcher::inst; // opaque pointer #ifndef WORKER_HPP #define WORKER_HPP using namespace QP; enum DPPSignals { DONE_SIG = Q_USER_SIG, // to signal when Worker is done // ... MAX_PUB_SIG, // the last published signal TIMEOUT_SIG, // for timeouts // ... MAX_SIG // the last signal }; $declare${AOs::Worker} $declare${AOs::AO_Launcher} #endif // WORKER_HPP #include "qpcpp.hpp" #include "Worker.hpp" #include "bsp.hpp" //Q_DEFINE_THIS_FILE $define${AOs::Worker} #include "qpcpp.hpp" #include "worker.hpp" #include "bsp.hpp" #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} $define${AOs::AO_Launcher} $define${AOs::Launcher}