summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Ekstrand <jason@jlekstrand.net>2013-03-08 22:26:13 -0600
committerKristian Høgsberg <krh@bitplanet.net>2013-03-18 23:04:32 -0400
commitbedc3432ff731b0ad680831ecc66a7a5829621a6 (patch)
tree5291c3126cf36a35e3bb82e1016d1158e6be4ad8
parentca5b1946cb0f186d604858bec75bba0435f9adc9 (diff)
Add wl_resource_init and use it in libwayland implementations of data sharing and SHM
This commit adds a wl_resource_init function for initializing wl_resource structures similar to wl_client_add_object. From this commit forward, wl_resource structures should not be initialized manually, but should use wl_resource_init. In the event of a change to the wl_resource structure, this allows us to protect against regressions by filling in added fields with reasonable defaults. In this way, while changing wl_object or wl_resource still constitutes an ABI break, compositors following this rule will only need to be recompiled in order to properly link against the new version. Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
-rw-r--r--src/data-device.c16
-rw-r--r--src/wayland-server.c6
-rw-r--r--src/wayland-server.h16
-rw-r--r--src/wayland-shm.c24
4 files changed, 27 insertions, 35 deletions
diff --git a/src/data-device.c b/src/data-device.c
index 4255c13..92ceb12 100644
--- a/src/data-device.c
+++ b/src/data-device.c
@@ -98,13 +98,9 @@ wl_data_source_send_offer(struct wl_data_source *source,
if (offer == NULL)
return NULL;
+ wl_resource_init(&offer->resource, &wl_data_offer_interface,
+ &data_offer_interface, 0, offer);
offer->resource.destroy = destroy_data_offer;
- offer->resource.object.id = 0;
- offer->resource.object.interface = &wl_data_offer_interface;
- offer->resource.object.implementation =
- (void (**)(void)) &data_offer_interface;
- offer->resource.data = offer;
- wl_signal_init(&offer->resource.destroy_signal);
offer->source = source;
offer->source_destroy_listener.notify = destroy_offer_data_source;
@@ -459,13 +455,9 @@ create_data_source(struct wl_client *client,
return;
}
+ wl_resource_init(&source->resource, &wl_data_source_interface,
+ &data_source_interface, id, source);
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->accept = client_source_accept;
source->send = client_source_send;
diff --git a/src/wayland-server.c b/src/wayland-server.c
index 130511d..dcb4435 100644
--- a/src/wayland-server.c
+++ b/src/wayland-server.c
@@ -1396,13 +1396,9 @@ wl_client_add_object(struct wl_client *client,
return NULL;
}
- resource->object.interface = interface;
- resource->object.implementation = implementation;
- resource->object.id = id;
+ wl_resource_init(resource, interface, implementation, id, data);
resource->client = client;
- resource->data = data;
resource->destroy = (void *) free;
- wl_signal_init(&resource->destroy_signal);
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 c7369eb..38b8303 100644
--- a/src/wayland-server.h
+++ b/src/wayland-server.h
@@ -190,6 +190,22 @@ struct wl_resource {
void *data;
};
+static inline void
+wl_resource_init(struct wl_resource *resource,
+ const struct wl_interface *interface,
+ const void *implementation, uint32_t id, void *data)
+{
+ resource->object.id = id;
+ resource->object.interface = interface;
+ resource->object.implementation = implementation;
+
+ wl_signal_init(&resource->destroy_signal);
+
+ resource->destroy = NULL;
+ resource->client = NULL;
+ resource->data = data;
+}
+
struct wl_buffer {
struct wl_resource resource;
int32_t width, height;
diff --git a/src/wayland-shm.c b/src/wayland-shm.c
index 47c126b..776c0f2 100644
--- a/src/wayland-shm.c
+++ b/src/wayland-shm.c
@@ -128,12 +128,8 @@ shm_pool_create_buffer(struct wl_client *client, struct wl_resource *resource,
buffer->pool = pool;
pool->refcount++;
- buffer->buffer.resource.object.id = id;
- buffer->buffer.resource.object.interface = &wl_buffer_interface;
- buffer->buffer.resource.object.implementation = (void (**)(void))
- &shm_buffer_interface;
-
- buffer->buffer.resource.data = buffer;
+ wl_resource_init(&buffer->buffer.resource, &wl_buffer_interface,
+ &shm_buffer_interface, id, buffer);
buffer->buffer.resource.client = resource->client;
buffer->buffer.resource.destroy = destroy_buffer;
@@ -211,12 +207,8 @@ shm_create_pool(struct wl_client *client, struct wl_resource *resource,
}
close(fd);
- pool->resource.object.id = id;
- pool->resource.object.interface = &wl_shm_pool_interface;
- pool->resource.object.implementation =
- (void (**)(void)) &shm_pool_interface;
-
- pool->resource.data = pool;
+ wl_resource_init(&pool->resource, &wl_shm_pool_interface,
+ &shm_pool_interface, id, pool);
pool->resource.client = client;
pool->resource.destroy = destroy_pool;
@@ -283,12 +275,8 @@ wl_shm_buffer_create(struct wl_client *client,
buffer->offset = 0;
buffer->pool = NULL;
- buffer->buffer.resource.object.id = id;
- buffer->buffer.resource.object.interface = &wl_buffer_interface;
- buffer->buffer.resource.object.implementation = (void (**)(void))
- &shm_buffer_interface;
-
- buffer->buffer.resource.data = buffer;
+ wl_resource_init(&buffer->buffer.resource, &wl_buffer_interface,
+ &shm_buffer_interface, id, buffer);
buffer->buffer.resource.client = client;
buffer->buffer.resource.destroy = destroy_buffer;