pw-cli: use core object to map id to proxy

We can use the core object to get a proxy for a given id. From there
we can find the user data and the associated global if any.
This commit is contained in:
Wim Taymans 2020-02-21 11:47:34 +01:00
parent 4175191d19
commit 918acd61ef

View file

@ -93,7 +93,7 @@ struct global {
uint32_t flags; uint32_t flags;
#define GLOBAL_CAN_SUBSCRIBE_PARAMS (1U << 0) #define GLOBAL_CAN_SUBSCRIBE_PARAMS (1U << 0)
#define GLOBAL_CAN_ENUM_PARAMS (1U << 1) #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_SUBSCRIBE_IN_PROGRESS (1U << 3)
#define GLOBAL_PARAM_ENUM_IN_PROGRESS (1U << 5) #define GLOBAL_PARAM_ENUM_IN_PROGRESS (1U << 5)
#define GLOBAL_PARAM_ENUM_COMPLETE (1U << 6) #define GLOBAL_PARAM_ENUM_COMPLETE (1U << 6)
@ -121,7 +121,6 @@ struct remote_data {
struct spa_hook registry_listener; struct spa_hook registry_listener;
struct pw_map globals; struct pw_map globals;
struct pw_map globals_by_proxy;
}; };
struct proxy_data; struct proxy_data;
@ -440,9 +439,6 @@ static int destroy_global(void *obj, void *data)
rd = global->rd; rd = global->rd;
if (global->proxy_id)
pw_map_remove(&rd->globals_by_proxy, global->proxy_id);
pw_map_remove(&rd->globals, global->id); pw_map_remove(&rd->globals, global->id);
if (global->properties) if (global->properties)
pw_properties_free(global->properties); pw_properties_free(global->properties);
@ -469,15 +465,21 @@ remote_global(struct remote_data *rd, uint32_t id)
static struct global * static struct global *
remote_global_by_proxy(struct remote_data *rd, uint32_t id) remote_global_by_proxy(struct remote_data *rd, uint32_t id)
{ {
struct global *global; struct pw_proxy *proxy;
struct proxy_data *pd;
if (!rd) if (!rd)
return NULL; return NULL;
global = pw_map_lookup(&rd->globals_by_proxy, id); proxy = pw_core_find_proxy(rd->core, id);
if (!global || !global->proxy || !pw_proxy_get_user_data(global->proxy)) if (proxy == NULL)
return NULL; return NULL;
return global;
pd = pw_proxy_get_user_data(proxy);
if (pd == NULL)
return NULL;
return pd->global;
} }
static bool global_can_subscribe_params(struct global *global) static bool global_can_subscribe_params(struct global *global)
@ -939,7 +941,6 @@ static bool do_connect(struct data *data, const char *cmd, char *args, char **er
rd->core = core; rd->core = core;
rd->data = data; rd->data = data;
pw_map_init(&rd->globals, 64, 16); 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); rd->id = pw_map_insert_new(&data->vars, rd);
spa_list_append(&data->remotes, &rd->link); spa_list_append(&data->remotes, &rd->link);
@ -1806,13 +1807,12 @@ 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) static bool bind_global(struct remote_data *rd, struct global *global, char **error)
{ {
const void *events; const void *events;
uint32_t client_version; uint32_t client_version;
info_func_t info_func; info_func_t info_func;
pw_destroy_t destroy; pw_destroy_t destroy;
struct proxy_data *pd; struct proxy_data *pd;
struct pw_proxy *proxy; struct pw_proxy *proxy;
size_t size;
if (strcmp(global->type, PW_TYPE_INTERFACE_Core) == 0) { if (strcmp(global->type, PW_TYPE_INTERFACE_Core) == 0) {
events = &core_events; events = &core_events;
@ -1897,11 +1897,6 @@ static bool bind_global(struct remote_data *rd, struct global *global, char **er
global->proxy = proxy; global->proxy = proxy;
global->proxy_id = pw_proxy_get_id(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; return true;
} }