Reference Manual For QP/C++ 8.1.6
Loading...
Searching...
No Matches
QP::QF Namespace Reference

QF Active Object Framework namespace. More...

Classes

class  Attr
 Private attributes of the QF framework. More...

Functions

void QF_INIT_CFGCHK_ ()
 QF initialization with the configuration-specific name (QP configuration check).
void init ()
 QF initialization.
void stop ()
 Invoked by the application layer to stop the QF framework and return control to the OS/Kernel (used in some QF ports).
int_t run ()
 Transfers control to QF to run the application.
void onStartup ()
 Startup QF callback.
void onCleanup ()
 Cleanup QF callback.
void psInit (QSubscrList *const subscrSto, QSignal const maxSignal) noexcept
void publish_ (QEvt const *const e, void const *const sender, std::uint_fast8_t const qsId) noexcept
std::uint_fast16_t getQueueMin (std::uint_fast8_t const prio) noexcept
void tick (std::uint_fast8_t const tickRate, void const *const sender) noexcept
QPrioSpec prioSpec (std::uint8_t const prio, std::uint8_t const pthre) noexcept
 Create a QP::QPrioSpec object to specify priority of an AO or a thread.
void poolInit (void *const poolSto, std::uint_fast32_t const poolSize, std::uint_fast16_t const evtSize) noexcept
 Event pool initialization for dynamic allocation of events.
std::uint16_t poolGetMaxBlockSize () noexcept
 Obtain the block size of any registered event pools.
std::uint16_t getPoolUse (std::uint_fast8_t const poolNum) noexcept
 Obtain the number of used entries of the given event pool or of all event pools.
std::uint16_t getPoolFree (std::uint_fast8_t const poolNum) noexcept
 Obtain the number of free entries of the given event pool.
std::uint16_t getPoolMin (std::uint_fast8_t const poolNum) noexcept
 Obtain the minimum of free entries of the given event pool.
QEvt * newX_ (std::uint_fast16_t const evtSize, std::uint_fast16_t const margin, QSignal const sig) noexcept
 Internal QF implementation of creating new mutable (dynamic) event.
void gc (QEvt const *const e) noexcept
 Recycle a mutable (dynamic) event.
QEvt const * newRef_ (QEvt const *const e, QEvt const *const evtRef) noexcept
 Internal QF implementation of creating new event reference.
void deleteRef_ (QEvt const *const evtRef) noexcept
 Internal QF implementation of deleting event reference.
template<class evtT_, typename... Args>
evtT_ * q_new (QSignal const sig, Args... args)
 Function template to allocate a dynamic event and asserting successful allocation.
template<class evtT_, typename... Args>
evtT_ * q_new_x (std::uint_fast16_t const margin, QSignal const sig, Args... args)
 Function template to allocate a dynamic event without asserting successful allocation.
template<class evtT_>
void q_new_ref (QP::QEvt const *const e, evtT_ const *&evtRef)
 Create a new reference of the current event e.
template<class evtT_>
void q_delete_ref (evtT_ const *&evtRef)
 Delete a new reference of the current event e.
QEvt * newXfromISR_ (std::uint_fast16_t const evtSize, std::uint_fast16_t const margin, QSignal const sig) noexcept
void gcFromISR (QEvt const *e) noexcept

Variables

constexpr std::uint_fast16_t NO_MARGIN {0xFFFFU}
 Special value of margin that causes asserting failure in case event allocation or event posting fails.
QF::Attr priv_
pthread_mutex_t critSectMutex_
int_t critSectNest_

Detailed Description

QF Active Object Framework namespace.

Backward Traceability

  • [SDS_QP_QF] Design view: QF Active Object Framework.

Function Documentation

◆ QF_INIT_CFGCHK_()

void QP::QF::QF_INIT_CFGCHK_ ( )

QF initialization with the configuration-specific name (QP configuration check).

Details

The QF initialization implemented in the QP port/kernel. The name QF_INIT_CFGCHK_ is a macro defined in qp_cfgchk.hpp, which expands to a name that encodes the QP configuration (e.g., QF_816U_a32t01p03e4q1m2s00). The inline function QP::QF::init() called by the application calls QP::QF::QF_INIT_CFGCHK_(). If the QP library has been built with a different configuration than the application, the names differ and the build fails at link time.

Note
QP::QF::QF_INIT_CFGCHK_() is not intended to be called directly by the application. The application calls QP::QF::init().

Backward Traceability

Forward Traceability

  • [TUN_QP_qk] Unit test for qk: Preemptive QK kernel implementation
  • [TUN_QP_qv] Unit test for qv: Non-preemptive QV kernel implementation
  • [TIN_QP_cfgchk] Build test of the link-time configuration check.

Definition at line 64 of file qv.cpp.

◆ init()

void QP::QF::init ( )
inline

QF initialization.

Details

Initializes QF and must be called exactly once before any other QF function. Typically, QF::init() is called from main() even before initializing the Board Support Package (BSP).

Note
QF::init() does not clear the internal QF variables: the QP/C++ Framework relies on the zero-initialization of static storage (.bss) by the startup code and on the constructors of its static objects, as required by the C++ Standard. QF::init() calls the kernel's QF::QF_INIT_CFGCHK_() (link-time configuration check, see qp_cfgchk.hpp), which initializes only what the static initialization does not provide. For example, the built-in kernels update the Duplicate Inverse Storage of the Active Object registry and of the Framework and kernel attributes (except in the Q_UNSAFE build), QK locks the scheduler until QF::run(), and both call the port-specific initialization (QV_INIT(), QK_INIT()).

Backward Traceability

Forward Traceability

  • [TUN_QP_qk] Unit test for qk: Preemptive QK kernel implementation
  • [TUN_QP_qv] Unit test for qv: Non-preemptive QV kernel implementation
  • [TIN_QP_cfgchk] Build test of the link-time configuration check.

Definition at line 469 of file qp.hpp.

◆ stop()

void QP::QF::stop ( )

Invoked by the application layer to stop the QF framework and return control to the OS/Kernel (used in some QF ports).

Details

This function stops the QF application. After calling this function, QF attempts to stop the application gracefully. This graceful shutdown might take some time to complete. The typical use of this function is for terminating the QF application to return to the operating system or for handling fatal errors that require shutting down (and possibly resetting) the system.

Attention
After calling QP::QF::stop(), the application must terminate and cannot continue. In particular, QP::QF::stop() is not intended to be followed by a call to QP::QF::init() to "resurrect" the application.

Backward Traceability

Forward Traceability

◆ run()

int_t QP::QF::run ( )

Transfers control to QF to run the application.

Details

QF::run() is typically called from your startup code after you initialize the QF and start at least one active object with QActive::start().

In the built-in kernels, QF::run() begins by flushing the QS software-tracing buffer (QS_FLUSH(), only with Q_SPY), which contains the trace data produced during the startup. If the startup produces more trace data than the QS buffer can hold (e.g., many active objects), the Application can call QS_FLUSH() between the QActive::start() calls.

Return values
no-returnTypically in embedded systems QF::run() does not return
statusIn case QF runs on top of a General-Purpose OS (GPOS), QF::run() returns the error status with value 0 representing success

Backward Traceability

  • [SRS_QP_REQ_601] QV kernel shall execute, in each pass through its event loop, exactly one RTC step of the highest-priority ready Active Object.
  • [SRS_QP_REQ_603] QV kernel shall not dispatch any event before the kernel is started.
  • [SRS_QP_REQ_701] QK kernel shall activate a ready Active Object only if its priority is higher than the system ceiling.
  • [SRS_QP_REQ_704] QK kernel shall not activate any Active Object before the kernel is started.
  • [SDS_QP_START] Design view: QP/C++ Framework startup sequence.
  • [SDS_QP_OSAL_KSVC] Design view: Framework services implemented by the kernel.

Forward Traceability

  • [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 70 of file qv.cpp.

◆ onStartup()

void QP::QF::onStartup ( )
callbackcrit-sect

Startup QF callback.

Details

The purpose of the QF_onStartup() callback is to configure and enable hardware interrupts. The callback is invoked from QF_run(), right before starting the underlying real-time kernel. By that time, the application is considered ready to receive and service interrupts.

This function is application-specific and is not implemented in QF, but rather in the Board Support Package (BSP) for the given application.

Backward Traceability

Forward Traceability

  • [TUN_QP_qk] Unit test for qk: Preemptive QK kernel implementation
  • [TUN_QP_qv] Unit test for qv: Non-preemptive QV kernel implementation
  • [TIN_QP_qk] Integration test suite for the preemptive QK kernel.
  • [TIN_QP_qv] Integration test suite for the non-preemptive QV kernel.

◆ onCleanup()

void QP::QF::onCleanup ( )
callback

Cleanup QF callback.

Details

QP::QF::onCleanup() is called in some QF ports before QF returns to the underlying real-time kernel or operating system.

This function is strongly platform-specific and is not implemented in the QF, but either in the QF port or in the Board Support Package (BSP) for the given application. Some QF ports might not require implementing QF_onCleanup() at all, because many embedded applications don't have anything to exit to.

Backward Traceability

Forward Traceability

◆ psInit()

void QP::QF::psInit ( QSubscrList *const subscrSto,
QSignal const maxSignal )
inlinenoexcept
Deprecated

Definition at line 751 of file qp.hpp.

◆ publish_()

void QP::QF::publish_ ( QEvt const *const e,
void const *const sender,
std::uint_fast8_t const qsId )
inlinenoexcept
Deprecated

Definition at line 759 of file qp.hpp.

◆ getQueueMin()

std::uint_fast16_t QP::QF::getQueueMin ( std::uint_fast8_t const prio)
inlinenoexcept
Deprecated

Definition at line 767 of file qp.hpp.

◆ tick()

void QP::QF::tick ( std::uint_fast8_t const tickRate,
void const *const sender )
inlinenoexcept
Deprecated

Definition at line 776 of file qp.hpp.

◆ prioSpec()

QPrioSpec QP::QF::prioSpec ( std::uint8_t const prio,
std::uint8_t const pthre )
noexcept

Create a QP::QPrioSpec object to specify priority of an AO or a thread.

Parameters
[in]prioQF priority [1..QF_MAX_ACTIVE]
[in]pthrePreemption threshold [1..QF_MAX_ACTIVE]
Return values
prio-specThe combined 16-bit priority specification (prio in bits [0..7] and pthre in bits [8..15]).

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 54 of file qf_qact.cpp.

◆ poolInit()

void QP::QF::poolInit ( void *const poolSto,
std::uint_fast32_t const poolSize,
std::uint_fast16_t const evtSize )
noexcept

Event pool initialization for dynamic allocation of events.

Details

This function initializes one event pool at a time and must be called exactly once for each event pool before the pool can be used.

Parameters
[in]poolStopointer to the storage for the event pool
[in]poolSizesize of the storage for the pool in bytes
[in]evtSizethe block-size of the pool in bytes, which determines the maximum size of events that can be allocated from the pool.

You may initialize multiple event pools by issuing consecutive calls to QF::poolInit(). For correctness and to simplify the internal implementation, event pools must be initialized in ascending order of event-block size. The total number of initialized pools must not exceed QF_MAX_EPOOL. (If QF_MAX_EPOOL is configured to 0, the framework does not support mutable events.)

To ensure proper alignment of memory blocks within each pool buffer, the framework provides the helper macro QF_MPOOL_EL().

Note
The actual number of events available in a pool may be slightly less than the nominal value (poolSize / evtSize) due to internal block-alignment requirements. You can always determine the exact capacity of a pool by calling QF::getPoolFree() before any events have been allocated from it.

Usage

void main() {
. . .
// initialize Event Memory Pools...
static QF_MPOOL_EL(QP::QEvt) smallPoolSto[20];
QF::poolInit(smallPoolSto, sizeof(smallPoolSto), sizeof(smallPoolSto[0]));
static QF_MPOOL_EL(MyMedEvt) mediumPoolSto[10];
QF::poolInit(mediumPoolSto, sizeof(mediumPoolSto), sizeof(mediumPoolSto[0]));
static QF_MPOOL_EL(MyLargeEvt) largePoolSto[5];
QF::poolInit(largePoolSto, sizeof(largePoolSto), sizeof(largePoolSto[0]));
. . .
}
Event class.
Definition qp.hpp:96
void poolInit(void *const poolSto, std::uint_fast32_t const poolSize, std::uint_fast16_t const evtSize) noexcept
Event pool initialization for dynamic allocation of events.
Definition qf_dyn.cpp:51
#define QF_MPOOL_EL(evType_)
Memory pool element to allocate correctly aligned storage for QMPool class.
Definition qmpool.hpp:36

Backward Traceability

  • [SRS_QP_REQ_360] QP/C++ Framework shall support mutable events.
  • [SRS_QP_REQ_361] QP/C++ Framework shall support up to 15 event pools for mutable events.
  • [SDS_QP_START] Design view: QP/C++ Framework startup sequence.

Forward Traceability

  • [TUN_QP_qf_dyn] Unit test for qf_dyn: QF dynamic (mutable) event management.

Definition at line 51 of file qf_dyn.cpp.

◆ poolGetMaxBlockSize()

std::uint16_t QP::QF::poolGetMaxBlockSize ( )
noexcept

Obtain the block size of any registered event pools.

Details

Obtain the block size of any registered event pools

Forward Traceability

  • [TUN_QP_qf_dyn] Unit test for qf_dyn: QF dynamic (mutable) event management.

Definition at line 88 of file qf_dyn.cpp.

◆ getPoolUse()

std::uint16_t QP::QF::getPoolUse ( std::uint_fast8_t const poolNum)
noexcept

Obtain the number of used entries of the given event pool or of all event pools.

Details

This function obtains the number of blocks currently in use (allocated) in the given event pool, or the sum of the used blocks in all initialized event pools.

Parameters
[in]poolNumevent pool ID in the range 1..max_pool, where max_pool is the number of event pools initialized with the function QF::poolInit(). The special value 0 requests the sum over all initialized event pools.
Return values
useThe number of used blocks in the given event pool (or in all event pools)

Forward Traceability

  • [TUN_QP_qf_dyn] Unit test for qf_dyn: QF dynamic (mutable) event management.

◆ getPoolFree()

std::uint16_t QP::QF::getPoolFree ( std::uint_fast8_t const poolNum)
noexcept

Obtain the number of free entries of the given event pool.

Details

This function obtains the number of blocks currently free (available for allocation) in the given event pool.

Parameters
[in]poolNumevent pool ID in the range 1..max_pool, where max_pool is the number of event pools initialized with the function QF::poolInit().
Return values
freeThe number of free blocks in the given event pool

Forward Traceability

  • [TUN_QP_qf_dyn] Unit test for qf_dyn: QF dynamic (mutable) event management.

◆ getPoolMin()

std::uint16_t QP::QF::getPoolMin ( std::uint_fast8_t const poolNum)
noexcept

Obtain the minimum of free entries of the given event pool.

Details

This function obtains the minimum number of free blocks in the given event pool since this pool has been initialized by a call to QF_poolInit().

Parameters
[in]poolNumevent pool ID in the range 1..max_pool, where max_pool is the number of event pools initialized with the function QF_poolInit().
Return values
minThe minimum number of unused blocks in the given event pool

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.

Forward Traceability

  • [TUN_QP_qf_dyn] Unit test for qf_dyn: QF dynamic (mutable) event management.

◆ newX_()

QEvt * QP::QF::newX_ ( std::uint_fast16_t const evtSize,
std::uint_fast16_t const margin,
QSignal const sig )
noexceptinternal

Internal QF implementation of creating new mutable (dynamic) event.

Details

Allocates an event dynamically from one of the QF event pools.

Parameters
[in]evtSizethe size (in bytes) of the event to allocate
[in]marginthe number of unallocated events still available in a given event pool after the allocation completes. The special value QF::NO_MARGIN means that this function will assert if allocation fails.
[in]sigthe signal to be assigned to the allocated event
Return values
evtPointer to the newly allocated event.
NULLOnly if margin != QF::NO_MARGIN and the event cannot be allocated with the specified margin still available in the given pool.
Note
The internal QF function QF_newX_() raises an assertion when the margin parameter is QF::NO_MARGIN and allocation of the event turns out to be impossible due to event pool depletion, or incorrect (too big) size of the requested event.
The application code should not call this function directly. The only allowed use is through the QP::QF::q_new() or QP::QF::q_new_x() function templates.

Backward Traceability

  • [SRS_QP_REQ_370] QP/C++ Framework shall provide a method of allocating mutable events at runtime.
  • [SRS_QP_REQ_334] Mutable event allocation shall be reliable. This requirement also means that the QP/C++ Application is responsible for adequately sizing all event pools.
  • [SRS_QP_REQ_335] QP/C++ Framework may provide alternative unreliable method of allocating mutable events.
  • [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.

Forward Traceability

  • [MISRA_QP_DVR_MP2_R11_6_1] MISRA-C++:2023 Rule 11.6.1(Advisory): All variables should be initialized
  • [TUN_QP_qf_dyn] Unit test for qf_dyn: QF dynamic (mutable) event management.
  • [TUN_QP_qf_dyn_raii] Unit test for qf_dyn with QEVT_PAR_INIT: initialization of mutable events at allocation (RAII).

Definition at line 193 of file qf_dyn.cpp.

◆ gc()

void QP::QF::gc ( QEvt const *const e)
noexcept

Recycle a mutable (dynamic) event.

Details

This function implements a simple garbage collector for the mutable events. Only mutable events are candidates for recycling. (A mutable event is allocated from an event-pool, which is determined as non-zero QEvt::getPoolId_(e).) Next, the function decrements the reference counter of the event (e->refCtr_). It recycles the event only if the counter drops to zero (meaning that no more references are outstanding for this event). The mutable event is recycled by returning it to the pool from which it was initially allocated.

Parameters
[in]epointer to the event to recycle
Note
QF invokes the garbage collector at all appropriate contexts, when an event can become garbage (automatic garbage collection), so the application code should not need to call QF::gc() directly. The QF::gc() function is exposed only for exceptional cases when your application sends mutable events to the "raw" thread-safe queues (see ::QEQueue). Such queues are processed outside of QF and the automatic garbage collection is NOT performed for these events. In this case, you need to call QF::gc() explicitly.

Backward Traceability

  • [SRS_QP_REQ_380] QP/C++ Framework shall support automatic recycling of mutable events according to the "zero-copy" memory management policy.
  • [SRS_QP_REQ_385] QP/C++ Framework shall provide a method of explicitly recycling mutable events.

Forward Traceability

  • [TUN_QP_qf_dyn] Unit test for qf_dyn: QF dynamic (mutable) event management.
  • [TUN_QP_qf_dyn_raii] Unit test for qf_dyn with QEVT_PAR_INIT: initialization of mutable events at allocation (RAII).

Definition at line 267 of file qf_dyn.cpp.

◆ newRef_()

QEvt const * QP::QF::newRef_ ( QEvt const *const e,
QEvt const *const evtRef )
noexceptinternal

Internal QF implementation of creating new event reference.

Details

Creates and returns a new reference to the current event e

Parameters
[in]epointer to the current event
[in]evtRefthe event reference
Return values
refThe newly created reference to the event e
Note
The application code should not call this function directly. The only allowed use is thorough the macro Q_NEW_REF().

Backward Traceability

  • [SRS_QP_REQ_380] QP/C++ Framework shall support automatic recycling of mutable events according to the "zero-copy" memory management policy.

Forward Traceability

  • [TUN_QP_qf_dyn] Unit test for qf_dyn: QF dynamic (mutable) event management.

Definition at line 322 of file qf_dyn.cpp.

◆ deleteRef_()

void QP::QF::deleteRef_ ( QEvt const *const evtRef)
noexceptinternal

Internal QF implementation of deleting event reference.

Details

Deletes an existing reference to the event e

Parameters
[in]evtRefthe event reference
Note
The application code should not call this function directly. The only allowed use is through the macro Q_DELETE_REF().

Backward Traceability

  • [SRS_QP_REQ_380] QP/C++ Framework shall support automatic recycling of mutable events according to the "zero-copy" memory management policy.

Forward Traceability

  • [TUN_QP_qf_dyn] Unit test for qf_dyn: QF dynamic (mutable) event management.

Definition at line 364 of file qf_dyn.cpp.

◆ q_new()

template<class evtT_, typename... Args>
evtT_ * QP::QF::q_new ( QSignal const sig,
Args... args )
inline

Function template to allocate a dynamic event and asserting successful allocation.

Details

This function template allocates a mutable (dynamic) event and asserts that the allocation was successful. The caller of this template does not need to check for validity of the returned event pointer. However, the QP/C++ Application is responsible for sizing the event pools adequately. (This is part of event-delivery guarantee.)

See also

Template Parameters
evtT_event class (class name) of the event to allocate
Parameters
[in]sigsignal to assign to the newly allocated event
[in]argsadditional arguments passed to the init() member function of the event class (#QEVT_PAR_INIT configured)
Return values
pointerA valid event pointer of the type evtT_*.
Note
If #QEVT_PAR_INIT is defined, the q_new<evtT> template becomes variadic and takes all the arguments needed by the init() member function of the event class being allocated. This enables initialization of the event at allocation (RAII). Every event class allocated in this way must declare its own init(); a missing init() in a class derived from QP::QEvt is detected at compile time (see QP::QEvt::init()).

Usage

The following example illustrates non-variadic version of the q_new<evtT> template (when #QEVT_PAR_INIT is NOT defined):

// event without parameters
QP::QEvt const *myEvt = QP::QF::q_new<QP::QEvt>(APP::MY_SIG); // <==
// post or publish the event... (no need to check for nullptr)
// event with parameter(s) (event parameter(s) initialized separately)
APP::KeypressEvt *kevt = QP::QF::q_new<APP::KeypressEvt>(APP::KEYPRESS_SIG); // <==
kevt->keyId = keyId; // initialize event parameters (no need to check for nullptr)
// post or publish the event...
evtT_ * q_new(QSignal const sig, Args... args)
Function template to allocate a dynamic event and asserting successful allocation.
Definition qp.hpp:847

The following example illustrates variadic version of the q_new<evtT> template (when #QEVT_PAR_INIT IS defined):

// event without parameters (note QP::QEvt::DYNAMIC dummy parameter)
QP::QEvt const *myEvt =
// post or publish the event... (no need to check for nullptr)
// event with parameters
namespace APP {
struct KeypressEvt : public QP::QEvt { // <=== inherit QP::QEvt
// event parameters follow...
std::uint8_t keyId; // ID of the key pressed
// when QEVT_PAR_INIT is defined, the "ctor" must be provided
#ifdef QEVT_PAR_INIT
void init(std::uint8_t id) {
keyId = id;
}
void init() { // init() might be overloaded
keyId = 123;
}
#endif // QEVT_PAR_INIT
};
} // namespace
// event with parameters (keyId passed to KeypressEvt::init())
APP::KeypressEvt const *kevt = QP::QF::q_new<APP::KeypressEvt>(APP::KEYPRESS_SIG, keyId); // <==
// post or publish the event... (no need to check for nullptr)
@ DYNAMIC
Dummy parameter for dynamic event initialization (see QP::QEvt::init(DynEvt)) \clearpage .
Definition qp.hpp:103
void init()
QF initialization.
Definition qp.hpp:469

Backward Traceability

  • [SRS_QP_REQ_370] QP/C++ Framework shall provide a method of allocating mutable events at runtime.
  • [SRS_QP_REQ_334] Mutable event allocation shall be reliable. This requirement also means that the QP/C++ Application is responsible for adequately sizing all event pools.

Forward Traceability

  • [TUN_QP_qf_dyn] Unit test for qf_dyn: QF dynamic (mutable) event management.
  • [TUN_QP_qf_dyn_raii] Unit test for qf_dyn with QEVT_PAR_INIT: initialization of mutable events at allocation (RAII).

Definition at line 847 of file qp.hpp.

◆ q_new_x()

template<class evtT_, typename... Args>
evtT_ * QP::QF::q_new_x ( std::uint_fast16_t const margin,
QSignal const sig,
Args... args )
inline

Function template to allocate a dynamic event without asserting successful allocation.

Details

This template allocates a mutable (dynamic) event, but only if the corresponding event pool has at least margin of free events left. If the event pool has insufficient number of events left, the template returns nullptr. The caller of this template is responsible for checking the returned event pointer for nullptr.

Template Parameters
evtT_event class (class name) of the event to allocate
Parameters
[in]marginnumber of events that must remain available in the given pool after this allocation. The special value ::QF_NO_MARGIN causes asserting failure in case event allocation fails.
[in]sigsignal to assign to the newly allocated event
[in]argsadditional arguments passed to the init() member function of the event class (#QEVT_PAR_INIT configured)
Return values
pointerAn event pointer of the type evtT_*
`nullptr`if the event cannot be allocated with the specified margin of events still left in the event pool.
Note
If #QEVT_PAR_INIT is defined, the q_new_x<evtT> template becomes variadic and takes all the arguments needed by the init() of the event class being allocated. This enables initialization of the event at allocation (RAII). When the allocation fails, init() is not called and the template returns nullptr. Every event class allocated in this way must declare its own init(); a missing init() in a class derived from QP::QEvt is detected at compile time (see QP::QEvt::init()).

Usage

The following example illustrates non-variadic version of the q_new_x<evtT> template (when #QEVT_PAR_INIT is NOT defined):

// event without parameters
QP::QEvt const *myEvt = QP::QF::q_new_x<QP::QEvt>(5U, APP::MY_SIG); // <== (margin == 5U)
if (myEvt) { // check the event pointer!
// post or publish the event...
}
// event with parameter(s) (event parameter(s) initialized separately)
APP::KeypressEvt *kevt = QP::QF::q_new_x<APP::KeypressEvt>(10U, APP::KEYPRESS_SIG); // <===
if (kevt) { // check the event pointer!
kevt->keyId = keyId; // initialize event parameters
// post or publish the event...
}
evtT_ * q_new_x(std::uint_fast16_t const margin, QSignal const sig, Args... args)
Function template to allocate a dynamic event without asserting successful allocation.
Definition qp.hpp:859

The following example illustrates variadic version of the q_new_x<evtT> template (when #QEVT_PAR_INIT IS defined):

// event without parameters (note QP::QEvt::DYNAMIC dummy parameter)
QP::QEvt const *myEvt =
QP::QF::q_new_x<QP::QEvt>(5U, APP::MY_SIG, QP::QEvt::DYNAMIC); // <== (margin == 5U)
if (myEvt) { // check the event pointer!
// post or publish the event...
}
// event with parameters
namespace APP {
struct KeypressEvt : public QP::QEvt { // <=== inherit QP::QEvt
// event parameters follow...
std::uint8_t keyId; // ID of the key pressed
// when QEVT_PAR_INIT is defined, the "ctor" must be provided
#ifdef QEVT_PAR_INIT
void init(std::uint8_t id) {
keyId = id;
}
void init() { // init() might be overloaded
keyId = 123;
}
#endif // QEVT_PAR_INIT
};
} // namespace
// event with parameters (keyId passed to KeypressEvt::init())
APP::KeypressEvt const *kevt =
QP::QF::q_new_x<APP::KeypressEvt>(10U, APP::KEYPRESS_SIG, keyId); // <==
if (kevt) { // check the event pointer!
// post or publish the event...
}

Usage

The example examples/posix-win32/reminder2 illustrates the use of QP::QF::q_new_x().

See also

Backward Traceability

  • [SRS_QP_REQ_335] QP/C++ Framework may provide alternative unreliable method of allocating mutable events.

Forward Traceability

  • [TUN_QP_qf_dyn] Unit test for qf_dyn: QF dynamic (mutable) event management.
  • [TUN_QP_qf_dyn_raii] Unit test for qf_dyn with QEVT_PAR_INIT: initialization of mutable events at allocation (RAII).

Definition at line 859 of file qp.hpp.

◆ q_new_ref()

template<class evtT_>
void QP::QF::q_new_ref ( QP::QEvt const *const e,
evtT_ const *& evtRef )
inline

Create a new reference of the current event e.

Details

The current event processed by an Active Object is available only for the duration of the run-to-completion (RTC) step. After that step, the current event is no longer available and the framework might recycle (garbage-collect) the event. The function template QP::QF::q_new_ref() explicitly creates a new reference to the current event that can be stored and used beyond the current RTC step, until the reference is explicitly recycled by means of the function template QP::QF::q_delete_ref().

See also

Template Parameters
evtT_event class (class name) of the event to allocate
Parameters
[in]eevent to create a reference to
[in,out]evtRefreference object (of the type evtT_*

This function template does not return a value, but it modifies the evtRef parameter.

Usage

The example examples/posix-win32/defer illustrates the use of QP::QF::q_new_ref()

Forward Traceability

  • [SSM_QP_ASR_413] Application-level state machines must not internally poll or block for events.
  • [SSM_QP_ASR_417] Application-level state machines must not use the current event after the dispatch.
  • [TUN_QP_qf_dyn] Unit test for qf_dyn: QF dynamic (mutable) event management.

Definition at line 878 of file qp.hpp.

◆ q_delete_ref()

template<class evtT_>
void QP::QF::q_delete_ref ( evtT_ const *& evtRef)
inline

Delete a new reference of the current event e.

Details

Every event reference created with the function template QP::QF::q_new_ref() needs to be eventually deleted by means of the function template QP::QF::q_delete_ref() to avoid leaking the event.

See also

Template Parameters
evtT_event class (class name) of the event to allocate
Parameters
[in,out]evtRefevent reference to delete

This function template does not return a value, but it modifies the evtRef parameter.

Usage

The example examples/posix-win32/defer illustrates the use of QP::QF::q_delete_ref()

Forward Traceability

  • [TUN_QP_qf_dyn] Unit test for qf_dyn: QF dynamic (mutable) event management.

Definition at line 887 of file qp.hpp.

Variable Documentation

◆ NO_MARGIN

std::uint_fast16_t QP::QF::NO_MARGIN {0xFFFFU}
constexpr

Special value of margin that causes asserting failure in case event allocation or event posting fails.

Backward Traceability

  • [SRS_QP_REQ_310] QP/C++ Framework shall provide event delivery guarantee for the direct event posting mechanism.

Definition at line 478 of file qp.hpp.

◆ priv_

Attr QP::QF::priv_

Definition at line 51 of file qf_qact.cpp.