Reference Manual For QP/C 8.1.6
Loading...
Searching...
No Matches
QActive Class Reference

Active Object class (based on the QHsm implementation strategy). More...

Inheritance diagram for QActive:
QAsm QActiveDummy QMActive QTicker QXThread

Public Member Functions

void QActive_setAttr (QActive *const me, uint32_t attr1, void const *attr2)
 Generic setting of additional attributes (defined in some QP ports).
void QActive_start (QActive *const me, QPrioSpec const prioSpec, QEvtPtr *const qSto, uint_fast16_t const qLen, void *const stkSto, uint_fast16_t const stkSize, void const *const par)
 Starts execution of an active object and registers the object with the framework.

Static Public Member Functions

void QActive_psInit (QSubscrList *const subscrSto, enum_t const maxSignal)
 Initializes the publish-subscribe facility for the application.
uint16_t QActive_getQueueUse (uint_fast8_t const prio)
 Obtain the number of entries in use in the queue.
uint16_t QActive_getQueueFree (uint_fast8_t const prio)
 Obtain the number of free entries still available in the queue.
uint16_t QActive_getQueueMin (uint_fast8_t const prio)
 Obtain the minimum of free entries of the given event queue since start.

Protected Member Functions

void QActive_ctor (QActive *const me, QStateHandler const initial)
 QActive constructor (abstract base class).
void QActive_stop (QActive *const me)
 Stops execution of an active object and removes it from the framework's supervision.
void QActive_subscribe (QActive const *const me, enum_t const sig)
 Subscribes for delivery of signal sig to the active object.
void QActive_unsubscribe (QActive const *const me, enum_t const sig)
 Unsubscribes from the delivery of signal sig to the active object.
void QActive_unsubscribeAll (QActive const *const me)
 Unsubscribes from the delivery of all signals to the active object.
bool QActive_defer (QActive const *const me, struct QEQueue *const eq, QEvt const *const e)
 Defer an event to a given separate event queue.
bool QActive_recall (QActive *const me, struct QEQueue *const eq)
 Recall a deferred event from a given event queue.
uint16_t QActive_flushDeferred (QActive const *const me, struct QEQueue *const eq, uint_fast16_t const num)
 Flush the specified number of events from the deferred queue eq.

Protected Attributes

QAsm super
uint8_t prio
 QF-priority [1..QF_MAX_ACTIVE] of this AO.
uint8_t pthre
 Preemption-threshold [1..QF_MAX_ACTIVE] of this AO.
QACTIVE_THREAD_TYPE thread
 Port-dependent representation of the thread of the active object.
QACTIVE_OS_OBJ_TYPE osObject
 Port-dependent per-thread object.
QACTIVE_EQUEUE_TYPE eQueue
 Port-dependent event-queue type (often QEQueue).
Protected Attributes inherited from QAsm
struct QAsmVtable const * vptr
 Virtual pointer inherited by all QAsm subclasses (see also [SAS_QP_TECH_20]) .
union QAsmAttr state
 Current state (pointer to the current state-handler function) .
union QAsmAttr temp
 Temporary storage for target/act-table etc..

Private Member Functions

void QActive_register_ (QActive *const me)
 Register this active object to be managed by the framework.
void QActive_unregister_ (QActive *const me)
 Un-register the active object from the framework.
bool QActive_post_ (QActive *const me, QEvt const *const e, uint_fast16_t const margin, void const *const sender)
 Posts an event e directly to the event queue of the active object using the First-In-First-Out (FIFO) policy.
void QActive_postLIFO_ (QActive *const me, QEvt const *const e)
 Posts an event e directly to the event queue of the active object using the Last-In-First-Out (LIFO) policy.
QEvt const * QActive_get_ (QActive *const me)
 Get an event from the event queue of an active object.
void QActive_evtLoop_ (QActive *const me)
 Event loop thread routine for executing an active object act (defined some in QP ports)Forward Traceability .

Static Private Member Functions

void QActive_publish_ (QEvt const *const e, void const *const sender, uint_fast8_t const qsId)
 Publish event to all subscribers of a given signal e->sig.
static void QActive_postFIFO_ (QActive *const me, QEvt const *const e, void const *const sender)
 Internal helper function to insert event to QEQueue queue.
static void QActive_multicast_ (QPSet *const subscrSet, QEvt const *const e, void const *const sender)

Private Attributes

