QP/C  7.3.4
Real-Time Embedded Framework
Loading...
Searching...
No Matches
QEvt Class Reference

Event class. More...

#include "qp.h"

Inheritance diagram for QEvt:
QTimeEvt

Static Public Member Functions

static QEvtQEvt_ctor (QEvt *const me, enum_t const sig)
 

Public Attributes

QSignal sig
 

Static Private Member Functions

static bool QEvt_verify_ (QEvt const *const me)
 
static uint_fast8_t QEvt_getPoolNum_ (QEvt const *const me)
 
static void QEvt_refCtr_inc_ (QEvt const *me)
 
static void QEvt_refCtr_dec_ (QEvt const *me)
 

Private Attributes

uint8_t volatile refCtr_
 
uint8_t evtTag_
 

Detailed Description

Event class.

Description
Class QEvt represents QP events and serves as the base class for derivation of events with parameters (see also Object Orientation).
Traceability
Usage
The following example illustrates how to add event parameter(s) by inheriting the QEvt class. Please note that the QEvt member super is defined as the FIRST member of the derived class:
typedef struct {
QEvt super; // <=== inherit QEvt
// event parameters follow...
uint8_t keyId; // ID of the key pressed
} KeypressEvt;
Event class.
Definition qp.h:147
The following examples illustrate recommended ways to instantiate event objects based on the RAII principle (Resource Acquisition Is Initialization). Please see also QEVT_INITIALIZER().
// immutable event without parameters
static QEvt const myEvt = QEVT_INITIALIZER(MY_SIG);
// post, publish, or dispatch the immutable event...
// immutable event with parameters
static KeypressEvt const keyEvt = {
QEVT_INITIALIZER(KEYPRESS_SIG),
.keyId = 12U
}
// post, publish, or dispatch the immutable event...
// mutable event without parameters (e.g., automatic object inside a function)
QEvt myEvt = QEVT_INITIALIZER(sig); // sig is a variable
// dispatch the event (asynchronous posting or publishing probably WRONG!)
// mutable event with parameters (e.g., automatic object inside a function)
KeypressEvt keyEvt = { // sig and keyId are variables
.keyId = keyId
};
// dispatch the event (asynchronous posting or publishing probably WRONG!)
#define QEVT_INITIALIZER(sig_)
Definition qp.h:455
QSignal sig
Definition qp.h:151
Note
Please see macros Q_NEW() or Q_NEW_X() for code examples of allocating dynamic mutable events.

Definition at line 147 of file qp.h.

Member Function Documentation

◆ QEvt_ctor()

QEvt::QEvt_ctor ( QEvt *const me,
enum_t const sig )
inlinestatic

Event constructor.

Description
The main purpose of the QEvt constructor is to support dynamic allocation of events without parameters with the macros Q_NEW() or Q_NEW_X().
Remarks
The QEvt_ctor() can be also used to initialize event instances (or the portion inherited from QEvt in events with parameters), but this is not recommended. Instead, the recommended ways of instantiating event objects use the RAII principle (Resource Acquisition Is Initialization) and are based on the QEVT_INITIALIZER() macro, as illustrated in the QEvt class.
Parameters
[in,out]mecurrent instance pointer (see Object Orientation)
[in]sigsignal of the event to initialize (for non-dynamic events) or QEVT_DYNAMIC for dynamic events.
Returns
Pointer to the initialized event (the me pointer, see Object Orientation).
Traceability
Usage
The following example illustrates the use of the QEvt_ctor() directly (not recommended because not based on RAII):
// mutable event without parameters (type QEvt)
QEvt myEvt; // <== event instance (e.g., on the stack)
QEvt_ctor(&myEvt, MY_SIG); // <== initialize the event (not recommended)
// dispatch the event (asynchronous posting or publishing probably WRONG!)
// mutable event with parameters (type KeypressEvt derived from QEvt)
KeypressEvt keypressEvt; // <== event instance (e.g., on the stack)
QEvt_ctor(&keypressEvt.super, KEYPRESS_SIG); // <== initialize the .super member
keypressEvt.keyId = 23U; // initialize the event parameter
// dispatch keypressEvt...
static QEvt * QEvt_ctor(QEvt *const me, enum_t const sig)
Definition qp.h:167
The following example illustrates the use of the QEvt_ctor() implicitly (called by the macro Q_NEW()) when the configuration macro QEVT_DYN_CTOR is defined:
// variadic version of Q_NEW() (QEVT_DYNAMIC passed to QEvt_ctor())
QEvt const *pe = Q_NEW(QEvt, MY_SIG, QEVT_DYNAMIC);
// post or publish the event...
#define Q_NEW(evtT_, sig_,...)
Definition qp.h:1167
#define QEVT_DYNAMIC
Definition qp.h:143

Definition at line 167 of file qp.h.

◆ QEvt_verify_()

QEvt::QEvt_verify_ ( QEvt const *const me)
inlinestaticprivate

Internal function to verify the event pointer and the memory marker in the event (QP FuSa Subsystem)

Parameters
[in]mecurrent instance pointer (see Object Orientation)
Returns
'true' if this event passes the integrity check and 'false' otherwise.

Definition at line 181 of file qp.h.

◆ QEvt_getPoolNum_()

static uint_fast8_t QEvt_getPoolNum_ ( QEvt const *const me)
inlinestaticprivate

Definition at line 187 of file qp.h.

◆ QEvt_refCtr_inc_()

QEvt::QEvt_refCtr_inc_ ( QEvt const * me)
inlinestaticprivate

Internal function to increment the refCtr of a const event.

Description
This function requires "casting `const` away" from the event pointer, which violates MISRA-C:2023 Rule 11.8. This function encapsulates this violation.
Traceability

Definition at line 87 of file qp_pkg.h.

◆ QEvt_refCtr_dec_()

QEvt::QEvt_refCtr_dec_ ( QEvt const * me)
inlinestaticprivate

Internal function to decrement the refCtr of a const event.

Description
This function requires "casting `const` away" from the event pointer, which violates MISRA-C:2023 Rule 11.8. This function encapsulates this violation.
Traceability

Definition at line 92 of file qp_pkg.h.

Member Data Documentation

◆ sig

QEvt::sig

Signal of the event (see Event Signal).

Traceability

Definition at line 151 of file qp.h.

◆ refCtr_

QEvt::refCtr_
private

Reference counter (for mutable events, and 0 for immutable (static) events)

Traceability

Definition at line 156 of file qp.h.

◆ evtTag_

QEvt::evtTag_
private

Event "tag" containing pool-ID (indicating which event pool it came from) plus event marker

Description
The 8-bit evtTag_ member stores the event-pool number (in bits 0:3) and the QEVT_MARKER memory marker for integrity checking (in bits 4:7). In the special case of immutable events (not from event pools) the event-pool number bits are 0 (but bits 4:7 must still hold the QEVT_MARKER memory marker).
Traceability

Definition at line 159 of file qp.h.


The documentation for this class was generated from the following files: