11#ifndef _APP_EVENT_MANAGER_H_
12#define _APP_EVENT_MANAGER_H_
22#include <zephyr/kernel.h>
23#include <zephyr/types.h>
24#include <zephyr/sys/__assert.h>
25#include <zephyr/logging/log.h>
27#include <app_event_manager_priv.h>
40typedef bool (*
cb_fn)(
const struct app_event_header *aeh);
73 return (et->flags & BIT(flag)) != 0;
84#define APP_EVENT_ID(ename) _EVENT_ID(ename)
91#define APP_EVENT_LISTENER(lname, cb_fn) _APP_EVENT_LISTENER(lname, cb_fn)
100#define APP_EVENT_SUBSCRIBE_FIRST(lname, ename) \
101 _APP_EVENT_SUBSCRIBE(lname, ename, _APP_EM_MARKER_FIRST_ELEMENT); \
102 const struct {} _CONCAT(_CONCAT(__event_subscriber_, ename), first_sub_redefined) = {}
111#define APP_EVENT_SUBSCRIBE_EARLY(lname, ename) \
112 _APP_EVENT_SUBSCRIBE(lname, ename, _APP_EM_SUBS_PRIO_ID(_APP_EM_SUBS_PRIO_EARLY))
121#define APP_EVENT_SUBSCRIBE(lname, ename) \
122 _APP_EVENT_SUBSCRIBE(lname, ename, _APP_EM_SUBS_PRIO_ID(_APP_EM_SUBS_PRIO_NORMAL))
131#define APP_EVENT_SUBSCRIBE_FINAL(lname, ename) \
132 _APP_EVENT_SUBSCRIBE(lname, ename, _APP_EM_MARKER_FINAL_ELEMENT); \
133 const struct {} _CONCAT(_CONCAT(__event_subscriber_, ename), final_sub_redefined) = {}
143#define APP_EVENT_TYPE_DECLARE(ename) _APP_EVENT_TYPE_DECLARE(ename)
154#define APP_EVENT_TYPE_DYNDATA_DECLARE(ename) _APP_EVENT_TYPE_DYNDATA_DECLARE(ename)
177#define APP_EVENT_TYPE_DEFINE(ename, log_fn, ev_info_struct, app_event_type_flags) \
178 _APP_EVENT_TYPE_DEFINE(ename, log_fn, ev_info_struct, app_event_type_flags)
189#define APP_EVENT_ASSERT_ID(id) \
190 __ASSERT_NO_MSG((id >= _event_type_list_start) && (id < _event_type_list_end))
198#define APP_EVENT_SUBMIT(event) _event_submit(&event->header)
210#define APP_EVENT_MANAGER_HOOK_POSTINIT_REGISTER(hook_fn) \
211 _APP_EVENT_MANAGER_HOOK_POSTINIT_REGISTER(hook_fn, \
212 _APP_EM_SUBS_PRIO_ID(_APP_EM_SUBS_PRIO_NORMAL))
228#if IS_ENABLED(CONFIG_APP_EVENT_MANAGER_PROVIDE_EVENT_SIZE)
229 size_t size = aeh->type_id->struct_size;
232 size += ((
const struct event_dyndata *)
233 (((
const uint8_t *)aeh) + size -
sizeof(
struct event_dyndata)))->size;
237 __ASSERT_NO_MSG(
false);
258#define APP_EVENT_HOOK_ON_SUBMIT_REGISTER_FIRST(hook_fn) \
259 const struct {} __event_hook_on_submit_first_sub_redefined = {}; \
260 _APP_EVENT_HOOK_ON_SUBMIT_REGISTER(hook_fn, _APP_EM_MARKER_FIRST_ELEMENT)
275#define APP_EVENT_HOOK_ON_SUBMIT_REGISTER(hook_fn) \
276 _APP_EVENT_HOOK_ON_SUBMIT_REGISTER(hook_fn, _APP_EM_SUBS_PRIO_ID(_APP_EM_SUBS_PRIO_NORMAL))
293#define APP_EVENT_HOOK_ON_SUBMIT_REGISTER_LAST(hook_fn) \
294 const struct {} __event_hook_on_submit_last_sub_redefined = {}; \
295 _APP_EVENT_HOOK_ON_SUBMIT_REGISTER(hook_fn, _APP_EM_MARKER_FINAL_ELEMENT)
306#define APP_EVENT_HOOK_PREPROCESS_REGISTER_FIRST(hook_fn) \
307 const struct {} __event_hook_preprocess_first_sub_redefined = {}; \
308 _APP_EVENT_HOOK_PREPROCESS_REGISTER(hook_fn, _APP_EM_MARKER_FIRST_ELEMENT)
318#define APP_EVENT_HOOK_PREPROCESS_REGISTER(hook_fn) \
319 _APP_EVENT_HOOK_PREPROCESS_REGISTER(hook_fn, _APP_EM_SUBS_PRIO_ID(_APP_EM_SUBS_PRIO_NORMAL))
331#define APP_EVENT_HOOK_PREPROCESS_REGISTER_LAST(hook_fn) \
332 const struct {} __event_hook_preprocess_last_sub_redefined = {}; \
333 _APP_EVENT_HOOK_PREPROCESS_REGISTER(hook_fn, _APP_EM_MARKER_FINAL_ELEMENT)
345#define APP_EVENT_HOOK_POSTPROCESS_REGISTER_FIRST(hook_fn) \
346 const struct {} __event_hook_postprocess_first_sub_redefined = {}; \
347 _APP_EVENT_HOOK_POSTPROCESS_REGISTER(hook_fn, _APP_EM_MARKER_FIRST_ELEMENT)
357#define APP_EVENT_HOOK_POSTPROCESS_REGISTER(hook_fn) \
358 _APP_EVENT_HOOK_POSTPROCESS_REGISTER(hook_fn, \
359 _APP_EM_SUBS_PRIO_ID(_APP_EM_SUBS_PRIO_NORMAL))
371#define APP_EVENT_HOOK_POSTPROCESS_REGISTER_LAST(hook_fn) \
372 const struct {} __event_hook_postprocess_last_sub_redefined = {}; \
373 _APP_EVENT_HOOK_POSTPROCESS_REGISTER(hook_fn, _APP_EM_MARKER_FINAL_ELEMENT)
415#define APP_EVENT_MANAGER_LOG(aeh, ...) do { \
416 LOG_MODULE_DECLARE(app_event_manager, CONFIG_APP_EVENT_MANAGER_LOG_LEVEL); \
417 if (IS_ENABLED(CONFIG_APP_EVENT_MANAGER_LOG_EVENT_TYPE)) { \
418 LOG_INF("e:%s " GET_ARG_N(1, __VA_ARGS__), aeh->type_id->name \
419 COND_CODE_0(NUM_VA_ARGS_LESS_1(__VA_ARGS__), \
421 (, GET_ARGS_LESS_N(1, __VA_ARGS__)) \
424 LOG_INF(__VA_ARGS__); \
435 #define APP_EVENT_FLAGS_CREATE(...) \
436 (FOR_EACH_NONEMPTY_TERM(_APP_EVENT_FLAGS_JOIN, (|), __VA_ARGS__) 0)
void * app_event_manager_alloc(size_t size)
Allocate event.
int app_event_manager_init(void)
Initialize the Application Event Manager.
static bool app_event_get_type_flag(const struct event_type *et, enum app_event_type_flags flag)
Get event type flag's value.
Definition app_event_manager.h:70
bool(* cb_fn)(const struct app_event_header *aeh)
Pointer to the event handler function.
Definition app_event_manager.h:40
app_event_type_flags
List of bits in event type flags.
Definition app_event_manager.h:44
@ APP_EVENT_TYPE_FLAGS_USER_SETTABLE_START
Definition app_event_manager.h:52
@ APP_EVENT_TYPE_FLAGS_INIT_LOG_ENABLE
Definition app_event_manager.h:56
@ APP_EVENT_TYPE_FLAGS_HAS_DYNDATA
Definition app_event_manager.h:50
@ APP_EVENT_TYPE_FLAGS_USER_DEFINED_START
Definition app_event_manager.h:61
@ APP_EVENT_TYPE_FLAGS_COUNT
Definition app_event_manager.h:59
@ APP_EVENT_TYPE_FLAGS_SYSTEM_START
Definition app_event_manager.h:46
static size_t app_event_manager_event_size(const struct app_event_header *aeh)
Get the event size.
Definition app_event_manager.h:226
void app_event_manager_free(void *addr)
Free memory occupied by the event.