QActive * QActive_registry_ [QF_MAX_ACTIVE+1U]
 Static (one per-class) array of registered active objects.
QSubscrList * QActive_subscrList_
 Static (one per-class) pointer to all subscriber AOs for a given event signal.
QSignal QActive_maxPubSignal_
 Static (one per-class) maximum published signal (the size of the subscrList_ array).

Detailed Description

Active Object class (based on the QHsm implementation strategy).

Details

Active Objects (a.k.a., Actors) are autonomous software objects, each possessing an event queue, execution context, and an internal state machine. All interactions with an Active Object occur by asynchronous posting of events, which are processed one at a time (to completion) in the execution context of the Active Object. As long as there is no sharing of data or resources among Active Objects (or any other concurrent entities), there are no concurrency hazards.

The QActive class 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 slightly slower than in the QMsm-style implementation strategy.

Note
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

Usage

The following example illustrates how to derive an active object from QActive.

typedef struct {
QActive super; // inherit QActive
QTimeEvt timeEvt; // to timeout the blinking
} Blinky;
. . . // class operations
Active Object class (based on the QHsm implementation strategy).
Definition qp.h:446
Time Event class.
Definition qp.h:572

Backward Traceability

Definition at line 446 of file qp.h.

Member Function Documentation

◆ QActive_ctor()

void QActive_ctor ( QActive *const me,
QStateHandler const initial )
protected

QActive constructor (abstract base class).

Parameters
[in,out]meinstance pointer (see [SAS_QP_TECH_20])
[in]initialpointer to the top-most initial state-handler function in the derived active object

Usage

void Blinky_ctor(Blinky * const me) {
// ctor of the superclass <---
QActive_ctor(&me->super, Q_STATE_CAST(&Blinky_initial));
. . . // call ctor of other members
}
#define Q_STATE_CAST(handler_)
Perform cast to QStateHandler.
Definition qp.h:172
void QActive_ctor(QActive *const me, QStateHandler const initial)
QActive constructor (abstract base class).
Definition qf_qact.c:50

See also

Backward Traceability

  • [SRS_QP_REQ_000] QP/C Framework shall provide the Active Object abstraction to QP/C Application

Forward Traceability

  • [MISRA_QP_DVR_MC5_R11_3C] MISRA-C:2025 Rule 11.3(Required): A conversion shall not be performed between a pointer to object type and a pointer to a different object type (unrelated types)
  • [TUN_QP_qf_qact64] Unit test for qf_qact: QActive registration, priority management (64 configured AOs)
  • [TUN_QP_qf_qact32] Unit test for qf_qact: QActive registration, priority management (32 configured AOs)
  • [TUN_QP_qf_qact16] Unit test for qf_qact: QActive registration, priority management (16 configured AOs)
  • [TUN_QP_qf_qact8] Unit test for qf_qact: QActive registration, priority management (8 configured AOs)

Definition at line 50 of file qf_qact.c.

◆ QActive_setAttr()

void QActive_setAttr ( QActive *const me,
uint32_t attr1,
void const * attr2 )

Generic setting of additional attributes (defined in some QP ports).

Backward Traceability

Forward Traceability

◆ QActive_start()

void QActive_start ( QActive *const me,
QPrioSpec const prioSpec,
QEvtPtr *const qSto,
uint_fast16_t const qLen,
void *const stkSto,
uint_fast16_t const stkSize,
void const *const par )

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.

The top-most initial transition of the AO is taken inside QActive_start(). With the preemptive QK kernel, QActive_start() locks the scheduler at the priority of the AO around the top-most initial transition (QK_schedLock()/QK_schedUnlock()), so that the AO cannot be activated before its top-most initial transition completes (e.g., by an event the AO posts to itself), and the AO is activated at the unlock if it is ready. Before QF_run() the scheduler is locked anyway, so the lock has no effect then.

QActive_start() does not flush the QS software-tracing buffer (only QF_run() does at its beginning), so that starting an AO does not block for the transmission of the trace data (QS dictionary records are still flushed as they are produced).

