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

@ -256,18 +256,17 @@ static int emit_info(struct impl *this, bool full)
return err;
}
static int impl_add_listener(struct spa_device *device,
static int impl_add_listener(void *object,
struct spa_hook *listener,
const struct spa_device_events *events,
void *data)
{
struct impl *this;
struct impl *this = object;
struct spa_hook_list save;
spa_return_val_if_fail(device != NULL, -EINVAL);
spa_return_val_if_fail(this != NULL, -EINVAL);
spa_return_val_if_fail(events != NULL, -EINVAL);
this = SPA_CONTAINER_OF(device, struct impl, device);
spa_hook_list_isolate(&this->hooks, &save, listener, events, data);
if (events->info || events->object_info)
@ -279,22 +278,20 @@ static int impl_add_listener(struct spa_device *device,
}
static int impl_enum_params(struct spa_device *device, int seq,
static int impl_enum_params(void *object, int seq,
uint32_t id, uint32_t start, uint32_t num,
const struct spa_pod *filter)
{
struct impl *this;
struct impl *this = object;
struct spa_pod *param;
struct spa_pod_builder b = { 0 };
uint8_t buffer[1024];
struct spa_result_device_params result;
uint32_t count = 0;
spa_return_val_if_fail(device != NULL, -EINVAL);
spa_return_val_if_fail(this != NULL, -EINVAL);
spa_return_val_if_fail(num != 0, -EINVAL);
this = SPA_CONTAINER_OF(device, struct impl, device);
result.id = id;
result.next = start;
next:
@ -351,16 +348,14 @@ static int impl_enum_params(struct spa_device *device, int seq,
return 0;
}
static int impl_set_param(struct spa_device *device,
static int impl_set_param(void *object,
uint32_t id, uint32_t flags,
const struct spa_pod *param)
{
struct impl *this;
struct impl *this = object;
int res;
spa_return_val_if_fail(device != NULL, -EINVAL);
this = SPA_CONTAINER_OF(device, struct impl, device);
spa_return_val_if_fail(this != NULL, -EINVAL);
switch (id) {
case SPA_PARAM_Profile:
@ -384,11 +379,11 @@ static int impl_set_param(struct spa_device *device,
return 0;
}
static const struct spa_device impl_device = {
SPA_VERSION_DEVICE,
impl_add_listener,
impl_enum_params,
impl_set_param,
static const struct spa_device_methods impl_device = {
SPA_VERSION_DEVICE_METHODS,
.add_listener = impl_add_listener,
.enum_params = impl_enum_params,
.set_param = impl_set_param,
};
static int impl_get_interface(struct spa_handle *handle, uint32_t type, void **interface)
@ -450,7 +445,10 @@ impl_init(const struct spa_handle_factory *factory,
return -EINVAL;
}
this->device = impl_device;
this->device.iface = SPA_INTERFACE_INIT(
SPA_TYPE_INTERFACE_Device,
SPA_VERSION_DEVICE,
&impl_device, this);
spa_hook_list_init(&this->hooks);
reset_props(&this->props);