diff --git a/src/pipewire/client.c b/src/pipewire/client.c index 51b6d94e5..e25eb648e 100644 --- a/src/pipewire/client.c +++ b/src/pipewire/client.c @@ -279,10 +279,11 @@ void *pw_client_get_user_data(struct pw_client *client) return client->user_data; } -static void destroy_resource(void *object, void *data) +static int destroy_resource(void *object, void *data) { if (object) pw_resource_destroy(object); + return 0; } diff --git a/src/pipewire/map.h b/src/pipewire/map.h index 9cd277563..4419383d4 100644 --- a/src/pipewire/map.h +++ b/src/pipewire/map.h @@ -161,18 +161,25 @@ static inline void *pw_map_lookup(struct pw_map *map, uint32_t id) /** Iterate all map items * \param map the map to iterate - * \param func the function to call for each item + * \param func the function to call for each item, the item data and \a data is + * passed to the function. When \a func returns a non-zero result, + * iteration ends and the result is returned. * \param data data to pass to \a func + * \return the result of the last call to \a func or 0 when all callbacks returned 0. * \memberof pw_map */ -static inline void pw_map_for_each(struct pw_map *map, void (*func) (void *, void *), void *data) +static inline int pw_map_for_each(struct pw_map *map, + int (*func) (void *item_data, void *data), void *data) { union pw_map_item *item; + int res = 0; pw_array_for_each(item, &map->items) { if (!pw_map_item_is_free(item)) - func(item->data, data); + if ((res = func(item->data, data)) != 0) + break; } + return res; } #ifdef __cplusplus diff --git a/src/tools/pipewire-cli.c b/src/tools/pipewire-cli.c index bf5ec0c21..bcfb3d769 100644 --- a/src/tools/pipewire-cli.c +++ b/src/tools/pipewire-cli.c @@ -259,13 +259,13 @@ static void on_sync_reply(void *_data, uint32_t seq) } } -static void print_global(void *obj, void *data) +static int print_global(void *obj, void *data) { struct global *global = obj; struct pw_type *t; if (global == NULL) - return; + return 0; t = global->rd->data->t; @@ -275,6 +275,7 @@ static void print_global(void *obj, void *data) if (global->properties) print_properties(&global->properties->dict, ' ', false); + return 0; } static void registry_event_global(void *data, uint32_t id, uint32_t parent_id, @@ -303,17 +304,18 @@ static void registry_event_global(void *data, uint32_t id, uint32_t parent_id, pw_map_insert_at(&rd->globals, id, global); } -static void destroy_global(void *obj, void *data) +static int destroy_global(void *obj, void *data) { struct global *global = obj; if (global == NULL) - return; + return 0; pw_map_remove(&global->rd->globals, global->id); if (global->properties) pw_properties_free(global->properties); free(global); + return 0; } static void registry_event_global_remove(void *data, uint32_t id) @@ -902,18 +904,19 @@ static bool do_global_info(struct global *global, char **error) } return true; } -static void do_global_info_all(void *obj, void *data) +static int do_global_info_all(void *obj, void *data) { struct global *global = obj; char *error; if (global == NULL) - return; + return 0; if (!do_global_info(global, &error)) { fprintf(stderr, "info: %s\n", error); free(error); } + return 0; } static bool do_info(struct data *data, const char *cmd, char *args, char **error)