mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-04 13:30:12 -05:00
map: make for_each use a return value
Make it possible to stop pw_map_for_each by adding a return value to the callback.
This commit is contained in:
parent
5fe230e5ff
commit
f71be550c3
3 changed files with 21 additions and 10 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue