Active object class (based on the QP::QHsm implementation strategy). More...
#include <qp.hpp>
Public Member Functions | |
| void | init (void const *const e, std::uint_fast8_t const qsId) override |
| Virtual function to take the top-most initial transition in the state machine. | |
| void | dispatch (QEvt const *const e, std::uint_fast8_t const qsId) override |
| Virtual function to dispatch an event to the state machine. | |
| bool | isIn (QStateHandler const stateHndl) noexcept override |
| Virtual function to check whether the state machine is in a given state. | |
| QStateHandler | getStateHandler () const noexcept override |
| Virtual method for getting the current state handler. | |
| QStateHandler | childState (QStateHandler const parentHandler) noexcept |
| void | setAttr (std::uint32_t attr1, void const *attr2=nullptr) |
| Generic setting of additional attributes (defined in some QP ports). | |
| void | start (QPrioSpec const prioSpec, QEvtPtr *const qSto, std::uint_fast16_t const qLen, void *const stkSto, std::uint_fast16_t const stkSize, void const *const par=nullptr) |
| Starts execution of an active object and registers the object with the framework. | |
| void | stop () |
| Stops execution of an active object and removes it from the framework's supervision. | |
| void | register_ () noexcept |
| Register this active object to be managed by the framework. | |
| void | unregister_ () noexcept |
| Un-register the active object from the framework. | |
| void | post_ (QEvt const *const e, void const *const sender) noexcept |
| Posts an event e directly to the event queue of the active object using the First-In-First-Out (FIFO) policy. | |
| bool | postx_ (QEvt const *const e, std::uint_fast16_t const margin, void const *const sender) noexcept |
| Posts an event e directly to the event queue of the active object using the First-In-First-Out (FIFO) policy. | |
| void | postLIFO (QEvt const *const e) noexcept |
| Posts an event e directly to the event queue of the active object using the Last-In-First-Out (LIFO) policy. | |
| QEvt const * | get_ () noexcept |
| Get an event from the event queue of an active object. | |
| void | subscribe (QSignal const sig) const noexcept |
| Subscribes for delivery of signal sig to the active object. | |
| void | unsubscribe (QSignal const sig) const noexcept |
| Unsubscribes from the delivery of signal sig to the active object. | |
| void | unsubscribeAll () const noexcept |
| Unsubscribes from the delivery of all signals to the active object. | |
| bool | defer (QEQueue *const eq, QEvt const *const e) const noexcept |
| Defer an event to a given separate event queue. | |
| bool | recall (QEQueue *const eq) noexcept |
| Recall a deferred event from a given event queue. | |
| std::uint16_t | flushDeferred (QEQueue *const eq, std::uint_fast16_t const num=0xFFFFU) const noexcept |
| Flush the specified deferred queue eq. | |
| std::uint8_t | getPrio () const noexcept |
| QACTIVE_THREAD_TYPE const & | getThread () const & |
| QACTIVE_THREAD_TYPE const & | getThread () const &&=delete |
| void | setThread (QACTIVE_THREAD_TYPE const &thr) noexcept |
| QACTIVE_OS_OBJ_TYPE const & | getOsObject () const & |
| QACTIVE_OS_OBJ_TYPE const & | getOsObject () const &&=delete |
| virtual bool | postFromISR (QEvt const *const e, std::uint_fast16_t const margin, void *par, void const *const sender) noexcept |
| The "FromISR" variant used in the QP port to "FreeRTOS". | |
| virtual void | init (std::uint_fast8_t const qsId) |
| Virtual function to take the top-most initial transition in the state machine (overloaded). | |
| Public Member Functions inherited from QP::QAsm | |
| virtual | ~QAsm () noexcept |
| Virtual destructor of the QP::QAsm abstract base class. | |
| QStateHandler | state () const noexcept |
| QMState const * | stateObj () const noexcept |
Static Public Member Functions | |
| static std::uint16_t | getQueueUse (std::uint_fast8_t const prio) noexcept |
| static std::uint16_t | getQueueFree (std::uint_fast8_t const prio) noexcept |
| static std::uint16_t | getQueueMin (std::uint_fast8_t const prio) noexcept |
| static void | psInit (QSubscrList *const subscrSto, QSignal const maxSignal) noexcept |
| Publish event to all subscribers of a given signal e->sig. | |
| static void | publish_ (QEvt const *const e, void const *const sender, std::uint_fast8_t const qsId) noexcept |
| Publish event to all subscribers of a given signal e->sig. | |
| static void | evtLoop_ (QActive *act) |
| Event loop thread routine for executing an active object act (defined some in QP ports). | |
| static QActive * | fromRegistry (std::uint_fast8_t const prio) |
| static void | publishFromISR (QEvt const *e, void *par, void const *sender) noexcept |
| The "FromISR" variant used in the QP port to "FreeRTOS". | |
| Static Public Member Functions inherited from QP::QAsm | |
| static constexpr QState | Q_HANDLED () |
| static constexpr QState | Q_UNHANDLED () |
| static constexpr QState | QM_HANDLED () |
| static constexpr QState | QM_UNHANDLED () |
| static constexpr QState | QM_SUPER () |
| static QState | top (void *const me, QEvt const *const e) noexcept |
| Top state handler that ignores all events. | |
Protected Member Functions | |
| QActive (QStateHandler const initial) noexcept | |
| QActive constructor (abstract base class). | |
| Protected Member Functions inherited from QP::QAsm | |
| QAsm () noexcept | |
| Constructor of the QP::QAsm base class. | |
| QState | tran (QStateHandler const target) noexcept |
| Internal helper function to take a state transition in sublclasses of QP::QAsm. | |
| QState | tran_hist (QStateHandler const hist) noexcept |
| Internal helper function to take a state transition to history in sublclasses of QP::QAsm. | |
| QState | super (QStateHandler const superstate) noexcept |
| Internal helper function to indicate superstate of a given state in sublclasses of QP::QAsm. | |
| QState | qm_tran (void const *const tatbl) noexcept |
| Internal helper function to take a state transition in QP::QMsm. | |
| QState | qm_tran_init (void const *const tatbl) noexcept |
| QState | qm_tran_hist (QMState const *const hist, void const *const tatbl) noexcept |
| Internal helper function to take a state transition to history in QP::QMsm. | |
| QState | qm_entry (QMState const *const s) noexcept |
| Internal helper function to execute state entry actions in QP::QMsm. | |
| QState | qm_exit (QMState const *const s) noexcept |
| Internal helper function to execute state exit actions in QP::QMsm. | |
Private Member Functions | |
| void | postFIFO_ (QEvt const *const e, void const *const sender) |
Static Private Member Functions | |
| static void | multicast_ (QPSet *const subscrSet, QEvt const *const e, void const *const sender) |
Private Attributes | |
| std::uint8_t | m_prio |
| QF-priority [1..QF_MAX_ACTIVE] of this AO. | |
| std::uint8_t | m_pthre |
| Preemption-threshold [1..QF_MAX_ACTIVE] of this AO. | |
| QACTIVE_THREAD_TYPE | m_thread |
| Port-dependent representation of the thread of the active object. | |
| QACTIVE_OS_OBJ_TYPE | m_osObject |
| Port-dependent per-thread object. | |
| QACTIVE_EQUEUE_TYPE | m_eQueue |
| Port-dependent event-queue type (often QP::QEQueue). | |
Friends | |
| class | QTimeEvt |
| class | QTicker |
| class | QXThread |
| class | QXMutex |
| class | QXSemaphore |
| class | QMActive |
| class | QActiveDummy |
| class | QK |
| class | QXK |
| class | QS |
| void | QF::init () |
| void | QF::stop () |
| int_t | QF::run () |
| void | QF::onStartup () |
| void | QF::onCleanup () |
Additional Inherited Members | |
| Public Attributes inherited from QP::QAsm | |
| QAsmAttr | m_state |
| Current state (pointer to the current state-handler function). | |
| QAsmAttr | m_temp |
| Temporary storage for target/act-table etc. | |
| Static Public Attributes inherited from QP::QAsm | |
| static constexpr QState | Q_RET_SUPER {0U} |
| static constexpr QState | Q_RET_UNHANDLED {1U} |
| static constexpr QState | Q_RET_HANDLED {2U} |
| static constexpr QState | Q_RET_TRAN {3U} |
| static constexpr QState | Q_RET_TRAN_HIST {4U} |
| static constexpr QState | Q_RET_IGNORED {5U} |
| static constexpr QState | Q_RET_ENTRY {6U} |
| static constexpr QState | Q_RET_EXIT {7U} |
| static constexpr QState | Q_RET_TRAN_INIT {8U} |
| static constexpr QSignal | Q_EMPTY_SIG {0U} |
| static constexpr QSignal | Q_ENTRY_SIG {1U} |
| static constexpr QSignal | Q_EXIT_SIG {2U} |
| static constexpr QSignal | Q_INIT_SIG {3U} |
| static constexpr QMState const * | QM_STATE_NULL { nullptr } |
| static constexpr QActionHandler const | Q_ACTION_NULL { nullptr } |
Active object class (based on the QP::QHsm implementation strategy).
Details
Active objects are encapsulated tasks (each containing an event queue and a state machine) that communicate with one another asynchronously by sending and receiving events. Within an active object, events are processed in a run-to-completion (RTC) fashion, while QF encapsulates all the details of thread-safe event exchange and queuing.
QP::QActive represents an active object that uses the QHsm-style implementation strategy for state machines. This strategy is tailored to manual coding, but it is also supported by the QM modeling tool. The resulting code is slower than in the QMsm-style implementation strategy.
Backward Traceability
Usage
The following example illustrates how to derive an active object from QP::QActive.
Forward Traceability
|
explicitprotectednoexcept |
QActive constructor (abstract base class).
| [in] | initial | pointer to the top-most initial state-handler function in the derived active object |
Definition at line 55 of file qf_qact.cpp.
|
overridevirtual |
Virtual function to take the top-most initial transition in the state machine.
Details
Synchronously executes the top-most initial transition in a state machine (must be overridden in the subclasses).
| [in] | e | pointer to an initialization parameter (might be nullptr) |
| [in] | qsId | QS-id of this state machine (for QS local filter) |
Implements QP::QAsm.
Reimplemented in QP::QActiveDummy, QP::QMActive, QP::QTicker, and QP::QXThread.
Definition at line 134 of file qf_qact.cpp.
|
overridevirtual |
Virtual function to dispatch an event to the state machine.
Details
Synchronously dispatches an event for processing to a state machine (must be overridden in the subclasses). The processing of an event represents one run-to-completion (RTC) step.
| [in] | e | pointer to the event to be dispatched to the MSM |
| [in] | qsId | QS-id of this state machine (for QS local filter) |
Implements QP::QAsm.
Reimplemented in QP::QActiveDummy, QP::QMActive, QP::QTicker, and QP::QXThread.
Definition at line 142 of file qf_qact.cpp.
|
overridevirtualnoexcept |
Virtual function to check whether the state machine is in a given state.
Details
Tests if a given state is part of the current active state configuration. Please note that in a hierarchical state machine, to "be in a state" means also to be in a superstate of the state.
| [in] | state | pointer to the state-handler function to be checked |
Backward Traceability
Implements QP::QAsm.
Reimplemented in QP::QMActive.
Definition at line 150 of file qf_qact.cpp.
|
overridevirtualnoexcept |
Virtual method for getting the current state handler.
Details
This virtual call applies to all subclasses of QP::QAsm, such as: QP::QHsm, QP::QMsm, QP::QActive, and QP::QMActive.
Backward Traceability
Usage
The following example illustrates how to obtain the current state handler of an Active Object:
Implements QP::QAsm.
Reimplemented in QP::QActiveDummy, and QP::QMActive.
Definition at line 165 of file qf_qact.cpp.
|
noexcept |
Definition at line 155 of file qf_qact.cpp.
| void QP::QActive::setAttr | ( | std::uint32_t | attr1, |
| void const * | attr2 = nullptr ) |
Generic setting of additional attributes (defined in some QP ports).
Forward Traceability
| void QP::QActive::start | ( | QPrioSpec const | prioSpec, |
| QEvtPtr *const | qSto, | ||
| std::uint_fast16_t const | qLen, | ||
| void *const | stkSto, | ||
| std::uint_fast16_t const | stkSize, | ||
| void const *const | par = nullptr ) |
Starts execution of an active object and registers the object with the framework.
Details
Starts execution of the AO and registers the AO with the framework.
| [in] | prioSpec | priority specification for the AO (See QP::QPrioSpec) |
| [in] | qSto | pointer to the storage for the ring buffer of the event queue |
| [in] | qLen | length of the event queue [# QP::QEvt* pointers] |
| [in] | stkSto | pointer to the stack storage (might be NULL) |
| [in] | stkSize | stack size [bytes] |
| [in] | par | initialization parameter (optional) |
Usage
The following example shows starting an AO when a per-task stack is NOT needed:
Forward Traceability
| void QP::QActive::stop | ( | ) |
Stops execution of an active object and removes it from the framework's supervision.
Forward Traceability
Definition at line 278 of file qutest.cpp.
|
noexcept |
Register this active object to be managed by the framework.
Details
This function adds a given active object to the active objects managed by the QF framework. It should not be called by the application directly, only through the function QActive::start().
Forward Traceability
Definition at line 68 of file qf_qact.cpp.
|
noexcept |
Un-register the active object from the framework.
Details
This function un-registers a given active object from the active objects managed by the QF framework. It should not be called by the QP ports.
Forward Traceability
Definition at line 116 of file qf_qact.cpp.
|
inlinenoexcept |
Posts an event e directly to the event queue of the active object using the First-In-First-Out (FIFO) policy.
Details
Direct event posting is the simplest asynchronous communication method available in QF.
| [in] | e | pointer to the event to be posted |
| [in] | sender | pointer to a sender object (used in QS only) |
Usage
Forward Traceability
|
noexcept |
Posts an event e directly to the event queue of the active object using the First-In-First-Out (FIFO) policy.
Details
Direct event posting is the simplest asynchronous communication method available in QF.
| [in] | e | pointer to the event to be posted |
| [in] | margin | number of required free slots in the queue after posting the event or QF::NO_MARGIN. |
| [in] | sender | pointer to a sender object (used in QS only) |
Usage
Forward Traceability
Definition at line 49 of file qf_actq.cpp.
|
noexcept |
Posts an event e directly to the event queue of the active object using the Last-In-First-Out (LIFO) policy.
Details
The LIFO policy should be used only for self-posting and with caution because it alters order of events in the queue.
| [in] | e | pointer to the event to be posted |
Forward Traceability
Definition at line 126 of file qf_actq.cpp.
|
noexcept |
Get an event from the event queue of an active object.
Details
The behavior of this function depends on the kernel used in the QF port. For built-in kernels (QV or QK) the function can be called only when the queue is not empty, so it doesn't block. For a blocking kernel/OS the function can block and wait for delivery of an event.
Forward Traceability
Definition at line 197 of file qf_actq.cpp.
|
staticnoexcept |
Definition at line 316 of file qf_actq.cpp.
|
staticnoexcept |
Definition at line 349 of file qf_actq.cpp.
|
staticnoexcept |
Definition at line 368 of file qf_actq.cpp.
|
staticnoexcept |
Publish event to all subscribers of a given signal e->sig.
Details
This function posts (using the FIFO policy) the event e to all active objects that have subscribed to the signal e->sig, which is called multicasting. The multicasting performed in this function is very efficient based on reference-counting inside the published event ("zero-copy" event multicasting). This function is designed to be callable from any part of the system, including ISRs, device drivers, and active objects.
Forward Traceability
|
staticnoexcept |
Publish event to all subscribers of a given signal e->sig.
Details
This function posts (using the FIFO policy) the event e to all active objects that have subscribed to the signal e->sig, which is called multicasting. The multicasting performed in this function is very efficient based on reference-counting inside the published event ("zero-copy" event multicasting). This function is designed to be callable from any part of the system, including ISRs, device drivers, and active objects.
Usage
Forward Traceability
|
noexcept |
Subscribes for delivery of signal sig to the active object.
Details
This function is part of the Publish-Subscribe event delivery mechanism available in QF. Subscribing to an event means that the framework will start posting all published events with a given signal sig to the event queue of the active object.
| [in] | sig | event signal to subscribe |
Usage
The following example shows how the Table active object subscribes to three signals in the initial transition:
Forward Traceability
|
noexcept |
Unsubscribes from the delivery of signal sig to the active object.
Details
This function is part of the Publish-Subscribe event delivery mechanism available in QF. Un-subscribing from an event means that the framework will stop posting published events with a given signal sig to the event queue of the active object.
| [in] | sig | event signal to unsubscribe |
Forward Traceability
|
noexcept |
Unsubscribes from the delivery of all signals to the active object.
Details
This function is part of the Publish-Subscribe event delivery mechanism available in QF. Un-subscribing from all events means that the framework will stop posting any published events to the event queue of the active object.
Forward Traceability
Defer an event to a given separate event queue.
Details
This function is part of the event deferral support. An active object uses this function to defer an event e to the QF-supported native event queue eq. QF correctly accounts for another outstanding reference to the event and will not recycle the event at the end of the RTC step. Later, the active object might recall one event at a time from the event queue.
| [in] | eq | pointer to a "raw" thread-safe queue to recall an event from. |
| [in] | e | pointer to the event to be deferred |
Forward Traceability
Definition at line 48 of file qf_defer.cpp.
|
noexcept |
Recall a deferred event from a given event queue.
Details
This function is part of the event deferral support. An active object uses this function to recall a deferred event from a given QF event queue. Recalling an event means that it is removed from the deferred event queue eq and posted (LIFO) to the event queue of the active object.
| [in] | eq | pointer to a "raw" thread-safe queue to recall an event from. |
Forward Traceability
Definition at line 81 of file qf_defer.cpp.
|
noexcept |
Flush the specified deferred queue eq.
Details
This function is part of the event deferral support. An active object can use this function to flush a given QF event queue. The function makes sure that the events are not leaked.
| [in] | eq | pointer to a "raw" thread-safe queue to flush. |
| [in] | num | number of events to flush (might exceed the capacity of the queue). |
Forward Traceability
Definition at line 135 of file qf_defer.cpp.
|
static |
Event loop thread routine for executing an active object act (defined some in QP ports).
Forward Traceability
|
static |
Definition at line 160 of file qf_qact.cpp.
|
inline |
|
delete |
|
inlinenoexcept |
|
inline |
|
delete |
|
virtualnoexcept |
The "FromISR" variant used in the QP port to "FreeRTOS".
|
staticnoexcept |
The "FromISR" variant used in the QP port to "FreeRTOS".
|
private |
Definition at line 261 of file qf_actq.cpp.
|
virtual |
Virtual function to take the top-most initial transition in the state machine (overloaded).
Details
Synchronously executes the top-most initial transition in a state machine. This overloaded version takes no initialization parameter.
| [in] | qsId | QS-id of this state machine (for QS local filter) |
Reimplemented from QP::QAsm.
Reimplemented in QP::QMActive, QP::QTicker, and QP::QXThread.
Definition at line 216 of file qf_act.cpp.
|
friend |
|
friend |
|
friend |
|
friend |
|
private |
QF-priority [1..QF_MAX_ACTIVE] of this AO.
|
private |
Preemption-threshold [1..QF_MAX_ACTIVE] of this AO.
|
private |
|
private |
|
private |
Port-dependent event-queue type (often QP::QEQueue).
Details
The type of the queue depends on the underlying operating system or a kernel. Many kernels support "message queues" that can be adapted to deliver QF events to the active object. Alternatively, QF provides a native event queue implementation that can be used as well.