interface: add an interface struct

The interface struct has the type,version and methods of the
interface.
Make spa interfaces extend from spa_interface and make a
separate structure for the methods.
Pass a generic void* as the first argument of methods, like
we don in PipeWire.
Bundle the methods + implementation in a versioned inteface
and use that to invoke methods. This way we can do version
checks on the methods.
Make resource and proxy interfaces that we can can call. We
can then make the core interfaces independent on proxy/resource and
hide them in the lower layers.
Add add_listener method to methods of core interfaces, just
like SPA.
This commit is contained in:
Wim Taymans 2019-05-20 16:11:23 +02:00
parent eb6481efb3
commit ff946e3d4b
85 changed files with 3051 additions and 3000 deletions

View file

@ -29,14 +29,20 @@
extern "C" {
#endif
struct spa_device;
#include <spa/utils/defs.h>
#include <spa/utils/dict.h>
#include <spa/support/plugin.h>
#include <spa/pod/builder.h>
#include <spa/pod/event.h>
/**
* spa_device:
*
* The device interface.
*/
#define SPA_VERSION_DEVICE 0
struct spa_device { struct spa_interface iface; };
struct spa_device_info {
#define SPA_VERSION_DEVICE_INFO 0
uint32_t version;
@ -103,14 +109,12 @@ struct spa_device_events {
};
/**
* spa_device:
*
* The device interface.
* spa_device_methods:
*/
struct spa_device {
/* the version of this device. This can be used to expand this
struct spa_device_methods {
/* the version of the methods. This can be used to expand this
* structure in the future */
#define SPA_VERSION_DEVICE 0
#define SPA_VERSION_DEVICE_METHODS 0
uint32_t version;
/**
@ -128,7 +132,7 @@ struct spa_device {
* \return 0 on success
* < 0 errno on error
*/
int (*add_listener) (struct spa_device *device,
int (*add_listener) (void *object,
struct spa_hook *listener,
const struct spa_device_events *events,
void *data);
@ -157,7 +161,7 @@ struct spa_device {
* -ENOTSUP when there are no parameters
* implemented on \a device
*/
int (*enum_params) (struct spa_device *device, int seq,
int (*enum_params) (void *object, int seq,
uint32_t id, uint32_t index, uint32_t max,
const struct spa_pod *filter);
@ -182,14 +186,24 @@ struct spa_device {
* -ENOTSUP when there are no parameters implemented on \a device
* -ENOENT the parameter is unknown
*/
int (*set_param) (struct spa_device *device,
int (*set_param) (void *object,
uint32_t id, uint32_t flags,
const struct spa_pod *param);
};
#define spa_device_add_listener(d,...) (d)->add_listener((d),__VA_ARGS__)
#define spa_device_enum_params(d,...) (d)->enum_params((d),__VA_ARGS__)
#define spa_device_set_param(d,...) (d)->set_param((d),__VA_ARGS__)
#define spa_device_method(o,method,version,...) \
({ \
int _res = -ENOTSUP; \
struct spa_device *_o = o; \
spa_interface_call_res(&_o->iface, \
struct spa_device_methods, _res, \
method, version, ##__VA_ARGS__); \
_res; \
})
#define spa_device_add_listener(d,...) spa_device_method(d, add_listener, 0, __VA_ARGS__)
#define spa_device_enum_params(d,...) spa_device_method(d, enum_params, 0, __VA_ARGS__)
#define spa_device_set_param(d,...) spa_device_method(d, set_param, 0, __VA_ARGS__)
#ifdef __cplusplus
} /* extern "C" */

View file

@ -29,13 +29,14 @@
extern "C" {
#endif
struct spa_monitor;
#include <spa/utils/defs.h>
#include <spa/utils/dict.h>
#include <spa/pod/event.h>
#include <spa/pod/builder.h>
#define SPA_VERSION_MONITOR 0
struct spa_monitor { struct spa_interface iface; };
enum spa_monitor_event {
SPA_MONITOR_EVENT_Invalid,
SPA_MONITOR_EVENT_Added,
@ -87,14 +88,14 @@ struct spa_monitor_callbacks {
};
/**
* spa_monitor:
* spa_monitor_methods:
*
* The device monitor interface.
* The device monitor methods.
*/
struct spa_monitor {
struct spa_monitor_methods {
/* the version of this monitor. This can be used to expand this
* structure in the future */
#define SPA_VERSION_MONITOR 0
#define SPA_VERSION_MONITOR_METHODS 0
uint32_t version;
/**
@ -108,12 +109,21 @@ struct spa_monitor {
* \return 0 on success
* < 0 errno on error
*/
int (*set_callbacks) (struct spa_monitor *monitor,
int (*set_callbacks) (void *object,
const struct spa_monitor_callbacks *callbacks,
void *data);
};
#define spa_monitor_set_callbacks(m,...) (m)->set_callbacks((m),__VA_ARGS__)
static inline int spa_monitor_set_callbacks(struct spa_monitor *m,
const struct spa_monitor_callbacks *callbacks, void *data)
{
int res = -ENOTSUP;
spa_interface_call_res(&m->iface,
struct spa_monitor_methods, res, set_callbacks, 0,
callbacks, data);
return res;
}
#ifdef __cplusplus
} /* extern "C" */