[PATCH 4/4] wl_resource: Add version field and getter/setter

alexl at redhat.com alexl at redhat.com
Thu May 23 10:31:24 PDT 2013


From: Alexander Larsson <alexl at redhat.com>

This lets us track the actual version of a resource which
is generally the min of what the client requested and what
the server supports. This will let us avoid sending messages
the client doesn't support and to not handle requests the
server doesn't support.
---
 src/wayland-private.h |  2 +-
 src/wayland-server.c  | 16 ++++++++++++++++
 src/wayland-server.h  |  6 ++++++
 3 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/src/wayland-private.h b/src/wayland-private.h
index 105f9b9..b184309 100644
--- a/src/wayland-private.h
+++ b/src/wayland-private.h
@@ -48,7 +48,7 @@ struct wl_map {
 };
 
 struct wl_resource_private {
-	uint32_t dummy;
+	uint32_t version;
 };
 
 typedef void (*wl_iterator_func_t)(void *element, void *data);
diff --git a/src/wayland-server.c b/src/wayland-server.c
index e3a0376..c7a5e1d 100644
--- a/src/wayland-server.c
+++ b/src/wayland-server.c
@@ -401,6 +401,7 @@ wl_client_add_resource(struct wl_client *client,
 
 	resource->priv = priv;
 	resource->client = client;
+	resource->priv->version = 1;
 	wl_signal_init(&resource->destroy_signal);
 
 	return resource->object.id;
@@ -912,6 +913,20 @@ wl_display_get_destroy_listener(struct wl_display *display,
 	return wl_signal_get(&display->destroy_signal, notify);
 }
 
+WL_EXPORT void
+wl_resource_set_version(struct wl_resource *resource,
+			uint32_t version)
+{
+	resource->priv->version = version;
+}
+
+WL_EXPORT uint32_t
+wl_resource_get_version(struct wl_resource *resource)
+{
+	return resource->priv->version;
+}
+
+
 WL_EXPORT struct wl_resource *
 wl_client_add_object(struct wl_client *client,
 		     const struct wl_interface *interface,
@@ -930,6 +945,7 @@ wl_client_add_object(struct wl_client *client,
 	resource->priv = (struct wl_resource_private *)(resource + 1);
 	resource->client = client;
 	resource->destroy = (void *) free;
+	resource->priv->version = 1;
 
 	if (wl_map_insert_at(&client->objects, resource->object.id, resource) < 0) {
 		wl_resource_post_error(client->display_resource,
diff --git a/src/wayland-server.h b/src/wayland-server.h
index 3ac0351..22b845c 100644
--- a/src/wayland-server.h
+++ b/src/wayland-server.h
@@ -135,6 +135,12 @@ wl_client_new_object(struct wl_client *client,
 struct wl_resource *
 wl_client_get_object(struct wl_client *client, uint32_t id);
 
+void
+wl_resource_set_version(struct wl_resource *resource,
+			uint32_t version);
+uint32_t
+wl_resource_get_version(struct wl_resource *resource);
+
 struct wl_listener {
 	struct wl_list link;
 	wl_notify_func_t notify;
-- 
1.8.1.4



More information about the wayland-devel mailing list