Parameters
[in,out]meinstance pointer (see [SAS_QP_TECH_20])
[in]prioSpecpriority specification for the AO (See QPrioSpec)
[in]qStopointer to the storage for the ring buffer of the event queue
[in]qLenlength of the event queue [# QEvtPtr pointers]
[in]stkStopointer to the stack storage (might be NULL)
[in]stkSizestack size [bytes]
[in]parpointer to an extra parameter (might be NULL)

Usage

The following example shows starting an AO when a per-task stack is NOT needed:

#include "qpc.h"
int main() {
QF_init(); // initialize the framework and the underlying RT kernel
BSP_init(); // initialize the Board Support Package
. . .
// instantiate and start the active objects...
Blinky_ctor();
static QEvtPtr l_blinkyQSto[10]; // Event queue storage for Blinky
QActive_start(AO_Blinky, // AO pointer to start
1U, // unique QP priority of the AO
l_blinkyQSto, // storage for the AO's queue
Q_DIM(l_blinkyQSto), // length of the queue [entries]
(void *)0, // stack storage (not used in QK)
0U, // stack size [bytes] (not used in QK)
(void *)0); // initialization parameter (or 0)
. . .
return QF_run(); // run the QF application
}
#define Q_DIM(array_)
Helper macro to calculate static dimension of a 1-dim array.
Definition qp.h:86
Top-level QP/C Framework in C interface for QP/C Applications Details.
void QActive_start(QActive *const me, QPrioSpec const prioSpec, QEvtPtr *const qSto, uint_fast16_t const qLen, void *const stkSto, uint_fast16_t const stkSize, void const *const par)
Starts execution of an active object and registers the object with the framework.
Definition qv.c:167
The data type to store in the event queue ring-buffer.
Definition qequeue.h:46

Backward Traceability

  • [SRS_QP_REQ_031] QP/C Framework shall allow Active Object instances to be started at runtime
  • [SRS_QP_REQ_731] The preemption-threshold assigned to an Active Object shall be consistent with its unique QP/C priority.
  • [SDS_QP_OSAL_KSVC] Design view: Framework services implemented by the kernel.

Forward Traceability

  • [MISRA_QP_DVR_MC5_R8_13] MISRA-C:2025 Rule 8.13(Advisory): A pointer should point to a const-qualified type whenever possible
  • [TUN_QP_qk] Unit test for qk: Preemptive QK kernel implementation
  • [TUN_QP_qv] Unit test for qv: Non-preemptive QV kernel implementation

Definition at line 167 of file qv.c.

◆ QActive_stop()

void QActive_stop ( QActive *const me)
protected

Stops execution of an active object and removes it from the framework's supervision.

Parameters
[in,out]meinstance pointer (see [SAS_QP_TECH_20])
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.

Backward Traceability

Forward Traceability

◆ QActive_register_()

void QActive_register_ ( QActive *const me)
privateinternal

Register this active object to be managed by the framework.

Details

This internal 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().

Parameters
[in,out]meinstance pointer (see [SAS_QP_TECH_20])

Backward Traceability

  • [SRS_QP_REQ_001] QP/C Framework shall be able to manage a compile-time configurable number of Active Objects not exceeding 64 instances.
  • [SRS_QP_REQ_010] Active Object abstraction shall provide the unique priority for each Active Object instance

Forward Traceability

  • [TUN_QP_qf_qact64] Unit test for qf_qact: QActive registration, priority management (64 configured AOs)
  • [TUN_QP_qf_qact32] Unit test for qf_qact: QActive registration, priority management (32 configured AOs)
  • [TUN_QP_qf_qact16] Unit test for qf_qact: QActive registration, priority management (16 configured AOs)
  • [TUN_QP_qf_qact8] Unit test for qf_qact: QActive registration, priority management (8 configured AOs)

Definition at line 75 of file qf_qact.c.

◆ QActive_unregister_()

void QActive_unregister_ ( QActive *const me)
privateinternal

Un-register the active object from the framework.

Details

This internal function unregisters a given active object from the active objects managed by the QF framework. The QP ports should not call it.

Parameters
[in]mepointer to the active object to remove from the framework.
Note
The active object that is removed from the framework can no longer participate in any event exchange.

Backward Traceability

  • [SRS_QP_REQ_032] QP/C Framework may allow Active Object instances to be stopped at runtime

Forward Traceability

  • [TUN_QP_qf_qact64] Unit test for qf_qact: QActive registration, priority management (64 configured AOs)
  • [TUN_QP_qf_qact32] Unit test for qf_qact: QActive registration, priority management (32 configured AOs)
  • [TUN_QP_qf_qact16] Unit test for qf_qact: QActive registration, priority management (16 configured AOs)
  • [TUN_QP_qf_qact8] Unit test for qf_qact: QActive registration, priority management (8 configured AOs)

Definition at line 127 of file qf_qact.c.

◆ QActive_post_()

bool QActive_post_ ( QActive *const me,
QEvt const *const e,
uint_fast16_t const margin,
void const *const sender )
privateinternal

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. Should be called only through the macro QACTIVE_POST().

Parameters
[in,out]meinstance pointer (see [SAS_QP_TECH_20])
[in]epointer to the event to be posted
[in]marginnumber of required free slots in the queue after posting the event or QF_NO_MARGIN.
[in]senderpointer to a sender object (used in QS only)
Return values
true(success) if the posting succeeded (with the provided margin)
false(failure) when the posting fails.
Attention
For margin == QF_NO_MARGIN, this function will assert internally if the event posting fails. In that case, it is unnecessary to check the return value from this function.
Note
This function should be called only through the macro QACTIVE_POST(). The reason is that the last parameter (sender) is needed only for software tracing, and typically is only defined when software tracing is enabled. When software tracing is disabled, the macro QACTIVE_POST() does not use the sender parameter, so it might not be defined.
Remarks
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.

Usage

extern QActive * const AO_Table;
QState Philo_hungry(Philo * const me, QEvt const * const e) {
QState status;
switch (e->sig) {
case Q_ENTRY_SIG: {
TableEvt *pe = Q_NEW(TableEvt, HUNGRY_SIG); // dynamic alloc
pe->philNum = me->num;
QACTIVE_POST(AO_Table, &pe->super, me); // <===
status = Q_HANDLED();
break;
}
. . .
}
return status;
}
#define Q_HANDLED()
Indicate that an action has been "handled." Applies to entry/exit actions and internal transitions.
Definition qp.h:307
#define Q_NEW(evtT_, sig_,...)
Allocate a mutable (dynamic) event.
Definition qp.h:737
#define Q_ENTRY_SIG
Reserved signal sent to state handler to execute the entry case. \clearpage .
Definition qp.h:202
#define QACTIVE_POST(me_, e_, sender_)
Invoke the direct event posting facility QActive_post_().
Definition qp.h:760
uint_fast8_t QState
Type returned from state-handler functions \clearpage .
Definition qp.h:141
Event class.
Definition qp.h:95
uint32_t sig
Event signal (see Event Signal).
Definition qp.h:96

Backward Traceability

  • [SRS_QP_REQ_300] QP/C Framework shall provide direct event posting to Active Object instances based on the FIFO policy.
  • [SRS_QP_REQ_310] QP/C Framework shall provide event delivery guarantee for the direct event posting mechanism.
  • [SRS_QP_REQ_331] QP/C Framework may provide alternative best-effort event posting mechanism without event delivery guarantee
  • [SSRS_QP_SREQ_400] QP/C Framework shall treat every condition that prevents the delivery of an event with event delivery guarantee as a fault.
  • [SSRS_QP_SREQ_401] QP/C best-effort event delivery shall not interfere with the event delivery guarantee.
  • [SDS_QP_POST] Design view: QP/C event posting sequence.

Forward Traceability

  • [MISRA_QP_DVR_QS_MC5_R15_5] MISRA-C:2025 Rule 15.5(Disapplied): A function should have a single point of exit at the end
  • [TUN_QP_qf_actq8] Unit test for qf_actq: QActive native event queue implementation based on QEQueue (8-bit queue counters).
  • [TUN_QP_qf_actq16] Unit test for qf_actq: QActive native event queue implementation based on QEQueue (16-bit queue counters).

Definition at line 50 of file qf_actq.c.

◆ QActive_postLIFO_()

void QActive_postLIFO_ ( QActive *const me,
QEvt const *const e )
privateinternal

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.

Parameters
[in,out]meinstance pointer (see [SAS_QP_TECH_20])
[in]epointer to the event to be posted
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.

See also

Backward Traceability

  • [SRS_QP_REQ_301] QP/C Framework shall provide direct event self-posting to Active Object instances based on the LIFO policy
  • [SDS_QP_POST] Design view: QP/C event posting sequence.

Forward Traceability

  • [MISRA_QP_DVR_QS_MC5_R15_5] MISRA-C:2025 Rule 15.5(Disapplied): A function should have a single point of exit at the end
  • [TUN_QP_qf_actq8] Unit test for qf_actq: QActive native event queue implementation based on QEQueue (8-bit queue counters).
  • [TUN_QP_qf_actq16] Unit test for qf_actq: QActive native event queue implementation based on QEQueue (16-bit queue counters).

Definition at line 114 of file qf_actq.c.

◆ QActive_get_()

QEvt const * QActive_get_ ( QActive *const me)
privateinternal

Get an event from the event queue of an active object.

Details

This function is only for internal use inside the QP/C Framework and QP/C Application should not call this function (there is never a need for it). 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.

Parameters
[in,out]meinstance pointer (see [SAS_QP_TECH_20])
Return values
pointerA 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 QEQueue class is used for the QActive event queue.

Backward Traceability

  • [SDS_QP_OSAL_EQ] Design view: Active Object event queue as an OSAL element.

Forward Traceability

  • [TUN_QP_qf_actq8] Unit test for qf_actq: QActive native event queue implementation based on QEQueue (8-bit queue counters).
  • [TUN_QP_qf_actq16] Unit test for qf_actq: QActive native event queue implementation based on QEQueue (16-bit queue counters).

Definition at line 179 of file qf_actq.c.

◆ QActive_psInit()

void QActive_psInit ( QSubscrList *const subscrSto,
enum_t const maxSignal )
static

Initializes the publish-subscribe facility for the application.

Details

This function must be called during system initialization, before any Active Object subscribes to signals or before any events are published. It configures the global subscription list used by the QP Framework's publish-subscribe mechanism.

Parameters
[in]subscrStoPointer to the storage for the subscription list. The storage must provide one entry for every signal below maxSignal (including the reserved signals below Q_USER_SIG).
[in]maxSignalThe number of entries in subscrSto, which is one more than the highest signal that may be published or subscribed at run time. All published and subscribed signals must be below maxSignal, and maxSignal must not be below Q_USER_SIG.
Note
The function must be called exactly once during system startup before any Active Object subscribes to signals or before any events are published.

Usage

void BSP_init(void const * const arg) {
. . .
// initialize publish-subscribe
static QSubscrList subscrSto[MAX_PUB_SIG];
QActive_psInit(subscrSto, Q_DIM(subscrSto)); // <===
. . .
}
void QActive_psInit(QSubscrList *const subscrSto, enum_t const maxSignal)
Initializes the publish-subscribe facility for the application.
Definition qf_ps.c:54
Subscriber List (for publish-subscribe).
Definition qp.h:437

Backward Traceability

  • [SRS_QP_REQ_321] The publish-subscribe event delivery mechanism shall be configurable and optional
  • [SDS_QP_START] Design view: QP/C Framework startup sequence.

Forward Traceability

  • [TUN_QP_qf_ps] Unit test for qf_ps: QActive publish-subscribe event delivery

Definition at line 54 of file qf_ps.c.

◆ QActive_publish_()

void QActive_publish_ ( QEvt const *const e,
void const *const sender,
uint_fast8_t const qsId )
staticprivateinternal

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.

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 QACTIVE_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

QState Philo_eating(Philo * const me, QEvt const * const e) {
QState status_;
switch (e->sig) {
. . .
case Q_EXIT_SIG: {
TableEvt const *pe = Q_NEW(TableEvt, DONE_SIG, me->id);
QACTIVE_PUBLISH(&me->super, pe, me); // <===
status_ = Q_RET_HANDLED;
break;
}
. . .
}
return status_;
}
#define QACTIVE_PUBLISH(e_, sender_)
Publish an event to all subscriber Active Objects.
Definition qp.h:764
#define Q_EXIT_SIG
Reserved signal sent to state handler to execute the exit case. \clearpage .
Definition qp.h:203
#define Q_RET_HANDLED
Return value from a state handler: the event was handled (Q_HANDLED()) \clearpage .
Definition qp.h:188

Backward Traceability

  • [SRS_QP_REQ_320] QP/C Framework shall provide publish-subscribe event delivery mechanism
  • [SRS_QP_REQ_325] Event multicasting during publishing shall be completed before the processing of the published events.
  • [SSRS_QP_SREQ_402] QP/C event multicasting shall be completed before any recipient processes the published event.
  • [SDS_QP_PUB] Design view: QP/C event publishing sequence.

Forward Traceability

  • [TUN_QP_qf_ps] Unit test for qf_ps: QActive publish-subscribe event delivery

Definition at line 83 of file qf_ps.c.

◆ QActive_getQueueUse()

uint16_t QActive_getQueueUse ( uint_fast8_t const prio)
static

Obtain the number of entries in use in the queue.

Details

Obtain the number of used slots in the Active Object's event queue based on the QEQueue class.

Parameters
[in]prioThe unique priority of the Active Object or zero
Return values
usedif prio != 0, the current number of used slots in the AO queue.
sumif prio == 0, the sum of all current numbers of used slots in all AO queues.
Note
This operation needs to be used with caution because the number of entries in use can change unexpectedly.

Backward Traceability

  • [SDS_QP_OSAL_EQ] Design view: Active Object event queue as an OSAL element.

Forward Traceability

  • [TUN_QP_qf_actq8] Unit test for qf_actq: QActive native event queue implementation based on QEQueue (8-bit queue counters).
  • [TUN_QP_qf_actq16] Unit test for qf_actq: QActive native event queue implementation based on QEQueue (16-bit queue counters).

Definition at line 300 of file qf_actq.c.

◆ QActive_getQueueFree()

uint16_t QActive_getQueueFree ( uint_fast8_t const prio)
static

Obtain the number of free entries still available in the queue.

Details

Obtain the number of free slots in the Active Object's event queue based on the QEQueue class.

Parameters
[in]prioPriority of the Active Object, whose queue is queried (must be valid).
Return values
numberthe current number of free slots in the queue.
Note
This operation needs to be used with caution because the number of free entries can change unexpectedly.

Backward Traceability

  • [SDS_QP_OSAL_EQ] Design view: Active Object event queue as an OSAL element.

Forward Traceability

  • [TUN_QP_qf_actq8] Unit test for qf_actq: QActive native event queue implementation based on QEQueue (8-bit queue counters).
  • [TUN_QP_qf_actq16] Unit test for qf_actq: QActive native event queue implementation based on QEQueue (16-bit queue counters).

Definition at line 334 of file qf_actq.c.

◆ QActive_getQueueMin()

uint16_t QActive_getQueueMin ( uint_fast8_t const prio)
static

Obtain the minimum of free entries of the given event queue since start.

Details

Queries the minimum of free ever present in the given event queue of an Active Object with priority prio, since the active object was started.

Note
This function is available only when the native QF event queue implementation is used. Requesting the queue minimum of an unused priority level raises an assertion in the QF. (A priority level becomes used in QF after the call to the QActive_register_() function.)
Parameters
[in]prioPriority of the Active Object, whose queue is queried (must be valid).
Return values
minThe minimum of free ever present in the given event queue of an active object with priority prio, since the Active Object was started.
Note
This operation needs to be used with caution because the "low-watermark" can change unexpectedly. The main intent for using this operation is to get an idea of queue usage to size the queue adequately.

Backward Traceability

  • [SSRS_QP_SREQ_212] QP/C software component shall apply self-monitoring SSFs based on "low watermark" to event queues and memory pools.
  • [SDS_QP_OSAL_EQ] Design view: Active Object event queue as an OSAL element.

Forward Traceability

  • [TUN_QP_qf_actq8] Unit test for qf_actq: QActive native event queue implementation based on QEQueue (8-bit queue counters).
  • [TUN_QP_qf_actq16] Unit test for qf_actq: QActive native event queue implementation based on QEQueue (16-bit queue counters).

Definition at line 354 of file qf_actq.c.

◆ QActive_subscribe()

void QActive_subscribe ( QActive const *const me,
enum_t const sig )
protected

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.

Parameters
[in,out]meinstance pointer (see [SAS_QP_TECH_20])
[in]sigevent signal to subscribe
Note
Subscribing to a signal that is already subscribed by this active object leaves the subscriptions unchanged (see [SRS_QP_REQ_322]).

Usage

The following example shows how the Table active object subscribes to three signals in the initial transition:

QState Table_initial(Table * const me, QEvt const * const e) {
// subscribe to event signals...
QActive_subscribe(&me->super, (enum_t)HUNGRY_SIG);
QActive_subscribe(&me->super, (enum_t)DONE_SIG);
QActive_subscribe(&me->super, (enum_t)TERMINATE_SIG);
. . .
return Q_TRAN(&Table_serving);
}
#define Q_UNUSED_PAR(par_)
Helper macro to mark unused parameters of functions.
Definition qp.h:85
#define Q_TRAN(target_)
Take transition to the specified target_ state.
Definition qp.h:298
void QActive_subscribe(QActive const *const me, enum_t const sig)
Subscribes for delivery of signal sig to the active object.
Definition qf_ps.c:200

Backward Traceability

  • [SRS_QP_REQ_322] QP/C Framework shall allow Active Object instances to subscribe to a given event signal at run-time.

Forward Traceability

  • [TUN_QP_qf_ps] Unit test for qf_ps: QActive publish-subscribe event delivery

Definition at line 200 of file qf_ps.c.

◆ QActive_unsubscribe()

void QActive_unsubscribe ( QActive const *const me,
enum_t const sig )
protected

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. Unsubscribing 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,out]meinstance pointer (see [SAS_QP_TECH_20])
[in]sigevent signal to unsubscribe
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 already be in the queue or just about to be posted, and the unsubscribe operation will not flush such events.
Unsubscribing from a signal that is not subscribed by this active object leaves the subscriptions unchanged (see [SRS_QP_REQ_323]).

