[PATCH wayland 6/6] Add dispatcher versions of functions that take an interface
Jason Ekstrand
jason at jlekstrand.net
Fri Mar 8 20:28:16 PST 2013
Specifically, the following functions have been added:
- wl_resource_init_d
- wl_client_add_object_d
- wl_client_new_object_d
- wl_proxy_add_listener_d
Signed-off-by: Jason Ekstrand <jason at jlekstrand.net>
---
src/wayland-client.c | 30 +++++++++++++++++++++++++++++-
src/wayland-client.h | 4 ++++
src/wayland-server.c | 29 ++++++++++++++++++++++++++---
src/wayland-server.h | 28 ++++++++++++++++++++++++----
4 files changed, 83 insertions(+), 8 deletions(-)
diff --git a/src/wayland-client.c b/src/wayland-client.c
index f07a1cd..92c2c06 100644
--- a/src/wayland-client.c
+++ b/src/wayland-client.c
@@ -1,6 +1,7 @@
/*
* Copyright © 2008-2012 Kristian Høgsberg
* Copyright © 2010-2012 Intel Corporation
+ * Copyright © 2013 Jason Ekstrand
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
@@ -313,13 +314,40 @@ WL_EXPORT int
wl_proxy_add_listener(struct wl_proxy *proxy,
void (**implementation)(void), void *data)
{
+ return wl_proxy_add_listener_d(proxy, NULL, implementation, data);
+}
+
+/** Set a proxy's listener
+ *
+ * \param proxy The proxy object
+ * \param dispatcher The listener dispatcher to be added to proxy
+ * \param implementation The listener data associated with the dispatcher
+ * \param data User data to be associated with the proxy
+ * \return 0 on success or -1 on failure
+ *
+ * Set proxy's listener to \c dispatcher with the associated implementation
+ * data given in \c implementation and its user data to \c data. If a listener
+ * has already been set, this function fails and nothing is changed.
+ *
+ * The exact details of \c implementation depends on the dispatcher used.
+ *
+ * Calling this function with a null dispatcher is exactly the same as calling
+ * \ref wl_proxy_add_listener.
+ *
+ * \memberof wl_proxy
+ */
+WL_EXPORT int
+wl_proxy_add_listener_d(struct wl_proxy *proxy,
+ wl_object_dispatcher_func_t dispatcher,
+ void *implementation, void *data)
+{
if (proxy->object.implementation || proxy->object.dispatcher) {
fprintf(stderr, "proxy already has listener\n");
return -1;
}
proxy->object.implementation = implementation;
- proxy->object.dispatcher = NULL;
+ proxy->object.dispatcher = dispatcher;
proxy->user_data = data;
return 0;
diff --git a/src/wayland-client.h b/src/wayland-client.h
index 442d221..5305946 100644
--- a/src/wayland-client.h
+++ b/src/wayland-client.h
@@ -1,5 +1,6 @@
/*
* Copyright © 2008 Kristian Høgsberg
+ * Copyright © 2013 Jason Ekstrand
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
@@ -130,6 +131,9 @@ struct wl_proxy *wl_proxy_create(struct wl_proxy *factory,
void wl_proxy_destroy(struct wl_proxy *proxy);
int wl_proxy_add_listener(struct wl_proxy *proxy,
void (**implementation)(void), void *data);
+int wl_proxy_add_listener_d(struct wl_proxy *proxy,
+ wl_object_dispatcher_func_t dispatcher,
+ void *implementation, void *data);
void wl_proxy_set_user_data(struct wl_proxy *proxy, void *user_data);
void *wl_proxy_get_user_data(struct wl_proxy *proxy);
uint32_t wl_proxy_get_id(struct wl_proxy *proxy);
diff --git a/src/wayland-server.c b/src/wayland-server.c
index 1c6899e..b3fe30b 100644
--- a/src/wayland-server.c
+++ b/src/wayland-server.c
@@ -1,5 +1,6 @@
/*
* Copyright © 2008 Kristian Høgsberg
+ * Copyright © 2013 Jason Ekstrand
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
@@ -1413,6 +1414,17 @@ wl_client_add_object(struct wl_client *client,
const void *implementation,
uint32_t id, void *data)
{
+ return wl_client_add_object_d(client, interface, NULL,
+ implementation, id, data);
+}
+
+WL_EXPORT struct wl_resource *
+wl_client_add_object_d(struct wl_client *client,
+ const struct wl_interface *interface,
+ wl_object_dispatcher_func_t dispatcher,
+ const void *implementation,
+ uint32_t id, void *data)
+{
struct wl_resource *resource;
resource = malloc(sizeof *resource);
@@ -1421,7 +1433,8 @@ wl_client_add_object(struct wl_client *client,
return NULL;
}
- wl_resource_init(resource, interface, implementation, id, data);
+ wl_resource_init_d(resource, interface, dispatcher,
+ implementation, id, data);
resource->client = client;
resource->destroy = (void *) free;
@@ -1442,11 +1455,21 @@ wl_client_new_object(struct wl_client *client,
const struct wl_interface *interface,
const void *implementation, void *data)
{
+ return wl_client_new_object_d(client, interface, NULL,
+ implementation, data);
+}
+
+WL_EXPORT struct wl_resource *
+wl_client_new_object_d(struct wl_client *client,
+ const struct wl_interface *interface,
+ wl_object_dispatcher_func_t dispatcher,
+ const void *implementation, void *data)
+{
uint32_t id;
id = wl_map_insert_new(&client->objects, WL_MAP_SERVER_SIDE, NULL);
- return wl_client_add_object(client,
- interface, implementation, id, data);
+ return wl_client_add_object_d(client, interface, dispatcher,
+ implementation, id, data);
}
diff --git a/src/wayland-server.h b/src/wayland-server.h
index 091e3d3..fffa76b 100644
--- a/src/wayland-server.h
+++ b/src/wayland-server.h
@@ -1,5 +1,6 @@
/*
* Copyright © 2008 Kristian Høgsberg
+ * Copyright © 2013 Jason Ekstrand
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
@@ -133,10 +134,20 @@ wl_client_add_object(struct wl_client *client,
const struct wl_interface *interface,
const void *implementation, uint32_t id, void *data);
struct wl_resource *
+wl_client_add_object_d(struct wl_client *client,
+ const struct wl_interface *interface,
+ wl_object_dispatcher_func_t dispatcher,
+ const void *implementation, uint32_t id, void *data);
+struct wl_resource *
wl_client_new_object(struct wl_client *client,
const struct wl_interface *interface,
const void *implementation, void *data);
struct wl_resource *
+wl_client_new_object_d(struct wl_client *client,
+ const struct wl_interface *interface,
+ wl_object_dispatcher_func_t dispatcher,
+ const void *implementation, void *data);
+struct wl_resource *
wl_client_get_object(struct wl_client *client, uint32_t id);
struct wl_listener {
@@ -191,14 +202,15 @@ struct wl_resource {
};
static inline void
-wl_resource_init(struct wl_resource *resource,
- const struct wl_interface *interface,
- const void *implementation, uint32_t id, void *data)
+wl_resource_init_d(struct wl_resource *resource,
+ const struct wl_interface *interface,
+ wl_object_dispatcher_func_t dispatcher,
+ const void *implementation, uint32_t id, void *data)
{
resource->object.id = id;
resource->object.interface = interface;
resource->object.implementation = implementation;
- resource->object.dispatcher = NULL;
+ resource->object.dispatcher = dispatcher;
wl_signal_init(&resource->destroy_signal);
@@ -207,6 +219,14 @@ wl_resource_init(struct wl_resource *resource,
resource->data = data;
}
+static inline void
+wl_resource_init(struct wl_resource *resource,
+ const struct wl_interface *interface,
+ const void *implementation, uint32_t id, void *data)
+{
+ wl_resource_init_d(resource, interface, NULL, implementation, id, data);
+}
+
struct wl_buffer {
struct wl_resource resource;
int32_t width, height;
--
1.8.1.4
More information about the wayland-devel
mailing list