spa: use static inline for interfaces instead of macro

It gives better typechecking and a path to make a library of functions.
This commit is contained in:
Wim Taymans 2024-11-19 19:57:37 +01:00
parent 5e0e1204d7
commit 84bd4b7ea9
32 changed files with 1069 additions and 563 deletions

View file

@ -79,29 +79,27 @@ struct spa_dbus_connection {
void *data);
};
#define spa_dbus_connection_call(c,method,vers,...) \
({ \
if (SPA_LIKELY(SPA_CALLBACK_CHECK(c,method,vers))) \
c->method((c), ## __VA_ARGS__); \
})
#define spa_dbus_connection_call_vp(c,method,vers,...) \
({ \
void *_res = NULL; \
if (SPA_LIKELY(SPA_CALLBACK_CHECK(c,method,vers))) \
_res = c->method((c), ## __VA_ARGS__); \
_res; \
})
/** \copydoc spa_dbus_connection.get
* \sa spa_dbus_connection.get */
#define spa_dbus_connection_get(c) spa_dbus_connection_call_vp(c,get,0)
static inline void *spa_dbus_connection_get(struct spa_dbus_connection *conn)
{
return spa_api_func_r(void *, NULL, conn, get, 0);
}
/** \copydoc spa_dbus_connection.destroy
* \sa spa_dbus_connection.destroy */
#define spa_dbus_connection_destroy(c) spa_dbus_connection_call(c,destroy,0)
static inline void spa_dbus_connection_destroy(struct spa_dbus_connection *conn)
{
spa_api_func_v(conn, destroy, 0);
}
/** \copydoc spa_dbus_connection.add_listener
* \sa spa_dbus_connection.add_listener */
#define spa_dbus_connection_add_listener(c,...) spa_dbus_connection_call(c,add_listener,1,__VA_ARGS__)
static inline void spa_dbus_connection_add_listener(struct spa_dbus_connection *conn,
struct spa_hook *listener,
const struct spa_dbus_connection_events *events,
void *data)
{
spa_api_func_v(conn, add_listener, 1, listener, events, data);
}
struct spa_dbus_methods {
#define SPA_VERSION_DBUS_METHODS 0
@ -129,11 +127,8 @@ struct spa_dbus_methods {
static inline struct spa_dbus_connection *
spa_dbus_get_connection(struct spa_dbus *dbus, enum spa_dbus_type type)
{
struct spa_dbus_connection *res = NULL;
spa_interface_call_res(&dbus->iface,
struct spa_dbus_methods, res,
get_connection, 0, type);
return res;
return spa_api_method_r(struct spa_dbus_connection *, NULL,
spa_dbus, &dbus->iface, get_connection, 0, type);
}
/**