From e6c42d3324fe91b5867bafa1b2c6d3b1e7f73cc2 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 14 May 2019 18:04:34 +0200 Subject: [PATCH] hook: add option to call hook with return value --- spa/include/spa/utils/hook.h | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/spa/include/spa/utils/hook.h b/spa/include/spa/utils/hook.h index 4ff379d23..3927a59ef 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,...) \