From 68748895ea6278a4213cf04bdc6545fabee1b0d0 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 7 Oct 2021 10:13:06 +0200 Subject: [PATCH] hook: add spa_callbacks_check That does a version and method check on the callbacks. --- spa/include/spa/utils/hook.h | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/spa/include/spa/utils/hook.h b/spa/include/spa/utils/hook.h index 37dfdff51..ed0cea242 100644 --- a/spa/include/spa/utils/hook.h +++ b/spa/include/spa/utils/hook.h @@ -191,6 +191,16 @@ struct spa_interface { SPA_CALLBACK_VERSION_MIN(_f,vers); \ }) +/** + * True if the \a callbacks contains \a method of version + * \a vers, false otherwise + */ +#define spa_callback_check(callbacks,type,method,vers) \ +({ \ + const type *_f = (const type *) (callbacks)->funcs; \ + SPA_CALLBACK_CHECK(_f,method,vers); \ +}) + /** * Invoke method named \a method in the \a callbacks. * The \a method_type defines the type of the method struct. @@ -206,17 +216,24 @@ struct spa_interface { }) /** - * True if the \a iface's \a callbacks are of version \a vers, false otherwise + * True if the \a iface's callbacks are of version \a vers, false otherwise */ -#define spa_interface_callback_version_min(iface,method_type,vers) \ +#define spa_interface_callback_version_min(iface,method_type,vers) \ spa_callback_version_min(&(iface)->cb, method_type, vers) +/** + * True if the \a iface's callback \a method is of version \a vers + * and exists, false otherwise + */ +#define spa_interface_callback_check(iface,method_type,method,vers) \ + spa_callback_check(&(iface)->cb, method_type, method, vers) + /** * Invoke method named \a method in the callbacks on the given interface object. * The \a method_type defines the type of the method struct, not the interface * itself. */ -#define spa_interface_call(iface,method_type,method,vers,...) \ +#define spa_interface_call(iface,method_type,method,vers,...) \ spa_callbacks_call(&(iface)->cb,method_type,method,vers,##__VA_ARGS__) /**