diff options
author | Wim Taymans <wtaymans@redhat.com> | 2019-02-20 17:51:05 +0100 |
---|---|---|
committer | Wim Taymans <wtaymans@redhat.com> | 2019-02-21 09:40:12 +0100 |
commit | 7b12212eeb0f2f7d30b6f9a7b239fe967b1276c1 (patch) | |
tree | 0bb32b2004cce5f0180080d00357b7df451aad4d /src/tools | |
parent | b743518f78ac9a763a31864cefcd832d518bc21b (diff) |
node: improve async handlingasync
Remove the done and error callbacks. The error callback is in an
error message. The done callback is replace with spa_pending.
Make enum_params take a callback and data for the results. This allows
us to push the results one after another to the app and avoids ownership
issues of the passed data. We can then extend this to handle the async
case by doing a _wait call with a spa_pending+callback+data that will
be called when the _enum_params returns and async result.
Add a sync method.
All methods can now return SPA_RESULT_IS_ASYNC return values and you
can use spa_node_wait() to register a callback when they complete
with optional extra parameters. This makes it easier to sync and
handle the reply.
Make helper methods to simulate the sync enum_params behaviour for
sync nodes.
Let the transport generate the sequence number for pw_resource_sync()
and pw_proxy_sync(). That way we don't need to keep track of numbers
ourselves and we can match the reply to the request easily.
Diffstat (limited to 'src/tools')
-rw-r--r-- | src/tools/pipewire-cli.c | 13 | ||||
-rw-r--r-- | src/tools/pipewire-monitor.c | 7 |
2 files changed, 7 insertions, 13 deletions
diff --git a/src/tools/pipewire-cli.c b/src/tools/pipewire-cli.c index 2bcbfb37..288e91dd 100644 --- a/src/tools/pipewire-cli.c +++ b/src/tools/pipewire-cli.c @@ -73,6 +73,7 @@ struct remote_data { struct pw_remote *remote; struct spa_hook remote_listener; + uint32_t prompt_pending; struct pw_core_proxy *core_proxy; struct spa_hook core_listener; @@ -261,13 +262,9 @@ static int on_core_done(void *_data, uint32_t id, uint32_t seq) { struct remote_data *rd = _data; - switch (seq) { - case 1: + if (seq == rd->prompt_pending) show_prompt(rd); - break; - default: - break; - } + return 0; } @@ -396,7 +393,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, 0, 1); + rd->prompt_pending = pw_core_proxy_sync(rd->core_proxy, 0); break; default: @@ -1390,7 +1387,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, 0, 1); + d->current->prompt_pending = pw_core_proxy_sync(d->current->core_proxy, 0); } } diff --git a/src/tools/pipewire-monitor.c b/src/tools/pipewire-monitor.c index d1acb12c..3e5c2083 100644 --- a/src/tools/pipewire-monitor.c +++ b/src/tools/pipewire-monitor.c @@ -52,7 +52,6 @@ struct data { struct pw_registry_proxy *registry_proxy; struct spa_hook registry_listener; - uint32_t seq; struct spa_list pending_list; }; @@ -81,8 +80,7 @@ static void add_pending(struct proxy_data *pd) struct data *d = pd->data; spa_list_append(&d->pending_list, &pd->pending_link); - pd->pending_seq = ++d->seq; - pw_core_proxy_sync(d->core_proxy, 0, pd->pending_seq); + pd->pending_seq = pw_core_proxy_sync(d->core_proxy, 0); } static void remove_pending(struct proxy_data *pd) @@ -126,7 +124,7 @@ static int add_param(struct proxy_data *data, const struct spa_pod *param) 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); + data->params[idx] = spa_pod_copy(param); return 0; } @@ -710,7 +708,6 @@ int main(int argc, char *argv[]) if (pw_remote_connect(data.remote) < 0) return -1; - data.seq = 1; spa_list_init(&data.pending_list); pw_main_loop_run(data.loop); |