QP/C  8.0.0
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 void QEvt_ctor (QEvt *const me, enum_t const sig)
 
static QEvtQEvt_init (QEvt *const me, uint8_t dummy)
 Event without parameters initialization.
 

Public Attributes

QSignal sig
 Signal of the event (see Event Signal)
 

Static Private Member Functions

static bool QEvt_verify_ (QEvt const *const me)
 Internal function to verify the internal integrity of the event instance (QP FuSa Subsystem)
 
static uint_fast8_t QEvt_getPoolNum_ (QEvt const *const me)
 Internal function to get the event pool-number of the given event.
 
static void QEvt_refCtr_inc_ (QEvt const *me)
 
static void QEvt_refCtr_dec_ (QEvt const *me)
 

Private Attributes

uint8_t evtTag_
 Event "tag" contains pool-ID plus the Duplicate Inverted Storage of the QEvt::refCtr_.
 
uint8_t volatile refCtr_
 Event reference counter.
 

Detailed Description

Event class.

Details
Class QEvt represents QP events and serves as the base class for derivation of events with parameters (see also Object Orientation). Please see the QEvt class design specifications linked in the "Backward Traceability" section.
Backward Traceability
Forward 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:131
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_)
Initializer for immutable (constant) QEvt instances.
Definition qp.h:430
QSignal sig
Signal of the event (see Event Signal)
Definition qp.h:135
Note
Please see macros Q_NEW() or Q_NEW_X() for code examples of allocating dynamic mutable events.

Definition at line 131 of file qp.h.

Member Function Documentation

◆ QEvt_ctor()

static void QEvt_ctor ( QEvt *const me,
enum_t const sig )
inlinestatic

Definition at line 151 of file qp.h.

◆ QEvt_init()

static QEvt * QEvt_init ( QEvt *const me,
uint8_t dummy )
inlinestatic

Event without parameters initialization.

Details
The main purpose of the QEvt initialization is to support dynamic allocation of events without parameters with the macros Q_NEW() or Q_NEW_X().
Remarks
The QEvt_init() 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]dummyshall be set to QEVT_DYNAMIC for dynamic events
Returns
Pointer to the initialized event (the me pointer, see Object Orientation).
Backward Traceability
  • SRS_QP_EVT_40 : QP/C Framework may be compile-time configurable to allow customized constructor and other custom operations on event instances
  • QEvt : Event class
Usage
The following example illustrates the use of the QEvt_init() directly (not recommended because not based on RAII):
// mutable event without parameters (type QEvt)
QEvt myEvt; // <== event instance (e.g., on the stack)
QEvt_init(&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_init(&keypressEvt.super, KEYPRESS_SIG); // <== initialize the .super member
keypressEvt.keyId = 23U; // initialize the event parameter
// dispatch keypressEvt...
static QEvt * QEvt_init(QEvt *const me, uint8_t dummy)
Event without parameters initialization.
Definition qp.h:160
The following example illustrates the use of the QEvt_init() implicitly (called by the macro Q_NEW()) when the configuration macro QEVT_PAR_INIT is defined:
// variadic version of Q_NEW() (QEVT_DYNAMIC passed to QEvt_init())
QEvt const *pe = Q_NEW(QEvt, MY_SIG, QEVT_DYNAMIC);
// post or publish the event...
#define Q_NEW(evtT_, sig_,...)
Allocate a mutable (dynamic) event.
Definition qp.h:1168
#define QEVT_DYNAMIC
dummy parameter for dynamic event initialization (see QEvt::QEvt_init())
Definition qp.h:433

Definition at line 160 of file qp.h.

◆ QEvt_verify_()

static bool QEvt_verify_ ( QEvt const *const me)
inlinestaticprivate

Internal function to verify the internal integrity of the event instance (QP FuSa Subsystem)

Description
The integrity checks include:
  • range check of the reference counter
  • Duplicate Inverse Storage check of bits reference counter bits 0:3
Parameters
[in]mecurrent instance pointer (see Object Orientation)
Returns
'true' if this event passes the integrity check and 'false' otherwise.

Definition at line 171 of file qp.h.

◆ QEvt_getPoolNum_()

static uint_fast8_t QEvt_getPoolNum_ ( QEvt const *const me)
inlinestaticprivate

Internal function to get the event pool-number of the given event.

Parameters
[in]mecurrent instance pointer (see Object Orientation)
Returns
Pool-ID of the event. The Pool-ID is zero for immutable (static) events.

Definition at line 179 of file qp.h.

◆ QEvt_refCtr_inc_()

static void QEvt_refCtr_inc_ ( QEvt const * me)
inlinestaticprivate

Internal function to increment the refCtr of a const event.

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

Backward Traceability

  • DVR_QP_MC4_R11_08

Definition at line 77 of file qp_pkg.h.

◆ QEvt_refCtr_dec_()

static void QEvt_refCtr_dec_ ( QEvt const * me)
inlinestaticprivate

Internal function to decrement the refCtr of a const event.

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

Backward Traceability

  • DVR_QP_MC4_R11_08

Definition at line 86 of file qp_pkg.h.

Member Data Documentation

◆ sig

QSignal sig

Signal of the event (see Event Signal)

Backward Traceability
  • QEvt : Event class
  • SRS_QP_EVT_20 : Each event instance shall contain the event Signal

Definition at line 135 of file qp.h.

◆ evtTag_

uint8_t evtTag_
private

Event "tag" contains pool-ID plus the Duplicate Inverted Storage of the QEvt::refCtr_.

Details
The 8-bit evtTag_ member stores the event-pool number (in bits 4:7) and the Duplicate Inverted Storage of the QEvt::refCtr_ for integrity checking (in bits 0:3). For mutable events, the QEvt_ctor() initializes refCtr_ to 0 and consequently evtTag_ to 0xF. For immutable events (not from event pools) the QEVT_INITIALIZER() macro initializes refCtr_ to 0xE and consequently evtTag_ to 0x1.
Backward Traceability
  • QEvt : Event class
  • SRS_QP_EVT_31 : Event abstraction may contain other data items for internal event management inside QP/C Framework
  • SRS_QP_EVT_30 : QP/C Framework shall allow Application to create event instances with Parameters defined by the Application

Definition at line 140 of file qp.h.

◆ refCtr_

uint8_t volatile refCtr_
private

Event reference counter.

Details
For mutable events (events from event pools), the 8-bit member QEvt::refCtr_ holds the reference count, which must be in the rage 0..2*QF_MAX_ACTIVE. For immutable (static) events, the member QEvt::refCtr_ holds the fixed value 0xE, which is initialized in the macro QEVT_INITIALIZER().
Backward Traceability
  • QEvt : Event class
  • SRS_QP_EVT_31 : Event abstraction may contain other data items for internal event management inside QP/C Framework
  • SRS_QP_EVT_30 : QP/C Framework shall allow Application to create event instances with Parameters defined by the Application

Definition at line 143 of file qp.h.


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