hook: separate spa_callbacks from the hook

Make a spa_callbacks with just the functions and data and use this
in the hook and objects.
This commit is contained in:
Wim Taymans 2019-05-15 12:17:52 +02:00
parent 6ee192dff5
commit 448c1937ad
28 changed files with 97 additions and 84 deletions

View file

@ -103,14 +103,14 @@ struct spa_graph_node {
struct spa_graph_state *state; /**< state of the node */
struct spa_graph_link graph_link; /**< link in graph */
struct spa_graph *subgraph; /**< subgraph or NULL */
struct spa_hook callbacks;
struct spa_callbacks callbacks;
struct spa_list sched_link; /**< link for scheduler */
};
#define spa_graph_node_call(n,method,version,...) \
({ \
int __res = 0; \
spa_hook_call_res(&(n)->callbacks, \
spa_callbacks_call_res(&(n)->callbacks, \
struct spa_graph_node_callbacks, __res, \
method, version, ##__VA_ARGS__); \
__res; \
@ -250,7 +250,7 @@ spa_graph_node_set_callbacks(struct spa_graph_node *node,
const struct spa_graph_node_callbacks *callbacks,
void *data)
{
node->callbacks = SPA_HOOK_INIT(callbacks, data);
node->callbacks = SPA_CALLBACKS_INIT(callbacks, data);
}
static inline void

View file

@ -86,11 +86,11 @@ struct spa_monitor_callbacks {
int (*event) (void *data, struct spa_event *event);
};
#define spa_monitor_call(hook,method,version,...) \
#define spa_monitor_call(callbacks,method,version,...) \
({ \
int __res = 0; \
spa_hook_call_res(hook, struct spa_monitor_callbacks, __res, \
method, version, ##__VA_ARGS__); \
spa_callbacks_call_res(callbacks, struct spa_monitor_callbacks, \
__res, method, version, ##__VA_ARGS__); \
__res; \
})

View file

@ -208,12 +208,12 @@ struct spa_node_callbacks {
uint32_t buffer_id);
};
#define spa_node_call(hook,method,version,...) \
#define spa_node_call(callbacks,method,version,...) \
({ \
int __res = 0; \
spa_hook_call_res(hook, struct spa_node_callbacks, __res, \
method, version, ##__VA_ARGS__); \
__res; \
int _res = 0; \
spa_callbacks_call_res(callbacks, struct spa_node_callbacks, \
_res, method, version, ##__VA_ARGS__); \
_res; \
})
#define spa_node_call_ready(hook,s) spa_node_call(hook, ready, 0, s)

View file

@ -57,7 +57,7 @@ struct spa_pod_builder {
uint32_t size;
uint32_t _padding;
struct spa_pod_builder_state state;
struct spa_hook callbacks;
struct spa_callbacks callbacks;
};
#define SPA_POD_BUILDER_INIT(buffer,size) (struct spa_pod_builder){ buffer, size, }
@ -72,7 +72,7 @@ static inline void
spa_pod_builder_set_callbacks(struct spa_pod_builder *builder,
const struct spa_pod_builder_callbacks *callbacks, void *data)
{
builder->callbacks = SPA_HOOK_INIT(callbacks, data);
builder->callbacks = SPA_CALLBACKS_INIT(callbacks, data);
}
static inline void
@ -127,7 +127,7 @@ static inline int spa_pod_builder_raw(struct spa_pod_builder *builder, const voi
if (offset + size > builder->size) {
res = -ENOSPC;
spa_hook_call_res(&builder->callbacks, struct spa_pod_builder_callbacks, res,
spa_callbacks_call_res(&builder->callbacks, struct spa_pod_builder_callbacks, res,
overflow, 0, offset + size);
}
if (res == 0)

View file

@ -42,19 +42,26 @@ struct spa_hook_list {
struct spa_list list;
};
/** Callbacks, contains the structure with functions and the data passed
* to the functions. The structure should also contain a version field that
* is checked. */
struct spa_callbacks {
const void *funcs;
void *data;
};
#define SPA_CALLBACKS_INIT(_funcs,_data) (struct spa_callbacks){ _funcs, _data, }
/** A hook, contains the structure with functions and the data passed
* to the functions. */
struct spa_hook {
struct spa_list link;
const void *funcs;
void *data;
struct spa_callbacks cb;
void *priv; /**< private data for the hook list */
void (*removed) (struct spa_hook *hook);
};
#define SPA_HOOK_INIT(_funcs,_data) (struct spa_hook){ .funcs = _funcs, .data = _data, }
/** Initialize a hook list */
static inline void spa_hook_list_init(struct spa_hook_list *list)
{
@ -66,8 +73,7 @@ static inline void spa_hook_list_append(struct spa_hook_list *list,
struct spa_hook *hook,
const void *funcs, void *data)
{
hook->funcs = funcs;
hook->data = data;
hook->cb = SPA_CALLBACKS_INIT(funcs, data);
spa_list_append(&list->list, &hook->link);
}
@ -76,8 +82,7 @@ static inline void spa_hook_list_prepend(struct spa_hook_list *list,
struct spa_hook *hook,
const void *funcs, void *data)
{
hook->funcs = funcs;
hook->data = data;
hook->cb = SPA_CALLBACKS_INIT(funcs, data);
spa_list_prepend(&list->list, &hook->link);
}
@ -110,18 +115,18 @@ spa_hook_list_join(struct spa_hook_list *list,
spa_list_insert_list(&list->list, &save->list);
}
#define spa_hook_call(hook,type,method,vers,...) \
#define spa_callbacks_call(callbacks,type,method,vers,...) \
({ \
const type *cb = (const type *) (hook)->funcs; \
if (cb && cb->version >= vers && cb->method) \
cb->method((hook)->data, ## __VA_ARGS__); \
const type *_f = (const type *) (callbacks)->funcs; \
if (_f && _f->version >= (vers) && _f->method) \
_f->method((callbacks)->data, ## __VA_ARGS__); \
})
#define spa_hook_call_res(hook,type,res,method,vers,...) \
#define spa_callbacks_call_res(callbacks,type,res,method,vers,...) \
({ \
const type *cb = (const type *) (hook)->funcs; \
if (cb && cb->version >= vers && cb->method) \
res = cb->method((hook)->data, ## __VA_ARGS__); \
const type *_f = (const type *) (callbacks)->funcs; \
if (_f && _f->version >= (vers) && _f->method) \
res = _f->method((callbacks)->data, ## __VA_ARGS__); \
res; \
})
@ -130,7 +135,7 @@ spa_hook_list_join(struct spa_hook_list *list,
struct spa_hook_list *_l = l; \
struct spa_hook *_h, *_t; \
spa_list_for_each_safe(_h, _t, &_l->list, link) \
spa_hook_call(_h,type,method,vers, ## __VA_ARGS__); \
spa_callbacks_call(&_h->cb,type,method,vers, ## __VA_ARGS__); \
})
/** Call all hooks in a list, starting from the given one and optionally stopping
@ -144,9 +149,9 @@ spa_hook_list_join(struct spa_hook_list *list,
int count = 0; \
spa_list_cursor_start(cursor, s, link); \
spa_list_for_each_cursor(ci, cursor, &list->list, link) { \
const type *cb = (const type *)ci->funcs; \
if (cb && cb->version >= vers && cb->method) { \
cb->method(ci->data, ## __VA_ARGS__); \
const type *_f = (const type *)ci->cb.funcs; \
if (_f && _f->version >= (vers) && _f->method) { \
_f->method(ci->cb.data, ## __VA_ARGS__); \
count++; \
if (once) \
break; \