inc/ecu/event.h File Reference

ECU: inc/ecu/event.h File Reference
ECU
event.h File Reference
#include <stddef.h>
#include <stdint.h>
#include "ecu/utils.h"
Include dependency graph for event.h:

Go to the source code of this file.

Data Structures

struct  ecu_event
 Base event class. Custom event data is stored by inheriting this class. More...
 

Macros

#define ECU_EVENT_BASE_CAST(event_ptr_)    ((struct ecu_event *)(event_ptr_))
 Upcasts derived event back into the ecu_event base class. More...
 
#define ECU_EVENT_CONST_BASE_CAST(event_ptr_)    ((const struct ecu_event *)(event_ptr_))
 Same as ECU_EVENT_BASE_CAST() but performs a const-qualified upcast. More...
 
#define ECU_EVENT_CTOR(id_, size_)
 Constructs an ecu_event at compile-time. More...
 
#define ECU_EVENT_IS_BASE_OF(base_, derived_)    ECU_IS_BASE_OF(base_, derived_)
 Verifies, at compile-time, that derived event correctly inherits base event class via C-style inheritance. Returns true if this condition is satisfied. False otherwise. More...
 
#define ECU_EVENT_SIZE_UNUSED    ((size_t)0)
 Helper macro supplied to event constructors if event's size field is unused.
 

Typedefs

typedef int32_t ecu_event_id_t
 Event ID type. Used so the library can implicitly typecast between this value, ecu_reserved_event_ids, and user-defined event ID enumerations. More...
 

Enumerations

enum  ecu_reserved_event_ids { ECU_RESERVED_EVENT_ID = -1, ECU_VALID_EVENT_ID_BEGIN = 0, ECU_USER_EVENT_ID_BEGIN = ECU_VALID_EVENT_ID_BEGIN }
 Event IDs reserved for ECU library. This scheme allows the library and users to uniquely define their own event IDs without conflicts. Event IDs reserved for ECU library will always be negative. Event IDs the user defines will start at 0 which is always ECU_USER_EVENT_ID_BEGIN. More...
 

Functions

Constructors
void ecu_event_ctor (struct ecu_event *me, ecu_event_id_t id, size_t size)
 Constructs an ecu_event at run-time. More...
 
Member Functions
ecu_event_id_t ecu_event_id (const struct ecu_event *me)
 Returns the event's ID. More...
 
size_t ecu_event_size (const struct ecu_event *me)
 Returns the size (number of bytes) of the derived event. More...
 

Detailed Description

See event.h section in Sphinx documentation.

Author
Ian Ress
Version
0.1
Date
2024-04-07

Macro Definition Documentation

◆ ECU_EVENT_BASE_CAST

#define ECU_EVENT_BASE_CAST (   event_ptr_)     ((struct ecu_event *)(event_ptr_))

Upcasts derived event back into the ecu_event base class.

Parameters
event_ptr_Pointer to derived event. This type must inherit ecu_event base class and must be pointer to non-const.

◆ ECU_EVENT_CONST_BASE_CAST

#define ECU_EVENT_CONST_BASE_CAST (   event_ptr_)     ((const struct ecu_event *)(event_ptr_))

Same as ECU_EVENT_BASE_CAST() but performs a const-qualified upcast.

Parameters
event_ptr_Pointer to derived event. This type must inherit ecu_event base class. Can be either pointer to const or non-const.

◆ ECU_EVENT_CTOR

#define ECU_EVENT_CTOR (   id_,
  size_ 
)
Value:
{ \
.id = id_, \
.size = size_ \
}

Constructs an ecu_event at compile-time.

Warning
Validity of ID is not checked.
Parameters
id_ID to assign event.
size_Number of bytes of derived event. Allows for easier handling. I.e. reading and writing events to queues. Supply ECU_EVENT_SIZE_UNUSED if unused.

◆ ECU_EVENT_IS_BASE_OF

#define ECU_EVENT_IS_BASE_OF (   base_,
  derived_ 
)     ECU_IS_BASE_OF(base_, derived_)

Verifies, at compile-time, that derived event correctly inherits base event class via C-style inheritance. Returns true if this condition is satisfied. False otherwise.

Parameters
base_Name of base class member within user's derived_ event type.
derived_Derived event type to check.

Typedef Documentation

◆ ecu_event_id_t

typedef int32_t ecu_event_id_t

Event ID type. Used so the library can implicitly typecast between this value, ecu_reserved_event_ids, and user-defined event ID enumerations.

Warning
This must be a signed integer type in order to handle ecu_reserved_event_ids enumerations less than 0. A compilation error will occur if this is declared as an unsigned type.

Enumeration Type Documentation

◆ ecu_reserved_event_ids

Event IDs reserved for ECU library. This scheme allows the library and users to uniquely define their own event IDs without conflicts. Event IDs reserved for ECU library will always be negative. Event IDs the user defines will start at 0 which is always ECU_USER_EVENT_ID_BEGIN.

Enumerator
ECU_RESERVED_EVENT_ID 

PRIVATE. FOR LIBRARY USE ONLY.

ECU_VALID_EVENT_ID_BEGIN 

PRIVATE. FOR LIBRARY USE ONLY. Start of reserved IDs that the user can assign to events.

ECU_USER_EVENT_ID_BEGIN 

0. Start of user-defined event IDs. Will always be 0 for future compatibility.

Function Documentation

◆ ecu_event_ctor()

void ecu_event_ctor ( struct ecu_event me,
ecu_event_id_t  id,
size_t  size 
)

Constructs an ecu_event at run-time.

Precondition
Memory already allocated for me
Parameters
meEvent to construct. This should be a derived event passed into this function via ECU_EVENT_BASE_CAST().
idUser-defined event ID. This must be greater than or equal to ECU_VALID_EVENT_ID_BEGIN.
sizeNumber of bytes of derived event. Allows for easier handling. I.e. reading and writing events to queues. Supply ECU_EVENT_SIZE_UNUSED if unused.

◆ ecu_event_id()

ecu_event_id_t ecu_event_id ( const struct ecu_event me)

Returns the event's ID.

Precondition
me constructed via ECU_EVENT_CTOR() or ecu_event_ctor().
Parameters
meEvent to check. This should be a derived event passed into this function via ECU_EVENT_CONST_BASE_CAST().

◆ ecu_event_size()

size_t ecu_event_size ( const struct ecu_event me)

Returns the size (number of bytes) of the derived event.

Precondition
me constructed via ECU_EVENT_CTOR() or ecu_event_ctor().
Parameters
meEvent to check. This should be a derived event passed into this function via ECU_EVENT_CONST_BASE_CAST().