Active object class (based on the QHsm implementation strategy)
More...
#include "qp.hpp"
|
void | init (void const *const e, std::uint_fast8_t const qsId) override |
|
void | init (std::uint_fast8_t const qsId) override |
|
void | dispatch (QEvt const *const e, std::uint_fast8_t const qsId) override |
|
bool | isIn (QStateHandler const state) noexcept override |
|
QStateHandler | childState (QStateHandler const parent) noexcept |
|
void | setAttr (std::uint32_t attr1, void const *attr2=nullptr) |
|
void | start (QPrioSpec const prioSpec, QEvt const **const qSto, std::uint_fast16_t const qLen, void *const stkSto, std::uint_fast16_t const stkSize, void const *const par) |
|
void | start (QPrioSpec const prioSpec, QEvt const **const qSto, std::uint_fast16_t const qLen, void *const stkSto, std::uint_fast16_t const stkSize) |
|
void | stop () |
|
void | register_ () noexcept |
|
void | unregister_ () noexcept |
|
bool | post_ (QEvt const *const e, std::uint_fast16_t const margin, void const *const sender) noexcept |
|
void | postLIFO (QEvt const *const e) noexcept |
|
QEvt const * | get_ () noexcept |
|
void | subscribe (enum_t const sig) const noexcept |
|
void | unsubscribe (enum_t const sig) const noexcept |
|
void | unsubscribeAll () const noexcept |
|
bool | defer (QEQueue *const eq, QEvt const *const e) const noexcept |
|
bool | recall (QEQueue *const eq) noexcept |
|
std::uint_fast16_t | flushDeferred (QEQueue *const eq, std::uint_fast16_t const num=0xFFFFU) const noexcept |
|
std::uint_fast8_t | getPrio () const noexcept |
|
void | setPrio (QPrioSpec const prio) noexcept |
|
std::uint_fast8_t | getPThre () const noexcept |
|
QACTIVE_EQUEUE_TYPE const & | getEQueue () const noexcept |
|
QACTIVE_OS_OBJ_TYPE const & | getOsObject () const noexcept |
|
QACTIVE_THREAD_TYPE const & | getThread () const noexcept |
|
void | setThread (QACTIVE_THREAD_TYPE const &thr) |
|
virtual bool | postFromISR (QEvt const *const e, std::uint_fast16_t const margin, void *par, void const *const sender) noexcept |
|
QStateHandler | state () const noexcept |
|
QMState const * | stateObj () const noexcept |
|
virtual QStateHandler | getStateHandler () noexcept |
|
|
enum | QStateRet : QState {
Q_RET_SUPER
, Q_RET_SUPER_SUB
, Q_RET_UNHANDLED
, Q_RET_HANDLED
,
Q_RET_IGNORED
, Q_RET_ENTRY
, Q_RET_EXIT
, Q_RET_NULL
,
Q_RET_TRAN
, Q_RET_TRAN_INIT
, Q_RET_TRAN_EP
, Q_RET_TRAN_HIST
,
Q_RET_TRAN_XP
} |
|
enum | ReservedSig : QSignal { Q_EMPTY_SIG
, Q_ENTRY_SIG
, Q_EXIT_SIG
, Q_INIT_SIG
} |
| Reserved signals by the QP-framework. More...
|
|
Active object class (based on the QHsm implementation strategy)
- Description
- 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.
- Note
- QP::QActive is not intended to be instantiated directly, but rather serves as the abstract base class for derivation of active objects in the applications.
- See also
- QP::QMActive
- Traceability
-
- Usage
- The following example illustrates how to derive an active object from QP::QActive.
private:
std::uint8_t m_id;
public:
static Philo inst[N_PHILO];
public:
Philo();
protected:
};
Active object class (based on the QHsm implementation strategy)
#define Q_STATE_DECL(state_)
Definition at line 724 of file qp.hpp.
◆ QActive()
|
inlineexplicitprotectednoexcept |
QActive constructor (abstract base class)
- Parameters
-
[in] | initial | pointer to the top-most initial state-handler function in the derived active object |
Definition at line 766 of file qp.hpp.
◆ init() [1/2]
void QP::QActive::init |
( |
void const *const | e, |
|
|
std::uint_fast8_t const | qsId ) |
|
inlineoverridevirtual |
Virtual function to take the top-most initial transition in the state machine.
- Description
- Synchronously executes the top-most initial transition in a state machine (must be overridden in the subclasses).
- Parameters
-
[in] | e | pointer to an initialization parameter (might be nullptr) |
[in] | qsId | QS-id of this state machine (for QS local filter) |
- Precondition
qep_asm:200
- the virtual pointer must be initialized,
- the top-most initial transition must be initialized,
- the initial transition must not be taken yet.
Implements QP::QAsm.
Reimplemented in QP::QMActive, QP::QTicker, QP::QActiveDummy, and QP::QXThread.
Definition at line 781 of file qp.hpp.
◆ init() [2/2]
void QP::QActive::init |
( |
std::uint_fast8_t const | qsId | ) |
|
|
inlineoverridevirtual |
Virtual function to take the top-most initial transition in the state machine (overloaded).
- Description
- Synchronously executes the top-most initial transition in a state machine. This overloaded version takes no initialization parameter.
- Parameters
-
[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 787 of file qp.hpp.
◆ dispatch()
void QP::QActive::dispatch |
( |
QEvt const *const | e, |
|
|
std::uint_fast8_t const | qsId ) |
|
inlineoverridevirtual |
Virtual function to dispatch an event to the state machine.
- Description
- 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.
- Parameters
-
[in] | e | pointer to the event to be dispatched to the MSM |
[in] | qsId | QS-id of this state machine (for QS local filter) |
- Precondition
qep_asm:302
- current state must be initialized
- check the internal integrity (Software Self-Monitoring (SSM))
Implements QP::QAsm.
Reimplemented in QP::QMActive, QP::QTicker, QP::QActiveDummy, and QP::QXThread.
Definition at line 790 of file qp.hpp.
◆ isIn()
|
inlineoverridevirtualnoexcept |
Virtual function to check whether the state machine is in a given state.
- Description
- 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 of the state.
- Parameters
-
[in] | state | pointer to the state-handler function to be checked |
- Returns
- 'true' if the state machine "is in" the
state
and 'false' otherwise
- Attention
- This function must be called only on a state machine that is in the "stable state configuration". Among others, this means that the state machine cannot call it in the middle of its own transition.
- Traceability
-
Reimplemented from QP::QAsm.
Reimplemented in QP::QMActive.
Definition at line 796 of file qp.hpp.
◆ childState()
◆ setAttr()
QP::QActive::setAttr |
( |
std::uint32_t | attr1, |
|
|
void const * | attr2 = nullptr ) |
Generic setting of additional attributes (defined in some QP ports)
◆ start() [1/2]
QP::QActive::start |
( |
QPrioSpec const | prioSpec, |
|
|
QEvt const **const | qSto, |
|
|
std::uint_fast16_t const | qLen, |
|
|
void *const | stkSto, |
|
|
std::uint_fast16_t const | stkSize, |
|
|
void const *const | par ) |
Starts execution of an active object and registers the object with the framework
- Description
- Starts execution of the AO and registers the AO with the framework.
- Parameters
-
[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 | pointer to an extra parameter (might be NULL) |
- Traceability
-
- Usage
- The following example shows starting an AO when a per-task stack is needed:
int main() {
BSP::init();
. . .
static QP::QEvt const *blinkyQueueSto[10];
APP::AO_Blinky->start(
1U,
blinkyQueueSto,
nullptr, 0U,
nullptr);
. . .
}
QP/C++ interface including the backwards-compatibility layer.
Definition at line 448 of file qk.cpp.
◆ start() [2/2]
QP::QActive::start |
( |
QPrioSpec const | prioSpec, |
|
|
QEvt const **const | qSto, |
|
|
std::uint_fast16_t const | qLen, |
|
|
void *const | stkSto, |
|
|
std::uint_fast16_t const | stkSize ) |
|
inline |
Starts execution of an active object and registers the object with the framework
- Description
- Starts execution of the AO and registers the AO with the framework.
- Parameters
-
[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] |
- Traceability
-
- Usage
- The following example shows starting an AO when a per-task stack is needed:
int main() {
BSP::init();
. . .
static QP::QEvt const *blinkyQueueSto[10];
APP::AO_Blinky->start(
1U,
blinkyQueueSto,
nullptr, 0U);
. . .
}
Definition at line 812 of file qp.hpp.
◆ stop()
Stops execution of an active object and removes it from the framework's supervision
- Attention
- QActive::stop() must be called only from the AO that is about to stop its execution. By that time, any pointers or references to the AO are considered invalid (dangling) and it becomes illegal for the rest of the application to post events to the AO.
Definition at line 264 of file qutest.cpp.
◆ register_()
QP::QActive::register_ |
( |
| ) |
|
|
noexcept |
Register this active object to be managed by the framework
- Description
- 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().
- Precondition
qf_qact:100
- the "QF-priority" of the AO must be in range (must be set before calling QActive_register_())
- the "QF-priority" must not be already in use (unique priority)
- the "QF-priority" must not exceed the "preemption-threshold"
- Postcondition
qf_qact:190
- the preceding pre-thre must not exceed the preemption-threshold
- the preemption-threshold must not exceed the next preemption-threshold
Definition at line 76 of file qf_qact.cpp.
◆ unregister_()
QP::QActive::unregister_ |
( |
| ) |
|
|
noexcept |
Un-register the active object from the framework
- Description
- 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.
- Precondition
qf_qact:200
- the priority of the active object must not be zero and cannot exceed the maximum QF_MAX_ACTIVE
- the priority of the AO must be already registered.
- Note
- The active object that is removed from the framework can no longer participate in any event exchange.
Definition at line 132 of file qf_qact.cpp.
◆ post_()
QP::QActive::post_ |
( |
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.
- Description
- Direct event posting is the simplest asynchronous communication method available in QF.
- Parameters
-
[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) |
- Returns
- 'true' (success) if the posting succeeded (with the provided margin) and 'false' (failure) when the posting fails.
- Precondition
qf_actq:102
- the event pointer must be valid
- check internal event integrity (QP FuSa Subsystem)
- Postcondition
qf_actq:190
-
- Attention
- This operation is typically used via macros POST() and POST_X(). This is because the last parameter
sender
might be defined/provided only in the Spy build configuration (see Q_SPY). The macros ignore the sender
parameter outside the Spy configuration, so the same code builds correctly in all configurations.
- Note
- This function might be implemented differently in various QP/C ports. The provided implementation assumes that the ::QEQueue class is used for the QActive event queue.
- Traceability
-
- Usage
. . .
Q_STATE_DEF(Philo, hungry) {
switch (e->sig) {
TableEvt
const *pe =
Q_NEW(TableEvt, HUNGRY_SIG, m_id);
AO_Table->POST(pe, this);
break;
}
. . .
}
return status_;
}
@ Q_RET_HANDLED
event handled (internal transition)
@ Q_ENTRY_SIG
signal for entry actions
#define Q_NEW(evtT_, sig_,...)
Definition at line 71 of file qf_actq.cpp.
◆ postLIFO()
QP::QActive::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.
- Description
- The LIFO policy should be used only for self-posting and with caution because it alters order of events in the queue.
- Parameters
-
[in] | e | pointer to the event to be posted |
- Precondition
qf_actq:200
- for the QXK kernel, postLIFO() cannot be called from an extended thread
- Precondition
qf_actq:201
- the queue must be able to accept the event (cannot overflow)
- Traceability
-
- Note
- This function might be implemented differently in various QP/C++ ports. The provided implementation assumes that the QP::QEQueue class is used for the QActive event queue.
- See also
- QActive_post()
Definition at line 221 of file qf_actq.cpp.
◆ get_()
Get an event from the event queue of an active object
- Description
- 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.
- Returns
- A pointer to the received event. The returned pointer is guaranteed to be valid (can't be NULL).
- Note
- This function might be implemented differently in various QP/C++ ports. The provided implementation assumes that the QP::QEQueue class is used for the QActive event queue.
Definition at line 308 of file qf_actq.cpp.
◆ getQueueMin()
static std::uint_fast16_t QP::QActive::getQueueMin |
( |
std::uint_fast8_t const | prio | ) |
|
|
staticnoexcept |
◆ psInit()
Publish event to all subscribers of a given signal e->sig
- Description
- 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.
- Note
- To avoid any unexpected re-ordering of events posted into AO queues, the event multicasting is performed with scheduler locked. However, the scheduler is locked only up to the priority level of the highest-priority subscriber, so any AOs of even higher priority, which did not subscribe to this event are not affected.
Definition at line 84 of file qf_ps.cpp.
◆ publish_()
QP::QActive::publish_ |
( |
QEvt const *const | e, |
|
|
void const *const | sender, |
|
|
std::uint_fast8_t const | qsId ) |
|
staticnoexcept |
Publish event to all subscribers of a given signal e->sig
- Description
- 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.
- Precondition
qf_ps:200
- the published signal must be within the configured range
- Precondition
qf_ps:202
- check the integrity of the subscriber set (QP FuSa Subsystem)
- Note
- To avoid any unexpected re-ordering of events posted into AO queues, the event multicasting is performed with scheduler locked. However, the scheduler is locked only up to the priority level of the highest-priority subscriber, so any AOs of even higher priority, which did not subscribe to this event are not affected.
- Attention
- This operation is typically used via macro PUBLISH(). This is because the last parameter
qsId
might be defined/provided only in the Spy build configuration (see Q_SPY). The macro ignores the qsId
parameter outside the Spy configuration, so the same code builds correctly in all configurations.
- Usage
switch (e->sig) {
. . .
m_timeEvt.disarm();
TableEvt
const *pe =
Q_NEW(TableEvt, DONE_SIG, m_id);
QP::QActive::PUBLISH(pe, this);
break;
}
. . .
}
return status_;
}
@ Q_EXIT_SIG
signal for exit actions
#define Q_STATE_DEF(subclass_, state_)
Definition at line 107 of file qf_ps.cpp.
◆ subscribe()
QP::QActive::subscribe |
( |
enum_t const | sig | ) |
const |
|
noexcept |
Subscribes for delivery of signal sig
to the active object
- Description
- 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.
- Parameters
-
[in] | sig | event signal to subscribe |
- Precondition
qf_ps:300
- signal must be in range of subscribe scignals
- subscriber AO priority must be in range
- the AO must be registered (started)
- Precondition
qf_ps:302
- check the integrity of the subscriber set (QP FuSa Subsystem)
- Usage
- The following example shows how the Table active object subscribes to three signals in the initial transition:
. . .
. . .
}
void subscribe(enum_t const sig) const noexcept
QState tran(QStateHandler const target) noexcept
#define Q_UNUSED_PAR(par_)
Definition at line 215 of file qf_ps.cpp.
◆ unsubscribe()
QP::QActive::unsubscribe |
( |
enum_t const | sig | ) |
const |
|
noexcept |
Unsubscribes from the delivery of signal sig
to the active object
- Description
- 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.
- Parameters
-
[in] | sig | event signal to unsubscribe |
- Precondition
qf_ps:400
- signal must be in range of subscribe scignals
- subscriber AO priority must be in range
- the AO must be registered (started)
- Precondition
qf_ps:402
- check the integrity of the subscriber set (QP FuSa Subsystem)
- Note
- Due to the latency of event queues, an active object should NOT assume that a given signal
sig
will never be dispatched to the state machine of the active object after un-subscribing from that signal. The event might be already in the queue, or just about to be posted and the un-subscribe operation will not flush such events.
-
Un-subscribing from a signal that has never been subscribed in the first place is considered an error and QF will raise an assertion.
Definition at line 252 of file qf_ps.cpp.
◆ unsubscribeAll()
QP::QActive::unsubscribeAll |
( |
| ) |
const |
|
noexcept |
Unsubscribes from the delivery of all signals to the active object
- Description
- 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.
- Precondition
qf_ps:500
- subscriber AO priority must be in range
- the AO must be registered (started)
- Note
- Due to the latency of event queues, an active object should NOT assume that no events will ever be dispatched to the state machine of the active object after un-subscribing from all events. The events might be already in the queue, or just about to be posted and the un-subscribe operation will not flush such events. Also, the alternative event-delivery mechanisms, such as direct event posting or time events, can be still delivered to the event queue of the active object.
Definition at line 289 of file qf_ps.cpp.
◆ defer()
QP::QActive::defer |
( |
QEQueue *const | eq, |
|
|
QEvt const *const | e ) const |
|
noexcept |
Defer an event to a given separate event queue
- Description
- 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.
- Parameters
-
[in] | eq | pointer to a "raw" thread-safe queue to recall an event from. |
[in] | e | pointer to the event to be deferred |
- Returns
- 'true' (success) when the event could be deferred and 'false' (failure) if event deferral failed due to overflowing the queue.
Definition at line 70 of file qf_defer.cpp.
◆ recall()
QP::QActive::recall |
( |
QEQueue *const | eq | ) |
|
|
noexcept |
Recall a deferred event from a given event queue
- Description
- 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.
- Parameters
-
[in] | eq | pointer to a "raw" thread-safe queue to recall an event from. |
- Returns
- 'true' if an event has been recalled and 'false' if not.
- Note
- An active object can use multiple event queues to defer events of different kinds.
Definition at line 99 of file qf_defer.cpp.
◆ flushDeferred()
QP::QActive::flushDeferred |
( |
QEQueue *const | eq, |
|
|
std::uint_fast16_t const | num = 0xFFFFU ) const |
|
noexcept |
Flush the specified deferred queue eq
- Description
- 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.
- Parameters
-
[in] | eq | pointer to a "raw" thread-safe queue to flush. |
- Returns
- the number of events actually flushed from the queue.
Definition at line 161 of file qf_defer.cpp.
◆ getPrio()
std::uint_fast8_t QP::QActive::getPrio |
( |
| ) |
const |
|
inlinenoexcept |
◆ setPrio()
void QP::QActive::setPrio |
( |
QPrioSpec const | prio | ) |
|
|
inlinenoexcept |
◆ getPThre()
std::uint_fast8_t QP::QActive::getPThre |
( |
| ) |
const |
|
inlinenoexcept |
◆ getEQueue()
◆ getOsObject()
◆ getThread()
◆ setThread()
◆ evtLoop_()
QP::QActive::evtLoop_ |
( |
QActive * | act | ) |
|
|
static |
Event loop thread routine for executing an active object act
(defined some in QP ports)
◆ postFromISR()
QP::QActive::postFromISR |
( |
QEvt const *const | e, |
|
|
std::uint_fast16_t const | margin, |
|
|
void * | par, |
|
|
void const *const | sender ) |
|
virtualnoexcept |
The "FromISR" variant used in the QP port to "FreeRTOS"
◆ publishFromISR()
QP::QActive::publishFromISR |
( |
QEvt const * | e, |
|
|
void * | par, |
|
|
void const * | sender ) |
|
staticnoexcept |
The "FromISR" variant used in the QP port to "FreeRTOS"
◆ QTimeEvt
◆ QTicker
◆ QXThread
◆ QXMutex
◆ QXSemaphore
◆ QActiveDummy
◆ GuiQActive
◆ GuiQMActive
◆ schedLock
◆ m_prio
◆ m_pthre
◆ m_thread
Port-dependent representation of the thread of the active object
- Description
- This data might be used in various ways, depending on the QF port. In some ports me->thread is used store the thread handle. In other ports me->thread can be a pointer to the Thread-Local-Storage (TLS).
Definition at line 730 of file qp.hpp.
◆ m_osObject
Port-dependent per-thread object.
- Description
- This data might be used in various ways, depending on the QF port. In some ports me->osObject is used to block the calling thread when the native QF queue is empty. In other QF ports the OS-dependent object might be used differently.
Definition at line 734 of file qp.hpp.
◆ m_eQueue
Port-dependent event-queue type (often QP::QEQueue)
- Description
- 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.
- Note
- The native QF event queue is configured by defining the macro QP::QACTIVE_EQUEUE_TYPE as QP::QEQueue.
Definition at line 738 of file qp.hpp.
◆ m_prio_dis
std::uint8_t QP::QActive::m_prio_dis |
◆ m_pthre_dis
std::uint8_t QP::QActive::m_pthre_dis |
◆ registry_
Static (one per-class) array of registered active objects
Definition at line 750 of file qp.hpp.
◆ subscrList_
Static (one per-class) pointer to all subscriber AOs for a given event signal.
Definition at line 751 of file qp.hpp.
◆ maxPubSignal_
Static (one per-class) maximum published signal (the size of the subscrList_ array)
Definition at line 752 of file qp.hpp.
The documentation for this class was generated from the following files: