[PATCH wayland 08/10] wl_data_source: don't open-code wl_client_add_object

Daniel Stone daniel at fooishbar.org
Mon Jul 23 11:54:45 PDT 2012


Signed-off-by: Daniel Stone <daniel at fooishbar.org>
---
 src/data-device.c    |   35 +++++++++++++++++++----------------
 src/wayland-server.h |    3 ++-
 2 files changed, 21 insertions(+), 17 deletions(-)

diff --git a/src/data-device.c b/src/data-device.c
index ac3c7fb..0249abb 100644
--- a/src/data-device.c
+++ b/src/data-device.c
@@ -113,7 +113,7 @@ wl_data_source_send_offer(struct wl_data_source *source,
 
 	offer->source = source;
 	offer->source_destroy_listener.notify = destroy_offer_data_source;
-	wl_signal_add(&source->resource.destroy_signal,
+	wl_signal_add(&source->resource->destroy_signal,
 		      &offer->source_destroy_listener);
 
 	wl_data_device_send_data_offer(target, offer->resource);
@@ -417,7 +417,7 @@ wl_seat_set_selection(struct wl_seat *seat, struct wl_data_source *source,
 	if (source) {
 		seat->selection_data_source_listener.notify =
 			destroy_selection_data_source;
-		wl_signal_add(&source->resource.destroy_signal,
+		wl_signal_add(&source->resource->destroy_signal,
 			      &seat->selection_data_source_listener);
 	}
 }
@@ -441,10 +441,10 @@ static const struct wl_data_device_interface data_device_interface = {
 };
 
 static void
-destroy_data_source(struct wl_resource *resource)
+destroy_data_source(struct wl_listener *listener, void *data)
 {
 	struct wl_data_source *source =
-		container_of(resource, struct wl_data_source, resource);
+		container_of(listener, struct wl_data_source, destroy_listener);
 	char **p;
 
 	wl_array_for_each(p, &source->mime_types)
@@ -452,28 +452,28 @@ destroy_data_source(struct wl_resource *resource)
 
 	wl_array_release(&source->mime_types);
 
-	source->resource.object.id = 0;
+	free(source);
 }
 
 static void
 client_source_accept(struct wl_data_source *source,
 		     uint32_t time, const char *mime_type)
 {
-	wl_data_source_send_target(&source->resource, mime_type);
+	wl_data_source_send_target(source->resource, mime_type);
 }
 
 static void
 client_source_send(struct wl_data_source *source,
 		   const char *mime_type, int32_t fd)
 {
-	wl_data_source_send_send(&source->resource, mime_type, fd);
+	wl_data_source_send_send(source->resource, mime_type, fd);
 	close(fd);
 }
 
 static void
 client_source_cancel(struct wl_data_source *source)
 {
-	wl_data_source_send_cancelled(&source->resource);
+	wl_data_source_send_cancelled(source->resource);
 }
 
 static void
@@ -488,20 +488,23 @@ create_data_source(struct wl_client *client,
 		return;
 	}
 
-	source->resource.destroy = destroy_data_source;
-	source->resource.object.id = id;
-	source->resource.object.interface = &wl_data_source_interface;
-	source->resource.object.implementation =
-		(void (**)(void)) &data_source_interface;
-	source->resource.data = source;
-	wl_signal_init(&source->resource.destroy_signal);
+	source->resource =
+		wl_client_add_object(client, &wl_data_source_interface,
+				     &data_source_interface, id, source);
+	if (source->resource == NULL) {
+		free(source);
+		wl_resource_post_no_memory(resource);
+		return;
+	}
+	source->destroy_listener.notify = destroy_data_source;
+	wl_signal_add(&source->resource->destroy_signal,
+		      &source->destroy_listener);
 
 	source->accept = client_source_accept;
 	source->send = client_source_send;
 	source->cancel = client_source_cancel;
 
 	wl_array_init(&source->mime_types);
-	wl_client_add_resource(client, &source->resource);
 }
 
 static void unbind_data_device(struct wl_resource *resource)
diff --git a/src/wayland-server.h b/src/wayland-server.h
index e1a8a2e..376a76f 100644
--- a/src/wayland-server.h
+++ b/src/wayland-server.h
@@ -230,7 +230,8 @@ struct wl_data_offer {
 };
 
 struct wl_data_source {
-	struct wl_resource resource;
+	struct wl_resource *resource;
+	struct wl_listener destroy_listener;
 	struct wl_array mime_types;
 
 	void (*accept)(struct wl_data_source *source,
-- 
1.7.10.4



More information about the wayland-devel mailing list