Loading...
Searching...
No Matches
callback.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2017 Inria
3 * 2017 Freie Universität Berlin
4 * 2017 Kaspar Schleiser <kaspar@schleiser.de>
5 *
6 * This file is subject to the terms and conditions of the GNU Lesser
7 * General Public License v2.1. See the file LICENSE in the top level
8 * directory for more details.
9 */
10
36#ifndef EVENT_CALLBACK_H
37#define EVENT_CALLBACK_H
38
39#include <assert.h>
40#include "event.h"
41
42#ifdef __cplusplus
43extern "C" {
44#endif
45
49typedef struct {
51 void (*callback)(void*);
52 void *arg;
54
62void event_callback_init(event_callback_t *event_callback, void (*callback)(void *), void *arg);
63
78{
79 assert(event->callback);
80 event_post(queue, &event->super);
81}
82
94 event_queue_t *queue,
95 void (*callback)(void *), void *arg)
96{
97 event_callback_init(event, callback, arg);
98 event_post(queue, &event->super);
99}
100
109
116#define EVENT_CALLBACK_INIT(_cb, _arg) \
117 { \
118 .super.handler = _event_callback_handler, \
119 .callback = _cb, \
120 .arg = (void *)_arg \
121 }
122
123#ifdef __cplusplus
124}
125#endif
126#endif /* EVENT_CALLBACK_H */
POSIX.1-2008 compliant version of the assert macro.
#define assert(cond)
abort the program if assertion is false
Definition assert.h:136
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:93
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:77
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:156
Callback Event structure definition.
Definition callback.h:49
event_t super
event_t structure that gets extended
Definition callback.h:50
void * arg
callback function argument
Definition callback.h:52
event structure
Definition event.h:148