Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
QActive Class Reference
Base class for derivation of application-level active object classes. More...
#include <qf.h>
Public Member Functions | |
| void | start (uint8_t prio, QEvent const *qSto[], uint32_t qLen, void *stkSto, uint32_t stkSize, QEvent const *ie=(QEvent *) 0) |
| Starts execution of an active object and registers the object with the framework. | |
| void | postFIFO (QEvent const *e) |
| Posts an event e directly to the event queue of the acitve object me using the First-In-First-Out (FIFO) policy. | |
| void | postLIFO (QEvent const *e) |
| Posts an event directly to the event queue of the active object me using the Last-In-First-Out (LIFO) policy. | |
| void | run (void) |
| Traditional loop-structured thread routine for an active object. | |
| QEvent const * | get_ (void) |
| Get an event from the event queue of an active object. | |
| void | unsubscribeAll (void) const |
| Un-subscribes from the delivery of all signals to the active object. | |
Data Fields | |
| QF_OS_OBJECT_TYPE | m_osObject |
| OS-dependent per-thread object. | |
| QF_THREAD_TYPE | m_thread |
| OS-dependent representation of the thread of the active object. | |
| uint8_t | m_prio |
| QF priority associated with the active object. | |
| uint8_t | m_running |
| The Boolean loop variable determining if the thread routine of the active object is running. | |
Protected Member Functions | |
| QActive (QF_ACTIVE_STATE_ initial) | |
| protected constructor | |
| void | stop (void) |
| Stops execution of an active object and removes it from the framework's supervision. | |
| void | subscribe (QSignal sig) const |
| Subscribes for delivery of signal sig to the active object. | |
| void | unsubscribe (QSignal sig) const |
| Un-subscribes from the delivery of signal sig to the active object. | |
| void | defer (QEQueue *eq, QEvent const *e) |
| Defer an event to a given separate event queue. | |
| QEvent const * | recall (QEQueue *eq) |
| Recall a deferred event from a given event queue. | |
Friends | |
| class | QF |
| class | QTimeEvt |
| void | QK_schedule_ (QF_INT_KEY_TYPE intLockKey) |
| The QK scheduler. | |
| void | QK_scheduleExt_ (QF_INT_KEY_TYPE intLockKey) |
| The QK extended scheduler for interrupt context. | |
Detailed Description
Base class for derivation of application-level active object classes.
QActive is the base class for derivation of active objects. Active objects in QF are encapsulated tasks (each embedding a state machine and an event queue) that communicate with one another asynchronously by sending and receiving events. Within an active object, events are processed sequentially in a run-to-completion (RTC) fashion, while QF encapsulates all the details of thread-safe event exchange and queuing.
- Note:
- QActive is not intended to be instantiated directly, but rather serves as the base class for derivation of active objects in the application code.
The following example illustrates how to derive an active object from QActive.
- See also:
- QF_ACTIVE_SUPER_ defines the base class for QActive
Definition at line 113 of file qf.h.
Constructor & Destructor Documentation
| QActive | ( | QF_ACTIVE_STATE_ | initial ) | [protected] |
protected constructor
Performs the first step of active object initialization by assigning the initial pseudostate to the currently active state of the state machine.
- Note:
- The constructor is protected to prevent direct instantiation of QActive objects. This class is intended only for derivation (abstract class).
Member Function Documentation
Defer an event to a given separate event queue.
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.
An active object can use multiple event queues to defer events of different kinds.
- See also:
- QActive::recall(), QEQueue
| QEvent const* get_ | ( | void | ) |
Get an event from the event queue of an active object.
This function is used internally by a QF port to extract events from the event queue of an active object. This function depends on the event queue implementation and is sometimes implemented in the QF port (qf_port.cpp file). Depending on the underlying OS or kernel, the function might block the calling thread when no events are available.
- Note:
- QActive::get_() is public because it often needs to be called from thread-run routines with difficult to foresee signature (so declaring friendship with such function(s) is not possible.)
- See also:
- QActive::postFIFO(), QActive::postLIFO()
| void postFIFO | ( | QEvent const * | e ) |
Posts an event e directly to the event queue of the acitve object me using the First-In-First-Out (FIFO) policy.
Direct event posting is the simplest asynchronous communication method available in QF. The following example illustrates how the Philosopher active obejct posts directly the HUNGRY event to the Table active object.
- Note:
- The producer of the event (Philosopher in this case) must only "know" the recipient (Table) by a generic (QActive *QDPP_table) pointer, but the specific definition of the Table class is not required.
- Direct event posting should not be confused with direct event dispatching. In contrast to asynchronous event posting through event queues, direct event dispatching is synchronous. Direct event dispatching occurs when you call QHsm::dispatch(), or QFsm::dispatch() function.
| void postLIFO | ( | QEvent const * | e ) |
Posts an event directly to the event queue of the active object me using the Last-In-First-Out (LIFO) policy.
- Note:
- The LIFO policy should be used only with great caution because it alters order of events in the queue.
- See also:
- QActive::postFIFO()
Recall a deferred event from a given event queue.
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.
QActive::recall() returns the pointer to the recalled event to the caller. The function returns NULL if no event has been recalled.
An active object can use multiple event queues to defer events of different kinds.
- See also:
- QActive::defer(), QEQueue, QActive::postLIFO()
Definition at line 43 of file qa_defer.cpp.
| void run | ( | void | ) |
Traditional loop-structured thread routine for an active object.
This function is only used when QF is ported to a traditional RTOS/Kernel. QActive::run() is structured as a typical endless loop, which blocks on the event queue get() operation of an active object. When an event becomes available, it's dispatched to the active object's state machine and after this recycled with QF::gc(). The loop might optionally use the QActive::m_running flag to terminate and cause QActive::run() to return which is often the cleanest way to terminate the thread.
Definition at line 35 of file qa_run.cpp.
| void start | ( | uint8_t | prio, |
| QEvent const * | qSto[], | ||
| uint32_t | qLen, | ||
| void * | stkSto, | ||
| uint32_t | stkSize, | ||
| QEvent const * | ie = (QEvent *)0 |
||
| ) |
Starts execution of an active object and registers the object with the framework.
The function takes six arguments. prio is the priority of the active object. QF allows you to start up to 63 active objects, each one having a unique priority number between 1 and 63 inclusive, where higher numerical values correspond to higher priority (urgency) of the active object relative to the others. qSto[] and qLen arguments are the storage and size of the event queue used by this active object. stkSto and stkSize are the stack storage and size in bytes. Please note that a per-active object stack is used only when the underlying OS requies it. If the stack is not required, or the underlying OS allocates the stack internally, the stkSto should be NULL and/or stkSize should be 0. ie is an optional initialization event that can be used to pass additional startup data to the active object. (Pass NULL if your active object does not expect the initialization event).
- Note:
- This function is strongly OS-dependent and must be defined in the QF port to a particular platform.
The following example shows starting of the Philosopher object when a per-task stack is required:
Definition at line 85 of file qvanilla.cpp.
| void stop | ( | void | ) | [protected] |
Stops execution of an active object and removes it from the framework's supervision.
The preferred way of calling this function is from within the active object that needs to stop (that's why this function is protected). In other words, an active object should stop itself rather than being stopped by some other entity. This policy works best, because only the active object itself "knows" when it has reached the appropriate state for the shutdown.
- Note:
- This function is strongly OS-dependent and should be defined in the QF port to a particular platform. This function is optional in embedded systems where active objects never need to be stopped.
Definition at line 101 of file qvanilla.cpp.
| void subscribe | ( | QSignal | sig ) | const [protected] |
Subscribes for delivery of signal sig to the active object.
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.
The following example shows how the Table active object subscribes to three signals in the initial transition:
- See also:
- QF::publish(), QActive::unsubscribe(), and QActive::unsubscribeAll()
| void unsubscribe | ( | QSignal | sig ) | const [protected] |
Un-subscribes from the delivery of signal sig to the active object.
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.
- 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 rise an assertion.
- See also:
- QF::publish(), QActive::subscribe(), and QActive::unsubscribeAll()
| void unsubscribeAll | ( | void | ) | const |
Un-subscribes from the delivery of all signals to the active object.
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.
- 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.
- See also:
- QF::publish(), QActive::subscribe(), and QActive::unsubscribe()
Friends And Related Function Documentation
| void QK_schedule_ | ( | QF_INT_KEY_TYPE | intLockKey ) | [friend] |
The QK scheduler.
- Note:
- The QK scheduler must be always called with the interrupts locked and unlocks interrupts internally.
The signature of QK_schedule_() depends on the policy of locking and unlocking interrupts. When the interrupt lock key is not used (QF_INT_KEY_TYPE undefined), the signature is as follows:
void QK_schedule_(void);
However, when the interrupt key lock is used (QF_INT_KEY_TYPE defined), the signature is different:
void QK_schedule_(QF_INT_KEY_TYPE intLockKey);
For the internal use, these differences are hidden by the macro QK_SCHEDULE_.
| void QK_scheduleExt_ | ( | QF_INT_KEY_TYPE | intLockKey ) | [friend] |
The QK extended scheduler for interrupt context.
- Note:
- The QK extended exscheduler must be always called with the interrupts locked and unlocks interrupts internally.
The signature of QK_scheduleExt_() depends on the policy of locking and unlocking interrupts. When the interrupt lock key is not used (QF_INT_KEY_TYPE undefined), the signature is as follows:
void QK_scheduleExt_(void);
However, when the interrupt key lock is used (QF_INT_KEY_TYPE defined), the signature is different:
void QK_scheduleExt_(QF_INT_KEY_TYPE intLockKey);
Field Documentation
| QF_OS_OBJECT_TYPE m_osObject |
| uint8_t m_prio |
QF priority associated with the active object.
- See also:
- QActive::start()
| uint8_t m_running |
The Boolean loop variable determining if the thread routine of the active object is running.
This flag is only used with the traditional loop-structured thread routines. Clearing this flag breaks out of the thread loop, which is often the cleanest way to terminate the thread. The following example illustrates the thread routine for Win32:
Generated on Tue Jul 12 2022 20:22:36 by
1.7.2