diff --git a/src/tools/pw-cli.c b/src/tools/pw-cli.c index 71a23b79a..a8f5d76d3 100644 --- a/src/tools/pw-cli.c +++ b/src/tools/pw-cli.c @@ -68,7 +68,6 @@ struct data { }; struct global { - struct spa_list link; struct remote_data *rd; uint32_t id; uint32_t permissions; @@ -94,7 +93,7 @@ struct remote_data { struct pw_registry *registry; struct spa_hook registry_listener; - struct spa_list globals; + struct pw_map globals; }; struct proxy_data; @@ -332,6 +331,7 @@ static void registry_event_global(void *data, uint32_t id, { struct remote_data *rd = data; struct global *global; + size_t size; char *error; bool ret; @@ -348,7 +348,10 @@ static void registry_event_global(void *data, uint32_t id, print_global(global, NULL); } - spa_list_append(&rd->globals, &global->link); + size = pw_map_get_size(&rd->globals); + while (id > size) + pw_map_insert_at(&rd->globals, size++, NULL); + pw_map_insert_at(&rd->globals, id, global); /* immediately bind the object always */ ret = bind_global(rd, global, &error); @@ -359,7 +362,7 @@ static void registry_event_global(void *data, uint32_t id, } } -static int destroy_global(void *obj) +static int destroy_global(void *obj, void *data) { struct global *global = obj; @@ -368,29 +371,19 @@ static int destroy_global(void *obj) if (global->proxy) pw_proxy_destroy(global->proxy); - spa_list_remove(&global->link); + pw_map_insert_at(&global->rd->globals, global->id, NULL); pw_properties_free(global->properties); free(global->type); free(global); return 0; } -static struct global *find_global(struct remote_data *rd, uint32_t id) -{ - struct global *g; - spa_list_for_each(g, &rd->globals, link) { - if (g->id == id) - return g; - } - return NULL; -} - static void registry_event_global_remove(void *data, uint32_t id) { struct remote_data *rd = data; struct global *global; - global = find_global(rd, id); + global = pw_map_lookup(&rd->globals, id); if (global == NULL) { fprintf(stdout, "remote %d removed unknown global %d\n", rd->id, id); return; @@ -401,7 +394,7 @@ static void registry_event_global_remove(void *data, uint32_t id) print_global(global, NULL); } - destroy_global(global); + destroy_global(global, rd); } static const struct pw_registry_events registry_events = { @@ -433,7 +426,6 @@ static void on_core_destroy(void *_data) { struct remote_data *rd = _data; struct data *data = rd->data; - struct global *g; spa_list_remove(&rd->link); @@ -441,8 +433,8 @@ static void on_core_destroy(void *_data) spa_hook_remove(&rd->proxy_core_listener); pw_map_remove(&data->vars, rd->id); - spa_list_consume(g, &rd->globals, link) - destroy_global(g); + pw_map_for_each(&rd->globals, destroy_global, rd); + pw_map_clear(&rd->globals); if (data->current == rd) data->current = NULL; @@ -482,7 +474,7 @@ static bool do_connect(struct data *data, const char *cmd, char *args, char **er rd = pw_proxy_get_user_data((struct pw_proxy*)core); rd->core = core; rd->data = data; - spa_list_init(&rd->globals); + pw_map_init(&rd->globals, 64, 16); rd->id = pw_map_insert_new(&data->vars, rd); spa_list_append(&data->remotes, &rd->link); @@ -759,7 +751,7 @@ static void core_event_info(void *object, const struct pw_core_info *info) fprintf(stdout, "remote %d core %d changed\n", rd->id, info->id); pd->info = pw_core_info_update(pd->info, info); if (pd->global == NULL) - pd->global = find_global(rd, info->id); + pd->global = pw_map_lookup(&rd->globals, info->id); if (pd->global && pd->global->info_pending) { info_core(pd); pd->global->info_pending = false; @@ -780,7 +772,7 @@ static void module_event_info(void *object, const struct pw_module_info *info) fprintf(stdout, "remote %d module %d changed\n", rd->id, info->id); pd->info = pw_module_info_update(pd->info, info); if (pd->global == NULL) - pd->global = find_global(rd, info->id); + pd->global = pw_map_lookup(&rd->globals, info->id); if (pd->global && pd->global->info_pending) { info_module(pd); pd->global->info_pending = false; @@ -800,7 +792,7 @@ static void node_event_info(void *object, const struct pw_node_info *info) fprintf(stdout, "remote %d node %d changed\n", rd->id, info->id); pd->info = pw_node_info_update(pd->info, info); if (pd->global == NULL) - pd->global = find_global(rd, info->id); + pd->global = pw_map_lookup(&rd->globals, info->id); if (pd->global && pd->global->info_pending) { info_node(pd); pd->global->info_pending = false; @@ -835,7 +827,7 @@ static void port_event_info(void *object, const struct pw_port_info *info) fprintf(stdout, "remote %d port %d changed\n", rd->id, info->id); pd->info = pw_port_info_update(pd->info, info); if (pd->global == NULL) - pd->global = find_global(rd, info->id); + pd->global = pw_map_lookup(&rd->globals, info->id); if (pd->global && pd->global->info_pending) { info_port(pd); pd->global->info_pending = false; @@ -856,7 +848,7 @@ static void factory_event_info(void *object, const struct pw_factory_info *info) fprintf(stdout, "remote %d factory %d changed\n", rd->id, info->id); pd->info = pw_factory_info_update(pd->info, info); if (pd->global == NULL) - pd->global = find_global(rd, info->id); + pd->global = pw_map_lookup(&rd->globals, info->id); if (pd->global && pd->global->info_pending) { info_factory(pd); pd->global->info_pending = false; @@ -876,7 +868,7 @@ static void client_event_info(void *object, const struct pw_client_info *info) fprintf(stdout, "remote %d client %d changed\n", rd->id, info->id); pd->info = pw_client_info_update(pd->info, info); if (pd->global == NULL) - pd->global = find_global(rd, info->id); + pd->global = pw_map_lookup(&rd->globals, info->id); if (pd->global && pd->global->info_pending) { info_client(pd); pd->global->info_pending = false; @@ -917,7 +909,7 @@ static void link_event_info(void *object, const struct pw_link_info *info) fprintf(stdout, "remote %d link %d changed\n", rd->id, info->id); pd->info = pw_link_info_update(pd->info, info); if (pd->global == NULL) - pd->global = find_global(rd, info->id); + pd->global = pw_map_lookup(&rd->globals, info->id); if (pd->global && pd->global->info_pending) { info_link(pd); pd->global->info_pending = false; @@ -938,7 +930,7 @@ static void device_event_info(void *object, const struct pw_device_info *info) fprintf(stdout, "remote %d device %d changed\n", rd->id, info->id); pd->info = pw_device_info_update(pd->info, info); if (pd->global == NULL) - pd->global = find_global(rd, info->id); + pd->global = pw_map_lookup(&rd->globals, info->id); if (pd->global && pd->global->info_pending) { info_device(pd); pd->global->info_pending = false; @@ -983,7 +975,7 @@ static void session_event_info(void *object, } if (pd->global == NULL) - pd->global = find_global(rd, info->id); + pd->global = pw_map_lookup(&rd->globals, info->id); if (pd->global && pd->global->info_pending) { info_session(pd); pd->global->info_pending = false; @@ -1038,7 +1030,7 @@ static void endpoint_event_info(void *object, } if (pd->global == NULL) - pd->global = find_global(rd, info->id); + pd->global = pw_map_lookup(&rd->globals, info->id); if (pd->global && pd->global->info_pending) { info_endpoint(pd); pd->global->info_pending = false; @@ -1086,7 +1078,7 @@ static void endpoint_stream_event_info(void *object, } if (pd->global == NULL) - pd->global = find_global(rd, info->id); + pd->global = pw_map_lookup(&rd->globals, info->id); if (pd->global && pd->global->info_pending) { info_endpoint_stream(pd); pd->global->info_pending = false; @@ -1134,9 +1126,7 @@ static const struct pw_proxy_events proxy_events = { static bool do_list_objects(struct data *data, const char *cmd, char *args, char **error) { struct remote_data *rd = data->current; - struct global *g; - spa_list_for_each(g, &rd->globals, link) - print_global(g, args); + pw_map_for_each(&rd->globals, print_global, args); return true; } @@ -1276,12 +1266,11 @@ static bool do_info(struct data *data, const char *cmd, char *args, char **error return false; } if (spa_streq(a[0], "all")) { - spa_list_for_each(global, &rd->globals, link) - do_global_info_all(global, NULL); + pw_map_for_each(&rd->globals, do_global_info_all, NULL); } else { id = atoi(a[0]); - global = find_global(rd, id); + global = pw_map_lookup(&rd->globals, id); if (global == NULL) { *error = spa_aprintf("%s: unknown global %d", cmd, id); return false; @@ -1383,7 +1372,7 @@ static bool do_destroy(struct data *data, const char *cmd, char *args, char **er return false; } id = atoi(a[0]); - global = find_global(rd, id); + global = pw_map_lookup(&rd->globals, id); if (global == NULL) { *error = spa_aprintf("%s: unknown global %d", cmd, id); return false; @@ -1525,7 +1514,7 @@ static bool do_enum_params(struct data *data, const char *cmd, char *args, char } param_id = ti->type; - global = find_global(rd, id); + global = pw_map_lookup(&rd->globals, id); if (global == NULL) { *error = spa_aprintf("%s: unknown global %d", cmd, id); return false; @@ -1686,7 +1675,7 @@ static bool do_set_param(struct data *data, const char *cmd, char *args, char ** id = atoi(a[0]); - global = find_global(rd, id); + global = pw_map_lookup(&rd->globals, id); if (global == NULL) { *error = spa_aprintf("%s: unknown global %d", cmd, id); return false; @@ -1751,7 +1740,7 @@ static bool do_permissions(struct data *data, const char *cmd, char *args, char } id = atoi(a[0]); - global = find_global(rd, id); + global = pw_map_lookup(&rd->globals, id); if (global == NULL) { *error = spa_aprintf("%s: unknown global %d", cmd, id); return false; @@ -1791,7 +1780,7 @@ static bool do_get_permissions(struct data *data, const char *cmd, char *args, c } id = atoi(a[0]); - global = find_global(rd, id); + global = pw_map_lookup(&rd->globals, id); if (global == NULL) { *error = spa_aprintf("%s: unknown global %d", cmd, id); return false; @@ -1833,7 +1822,7 @@ obj_global(struct remote_data *rd, uint32_t id) if (!rd) return NULL; - global = find_global(rd, id); + global = pw_map_lookup(&rd->globals, id); if (!global) return NULL; @@ -1923,6 +1912,7 @@ children_of(struct remote_data *rd, uint32_t parent_id, const char *child_type, uint32_t **children) { const char *parent_type; + union pw_map_item *item; struct global *global; struct proxy_data *pd; const char *parent_key = NULL, *child_key = NULL; @@ -1982,7 +1972,12 @@ children_of(struct remote_data *rd, uint32_t parent_id, return -1; } i = 0; - spa_list_for_each(global, &rd->globals, link) { + pw_array_for_each(item, &rd->globals.items) { + if (pw_map_item_is_free(item) || item->data == NULL) + continue; + + global = item->data; + if (!spa_streq(global->type, child_type)) continue; @@ -2782,6 +2777,7 @@ dump(struct data *data, struct global *global, static bool do_dump(struct data *data, const char *cmd, char *args, char **error) { struct remote_data *rd = data->current; + union pw_map_item *item; struct global *global; char *aa[32], **a; char c; @@ -2849,7 +2845,12 @@ static bool do_dump(struct data *data, const char *cmd, char *args, char **error flags |= is_notype; } - spa_list_for_each(global, &rd->globals, link) { + pw_array_for_each(item, &rd->globals.items) { + if (pw_map_item_is_free(item) || item->data == NULL) + continue; + + global = item->data; + /* unknown type, ignore completely */ idx = dump_type_index(global->type); if (idx < 0)