Backward Traceability

  • [SRS_QP_REQ_323] QP/C Framework shall allow Active Object instances to unsubscribe from a subscribed event signal at run-time.

Forward Traceability

  • [TUN_QP_qf_ps] Unit test for qf_ps: QActive publish-subscribe event delivery

Definition at line 234 of file qf_ps.c.

◆ QActive_unsubscribeAll()

void QActive_unsubscribeAll ( QActive const *const me)
protected

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.

Parameters
[in,out]meinstance pointer (see [SAS_QP_TECH_20])
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 unsubscribing from all events. The events might already be in the queue or just about to be posted, and the unsubscribe operation will not flush such events. Also, the alternative event-delivery mechanisms, such as direct event posting or time events, can still be delivered to the event queue of the active object.

Backward Traceability

  • [SRS_QP_REQ_324] QP/C Framework shall allow Active Object instances to unsubscribe from all subscribed event signals at run-time.

Forward Traceability

  • [TUN_QP_qf_ps] Unit test for qf_ps: QActive publish-subscribe event delivery

Definition at line 268 of file qf_ps.c.

◆ QActive_defer()

bool QActive_defer ( QActive const *const me,
struct QEQueue *const eq,
QEvt const *const e )
protected

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.

Remarks
An active object can use multiple event queues to defer events of different kinds.
Parameters
[in,out]meinstance pointer (see [SAS_QP_TECH_20])
[in]eqpointer to a raw thread-safe queue to defer the event to.
[in]epointer to the event to be deferred
Return values
true(Success) when the event could be deferred
false(Failure) if event deferral failed due to overflowing the queue

