[PATCH wayland] Add accessor functions for wl_resource and deprecate wl_client_add_resource
Jason Ekstrand
jason at jlekstrand.net
Tue Mar 19 11:12:22 PDT 2013
This is the first step towards deprecating wl_resource as a transparent
structure. In the future, wl_resource will be an opaque pointer type and
client code will not have access to its memebers.
---
src/wayland-server.c | 39 +++++++++++++++++++++++++++++++++++++++
src/wayland-server.h | 27 +++++++++++++++++++++++++--
src/wayland-util.h | 7 +++++++
3 files changed, 71 insertions(+), 2 deletions(-)
diff --git a/src/wayland-server.c b/src/wayland-server.c
index dcb4435..5a6bccb 100644
--- a/src/wayland-server.c
+++ b/src/wayland-server.c
@@ -440,6 +440,45 @@ wl_resource_destroy(struct wl_resource *resource)
}
}
+WL_EXPORT struct wl_list *
+wl_resource_get_link(struct wl_resource *resource)
+{
+ return &resource->link;
+}
+
+WL_EXPORT struct wl_client *
+wl_resource_get_client(struct wl_resource *resource)
+{
+ return resource->client;
+}
+
+WL_EXPORT void *
+wl_resource_get_user_data(struct wl_resource *resource)
+{
+ return resource->data;
+}
+
+WL_EXPORT void
+wl_resource_set_destructor(struct wl_resource *resource,
+ wl_resource_destroy_func_t destroy)
+{
+ resource->destroy = destroy;
+}
+
+WL_EXPORT void
+wl_resource_add_destroy_listener(struct wl_resource *resource,
+ struct wl_listener * listener)
+{
+ wl_signal_add(&resource->destroy_signal, listener);
+}
+
+WL_EXPORT struct wl_listener *
+wl_resource_get_destroy_listener(struct wl_resource *resource,
+ wl_notify_func_t notify)
+{
+ return wl_signal_get(&resource->destroy_signal, notify);
+}
+
WL_EXPORT void
wl_client_add_destroy_listener(struct wl_client *client,
struct wl_listener *listener)
diff --git a/src/wayland-server.h b/src/wayland-server.h
index 38b8303..2c6efc9 100644
--- a/src/wayland-server.h
+++ b/src/wayland-server.h
@@ -181,9 +181,17 @@ wl_signal_emit(struct wl_signal *signal, void *data)
l->notify(l, data);
}
+typedef void (*wl_resource_destroy_func_t)(struct wl_resource *resource);
+
+/* The wl_resource structure has be deprecated as a transparent structure.
+ * While wl_resource will still exist, it will, in the future, be an opaque
+ * pointer. Instead of accessing wl_resource directly, it should be created by
+ * wl_client_add_object and wl_client_new_object and only accessed by the
+ * accessor functions provided.
+ */
struct wl_resource {
struct wl_object object;
- void (*destroy)(struct wl_resource *resource);
+ wl_resource_destroy_func_t destroy;
struct wl_list link;
struct wl_signal destroy_signal;
struct wl_client *client;
@@ -417,13 +425,28 @@ void wl_resource_post_no_memory(struct wl_resource *resource);
uint32_t
wl_client_add_resource(struct wl_client *client,
- struct wl_resource *resource);
+ struct wl_resource *resource) WL_DEPRECATED;
struct wl_display *
wl_client_get_display(struct wl_client *client);
void
wl_resource_destroy(struct wl_resource *resource);
+struct wl_list *
+wl_resource_get_link(struct wl_resource *resource);
+struct wl_client *
+wl_resource_get_client(struct wl_resource *resource);
+void *
+wl_resource_get_user_data(struct wl_resource *resource);
+void
+wl_resource_set_destructor(struct wl_resource *resource,
+ wl_resource_destroy_func_t destroy);
+void
+wl_resource_add_destroy_listener(struct wl_resource *resource,
+ struct wl_listener * listener);
+struct wl_listener *
+wl_resource_get_destroy_listener(struct wl_resource *resource,
+ wl_notify_func_t notify);
void
wl_seat_init(struct wl_seat *seat);
diff --git a/src/wayland-util.h b/src/wayland-util.h
index 257a5d1..d01304c 100644
--- a/src/wayland-util.h
+++ b/src/wayland-util.h
@@ -39,6 +39,13 @@ extern "C" {
#define WL_EXPORT
#endif
+/* Deprecated attribute */
+#if defined(__GNUC__) && __GNUC__ >= 4
+#define WL_DEPRECATED __attribute__ ((deprecated))
+#else
+#define WL_DEPRECATED
+#endif
+
struct wl_message {
const char *name;
const char *signature;
--
1.8.1.4
More information about the wayland-devel
mailing list