A SPA Hook is a data structure to keep track of callbacks.
More...
|
#define | spa_hook_list_call_simple(l, type, method, vers, ...) |
|
#define | spa_hook_list_do_call(l, start, type, method, vers, once, ...) |
| Call all hooks in a list, starting from the given one and optionally stopping after calling the first non-NULL function, returns the number of methods called. More...
|
|
#define | spa_hook_list_call(l, t, m, v, ...) spa_hook_list_do_call(l,NULL,t,m,v,false,##__VA_ARGS__) |
| Call the method named m for each element in list l. More...
|
|
#define | spa_hook_list_call_once(l, t, m, v, ...) spa_hook_list_do_call(l,NULL,t,m,v,true,##__VA_ARGS__) |
| Call the method named m for each element in list l, stopping after the first invocation. More...
|
|
#define | spa_hook_list_call_start(l, s, t, m, v, ...) spa_hook_list_do_call(l,s,t,m,v,false,##__VA_ARGS__) |
|
#define | spa_hook_list_call_once_start(l, s, t, m, v, ...) spa_hook_list_do_call(l,s,t,m,v,true,##__VA_ARGS__) |
|
|
static void | spa_hook_list_init (struct spa_hook_list *list) |
| Initialize a hook list to the empty list. More...
|
|
static bool | spa_hook_list_is_empty (struct spa_hook_list *list) |
|
static void | spa_hook_list_append (struct spa_hook_list *list, struct spa_hook *hook, const void *funcs, void *data) |
| Append a hook. More...
|
|
static void | spa_hook_list_prepend (struct spa_hook_list *list, struct spa_hook *hook, const void *funcs, void *data) |
| Prepend a hook. More...
|
|
static void | spa_hook_remove (struct spa_hook *hook) |
| Remove a hook. More...
|
|
static void | spa_hook_list_clean (struct spa_hook_list *list) |
| Remove all hooks from the list. More...
|
|
static void | spa_hook_list_isolate (struct spa_hook_list *list, struct spa_hook_list *save, struct spa_hook *hook, const void *funcs, void *data) |
|
static void | spa_hook_list_join (struct spa_hook_list *list, struct spa_hook_list *save) |
|
A SPA Hook is a data structure to keep track of callbacks.
It is similar to the Interfaces and typically used where an implementation allows for multiple external callback functions. For example, an implementation may use a hook list to implement signals with each caller using a hook to register callbacks to be invoked on those signals.
The below (pseudo)code is a minimal example outlining the use of hooks:
#define VERSION_BAR_EVENTS 0
struct bar_events {
uint32_t version;
void (*boom)(void *data, const char *msg);
};
struct party {
};
void party_add_event_listener(
struct party *p,
struct spa_hook *listener,
const struct bar_events *events, void *data)
{
}
static void party_on(struct party *p)
{
struct bar_events,
boom,
0,
"party on, wayne"
);
}
#define spa_hook_list_call(l, t, m, v,...)
Call the method named m for each element in list l.
Definition: hook.h:461
static void spa_hook_list_append(struct spa_hook_list *list, struct spa_hook *hook, const void *funcs, void *data)
Append a hook.
Definition: hook.h:372
A list of hooks.
Definition: hook.h:340
A hook, contains the structure with functions and the data passed to the functions.
Definition: hook.h:351
In the caller, the hooks can be used like this:
static void boom_cb(void *data, const char *msg) {
printf("%s", msg);
}
static const struct bar_events events = {
.version = VERSION_BAR_EVENTS,
.boom = boom_cb,
};
void main(void) {
void *userdata = whatever;
struct party *p = start_the_party();
party_add_event_listener(p, &hook, &events, userdata);
mainloop();
return 0;
}
◆ spa_hook_list_call_simple
#define spa_hook_list_call_simple |
( |
|
l, |
|
|
|
type, |
|
|
|
method, |
|
|
|
vers, |
|
|
|
... |
|
) |
| |
◆ spa_hook_list_do_call
#define spa_hook_list_do_call |
( |
|
l, |
|
|
|
start, |
|
|
|
type, |
|
|
|
method, |
|
|
|
vers, |
|
|
|
once, |
|
|
|
... |
|
) |
| |
Call all hooks in a list, starting from the given one and optionally stopping after calling the first non-NULL function, returns the number of methods called.
◆ spa_hook_list_call
#define spa_hook_list_call |
( |
|
l, |
|
|
|
t, |
|
|
|
m, |
|
|
|
v, |
|
|
|
... |
|
) |
| spa_hook_list_do_call(l,NULL,t,m,v,false,##__VA_ARGS__) |
Call the method named m for each element in list l.
t specifies the type of the callback struct.
◆ spa_hook_list_call_once
#define spa_hook_list_call_once |
( |
|
l, |
|
|
|
t, |
|
|
|
m, |
|
|
|
v, |
|
|
|
... |
|
) |
| spa_hook_list_do_call(l,NULL,t,m,v,true,##__VA_ARGS__) |
Call the method named m for each element in list l, stopping after the first invocation.
t specifies the type of the callback struct.
◆ spa_hook_list_call_start
#define spa_hook_list_call_start |
( |
|
l, |
|
|
|
s, |
|
|
|
t, |
|
|
|
m, |
|
|
|
v, |
|
|
|
... |
|
) |
| spa_hook_list_do_call(l,s,t,m,v,false,##__VA_ARGS__) |
◆ spa_hook_list_call_once_start
#define spa_hook_list_call_once_start |
( |
|
l, |
|
|
|
s, |
|
|
|
t, |
|
|
|
m, |
|
|
|
v, |
|
|
|
... |
|
) |
| spa_hook_list_do_call(l,s,t,m,v,true,##__VA_ARGS__) |
◆ spa_hook_list_init()
◆ spa_hook_list_is_empty()
static bool spa_hook_list_is_empty |
( |
struct spa_hook_list * |
list | ) |
|
|
inlinestatic |
◆ spa_hook_list_append()
static void spa_hook_list_append |
( |
struct spa_hook_list * |
list, |
|
|
struct spa_hook * |
hook, |
|
|
const void * |
funcs, |
|
|
void * |
data |
|
) |
| |
|
inlinestatic |
◆ spa_hook_list_prepend()
static void spa_hook_list_prepend |
( |
struct spa_hook_list * |
list, |
|
|
struct spa_hook * |
hook, |
|
|
const void * |
funcs, |
|
|
void * |
data |
|
) |
| |
|
inlinestatic |
◆ spa_hook_remove()
static void spa_hook_remove |
( |
struct spa_hook * |
hook | ) |
|
|
inlinestatic |
◆ spa_hook_list_clean()
Remove all hooks from the list.
◆ spa_hook_list_isolate()
◆ spa_hook_list_join()