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
11#pragma once
12
37
38#include <assert.h>
39#include "event.h"
40
41#ifdef __cplusplus
42extern "C" {
43#endif
44
48typedef struct {
50 void (*callback)(void*);
51 void *arg;
53
61void event_callback_init(event_callback_t *event_callback, void (*callback)(void *), void *arg);
62
77{
78 assert(event->callback);
79 event_post(queue, &event->super);
80}
81
93 event_queue_t *queue,
94 void (*callback)(void *), void *arg)
95{
96 event_callback_init(event, callback, arg);
97 event_post(queue, &event->super);
98}
99
108
115#define EVENT_CALLBACK_INIT(_cb, _arg) \
116 { \
117 .super.handler = _event_callback_handler, \
118 .callback = _cb, \
119 .arg = (void *)_arg \
120 }
121
122#ifdef __cplusplus
123}
124#endif
POSIX.1-2008 compliant version of the assert macro.
#define assert(cond)
abort the program if assertion is false
Definition assert.h:135
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:92
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:76
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.
struct PTRTAG event_queue_t
event queue structure
struct event event_t
event structure forward declaration
Definition event.h:135
Callback Event structure definition.
Definition callback.h:48
void(* callback)(void *)
callback function
Definition callback.h:50
event_t super
event_t structure that gets extended
Definition callback.h:49
void * arg
callback function argument
Definition callback.h:51
event structure
Definition event.h:145