Loading...
Searching...
No Matches
callback.h File Reference

Provides a callback-with-argument event type. More...

Detailed Description

Provides a callback-with-argument event type.

Example:

void callback(void *arg)
{
printf("%s called with arg %p\n", __func__, arg);
}
[...]
event_callback_t event_callback = EVENT_CALLBACK_INIT(callback, 0x12345678);
event_post(&queue, &event_callback);
#define EVENT_CALLBACK_INIT(_cb, _arg)
Callback Event static initializer.
Definition callback.h:116
#define printf(...)
A wrapper for the printf() function that passes arguments through unmodified, but fails to compile if...
Definition stdio.h:60
void event_post(event_queue_t *queue, event_t *event)
Queue an event.
Callback Event structure definition.
Definition callback.h:49

Event Callback API

Author
Kaspar Schleiser kaspa.nosp@m.r@sc.nosp@m.hleis.nosp@m.er.d.nosp@m.e

Definition in file callback.h.

#include <assert.h>
#include "event.h"
+ Include dependency graph for callback.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  event_callback_t
 Callback Event structure definition. More...
 
#define EVENT_CALLBACK_INIT(_cb, _arg)
 Callback Event static initializer.
 
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.
 
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.
 
void _event_callback_handler (event_t *event)
 event callback handler function (used internally)
 

Macro Definition Documentation

◆ EVENT_CALLBACK_INIT

#define EVENT_CALLBACK_INIT (   _cb,
  _arg 
)
Value:
{ \
.super.handler = _event_callback_handler, \
.callback = _cb, \
.arg = (void *)_arg \
}
void _event_callback_handler(event_t *event)
event callback handler function (used internally)

Callback Event static initializer.

Parameters
[in]_cbcallback function to set
[in]_argarguments to set

Definition at line 116 of file callback.h.

Function Documentation

◆ event_callback_init()

void event_callback_init ( event_callback_t event_callback,
void(*)(void *)  callback,
void *  arg 
)

event callback initialization function

Parameters
[out]event_callbackobject to initialize
[in]callbackcallback to set up
[in]argcallback argument to set up

◆ event_callback_oneshot()

static void event_callback_oneshot ( event_callback_t event,
event_queue_t queue,
void(*)(void *)  callback,
void *  arg 
)
inlinestatic

Generate a one-shot callback event on queue.

This will initialize event and post it immediately

Parameters
[in]eventevent_callback object to initialize
[in]queuequeue that the event will be added to
[in]callbackcallback to set up
[in]argcallback argument to set up

Definition at line 93 of file callback.h.

◆ event_callback_post()

static void event_callback_post ( event_queue_t queue,
event_callback_t event 
)
inlinestatic

Queue an event.

The given event will be posted on the given queue. If the event is already queued when calling this function, the event will not be touched and remain in the previous position on the queue. So reposting an event while it is already on the queue will have no effect.

Precondition
queue should be initialized
Parameters
[in]queueevent queue to queue event in
[in]eventevent to queue in event queue

Definition at line 77 of file callback.h.