This commit changes the resource createion/setup API to be more like wl_proxy. Instead of having one master function that does everything except setup the destructor it is broken into two more balanced functions. First, the wl_client_add/new_versioned_object function sets up all of the immutable bits such as the version and the interface. Then wl_resource_set_implementation is called to set up all of the mutable bits such as implementation, user data, and destructor. This more closely matches client-side and (I think) makes more sense.
Signed-off-by: Jason Ekstrand <ja...@jlekstrand.net> --- src/wayland-server.c | 65 ++++++++++++++++++++++++++++++---------------------- src/wayland-server.h | 13 +++++------ src/wayland-shm.c | 29 ++++++++++++----------- 3 files changed, 59 insertions(+), 48 deletions(-) diff --git a/src/wayland-server.c b/src/wayland-server.c index bd323e4..5c6d36a 100644 --- a/src/wayland-server.c +++ b/src/wayland-server.c @@ -516,6 +516,16 @@ wl_resource_get_client(struct wl_resource *resource) } WL_EXPORT void +wl_resource_set_implementation(struct wl_resource *resource, + const void *implementation, void *data, + wl_resource_destroy_func_t destroy) +{ + resource->object.implementation = implementation; + resource->data = data; + resource->destroy = destroy; +} + +WL_EXPORT void wl_resource_set_user_data(struct wl_resource *resource, void *data) { resource->data = data; @@ -533,13 +543,6 @@ wl_resource_get_version(struct wl_resource *resource) return resource->version; } -WL_EXPORT void -wl_resource_set_destructor(struct wl_resource *resource, - wl_resource_destroy_func_t destroy) -{ - resource->destroy = destroy; -} - WL_EXPORT int wl_resource_instance_of(struct wl_resource *resource, const struct wl_interface *interface, @@ -627,8 +630,7 @@ display_sync(struct wl_client *client, uint32_t serial; callback = wl_client_add_versioned_object(client, - &wl_callback_interface, 1, - NULL, id, NULL); + &wl_callback_interface, 1, id); serial = wl_display_get_serial(client->display); wl_callback_send_done(callback, serial); wl_resource_destroy(callback); @@ -651,9 +653,9 @@ display_get_registry(struct wl_client *client, registry_resource = wl_client_add_versioned_object(client, &wl_registry_interface, - 1, ®istry_interface, id, - display); - registry_resource->destroy = unbind_resource; + 1, id); + wl_resource_set_implementation(registry_resource, ®istry_interface, + display, unbind_resource); wl_list_insert(&display->registry_resource_list, ®istry_resource->link); @@ -685,11 +687,13 @@ bind_display(struct wl_client *client, struct wl_display *display = data; client->display_resource = - wl_client_add_versioned_object(client, &wl_display_interface, 1, - &display_interface, id, display); + wl_client_add_versioned_object(client, &wl_display_interface, + 1, id); if(client->display_resource) - client->display_resource->destroy = destroy_client_display_resource; + wl_resource_set_implementation(client->display_resource, + &display_interface, display, + destroy_client_display_resource); } WL_EXPORT struct wl_display * @@ -1044,15 +1048,19 @@ wl_client_add_object(struct wl_client *client, const struct wl_interface *interface, const void *implementation, uint32_t id, void *data) { - return wl_client_add_versioned_object(client, interface, -1, - implementation, id, data); + struct wl_resource *resource = + wl_client_add_versioned_object(client, interface, -1, id); + if (resource) + wl_resource_set_implementation(resource, implementation, + data, NULL); + + return resource; } WL_EXPORT struct wl_resource * wl_client_add_versioned_object(struct wl_client *client, const struct wl_interface *interface, - int version, const void *implementation, - uint32_t id, void *data) + int version, uint32_t id) { struct wl_resource *resource; @@ -1064,13 +1072,13 @@ wl_client_add_versioned_object(struct wl_client *client, resource->object.id = id; resource->object.interface = interface; - resource->object.implementation = implementation; + resource->object.implementation = NULL; wl_signal_init(&resource->destroy_signal); resource->destroy = NULL; resource->client = client; - resource->data = data; + resource->data = NULL; resource->version = version; if (wl_map_insert_at(&client->objects, 0, resource->object.id, resource) < 0) { @@ -1090,21 +1098,24 @@ wl_client_new_object(struct wl_client *client, const struct wl_interface *interface, const void *implementation, void *data) { - return wl_client_new_versioned_object(client, interface, -1, - implementation, data); + struct wl_resource *resource = + wl_client_new_versioned_object(client, interface, -1); + if (resource) + wl_resource_set_implementation(resource, implementation, + data, NULL); + + return resource; } WL_EXPORT struct wl_resource * wl_client_new_versioned_object(struct wl_client *client, const struct wl_interface *interface, - int version, const void *implementation, - void *data) + int version) { uint32_t id; id = wl_map_insert_new(&client->objects, 0, NULL); - return wl_client_add_versioned_object(client, interface, version, - implementation, id, data); + return wl_client_add_versioned_object(client, interface, version, id); } diff --git a/src/wayland-server.h b/src/wayland-server.h index 4c8381a..5908c9b 100644 --- a/src/wayland-server.h +++ b/src/wayland-server.h @@ -137,8 +137,7 @@ wl_client_add_object(struct wl_client *client, struct wl_resource * wl_client_add_versioned_object(struct wl_client *client, const struct wl_interface *interface, - int version, const void *implementation, - uint32_t id, void *data); + int version, uint32_t id); struct wl_resource * wl_client_new_object(struct wl_client *client, const struct wl_interface *interface, @@ -146,8 +145,7 @@ wl_client_new_object(struct wl_client *client, struct wl_resource * wl_client_new_versioned_object(struct wl_client *client, const struct wl_interface *interface, - int version, const void *implementation, - void *data); + int version); struct wl_resource * wl_client_get_object(struct wl_client *client, uint32_t id); @@ -269,14 +267,15 @@ wl_resource_find_for_client(struct wl_list *list, struct wl_client *client); struct wl_client * wl_resource_get_client(struct wl_resource *resource); void +wl_resource_set_implementation(struct wl_resource *resource, + const void *implementation, void *data, + wl_resource_destroy_func_t destructor); +void wl_resource_set_user_data(struct wl_resource *resource, void *data); void * wl_resource_get_user_data(struct wl_resource *resource); int wl_resource_get_version(struct wl_resource *resource); -void -wl_resource_set_destructor(struct wl_resource *resource, - wl_resource_destroy_func_t destroy); int wl_resource_instance_of(struct wl_resource *resource, const struct wl_interface *interface, diff --git a/src/wayland-shm.c b/src/wayland-shm.c index e37b7d9..f4f2cce 100644 --- a/src/wayland-shm.c +++ b/src/wayland-shm.c @@ -128,10 +128,10 @@ shm_pool_create_buffer(struct wl_client *client, struct wl_resource *resource, pool->refcount++; buffer->resource = - wl_client_add_versioned_object(client, &wl_buffer_interface, 1, - &shm_buffer_interface, - id, buffer); - wl_resource_set_destructor(buffer->resource, destroy_buffer); + wl_client_add_versioned_object(client, &wl_buffer_interface, + 1, id); + wl_resource_set_implementation(buffer->resource, &shm_buffer_interface, + buffer, destroy_buffer); } static void @@ -206,12 +206,13 @@ shm_create_pool(struct wl_client *client, struct wl_resource *resource, close(fd); pool->resource = - wl_client_add_versioned_object(client, &wl_shm_pool_interface, 1, - &shm_pool_interface, id, pool); + wl_client_add_versioned_object(client, &wl_shm_pool_interface, + 1, id); if (!pool->resource) goto err_free; - wl_resource_set_destructor(pool->resource, destroy_pool); + wl_resource_set_implementation(pool->resource, &shm_pool_interface, + pool, destroy_pool); return; @@ -231,8 +232,9 @@ bind_shm(struct wl_client *client, { struct wl_resource *resource; - resource = wl_client_add_versioned_object(client, &wl_shm_interface, 1, - &shm_interface, id, data); + resource = wl_client_add_versioned_object(client, &wl_shm_interface, + 1, id); + wl_resource_set_implementation(resource, &shm_interface, data, NULL); wl_shm_send_format(resource, WL_SHM_FORMAT_ARGB8888); wl_shm_send_format(resource, WL_SHM_FORMAT_XRGB8888); @@ -275,11 +277,10 @@ wl_shm_buffer_create(struct wl_client *client, buffer->resource = - wl_client_add_versioned_object(client, - &wl_buffer_interface, 1, - &shm_buffer_interface, - id, buffer); - wl_resource_set_destructor(buffer->resource, destroy_buffer); + wl_client_add_versioned_object(client, &wl_buffer_interface, + 1, id); + wl_resource_set_implementation(buffer->resource, &shm_buffer_interface, + buffer, destroy_buffer); return buffer; } -- 1.8.2.1 _______________________________________________ wayland-devel mailing list wayland-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/wayland-devel