From d880db393368c7e682181614ae53ee8db230d8c1 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 6 Mar 2020 16:30:18 +0100 Subject: [PATCH] Revert "pw-cli: use core object to map id to proxy" This reverts commit 918acd61eff0883d3426bfa54bfa1a856f337cc5. --- src/tools/pw-cli.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/tools/pw-cli.c b/src/tools/pw-cli.c index d91e2fd96..506b7940f 100644 --- a/src/tools/pw-cli.c +++ b/src/tools/pw-cli.c @@ -93,7 +93,7 @@ struct global { uint32_t flags; #define GLOBAL_CAN_SUBSCRIBE_PARAMS (1U << 0) #define GLOBAL_CAN_ENUM_PARAMS (1U << 1) -#define GLOBAL_PARAM_LIST_VALID (1U << 2) +#define GLOBAL_PARAM_LIST_VALID (1U << 2) #define GLOBAL_PARAM_SUBSCRIBE_IN_PROGRESS (1U << 3) #define GLOBAL_PARAM_ENUM_IN_PROGRESS (1U << 5) #define GLOBAL_PARAM_ENUM_COMPLETE (1U << 6) @@ -121,6 +121,7 @@ struct remote_data { struct spa_hook registry_listener; struct pw_map globals; + struct pw_map globals_by_proxy; }; struct proxy_data; @@ -441,6 +442,9 @@ static int destroy_global(void *obj, void *data) rd = global->rd; + if (global->proxy_id) + pw_map_remove(&rd->globals_by_proxy, global->proxy_id); + pw_map_remove(&rd->globals, global->id); if (global->properties) pw_properties_free(global->properties); @@ -467,21 +471,15 @@ remote_global(struct remote_data *rd, uint32_t id) static struct global * remote_global_by_proxy(struct remote_data *rd, uint32_t id) { - struct pw_proxy *proxy; - struct proxy_data *pd; + struct global *global; if (!rd) return NULL; - proxy = pw_core_find_proxy(rd->core, id); - if (proxy == NULL) + global = pw_map_lookup(&rd->globals_by_proxy, id); + if (!global || !global->proxy || !pw_proxy_get_user_data(global->proxy)) return NULL; - - pd = pw_proxy_get_user_data(proxy); - if (pd == NULL) - return NULL; - - return pd->global; + return global; } static bool global_can_subscribe_params(struct global *global) @@ -943,6 +941,7 @@ static bool do_connect(struct data *data, const char *cmd, char *args, char **er rd->core = core; rd->data = data; pw_map_init(&rd->globals, 64, 16); + pw_map_init(&rd->globals_by_proxy, 64, 16); rd->id = pw_map_insert_new(&data->vars, rd); spa_list_append(&data->remotes, &rd->link); @@ -1809,12 +1808,13 @@ static bool do_list_objects(struct data *data, const char *cmd, char *args, char static bool bind_global(struct remote_data *rd, struct global *global, char **error) { - const void *events; - uint32_t client_version; + const void *events; + uint32_t client_version; info_func_t info_func; - pw_destroy_t destroy; + pw_destroy_t destroy; struct proxy_data *pd; struct pw_proxy *proxy; + size_t size; if (strcmp(global->type, PW_TYPE_INTERFACE_Core) == 0) { events = &core_events; @@ -1899,6 +1899,11 @@ static bool bind_global(struct remote_data *rd, struct global *global, char **er global->proxy = proxy; global->proxy_id = pw_proxy_get_id(proxy); + size = pw_map_get_size(&rd->globals_by_proxy); + while (global->proxy_id > size) + pw_map_insert_at(&rd->globals_by_proxy, size++, NULL); + pw_map_insert_at(&rd->globals_by_proxy, global->proxy_id, global); + return true; }