mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-06 13:30:01 -05:00
interfaces: improve remote API
Add return values to events and method callbacks. This makes it possible to pass any error or async return value. Add sync/done/error in both directions so that both proxy and resource and perform/reply sync and produce errors. Return a SPA_ASYNC from remote method calls (and events), keep the sequence number in the connection. With the core sync/done we can remove the client-node done method and it's internal sequence number along with the seq number in method calls. We can also use the method/event async return value to perform a sync with as the unique sequence number for this method. Add sync method and done/error event to proxy and resource.
This commit is contained in:
parent
0d8821096a
commit
eea062ee53
41 changed files with 1180 additions and 817 deletions
|
|
@ -242,12 +242,13 @@ static bool do_load_module(struct data *data, const char *cmd, char *args, char
|
|||
return true;
|
||||
}
|
||||
|
||||
static void on_core_info(void *_data, const struct pw_core_info *info)
|
||||
static int on_core_info(void *_data, const struct pw_core_info *info)
|
||||
{
|
||||
struct remote_data *rd = _data;
|
||||
free(rd->name);
|
||||
rd->name = strdup(info->name);
|
||||
fprintf(stdout, "remote %d is named '%s'\n", rd->id, rd->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void show_prompt(struct remote_data *rd)
|
||||
|
|
@ -256,7 +257,7 @@ static void show_prompt(struct remote_data *rd)
|
|||
fflush(stdout);
|
||||
}
|
||||
|
||||
static void on_core_done(void *_data, uint32_t seq)
|
||||
static int on_core_done(void *_data, uint32_t id, uint32_t seq)
|
||||
{
|
||||
struct remote_data *rd = _data;
|
||||
|
||||
|
|
@ -267,6 +268,7 @@ static void on_core_done(void *_data, uint32_t seq)
|
|||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int print_global(void *obj, void *data)
|
||||
|
|
@ -285,9 +287,9 @@ static int print_global(void *obj, void *data)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void registry_event_global(void *data, uint32_t id, uint32_t parent_id,
|
||||
uint32_t permissions, uint32_t type, uint32_t version,
|
||||
const struct spa_dict *props)
|
||||
static int registry_event_global(void *data, uint32_t id, uint32_t parent_id,
|
||||
uint32_t permissions, uint32_t type, uint32_t version,
|
||||
const struct spa_dict *props)
|
||||
{
|
||||
struct remote_data *rd = data;
|
||||
struct global *global;
|
||||
|
|
@ -309,6 +311,7 @@ static void registry_event_global(void *data, uint32_t id, uint32_t parent_id,
|
|||
while (id > size)
|
||||
pw_map_insert_at(&rd->globals, size++, NULL);
|
||||
pw_map_insert_at(&rd->globals, id, global);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int destroy_global(void *obj, void *data)
|
||||
|
|
@ -325,7 +328,7 @@ static int destroy_global(void *obj, void *data)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void registry_event_global_remove(void *data, uint32_t id)
|
||||
static int registry_event_global_remove(void *data, uint32_t id)
|
||||
{
|
||||
struct remote_data *rd = data;
|
||||
struct global *global;
|
||||
|
|
@ -333,12 +336,13 @@ static void registry_event_global_remove(void *data, uint32_t id)
|
|||
global = pw_map_lookup(&rd->globals, id);
|
||||
if (global == NULL) {
|
||||
fprintf(stdout, "remote %d removed unknown global %d\n", rd->id, id);
|
||||
return;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
fprintf(stdout, "remote %d removed global: ", rd->id);
|
||||
print_global(global, NULL);
|
||||
destroy_global(global, rd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct pw_registry_proxy_events registry_events = {
|
||||
|
|
@ -392,7 +396,7 @@ static void on_state_changed(void *_data, enum pw_remote_state old,
|
|||
pw_registry_proxy_add_listener(rd->registry_proxy,
|
||||
&rd->registry_listener,
|
||||
®istry_events, rd);
|
||||
pw_core_proxy_sync(rd->core_proxy, 1);
|
||||
pw_core_proxy_sync(rd->core_proxy, 0, 1);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
@ -627,7 +631,7 @@ static void info_device(struct proxy_data *pd)
|
|||
info->change_mask = 0;
|
||||
}
|
||||
|
||||
static void core_event_info(void *object, const struct pw_core_info *info)
|
||||
static int core_event_info(void *object, const struct pw_core_info *info)
|
||||
{
|
||||
struct proxy_data *pd = object;
|
||||
struct remote_data *rd = pd->rd;
|
||||
|
|
@ -640,6 +644,7 @@ static void core_event_info(void *object, const struct pw_core_info *info)
|
|||
info_core(pd);
|
||||
pd->global->info_pending = false;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct pw_core_proxy_events core_events = {
|
||||
|
|
@ -648,7 +653,7 @@ static const struct pw_core_proxy_events core_events = {
|
|||
};
|
||||
|
||||
|
||||
static void module_event_info(void *object, const struct pw_module_info *info)
|
||||
static int module_event_info(void *object, const struct pw_module_info *info)
|
||||
{
|
||||
struct proxy_data *pd = object;
|
||||
struct remote_data *rd = pd->rd;
|
||||
|
|
@ -661,6 +666,7 @@ static void module_event_info(void *object, const struct pw_module_info *info)
|
|||
info_module(pd);
|
||||
pd->global->info_pending = false;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct pw_module_proxy_events module_events = {
|
||||
|
|
@ -668,7 +674,7 @@ static const struct pw_module_proxy_events module_events = {
|
|||
.info = module_event_info
|
||||
};
|
||||
|
||||
static void node_event_info(void *object, const struct pw_node_info *info)
|
||||
static int node_event_info(void *object, const struct pw_node_info *info)
|
||||
{
|
||||
struct proxy_data *pd = object;
|
||||
struct remote_data *rd = pd->rd;
|
||||
|
|
@ -681,9 +687,10 @@ static void node_event_info(void *object, const struct pw_node_info *info)
|
|||
info_node(pd);
|
||||
pd->global->info_pending = false;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void node_event_param(void *object, uint32_t id, uint32_t index, uint32_t next,
|
||||
static int node_event_param(void *object, uint32_t id, uint32_t index, uint32_t next,
|
||||
const struct spa_pod *param)
|
||||
{
|
||||
struct proxy_data *data = object;
|
||||
|
|
@ -696,6 +703,7 @@ static void node_event_param(void *object, uint32_t id, uint32_t index, uint32_t
|
|||
spa_debug_format(2, NULL, param);
|
||||
else
|
||||
spa_debug_pod(2, NULL, param);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct pw_node_proxy_events node_events = {
|
||||
|
|
@ -705,7 +713,7 @@ static const struct pw_node_proxy_events node_events = {
|
|||
};
|
||||
|
||||
|
||||
static void port_event_info(void *object, const struct pw_port_info *info)
|
||||
static int port_event_info(void *object, const struct pw_port_info *info)
|
||||
{
|
||||
struct proxy_data *pd = object;
|
||||
struct remote_data *rd = pd->rd;
|
||||
|
|
@ -718,9 +726,10 @@ static void port_event_info(void *object, const struct pw_port_info *info)
|
|||
info_port(pd);
|
||||
pd->global->info_pending = false;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void port_event_param(void *object, uint32_t id, uint32_t index, uint32_t next,
|
||||
static int port_event_param(void *object, uint32_t id, uint32_t index, uint32_t next,
|
||||
const struct spa_pod *param)
|
||||
{
|
||||
struct proxy_data *data = object;
|
||||
|
|
@ -733,6 +742,7 @@ static void port_event_param(void *object, uint32_t id, uint32_t index, uint32_t
|
|||
spa_debug_format(2, NULL, param);
|
||||
else
|
||||
spa_debug_pod(2, NULL, param);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct pw_port_proxy_events port_events = {
|
||||
|
|
@ -741,7 +751,7 @@ static const struct pw_port_proxy_events port_events = {
|
|||
.param = port_event_param
|
||||
};
|
||||
|
||||
static void factory_event_info(void *object, const struct pw_factory_info *info)
|
||||
static int factory_event_info(void *object, const struct pw_factory_info *info)
|
||||
{
|
||||
struct proxy_data *pd = object;
|
||||
struct remote_data *rd = pd->rd;
|
||||
|
|
@ -754,6 +764,7 @@ static void factory_event_info(void *object, const struct pw_factory_info *info)
|
|||
info_factory(pd);
|
||||
pd->global->info_pending = false;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct pw_factory_proxy_events factory_events = {
|
||||
|
|
@ -761,7 +772,7 @@ static const struct pw_factory_proxy_events factory_events = {
|
|||
.info = factory_event_info
|
||||
};
|
||||
|
||||
static void client_event_info(void *object, const struct pw_client_info *info)
|
||||
static int client_event_info(void *object, const struct pw_client_info *info)
|
||||
{
|
||||
struct proxy_data *pd = object;
|
||||
struct remote_data *rd = pd->rd;
|
||||
|
|
@ -774,9 +785,10 @@ static void client_event_info(void *object, const struct pw_client_info *info)
|
|||
info_client(pd);
|
||||
pd->global->info_pending = false;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void client_event_permissions(void *object, uint32_t index,
|
||||
static int client_event_permissions(void *object, uint32_t index,
|
||||
uint32_t n_permissions, const struct pw_permission *permissions)
|
||||
{
|
||||
struct proxy_data *data = object;
|
||||
|
|
@ -793,6 +805,7 @@ static void client_event_permissions(void *object, uint32_t index,
|
|||
fprintf(stdout, " %u:", permissions[i].id);
|
||||
fprintf(stdout, " %08x\n", permissions[i].permissions);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct pw_client_proxy_events client_events = {
|
||||
|
|
@ -801,7 +814,7 @@ static const struct pw_client_proxy_events client_events = {
|
|||
.permissions = client_event_permissions
|
||||
};
|
||||
|
||||
static void link_event_info(void *object, const struct pw_link_info *info)
|
||||
static int link_event_info(void *object, const struct pw_link_info *info)
|
||||
{
|
||||
struct proxy_data *pd = object;
|
||||
struct remote_data *rd = pd->rd;
|
||||
|
|
@ -814,6 +827,7 @@ static void link_event_info(void *object, const struct pw_link_info *info)
|
|||
info_link(pd);
|
||||
pd->global->info_pending = false;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct pw_link_proxy_events link_events = {
|
||||
|
|
@ -822,7 +836,7 @@ static const struct pw_link_proxy_events link_events = {
|
|||
};
|
||||
|
||||
|
||||
static void device_event_info(void *object, const struct pw_device_info *info)
|
||||
static int device_event_info(void *object, const struct pw_device_info *info)
|
||||
{
|
||||
struct proxy_data *pd = object;
|
||||
struct remote_data *rd = pd->rd;
|
||||
|
|
@ -835,6 +849,7 @@ static void device_event_info(void *object, const struct pw_device_info *info)
|
|||
info_device(pd);
|
||||
pd->global->info_pending = false;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct pw_device_proxy_events device_events = {
|
||||
|
|
@ -1375,7 +1390,7 @@ static void do_input(void *data, int fd, enum spa_io mask)
|
|||
if (d->current == NULL)
|
||||
pw_main_loop_quit(d->loop);
|
||||
else if (d->current->core_proxy)
|
||||
pw_core_proxy_sync(d->current->core_proxy, 1);
|
||||
pw_core_proxy_sync(d->current->core_proxy, 0, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ static void add_pending(struct proxy_data *pd)
|
|||
|
||||
spa_list_append(&d->pending_list, &pd->pending_link);
|
||||
pd->pending_seq = ++d->seq;
|
||||
pw_core_proxy_sync(d->core_proxy, pd->pending_seq);
|
||||
pw_core_proxy_sync(d->core_proxy, 0, pd->pending_seq);
|
||||
}
|
||||
|
||||
static void remove_pending(struct proxy_data *pd)
|
||||
|
|
@ -93,7 +93,7 @@ static void remove_pending(struct proxy_data *pd)
|
|||
}
|
||||
}
|
||||
|
||||
static void on_core_done(void *data, uint32_t seq)
|
||||
static int on_core_done(void *data, uint32_t id, uint32_t seq)
|
||||
{
|
||||
struct data *d = data;
|
||||
struct proxy_data *pd, *t;
|
||||
|
|
@ -104,6 +104,7 @@ static void on_core_done(void *data, uint32_t seq)
|
|||
pd->print_func(pd);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void clear_params(struct proxy_data *data)
|
||||
|
|
@ -118,12 +119,15 @@ static void clear_params(struct proxy_data *data)
|
|||
data->params = NULL;
|
||||
}
|
||||
|
||||
static void add_param(struct proxy_data *data, const struct spa_pod *param)
|
||||
static int add_param(struct proxy_data *data, const struct spa_pod *param)
|
||||
{
|
||||
uint32_t idx = data->n_params++;
|
||||
|
||||
data->params = realloc(data->params, sizeof(struct spa_pod *) * data->n_params);
|
||||
if (data->params == NULL)
|
||||
return -ENOMEM;
|
||||
data->params[idx] = pw_spa_pod_copy(param);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void print_properties(const struct spa_dict *props, char mark)
|
||||
|
|
@ -146,7 +150,7 @@ static void print_properties(const struct spa_dict *props, char mark)
|
|||
|
||||
#define MARK_CHANGE(f) ((print_mark && ((info)->change_mask & (1 << (f)))) ? '*' : ' ')
|
||||
|
||||
static void on_core_info(void *data, const struct pw_core_info *info)
|
||||
static int on_core_info(void *data, const struct pw_core_info *info)
|
||||
{
|
||||
bool print_all = true, print_mark = false;
|
||||
|
||||
|
|
@ -159,9 +163,10 @@ static void on_core_info(void *data, const struct pw_core_info *info)
|
|||
printf("%c\tname: \"%s\"\n", MARK_CHANGE(3), info->name);
|
||||
print_properties(info->props, MARK_CHANGE(4));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void module_event_info(void *object, const struct pw_module_info *info)
|
||||
static int module_event_info(void *object, const struct pw_module_info *info)
|
||||
{
|
||||
struct proxy_data *data = object;
|
||||
bool print_all, print_mark;
|
||||
|
|
@ -191,6 +196,7 @@ static void module_event_info(void *object, const struct pw_module_info *info)
|
|||
printf("%c\targs: \"%s\"\n", MARK_CHANGE(2), info->args);
|
||||
print_properties(info->props, MARK_CHANGE(3));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct pw_module_proxy_events module_events = {
|
||||
|
|
@ -247,7 +253,7 @@ static void print_node(struct proxy_data *data)
|
|||
}
|
||||
}
|
||||
|
||||
static void node_event_info(void *object, const struct pw_node_info *info)
|
||||
static int node_event_info(void *object, const struct pw_node_info *info)
|
||||
{
|
||||
struct proxy_data *data = object;
|
||||
bool is_new = data->info == NULL;
|
||||
|
|
@ -261,13 +267,14 @@ static void node_event_info(void *object, const struct pw_node_info *info)
|
|||
}
|
||||
if (data->pending_seq == SPA_ID_INVALID)
|
||||
data->print_func(data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void node_event_param(void *object, uint32_t id, uint32_t index, uint32_t next,
|
||||
static int node_event_param(void *object, uint32_t id, uint32_t index, uint32_t next,
|
||||
const struct spa_pod *param)
|
||||
{
|
||||
struct proxy_data *data = object;
|
||||
add_param(data, param);
|
||||
return add_param(data, param);
|
||||
}
|
||||
|
||||
static const struct pw_node_proxy_events node_events = {
|
||||
|
|
@ -313,7 +320,7 @@ static void print_port(struct proxy_data *data)
|
|||
}
|
||||
}
|
||||
|
||||
static void port_event_info(void *object, const struct pw_port_info *info)
|
||||
static int port_event_info(void *object, const struct pw_port_info *info)
|
||||
{
|
||||
|
||||
struct proxy_data *data = object;
|
||||
|
|
@ -328,13 +335,14 @@ static void port_event_info(void *object, const struct pw_port_info *info)
|
|||
}
|
||||
if (data->pending_seq == SPA_ID_INVALID)
|
||||
data->print_func(data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void port_event_param(void *object, uint32_t id, uint32_t index, uint32_t next,
|
||||
static int port_event_param(void *object, uint32_t id, uint32_t index, uint32_t next,
|
||||
const struct spa_pod *param)
|
||||
{
|
||||
struct proxy_data *data = object;
|
||||
add_param(data, param);
|
||||
return add_param(data, param);
|
||||
}
|
||||
|
||||
static const struct pw_port_proxy_events port_events = {
|
||||
|
|
@ -343,7 +351,7 @@ static const struct pw_port_proxy_events port_events = {
|
|||
.param = port_event_param
|
||||
};
|
||||
|
||||
static void factory_event_info(void *object, const struct pw_factory_info *info)
|
||||
static int factory_event_info(void *object, const struct pw_factory_info *info)
|
||||
{
|
||||
struct proxy_data *data = object;
|
||||
bool print_all, print_mark;
|
||||
|
|
@ -372,6 +380,7 @@ static void factory_event_info(void *object, const struct pw_factory_info *info)
|
|||
if (print_all) {
|
||||
print_properties(info->props, MARK_CHANGE(0));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct pw_factory_proxy_events factory_events = {
|
||||
|
|
@ -379,7 +388,7 @@ static const struct pw_factory_proxy_events factory_events = {
|
|||
.info = factory_event_info
|
||||
};
|
||||
|
||||
static void client_event_info(void *object, const struct pw_client_info *info)
|
||||
static int client_event_info(void *object, const struct pw_client_info *info)
|
||||
{
|
||||
struct proxy_data *data = object;
|
||||
bool print_all, print_mark;
|
||||
|
|
@ -406,6 +415,7 @@ static void client_event_info(void *object, const struct pw_client_info *info)
|
|||
if (print_all) {
|
||||
print_properties(info->props, MARK_CHANGE(0));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct pw_client_proxy_events client_events = {
|
||||
|
|
@ -413,7 +423,7 @@ static const struct pw_client_proxy_events client_events = {
|
|||
.info = client_event_info
|
||||
};
|
||||
|
||||
static void link_event_info(void *object, const struct pw_link_info *info)
|
||||
static int link_event_info(void *object, const struct pw_link_info *info)
|
||||
{
|
||||
struct proxy_data *data = object;
|
||||
bool print_all, print_mark;
|
||||
|
|
@ -454,6 +464,7 @@ static void link_event_info(void *object, const struct pw_link_info *info)
|
|||
printf("\t\tnone\n");
|
||||
print_properties(info->props, MARK_CHANGE(4));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct pw_link_proxy_events link_events = {
|
||||
|
|
@ -461,9 +472,7 @@ static const struct pw_link_proxy_events link_events = {
|
|||
.info = link_event_info
|
||||
};
|
||||
|
||||
|
||||
|
||||
static void device_event_info(void *object, const struct pw_device_info *info)
|
||||
static int device_event_info(void *object, const struct pw_device_info *info)
|
||||
{
|
||||
struct proxy_data *data = object;
|
||||
bool print_all, print_mark;
|
||||
|
|
@ -490,6 +499,7 @@ static void device_event_info(void *object, const struct pw_device_info *info)
|
|||
if (print_all) {
|
||||
print_properties(info->props, MARK_CHANGE(0));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct pw_device_proxy_events device_events = {
|
||||
|
|
@ -518,7 +528,7 @@ static const struct pw_proxy_events proxy_events = {
|
|||
.destroy = destroy_proxy,
|
||||
};
|
||||
|
||||
static void registry_event_global(void *data, uint32_t id, uint32_t parent_id,
|
||||
static int registry_event_global(void *data, uint32_t id, uint32_t parent_id,
|
||||
uint32_t permissions, uint32_t type, uint32_t version,
|
||||
const struct spa_dict *props)
|
||||
{
|
||||
|
|
@ -577,7 +587,7 @@ static void registry_event_global(void *data, uint32_t id, uint32_t parent_id,
|
|||
permissions & PW_PERM_X ? 'x' : '-');
|
||||
printf("\ttype: %s (version %d)\n", spa_debug_type_find_name(pw_type_info(), type), version);
|
||||
print_properties(props, ' ');
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
proxy = pw_registry_proxy_bind(d->registry_proxy, id, type,
|
||||
|
|
@ -600,18 +610,18 @@ static void registry_event_global(void *data, uint32_t id, uint32_t parent_id,
|
|||
pd->print_func = print_func;
|
||||
pw_proxy_add_proxy_listener(proxy, &pd->proxy_proxy_listener, events, pd);
|
||||
pw_proxy_add_listener(proxy, &pd->proxy_listener, &proxy_events, pd);
|
||||
|
||||
return;
|
||||
return 0;
|
||||
|
||||
no_mem:
|
||||
printf("failed to create proxy");
|
||||
return;
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
static void registry_event_global_remove(void *object, uint32_t id)
|
||||
static int registry_event_global_remove(void *object, uint32_t id)
|
||||
{
|
||||
printf("removed:\n");
|
||||
printf("\tid: %u\n", id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct pw_registry_proxy_events registry_events = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue