summaryrefslogtreecommitdiff
path: root/spa/include
diff options
context:
space:
mode:
authorWim Taymans <wtaymans@redhat.com>2019-05-15 12:17:52 +0200
committerWim Taymans <wtaymans@redhat.com>2019-05-15 12:17:52 +0200
commit448c1937adb1f15fe14e7262b2625431998b1dc3 (patch)
tree5e9568a632d697258cee58fb2edf9dae27c5a55f /spa/include
parent6ee192dff5a19f95b25b5eaf11be42cf7b9990b5 (diff)
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.
Diffstat (limited to 'spa/include')
-rw-r--r--spa/include/spa/graph/graph.h6
-rw-r--r--spa/include/spa/monitor/monitor.h6
-rw-r--r--spa/include/spa/node/node.h10
-rw-r--r--spa/include/spa/pod/builder.h6
-rw-r--r--spa/include/spa/utils/hook.h45
5 files changed, 39 insertions, 34 deletions
diff --git a/spa/include/spa/graph/graph.h b/spa/include/spa/graph/graph.h
index 068b47ac..a9075413 100644
--- a/spa/include/spa/graph/graph.h
+++ b/spa/include/spa/graph/graph.h
@@ -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
diff --git a/spa/include/spa/monitor/monitor.h b/spa/include/spa/monitor/monitor.h
index f7f7da2b..605f8913 100644
--- a/spa/include/spa/monitor/monitor.h
+++ b/spa/include/spa/monitor/monitor.h
@@ -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; \
})
diff --git a/spa/include/spa/node/node.h b/spa/include/spa/node/node.h
index ba7fc317..19fad83d 100644
--- a/spa/include/spa/node/node.h
+++ b/spa/include/spa/node/node.h
@@ -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)
diff --git a/spa/include/spa/pod/builder.h b/spa/include/spa/pod/builder.h
index eb57b5d8..9be8d3f3 100644
--- a/spa/include/spa/pod/builder.h
+++ b/spa/include/spa/pod/builder.h
@@ -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)
diff --git a/spa/include/spa/utils/hook.h b/spa/include/spa/utils/hook.h
index f29f42f7..ea461de0 100644
--- a/spa/include/spa/utils/hook.h
+++ b/spa/include/spa/utils/hook.h
@@ -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; \