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

@ -250,9 +250,9 @@ static const struct spa_node_callbacks sink_callbacks = {
.reuse_buffer = on_sink_reuse_buffer
};
static int do_add_source(struct spa_loop *loop, struct spa_source *source)
static int do_add_source(void *object, struct spa_source *source)
{
struct data *data = SPA_CONTAINER_OF(loop, struct data, data_loop);
struct data *data = object;
data->sources[data->n_sources] = *source;
data->n_sources++;
@ -261,22 +261,19 @@ static int do_add_source(struct spa_loop *loop, struct spa_source *source)
return 0;
}
static int do_update_source(struct spa_source *source)
{
return 0;
}
static void do_remove_source(struct spa_source *source)
{
}
static int
do_invoke(struct spa_loop *loop,
do_invoke(void *object,
spa_invoke_func_t func, uint32_t seq, const void *data, size_t size, bool block, void *user_data)
{
return func(loop, false, seq, data, size, user_data);
return func(object, false, seq, data, size, user_data);
}
static const struct spa_loop_methods impl_loop = {
SPA_VERSION_LOOP_METHODS,
.add_source = do_add_source,
.invoke = do_invoke,
};
static int make_nodes(struct data *data, const char *device)
{
int res;
@ -505,11 +502,8 @@ int main(int argc, char *argv[])
spa_graph_init(&data.graph, &data.graph_state);
data.log = &default_log.log;
data.data_loop.version = SPA_VERSION_LOOP;
data.data_loop.add_source = do_add_source;
data.data_loop.update_source = do_update_source;
data.data_loop.remove_source = do_remove_source;
data.data_loop.invoke = do_invoke;
data.data_loop.iface = SPA_INTERFACE_INIT(
SPA_TYPE_INTERFACE_Loop, SPA_VERSION_LOOP, &impl_loop, &data);
if ((str = getenv("SPA_DEBUG")))
data.log->level = atoi(str);