inc/ecu/event.h Source File

ECU: inc/ecu/event.h Source File
ECU
event.h
Go to the documentation of this file.
1 
14 #ifndef ECU_EVENT_H_
15 #define ECU_EVENT_H_
16 
17 /*------------------------------------------------------------*/
18 /*------------------------- INCLUDES -------------------------*/
19 /*------------------------------------------------------------*/
20 
21 /* STDLib. */
22 #include <stddef.h>
23 #include <stdint.h>
24 
25 /* ECU. */
26 #include "ecu/utils.h"
27 
28 /*------------------------------------------------------------*/
29 /*-------------------------- MACROS --------------------------*/
30 /*------------------------------------------------------------*/
31 
40 #define ECU_EVENT_BASE_CAST(event_ptr_) \
41  ((struct ecu_event *)(event_ptr_))
42 
51 #define ECU_EVENT_CONST_BASE_CAST(event_ptr_) \
52  ((const struct ecu_event *)(event_ptr_))
53 
64 #define ECU_EVENT_CTOR(id_, size_) \
65  { \
66  .id = id_, \
67  .size = size_ \
68  }
69 
79 #define ECU_EVENT_IS_BASE_OF(base_, derived_) \
80  ECU_IS_BASE_OF(base_, derived_)
81 
86 #define ECU_EVENT_SIZE_UNUSED \
87  ((size_t)0)
88 
89 /*------------------------------------------------------------*/
90 /*------------------------ EVENT IDS -------------------------*/
91 /*------------------------------------------------------------*/
92 
101 {
102  /*------------------------------------------------------------------*/
103  /*--------------------- RESERVED EVENT IDS SECTION -----------------*/
104  /*--------- LAST MEMBER MUST EQUAL ECU_VALID_EVENT_ID_BEGIN --------*/
105  /*------------------------------------------------------------------*/
106  /* ADD FUTURE PRIVATE AND RESERVED EVENTS HERE. */
108  /*******************************/
111  /*------------------------------------------------------------------*/
112  /*--------------------- AVAILABLE EVENT IDS SECTION ----------------*/
113  /*--------- FIRST MEMBER MUST EQUAL ECU_VALID_EVENT_ID_BEGIN -------*/
114  /*------------------------------------------------------------------*/
116 };
117 
128 typedef int32_t ecu_event_id_t;
129 
130 /*------------------------------------------------------------*/
131 /*--------------------------- EVENT --------------------------*/
132 /*------------------------------------------------------------*/
133 
141 struct ecu_event
142 {
145 
148  size_t size;
149 };
150 
151 /*------------------------------------------------------------*/
152 /*------------------ EVENT MEMBER FUNCTIONS ------------------*/
153 /*------------------------------------------------------------*/
154 
155 #ifdef __cplusplus
156 extern "C" {
157 #endif
158 
175 extern void ecu_event_ctor(struct ecu_event *me, ecu_event_id_t id, size_t size);
189 extern ecu_event_id_t ecu_event_id(const struct ecu_event *me);
190 
198 extern size_t ecu_event_size(const struct ecu_event *me);
201 #ifdef __cplusplus
202 }
203 #endif
204 
205 #endif /* ECU_EVENT_H_ */
size_t ecu_event_size(const struct ecu_event *me)
Returns the size (number of bytes) of the derived event.
int32_t ecu_event_id_t
Event ID type. Used so the library can implicitly typecast between this value, ecu_reserved_event_ids...
Definition: event.h:128
ecu_reserved_event_ids
Event IDs reserved for ECU library. This scheme allows the library and users to uniquely define their...
Definition: event.h:101
@ ECU_VALID_EVENT_ID_BEGIN
Definition: event.h:109
@ ECU_USER_EVENT_ID_BEGIN
Definition: event.h:115
@ ECU_RESERVED_EVENT_ID
Definition: event.h:107
void ecu_event_ctor(struct ecu_event *me, ecu_event_id_t id, size_t size)
Constructs an ecu_event at run-time.
ecu_event_id_t ecu_event_id(const struct ecu_event *me)
Returns the event's ID.
Base event class. Custom event data is stored by inheriting this class.
Definition: event.h:142
ecu_event_id_t id
Identifies the event type.
Definition: event.h:144
size_t size
Number of bytes of derived event. Allows for easier handling. I.e. reading and writing events to queu...
Definition: event.h:148