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:
Wim Taymans 2019-02-18 12:31:36 +01:00
parent 0d8821096a
commit eea062ee53
41 changed files with 1180 additions and 817 deletions

View file

@ -193,7 +193,7 @@ static void *find_object(struct impl *impl, uint32_t id)
static void schedule_rescan(struct impl *impl)
{
if (impl->core_proxy)
pw_core_proxy_sync(impl->core_proxy, ++impl->seq);
pw_core_proxy_sync(impl->core_proxy, 0, ++impl->seq);
}
static void remove_idle_timeout(struct session *sess)
@ -344,7 +344,7 @@ static int on_node_running(struct impl *impl, struct node *node)
return 0;
}
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 node *n = object;
struct impl *impl = n->obj.impl;
@ -364,10 +364,10 @@ static void node_event_info(void *object, const struct pw_node_info *info)
default:
break;
}
return 0;
}
static void node_event_param(void *object,
static int node_event_param(void *object,
uint32_t id, uint32_t index, uint32_t next,
const struct spa_pod *param)
{
@ -385,7 +385,7 @@ static void node_event_param(void *object,
if (n->media_type != SPA_MEDIA_TYPE_audio ||
n->media_subtype != SPA_MEDIA_SUBTYPE_raw)
return;
return 0;
spa_pod_object_fixate((struct spa_pod_object*)param);
@ -393,12 +393,12 @@ static void node_event_param(void *object,
goto error;
n->format = info;
return;
return 0;
error:
pw_log_warn("unhandled param:");
spa_debug_pod(2, NULL, param);
return;
return -EINVAL;
}
static const struct pw_node_proxy_events node_events = {
@ -579,14 +579,15 @@ handle_node(struct impl *impl, uint32_t id, uint32_t parent_id,
return 1;
}
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 port *p = object;
pw_log_debug(NAME" %p: info for port %d", p->obj.impl, p->obj.id);
p->info = pw_port_info_update(p->info, info);
return 0;
}
static void port_event_param(void *object,
static int port_event_param(void *object,
uint32_t id, uint32_t index, uint32_t next,
const struct spa_pod *param)
{
@ -597,28 +598,29 @@ static void port_event_param(void *object,
pw_log_debug(NAME" %p: param for port %d", p->obj.impl, p->obj.id);
if (node == NULL)
return;
return 0;
if (id != SPA_PARAM_EnumFormat)
return;
return 0;
if (node->manager)
node->manager->enabled = true;
if (spa_format_parse(param, &node->media_type, &node->media_subtype) < 0)
return;
return 0;
if (node->media_type != SPA_MEDIA_TYPE_audio ||
node->media_subtype != SPA_MEDIA_SUBTYPE_raw)
return;
return 0;
spa_pod_fixate((struct spa_pod*)param);
if (spa_format_audio_raw_parse(param, &info) < 0)
return;
return -EINVAL;
if (info.channels > node->format.channels)
node->format = info;
return 0;
}
static const struct pw_port_proxy_events port_events = {
@ -697,7 +699,7 @@ handle_port(struct impl *impl, uint32_t id, uint32_t parent_id, uint32_t type,
return 0;
}
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 client *c = object;
uint32_t i;
@ -708,7 +710,7 @@ static void client_event_info(void *object, const struct pw_client_info *info)
pw_log_debug(NAME" %p: %s = %s", c,
info->props->items[i].key,
info->props->items[i].value);
return 0;
}
static const struct pw_client_proxy_events client_events = {
@ -772,7 +774,7 @@ handle_client(struct impl *impl, uint32_t id, uint32_t parent_id,
return 0;
}
static void
static int
registry_global(void *data,uint32_t id, uint32_t parent_id,
uint32_t permissions, uint32_t type, uint32_t version,
const struct spa_dict *props)
@ -804,9 +806,11 @@ registry_global(void *data,uint32_t id, uint32_t parent_id,
}
else
schedule_rescan(impl);
return res;
}
static void
static int
registry_global_remove(void *data, uint32_t id)
{
struct impl *impl = data;
@ -815,7 +819,7 @@ registry_global_remove(void *data, uint32_t id)
pw_log_debug(NAME " %p: remove global '%d'", impl, id);
if ((obj = find_object(impl, id)) == NULL)
return;
return 0;
switch (obj->type) {
case PW_TYPE_INTERFACE_Node:
@ -825,13 +829,13 @@ registry_global_remove(void *data, uint32_t id)
remove_session(impl, node->manager);
node->manager = NULL;
break;
}
default:
break;
}
remove_object(impl, obj);
schedule_rescan(impl);
return 0;
}
static const struct pw_registry_proxy_events registry_events = {
@ -1196,13 +1200,13 @@ do_link:
return 1;
}
static void dsp_node_event_info(void *object, const struct pw_node_info *info)
static int dsp_node_event_info(void *object, const struct pw_node_info *info)
{
struct session *s = object;
struct node *dsp;
if ((dsp = find_object(s->impl, info->id)) == NULL)
return;
return 0;
pw_log_debug(NAME" %p: dsp node session %d id %d", dsp->obj.impl, s->id, info->id);
@ -1217,6 +1221,7 @@ static void dsp_node_event_info(void *object, const struct pw_node_info *info)
dsp->format = s->node->format;
dsp->profile_format = dsp->format;
dsp->profile_format.format = SPA_AUDIO_FORMAT_F32P;
return 0;
}
static const struct pw_node_proxy_events dsp_node_events = {
@ -1292,11 +1297,12 @@ static void do_rescan(struct impl *impl)
rescan_node(impl, node);
}
static void core_done(void *data, uint32_t seq)
static int core_done(void *data, uint32_t id, uint32_t seq)
{
struct impl *impl = data;
if (impl->seq == seq)
do_rescan(impl);
return 0;
}
static const struct pw_core_proxy_events core_events = {