diff options
author | Wim Taymans <wtaymans@redhat.com> | 2019-05-14 18:04:34 +0200 |
---|---|---|
committer | Wim Taymans <wtaymans@redhat.com> | 2019-05-14 18:04:34 +0200 |
commit | e6c42d3324fe91b5867bafa1b2c6d3b1e7f73cc2 (patch) | |
tree | b864d74e7fd71f4647a182648d7c0fa5b7faff44 /spa/include | |
parent | 674f3e197e9209df1f27fb6f4f1abc4f5cff3090 (diff) |
hook: add option to call hook with return value
Diffstat (limited to 'spa/include')
-rw-r--r-- | spa/include/spa/utils/hook.h | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/spa/include/spa/utils/hook.h b/spa/include/spa/utils/hook.h index 4ff379d2..3927a59e 100644 --- a/spa/include/spa/utils/hook.h +++ b/spa/include/spa/utils/hook.h @@ -53,6 +53,8 @@ struct spa_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) { @@ -110,10 +112,17 @@ spa_hook_list_join(struct spa_hook_list *list, #define spa_hook_call(hook,type,method,vers,...) \ ({ \ - const type *cb = hook->funcs; \ - if (cb && cb->version >= vers && cb->method) { \ - cb->method(hook->data, ## __VA_ARGS__); \ - } \ + const type *cb = (hook)->funcs; \ + if (cb && cb->version >= vers && cb->method) \ + cb->method((hook)->data, ## __VA_ARGS__); \ +}) + +#define spa_hook_call_res(hook,type,res,method,vers,...) \ +({ \ + const type *cb = (hook)->funcs; \ + if (cb && cb->version >= vers && cb->method) \ + res = cb->method((hook)->data, ## __VA_ARGS__); \ + res; \ }) #define spa_hook_list_call_simple(l,type,method,vers,...) \ |