Backward Traceability

  • [SRS_QP_REQ_080] Active Object abstraction shall provide support for event deferral.
  • [SDS_QP_DEFER] Design view: QP/C event deferral sequence.

Forward Traceability

  • [SSM_QP_ASR_417] Application-level state machines must not use the current event after the dispatch.
  • [TUN_QP_qf_defer] Unit test for qf_defer: event deferral for QActive class.

Definition at line 44 of file qf_defer.c.

◆ QActive_recall()

bool QActive_recall ( QActive *const me,
struct QEQueue *const eq )
protected

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.

Parameters
[in,out]meinstance pointer (see [SAS_QP_TECH_20])
[in]eqpointer to a raw thread-safe queue to recall an event from.
Return values
trueIf an event has been recalled
falseOtherwise
Note
An active object can use multiple event queues to defer events of different kinds.

Backward Traceability

  • [SRS_QP_REQ_080] Active Object abstraction shall provide support for event deferral.
  • [SSRS_QP_SREQ_403] A recalled event shall be processed next by the recalling Active Object.
  • [SDS_QP_DEFER] Design view: QP/C event deferral sequence.

Forward Traceability

  • [TUN_QP_qf_defer] Unit test for qf_defer: event deferral for QActive class.

Definition at line 78 of file qf_defer.c.

◆ QActive_flushDeferred()

uint16_t QActive_flushDeferred ( QActive const *const me,
struct QEQueue *const eq,
uint_fast16_t const num )
protected

Flush the specified number of events from the 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.

Parameters
[in,out]meinstance pointer (see [SAS_QP_TECH_20])
[in]eqpointer to a raw thread-safe queue to flush.
[in]numnumber of events to flush (note can be a big number, like 0xFFFFU to flush all events)
Return values
numberThe number of events flushed from the queue.

Backward Traceability

  • [SRS_QP_REQ_080] Active Object abstraction shall provide support for event deferral.

Forward Traceability

  • [TUN_QP_qf_defer] Unit test for qf_defer: event deferral for QActive class.

Definition at line 136 of file qf_defer.c.

◆ QActive_evtLoop_()

void QActive_evtLoop_ ( QActive *const me)
privateinternal

Event loop thread routine for executing an active object act (defined some in QP ports)Forward Traceability .

◆ QActive_postFIFO_()

void QActive_postFIFO_ ( QActive *const me,
QEvt const *const e,
void const *const sender )
staticprivateinternal

Internal helper function to insert event to QEQueue queue.

Details

This internal function is called from QActive::QActive_post_() and only when QActive uses the native QEQueue. Also, by the time this function is called, the caller has determined that the event will fit in the queue and all the event reference counting has been performed.

