[PATCH wayland 5/5] Add API to retrieve and iterate over the resources list of a client

Giulio Camuffo giuliocamuffo at gmail.com
Mon Mar 7 17:31:35 UTC 2016


To complement on the new resource created signal, this allows to
iterate over the existing resources of a client.
---
 src/wayland-server-core.h |  8 ++++++++
 src/wayland-server.c      | 23 +++++++++++++++++++++++
 2 files changed, 31 insertions(+)

diff --git a/src/wayland-server-core.h b/src/wayland-server-core.h
index 9af2481..9980c29 100644
--- a/src/wayland-server-core.h
+++ b/src/wayland-server-core.h
@@ -221,6 +221,14 @@ void
 wl_client_add_resource_created_listener(struct wl_client *client,
                                         struct wl_listener *listener);
 
+typedef void (*wl_client_for_each_resource_iterator_func_t)(struct wl_resource *,
+                                                            void *user_data);
+
+void
+wl_client_for_each_resource(struct wl_client *client,
+                            wl_client_for_each_resource_iterator_func_t iterator,
+                            void *user_data);
+
 /** \class wl_listener
  *
  * \brief A single listener for Wayland signals
diff --git a/src/wayland-server.c b/src/wayland-server.c
index 56e17c3..e47ccec 100644
--- a/src/wayland-server.c
+++ b/src/wayland-server.c
@@ -1584,6 +1584,29 @@ wl_client_add_resource_created_listener(struct wl_client *client,
 	wl_signal_add(&client->resource_created_signal, listener);
 }
 
+/** Iterate over all the resources of a client
+ *
+ * \param client The client object
+ * \param iterator The iterator function
+ * \param user_data The user data pointer
+ *
+ * The function pointed by \a iterator will be called for each
+ * resource owned by the client. The \a user_data will be passed
+ * as the second argument of the iterator function.
+ *
+ * \memberof wl_client
+ */
+WL_EXPORT void
+wl_client_for_each_resource(struct wl_client *client,
+			    wl_client_for_each_resource_iterator_func_t iterator,
+			    void *user_data)
+{
+	/* wl_iterator_func_t passes wl_object as the first argument, and
+	 * wl_resource is a wl_object, so we can safely cast it. */
+	wl_iterator_func_t it = (wl_iterator_func_t)iterator;
+	wl_map_for_each(&client->objects, it, user_data);
+}
+
 /** \cond */ /* Deprecated functions below. */
 
 uint32_t
-- 
2.7.2



More information about the wayland-devel mailing list