Add API to retrieve and iterate over the resources list of a client

To complement on the new resource created signal, this allows to
iterate over the existing resources of a client.

Signed-off-by: Giulio Camuffo <giulio.camuffo@kdab.com>
Reviewed-by: Jonas Ådahl <jadahl@gmail.com>
[Pekka: added empty lines, init ret in for_each_helper()]
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
This commit is contained in:
Giulio Camuffo 2016-08-11 17:23:10 +02:00 committed by Pekka Paalanen
parent c55c1d787c
commit 2f617250d2
5 changed files with 85 additions and 7 deletions

View file

@ -359,24 +359,33 @@ wl_map_lookup_flags(struct wl_map *map, uint32_t i)
return 0;
}
static void
static enum wl_iterator_result
for_each_helper(struct wl_array *entries, wl_iterator_func_t func, void *data)
{
union map_entry *start, *end, *p;
enum wl_iterator_result ret = WL_ITERATOR_CONTINUE;
start = entries->data;
end = (union map_entry *) ((char *) entries->data + entries->size);
for (p = start; p < end; p++)
if (p->data && !map_entry_is_free(*p))
func(map_entry_get_data(*p), data);
if (p->data && !map_entry_is_free(*p)) {
ret = func(map_entry_get_data(*p), data);
if (ret != WL_ITERATOR_CONTINUE)
break;
}
return ret;
}
WL_EXPORT void
wl_map_for_each(struct wl_map *map, wl_iterator_func_t func, void *data)
{
for_each_helper(&map->client_entries, func, data);
for_each_helper(&map->server_entries, func, data);
enum wl_iterator_result ret;
ret = for_each_helper(&map->client_entries, func, data);
if (ret == WL_ITERATOR_CONTINUE)
for_each_helper(&map->server_entries, func, data);
}
static void