Parameters
[in,out]meinstance pointer (see [SAS_QP_TECH_20])
[in]epointer to the event to be posted
[in]senderpointer to a sender object (used in QS only)

See also

Forward Traceability

  • [TUN_QP_qf_actq8] Unit test for qf_actq: QActive native event queue implementation based on QEQueue (8-bit queue counters).
  • [TUN_QP_qf_actq16] Unit test for qf_actq: QActive native event queue implementation based on QEQueue (16-bit queue counters).

Definition at line 244 of file qf_actq.c.

◆ QActive_multicast_()

void QActive_multicast_ ( QPSet *const subscrSet,
QEvt const *const e,
void const *const sender )
staticprivate

Definition at line 140 of file qf_ps.c.

Member Data Documentation

◆ super

QAsm super
protected

Definition at line 447 of file qp.h.

◆ prio

uint8_t prio
protected

QF-priority [1..QF_MAX_ACTIVE] of this AO.

See also

Definition at line 448 of file qp.h.

◆ pthre

uint8_t pthre
protected

Preemption-threshold [1..QF_MAX_ACTIVE] of this AO.

See also

Definition at line 449 of file qp.h.

◆ thread

QACTIVE_THREAD_TYPE thread
protected

Port-dependent representation of the thread of the active object.

Details

This data might be used in various ways, depending on the QF port. In some ports, me->thread is used to store the thread handle. In other ports, me->thread can be a pointer to the Thread-Local-Storage (TLS).

Definition at line 452 of file qp.h.

◆ osObject

QACTIVE_OS_OBJ_TYPE osObject
protected

Port-dependent per-thread object.

Details

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 456 of file qp.h.

◆ eQueue

QACTIVE_EQUEUE_TYPE eQueue
protected

Port-dependent event-queue type (often QEQueue).

Details

The type of the queue depends on the underlying operating system or 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 QACTIVE_EQUEUE_TYPE as QEQueue.

Definition at line 460 of file qp.h.

◆ QActive_registry_

QActive * QActive_registry_
privateinternal

Static (one per-class) array of registered active objects.

Forward Traceability

  • [TUN_QP_qf_qact64] Unit test for qf_qact: QActive registration, priority management (64 configured AOs)
  • [TUN_QP_qf_qact32] Unit test for qf_qact: QActive registration, priority management (32 configured AOs)
  • [TUN_QP_qf_qact16] Unit test for qf_qact: QActive registration, priority management (16 configured AOs)
  • [TUN_QP_qf_qact8] Unit test for qf_qact: QActive registration, priority management (8 configured AOs)

Definition at line 38 of file qp_pkg.h.

◆ QActive_subscrList_

QSubscrList* QActive_subscrList_
privateinternal

Static (one per-class) pointer to all subscriber AOs for a given event signal.

Forward Traceability

  • [TUN_QP_qf_ps] Unit test for qf_ps: QActive publish-subscribe event delivery

Definition at line 41 of file qp_pkg.h.

◆ QActive_maxPubSignal_

QSignal QActive_maxPubSignal_
privateinternal

Static (one per-class) maximum published signal (the size of the subscrList_ array).

Forward Traceability

  • [TUN_QP_qf_ps] Unit test for qf_ps: QActive publish-subscribe event delivery

Definition at line 44 of file qp_pkg.h.