Skip to content

Commit 31c13c8

Browse files
dcpleungcarlescufi
authored andcommitted
logging: backend: add event notification support
This adds an API for backends to support event notification. Signed-off-by: Daniel Leung <[email protected]>
1 parent eda0bef commit 31c13c8

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

include/zephyr/logging/log_backend.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,23 @@ extern "C" {
2626
/* Forward declaration of the log_backend type. */
2727
struct log_backend;
2828

29+
30+
/**
31+
* @brief Backend events
32+
*/
33+
enum log_backend_evt {
34+
/** @brief Maximum number of backend events */
35+
LOG_BACKEND_EVT_MAX,
36+
};
37+
38+
/**
39+
* @brief Argument(s) for backend events.
40+
*/
41+
union log_backend_evt_arg {
42+
/** @brief Unspecified argument(s). */
43+
void *raw;
44+
};
45+
2946
/**
3047
* @brief Logger backend API.
3148
*/
@@ -39,6 +56,10 @@ struct log_backend_api {
3956
int (*is_ready)(const struct log_backend *const backend);
4057
int (*format_set)(const struct log_backend *const backend,
4158
uint32_t log_type);
59+
60+
void (*notify)(const struct log_backend *const backend,
61+
enum log_backend_evt event,
62+
union log_backend_evt_arg *arg);
4263
};
4364

4465
/**
@@ -297,6 +318,24 @@ static inline int log_backend_format_set(const struct log_backend *backend, uint
297318
return backend->api->format_set(backend, log_type);
298319
}
299320

321+
/**
322+
* @brief Notify a backend of an event.
323+
*
324+
* @param backend Pointer to the backend instance.
325+
* @param event Event to be notified.
326+
* @param arg Pointer to the argument(s).
327+
*/
328+
static inline void log_backend_notify(const struct log_backend *const backend,
329+
enum log_backend_evt event,
330+
union log_backend_evt_arg *arg)
331+
{
332+
__ASSERT_NO_MSG(backend != NULL);
333+
334+
if (backend->api->notify) {
335+
backend->api->notify(backend, event, arg);
336+
}
337+
}
338+
300339
/**
301340
* @}
302341
*/

0 commit comments

Comments
 (0)