Skip to content

Commit 3fdc2bf

Browse files
committed
event_manager: Event manager cleanup v2
Add changes cleaning event manager. Signed-off-by: Jan Zyczkowski <[email protected]>
1 parent 9dd42fc commit 3fdc2bf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+585
-328
lines changed

doc/reference/app_event_manager/index.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ To create a header file for the event type you want to define:
8282

8383
.. code-block:: c
8484
85-
#include <app_event_manager.h>
85+
#include <app_event_manager/app_event_manager.h>
8686

8787
#. Define the new event type by creating a structure that contains an :c:struct:`app_event_header` named ``header`` as the first field.
8888
#. Optionally, add additional custom data fields to the structure.
@@ -92,7 +92,7 @@ The following code example shows a header file for the event type :c:struct:`sam
9292

9393
.. code-block:: c
9494
95-
#include <app_event_manager.h>
95+
#include <app_event_manager/app_event_manager.h>
9696
9797
struct sample_event {
9898
struct app_event_header header;
@@ -112,7 +112,7 @@ For example, you can add variable sized data to the previously defined event by
112112

113113
.. code-block:: c
114114
115-
#include <app_event_manager.h>
115+
#include <app_event_manager/app_event_manager.h>
116116
117117
struct sample_event {
118118
struct app_event_header header;
@@ -143,7 +143,7 @@ To create a source file for the event type you defined in the header file:
143143
The :c:macro:`APP_EVENT_TYPE_DEFINE` macro adds flags as a last parameter.
144144
These flags are constant and can only be set using :c:macro:`APP_EVENT_FLAGS_CREATE` on :c:macro:`APP_EVENT_TYPE_DEFINE` macro.
145145
To not set any flag, use :c:macro:`APP_EVENT_FLAGS_CREATE` without any argument as shown in the below example.
146-
To get value of specific flag, use :c:func:`get_app_event_type_flag` function.
146+
To get value of specific flag, use :c:func:`app_event_get_type_flag` function.
147147

148148
The following code example shows a source file for the event type ``sample_event``:
149149

include/app_event_manager/app_event_manager.h

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,16 @@
2323
#include <sys/__assert.h>
2424
#include <logging/log.h>
2525

26-
#include <app_event_manager_priv.h>
26+
#include <app_event_manager/app_event_manager_priv.h>
2727

2828
#ifdef __cplusplus
2929
extern "C" {
3030
#endif
3131

3232
/** @brief Pointer to the event handler function.
3333
*
34-
* @param aeh Pointer to the application event header of the event that is processed by app_event_manager.
34+
* @param aeh Pointer to the application event header of the event that is
35+
* processed by app_event_manager.
3536
* @retval True if event was consumed and should not be propagated to other listeners,
3637
* false otherwise.
3738
*/
@@ -62,7 +63,7 @@ enum app_event_type_flags {
6263
* @param et Pointer to the event type.
6364
* @retval Boolean value of requested flag.
6465
*/
65-
static inline bool get_app_event_type_flag(const struct event_type *et,
66+
static inline bool app_event_get_type_flag(const struct event_type *et,
6667
enum app_event_type_flags flag)
6768
{
6869
return (et->flags & BIT(flag)) != 0;
@@ -73,7 +74,7 @@ static inline bool get_app_event_type_flag(const struct event_type *et,
7374
* @param lname Listener name.
7475
* @param cb_fn Pointer to the event handler function.
7576
*/
76-
#define APP_EVENT_LISTENER(lname, cb_fn) _APP_EVENT_LISTENER(lname, cb_fn)
77+
#define APP_EVENT_LISTENER(lname, cb_fn) Z_APP_EVENT_LISTENER(lname, cb_fn)
7778

7879
/** @brief Subscribe a listener to an event type as first module that is
7980
* being notified.
@@ -82,7 +83,7 @@ static inline bool get_app_event_type_flag(const struct event_type *et,
8283
* @param ename Name of the event.
8384
*/
8485
#define APP_EVENT_SUBSCRIBE_FIRST(lname, ename) \
85-
_APP_EVENT_SUBSCRIBE(lname, ename, _EM_MARKER_FIRST_ELEMENT); \
86+
Z_APP_EVENT_SUBSCRIBE(lname, ename, Z_APP_EM_MARKER_FIRST_ELEMENT); \
8687
const struct {} _CONCAT(_CONCAT(__event_subscriber_, ename), first_sub_redefined) = {}
8788

8889
/** @brief Subscribe a listener to the early notification list for an
@@ -92,7 +93,7 @@ static inline bool get_app_event_type_flag(const struct event_type *et,
9293
* @param ename Name of the event.
9394
*/
9495
#define APP_EVENT_SUBSCRIBE_EARLY(lname, ename) \
95-
_APP_EVENT_SUBSCRIBE(lname, ename, _EM_SUBS_PRIO_ID(_EM_SUBS_PRIO_EARLY))
96+
Z_APP_EVENT_SUBSCRIBE(lname, ename, Z_APP_EM_SUBS_PRIO_ID(Z_APP_EM_SUBS_PRIO_EARLY))
9697

9798
/** @brief Subscribe a listener to the normal notification list for an event
9899
* type.
@@ -101,7 +102,7 @@ static inline bool get_app_event_type_flag(const struct event_type *et,
101102
* @param ename Name of the event.
102103
*/
103104
#define APP_EVENT_SUBSCRIBE(lname, ename) \
104-
_APP_EVENT_SUBSCRIBE(lname, ename, _EM_SUBS_PRIO_ID(_EM_SUBS_PRIO_NORMAL))
105+
Z_APP_EVENT_SUBSCRIBE(lname, ename, Z_APP_EM_SUBS_PRIO_ID(Z_APP_EM_SUBS_PRIO_NORMAL))
105106

106107
/** @brief Subscribe a listener to an event type as final module that is
107108
* being notified.
@@ -110,7 +111,7 @@ static inline bool get_app_event_type_flag(const struct event_type *et,
110111
* @param ename Name of the event.
111112
*/
112113
#define APP_EVENT_SUBSCRIBE_FINAL(lname, ename) \
113-
_APP_EVENT_SUBSCRIBE(lname, ename, _EM_MARKER_FINAL_ELEMENT); \
114+
Z_APP_EVENT_SUBSCRIBE(lname, ename, Z_APP_EM_MARKER_FINAL_ELEMENT); \
114115
const struct {} _CONCAT(_CONCAT(__event_subscriber_, ename), final_sub_redefined) = {}
115116

116117
/** @brief Declare an event type.
@@ -120,7 +121,7 @@ static inline bool get_app_event_type_flag(const struct event_type *et,
120121
*
121122
* @param ename Name of the event.
122123
*/
123-
#define APP_EVENT_TYPE_DECLARE(ename) _APP_EVENT_TYPE_DECLARE(ename)
124+
#define APP_EVENT_TYPE_DECLARE(ename) Z_APP_EVENT_TYPE_DECLARE(ename)
124125

125126
/** @brief Declare an event type with dynamic data size.
126127
*
@@ -130,7 +131,7 @@ static inline bool get_app_event_type_flag(const struct event_type *et,
130131
*
131132
* @param ename Name of the event.
132133
*/
133-
#define APP_EVENT_TYPE_DYNDATA_DECLARE(ename) _APP_EVENT_TYPE_DYNDATA_DECLARE(ename)
134+
#define APP_EVENT_TYPE_DYNDATA_DECLARE(ename) Z_APP_EVENT_TYPE_DYNDATA_DECLARE(ename)
134135

135136
/** @brief Define an event type.
136137
*
@@ -153,7 +154,7 @@ static inline bool get_app_event_type_flag(const struct event_type *et,
153154
* You should use APP_EVENT_FLAGS_CREATE to define them.
154155
*/
155156
#define APP_EVENT_TYPE_DEFINE(ename, log_fn, ev_info_struct, app_event_type_flags) \
156-
_APP_EVENT_TYPE_DEFINE(ename, log_fn, ev_info_struct, app_event_type_flags)
157+
Z_APP_EVENT_TYPE_DEFINE(ename, log_fn, ev_info_struct, app_event_type_flags)
157158

158159
/** @brief Verify if an event ID is valid.
159160
*
@@ -163,7 +164,7 @@ static inline bool get_app_event_type_flag(const struct event_type *et,
163164
*
164165
* @param id ID.
165166
*/
166-
#define ASSERT_APP_EVENT_ID(id) \
167+
#define APP_EVENT_ASSERT_ID(id) \
167168
__ASSERT_NO_MSG((id >= _event_type_list_start) && (id < _event_type_list_end))
168169

169170
/** @brief Submit an event.
@@ -185,8 +186,8 @@ static inline bool get_app_event_type_flag(const struct event_type *et,
185186
* @param hook_fn Hook function.
186187
*/
187188
#define APP_EVENT_MANAGER_HOOK_POSTINIT_REGISTER(hook_fn) \
188-
_APP_EVENT_MANAGER_HOOK_POSTINIT_REGISTER(hook_fn, \
189-
_EM_SUBS_PRIO_ID(_EM_SUBS_PRIO_NORMAL))
189+
Z_APP_EVENT_MANAGER_HOOK_POSTINIT_REGISTER(hook_fn, \
190+
Z_APP_EM_SUBS_PRIO_ID(Z_APP_EM_SUBS_PRIO_NORMAL))
190191

191192
/**
192193
* @brief Get the event size
@@ -205,7 +206,7 @@ static inline size_t app_event_manager_event_size(const struct app_event_header
205206
#if IS_ENABLED(CONFIG_APP_EVENT_MANAGER_PROVIDE_EVENT_SIZE)
206207
size_t size = aeh->type_id->struct_size;
207208

208-
if (get_app_event_type_flag(aeh->type_id, APP_EVENT_TYPE_FLAGS_HAS_DYNDATA)) {
209+
if (app_event_get_type_flag(aeh->type_id, APP_EVENT_TYPE_FLAGS_HAS_DYNDATA)) {
209210
size += ((const struct event_dyndata *)
210211
(((const uint8_t *)aeh) + size - sizeof(struct event_dyndata)))->size;
211212
}
@@ -234,7 +235,7 @@ static inline size_t app_event_manager_event_size(const struct app_event_header
234235
*/
235236
#define APP_EVENT_HOOK_ON_SUBMIT_REGISTER_FIRST(hook_fn) \
236237
const struct {} __event_hook_on_submit_first_sub_redefined = {}; \
237-
_APP_EVENT_HOOK_ON_SUBMIT_REGISTER(hook_fn, _EM_MARKER_FIRST_ELEMENT)
238+
Z_APP_EVENT_HOOK_ON_SUBMIT_REGISTER(hook_fn, Z_APP_EM_MARKER_FIRST_ELEMENT)
238239

239240
/**
240241
* @brief Register event hook on submission.
@@ -250,7 +251,7 @@ static inline size_t app_event_manager_event_size(const struct app_event_header
250251
* @param hook_fn Hook function.
251252
*/
252253
#define APP_EVENT_HOOK_ON_SUBMIT_REGISTER(hook_fn) \
253-
_APP_EVENT_HOOK_ON_SUBMIT_REGISTER(hook_fn, _EM_SUBS_PRIO_ID(_EM_SUBS_PRIO_NORMAL))
254+
Z_APP_EVENT_HOOK_ON_SUBMIT_REGISTER(hook_fn, Z_APP_EM_SUBS_PRIO_ID(Z_APP_EM_SUBS_PRIO_NORMAL))
254255

255256
/**
256257
* @brief Register event hook on submission. The hook would be called last.
@@ -269,7 +270,7 @@ static inline size_t app_event_manager_event_size(const struct app_event_header
269270
*/
270271
#define APP_EVENT_HOOK_ON_SUBMIT_REGISTER_LAST(hook_fn) \
271272
const struct {} __event_hook_on_submit_last_sub_redefined = {}; \
272-
_APP_EVENT_HOOK_ON_SUBMIT_REGISTER(hook_fn, _EM_MARKER_FINAL_ELEMENT)
273+
Z_APP_EVENT_HOOK_ON_SUBMIT_REGISTER(hook_fn, Z_APP_EM_MARKER_FINAL_ELEMENT)
273274

274275
/**
275276
* @brief Register event hook on the start of event processing. The hook would be called first.
@@ -282,7 +283,7 @@ static inline size_t app_event_manager_event_size(const struct app_event_header
282283
*/
283284
#define APP_EVENT_HOOK_PREPROCESS_REGISTER_FIRST(hook_fn) \
284285
const struct {} __event_hook_preprocess_first_sub_redefined = {}; \
285-
_APP_EVENT_HOOK_PREPROCESS_REGISTER(hook_fn, _EM_MARKER_FIRST_ELEMENT)
286+
Z_APP_EVENT_HOOK_PREPROCESS_REGISTER(hook_fn, Z_APP_EM_MARKER_FIRST_ELEMENT)
286287

287288
/**
288289
* @brief Register event hook on the start of event processing.
@@ -293,7 +294,7 @@ static inline size_t app_event_manager_event_size(const struct app_event_header
293294
* @param hook_fn Hook function.
294295
*/
295296
#define APP_EVENT_HOOK_PREPROCESS_REGISTER(hook_fn) \
296-
_APP_EVENT_HOOK_PREPROCESS_REGISTER(hook_fn, _EM_SUBS_PRIO_ID(_EM_SUBS_PRIO_NORMAL))
297+
Z_APP_EVENT_HOOK_PREPROCESS_REGISTER(hook_fn, Z_APP_EM_SUBS_PRIO_ID(Z_APP_EM_SUBS_PRIO_NORMAL))
297298

298299
/**
299300
* @brief Register event hook on the start of event processing. The hook would be called last.
@@ -307,7 +308,7 @@ static inline size_t app_event_manager_event_size(const struct app_event_header
307308
*/
308309
#define APP_EVENT_HOOK_PREPROCESS_REGISTER_LAST(hook_fn) \
309310
const struct {} __event_hook_preprocess_last_sub_redefined = {}; \
310-
_APP_EVENT_HOOK_PREPROCESS_REGISTER(hook_fn, _EM_MARKER_FINAL_ELEMENT)
311+
Z_APP_EVENT_HOOK_PREPROCESS_REGISTER(hook_fn, Z_APP_EM_MARKER_FINAL_ELEMENT)
311312

312313
/**
313314
* @brief Register event hook on the end of event processing. The hook would be called first.
@@ -321,7 +322,7 @@ static inline size_t app_event_manager_event_size(const struct app_event_header
321322
*/
322323
#define APP_EVENT_HOOK_POSTPROCESS_REGISTER_FIRST(hook_fn) \
323324
const struct {} __event_hook_postprocess_first_sub_redefined = {}; \
324-
_APP_EVENT_HOOK_POSTPROCESS_REGISTER(hook_fn, _EM_MARKER_FIRST_ELEMENT)
325+
Z_APP_EVENT_HOOK_POSTPROCESS_REGISTER(hook_fn, Z_APP_EM_MARKER_FIRST_ELEMENT)
325326

326327
/**
327328
* @brief Register event hook on the end of event processing.
@@ -332,8 +333,8 @@ static inline size_t app_event_manager_event_size(const struct app_event_header
332333
* @param hook_fn Hook function.
333334
*/
334335
#define APP_EVENT_HOOK_POSTPROCESS_REGISTER(hook_fn) \
335-
_APP_EVENT_HOOK_POSTPROCESS_REGISTER(hook_fn, \
336-
_EM_SUBS_PRIO_ID(_EM_SUBS_PRIO_NORMAL))
336+
Z_APP_EVENT_HOOK_POSTPROCESS_REGISTER(hook_fn, \
337+
Z_APP_EM_SUBS_PRIO_ID(Z_APP_EM_SUBS_PRIO_NORMAL))
337338

338339
/**
339340
* @brief Register event hook on the end of event processing. The hook would be called last.
@@ -345,9 +346,9 @@ static inline size_t app_event_manager_event_size(const struct app_event_header
345346
*
346347
* @param hook_fn Hook function.
347348
*/
348-
#define APP_EVENT_HOOK_POSTPROCESS_REGISTER_LAST(hook_fn) \
349-
const struct {} __event_hook_postprocess_last_sub_redefined = {}; \
350-
_APP_EVENT_HOOK_POSTPROCESS_REGISTER(hook_fn, _EM_MARKER_FINAL_ELEMENT)
349+
#define APP_EVENT_HOOK_POSTPROCESS_REGISTER_LAST(hook_fn) \
350+
const struct {} __event_hook_postprocess_last_sub_redefined = {}; \
351+
Z_APP_EVENT_HOOK_POSTPROCESS_REGISTER(hook_fn, Z_APP_EM_MARKER_FINAL_ELEMENT)
351352

352353

353354
/** @brief Initialize the Application Event Manager.
@@ -383,7 +384,8 @@ void app_event_manager_free(void *addr);
383384
*
384385
* This helper macro simplifies event logging.
385386
*
386-
* @param aeh Pointer to the application event header of the event that is processed by app_event_manager.
387+
* @param aeh Pointer to the application event header of the event that is
388+
* processed by app_event_manager.
387389
* @param ... `printf`- like format string and variadic list of arguments corresponding to
388390
* the format string.
389391
*/
@@ -408,7 +410,7 @@ void app_event_manager_free(void *addr);
408410
* In case no flags should be set leave it empty.
409411
*/
410412
#define APP_EVENT_FLAGS_CREATE(...) \
411-
(FOR_EACH_NONEMPTY_TERM(_EVENT_FLAGS_JOIN, (|), __VA_ARGS__) 0)
413+
(FOR_EACH_NONEMPTY_TERM(Z_APP_EVENT_FLAGS_JOIN, (|), __VA_ARGS__) 0)
412414

413415

414416
#ifdef __cplusplus

0 commit comments

Comments
 (0)