callback.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2017 Inria
3  * SPDX-FileCopyrightText: 2017 Freie Universität Berlin
4  * SPDX-FileCopyrightText: 2017 Kaspar Schleiser <kaspar@schleiser.de>
5  * SPDX-License-Identifier: LGPL-2.1-only
6  */
7 
8 #pragma once
9 
35 #include <assert.h>
36 #include "event.h"
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
45 typedef struct {
47  void (*callback)(void*);
48  void *arg;
50 
58 void event_callback_init(event_callback_t *event_callback, void (*callback)(void *), void *arg);
59 
74 {
75  assert(event->callback);
76  event_post(queue, &event->super);
77 }
78 
90  event_queue_t *queue,
91  void (*callback)(void *), void *arg)
92 {
93  event_callback_init(event, callback, arg);
94  event_post(queue, &event->super);
95 }
96 
105 
112 #define EVENT_CALLBACK_INIT(_cb, _arg) \
113  { \
114  .super.handler = _event_callback_handler, \
115  .callback = _cb, \
116  .arg = (void *)_arg \
117  }
118 
119 #ifdef __cplusplus
120 }
121 #endif
POSIX.1-2008 compliant version of the assert macro.
#define assert(cond)
abort the program if assertion is false
Definition: assert.h:143
static void event_callback_oneshot(event_callback_t *event, event_queue_t *queue, void(*callback)(void *), void *arg)
Generate a one-shot callback event on queue.
Definition: callback.h:89
void event_callback_init(event_callback_t *event_callback, void(*callback)(void *), void *arg)
event callback initialization function
static void event_callback_post(event_queue_t *queue, event_callback_t *event)
Queue an event.
Definition: callback.h:73
void _event_callback_handler(event_t *event)
event callback handler function (used internally)
void event_post(event_queue_t *queue, event_t *event)
Queue an event.
event queue structure
Definition: event.h:150
Callback Event structure definition.
Definition: callback.h:45
event_t super
event_t structure that gets extended
Definition: callback.h:46
void * arg
callback function argument
Definition: callback.h:48
event structure
Definition: event.h:142