mirror of
https://gitlab.freedesktop.org/wayland/wayland.git
synced 2025-10-31 22:25:25 -04:00
Add wl_resource_create() and a version field to wl_resource
A new function, wl_resource_create(), lets the compositor create a wl_resource for a given version of the interface. Passing 0 for the object ID will allocate a new ID. The implementation, user data and destructor can be set with wl_resource_set_implementation(). These two functions deprecates wl_client_add/new_object and the main difference and motivation is the ability to provide a version number for the resource. This lets the compositor track which version of the interface a client has created and we'll use that to verify incoming requests. Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
This commit is contained in:
parent
d35b6278c0
commit
4917a967bd
3 changed files with 80 additions and 32 deletions
|
|
@ -109,6 +109,7 @@ struct wl_resource {
|
||||||
struct wl_signal destroy_signal;
|
struct wl_signal destroy_signal;
|
||||||
struct wl_client *client;
|
struct wl_client *client;
|
||||||
void *data;
|
void *data;
|
||||||
|
int version;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int wl_debug = 0;
|
static int wl_debug = 0;
|
||||||
|
|
@ -510,6 +511,12 @@ wl_resource_get_user_data(struct wl_resource *resource)
|
||||||
return resource->data;
|
return resource->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WL_EXPORT int
|
||||||
|
wl_resource_get_version(struct wl_resource *resource)
|
||||||
|
{
|
||||||
|
return resource->version;
|
||||||
|
}
|
||||||
|
|
||||||
WL_EXPORT void
|
WL_EXPORT void
|
||||||
wl_resource_set_destructor(struct wl_resource *resource,
|
wl_resource_set_destructor(struct wl_resource *resource,
|
||||||
wl_resource_destroy_func_t destroy)
|
wl_resource_destroy_func_t destroy)
|
||||||
|
|
@ -603,8 +610,7 @@ display_sync(struct wl_client *client,
|
||||||
struct wl_resource *callback;
|
struct wl_resource *callback;
|
||||||
uint32_t serial;
|
uint32_t serial;
|
||||||
|
|
||||||
callback = wl_client_add_object(client,
|
callback = wl_resource_create(client, &wl_callback_interface, 1, id);
|
||||||
&wl_callback_interface, NULL, id, NULL);
|
|
||||||
serial = wl_display_get_serial(client->display);
|
serial = wl_display_get_serial(client->display);
|
||||||
wl_callback_send_done(callback, serial);
|
wl_callback_send_done(callback, serial);
|
||||||
wl_resource_destroy(callback);
|
wl_resource_destroy(callback);
|
||||||
|
|
@ -626,9 +632,10 @@ display_get_registry(struct wl_client *client,
|
||||||
struct wl_global *global;
|
struct wl_global *global;
|
||||||
|
|
||||||
registry_resource =
|
registry_resource =
|
||||||
wl_client_add_object(client, &wl_registry_interface,
|
wl_resource_create(client, &wl_registry_interface, 1, id);
|
||||||
®istry_interface, id, display);
|
wl_resource_set_implementation(registry_resource,
|
||||||
registry_resource->destroy = unbind_resource;
|
®istry_interface,
|
||||||
|
display, unbind_resource);
|
||||||
|
|
||||||
wl_list_insert(&display->registry_resource_list,
|
wl_list_insert(&display->registry_resource_list,
|
||||||
®istry_resource->link);
|
®istry_resource->link);
|
||||||
|
|
@ -660,11 +667,10 @@ bind_display(struct wl_client *client,
|
||||||
struct wl_display *display = data;
|
struct wl_display *display = data;
|
||||||
|
|
||||||
client->display_resource =
|
client->display_resource =
|
||||||
wl_client_add_object(client, &wl_display_interface,
|
wl_resource_create(client, &wl_display_interface, 1, id);
|
||||||
&display_interface, id, display);
|
wl_resource_set_implementation(client->display_resource,
|
||||||
|
&display_interface, display,
|
||||||
if(client->display_resource)
|
destroy_client_display_resource);
|
||||||
client->display_resource->destroy = destroy_client_display_resource;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WL_EXPORT struct wl_display *
|
WL_EXPORT struct wl_display *
|
||||||
|
|
@ -998,8 +1004,31 @@ wl_display_get_destroy_listener(struct wl_display *display,
|
||||||
WL_EXPORT struct wl_resource *
|
WL_EXPORT struct wl_resource *
|
||||||
wl_client_add_object(struct wl_client *client,
|
wl_client_add_object(struct wl_client *client,
|
||||||
const struct wl_interface *interface,
|
const struct wl_interface *interface,
|
||||||
const void *implementation,
|
const void *implementation, uint32_t id, void *data)
|
||||||
uint32_t id, void *data)
|
{
|
||||||
|
struct wl_resource *resource;
|
||||||
|
|
||||||
|
resource = wl_resource_create(client, interface, -1, id);
|
||||||
|
wl_resource_set_implementation(resource, implementation, data, NULL);
|
||||||
|
|
||||||
|
return 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 struct wl_resource *
|
||||||
|
wl_resource_create(struct wl_client *client,
|
||||||
|
const struct wl_interface *interface,
|
||||||
|
int version, uint32_t id)
|
||||||
{
|
{
|
||||||
struct wl_resource *resource;
|
struct wl_resource *resource;
|
||||||
|
|
||||||
|
|
@ -1009,15 +1038,19 @@ wl_client_add_object(struct wl_client *client,
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (id == 0)
|
||||||
|
id = wl_map_insert_new(&client->objects, 0, NULL);
|
||||||
|
|
||||||
resource->object.id = id;
|
resource->object.id = id;
|
||||||
resource->object.interface = interface;
|
resource->object.interface = interface;
|
||||||
resource->object.implementation = implementation;
|
resource->object.implementation = NULL;
|
||||||
|
|
||||||
wl_signal_init(&resource->destroy_signal);
|
wl_signal_init(&resource->destroy_signal);
|
||||||
|
|
||||||
resource->destroy = NULL;
|
resource->destroy = NULL;
|
||||||
resource->client = client;
|
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) {
|
if (wl_map_insert_at(&client->objects, 0, resource->object.id, resource) < 0) {
|
||||||
wl_resource_post_error(client->display_resource,
|
wl_resource_post_error(client->display_resource,
|
||||||
|
|
@ -1036,12 +1069,12 @@ wl_client_new_object(struct wl_client *client,
|
||||||
const struct wl_interface *interface,
|
const struct wl_interface *interface,
|
||||||
const void *implementation, void *data)
|
const void *implementation, void *data)
|
||||||
{
|
{
|
||||||
uint32_t id;
|
struct wl_resource *resource;
|
||||||
|
|
||||||
id = wl_map_insert_new(&client->objects, 0, NULL);
|
resource = wl_resource_create(client, interface, -1, 0);
|
||||||
return wl_client_add_object(client,
|
wl_resource_set_implementation(resource, implementation, data, NULL);
|
||||||
interface, implementation, id, data);
|
|
||||||
|
|
||||||
|
return resource;
|
||||||
}
|
}
|
||||||
|
|
||||||
WL_EXPORT void
|
WL_EXPORT void
|
||||||
|
|
|
||||||
|
|
@ -242,6 +242,16 @@ void wl_resource_post_no_memory(struct wl_resource *resource);
|
||||||
struct wl_display *
|
struct wl_display *
|
||||||
wl_client_get_display(struct wl_client *client);
|
wl_client_get_display(struct wl_client *client);
|
||||||
|
|
||||||
|
struct wl_resource *
|
||||||
|
wl_resource_create(struct wl_client *client,
|
||||||
|
const struct wl_interface *interface,
|
||||||
|
int version, uint32_t id);
|
||||||
|
void
|
||||||
|
wl_resource_set_implementation(struct wl_resource *resource,
|
||||||
|
const void *implementation,
|
||||||
|
void *data,
|
||||||
|
wl_resource_destroy_func_t destroy);
|
||||||
|
|
||||||
void
|
void
|
||||||
wl_resource_destroy(struct wl_resource *resource);
|
wl_resource_destroy(struct wl_resource *resource);
|
||||||
uint32_t
|
uint32_t
|
||||||
|
|
@ -258,6 +268,8 @@ void
|
||||||
wl_resource_set_user_data(struct wl_resource *resource, void *data);
|
wl_resource_set_user_data(struct wl_resource *resource, void *data);
|
||||||
void *
|
void *
|
||||||
wl_resource_get_user_data(struct wl_resource *resource);
|
wl_resource_get_user_data(struct wl_resource *resource);
|
||||||
|
int
|
||||||
|
wl_resource_get_version(struct wl_resource *resource);
|
||||||
void
|
void
|
||||||
wl_resource_set_destructor(struct wl_resource *resource,
|
wl_resource_set_destructor(struct wl_resource *resource,
|
||||||
wl_resource_destroy_func_t destroy);
|
wl_resource_destroy_func_t destroy);
|
||||||
|
|
|
||||||
|
|
@ -127,10 +127,11 @@ shm_pool_create_buffer(struct wl_client *client, struct wl_resource *resource,
|
||||||
buffer->pool = pool;
|
buffer->pool = pool;
|
||||||
pool->refcount++;
|
pool->refcount++;
|
||||||
|
|
||||||
buffer->resource = wl_client_add_object(client, &wl_buffer_interface,
|
buffer->resource =
|
||||||
&shm_buffer_interface,
|
wl_resource_create(client, &wl_buffer_interface, 1, id);
|
||||||
id, buffer);
|
wl_resource_set_implementation(buffer->resource,
|
||||||
wl_resource_set_destructor(buffer->resource, destroy_buffer);
|
&shm_buffer_interface,
|
||||||
|
buffer, destroy_buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -204,12 +205,14 @@ shm_create_pool(struct wl_client *client, struct wl_resource *resource,
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
pool->resource = wl_client_add_object(client, &wl_shm_pool_interface,
|
pool->resource =
|
||||||
&shm_pool_interface, id, pool);
|
wl_resource_create(client, &wl_shm_pool_interface, 1, id);
|
||||||
if (!pool->resource)
|
if (!pool->resource)
|
||||||
goto err_free;
|
goto err_free;
|
||||||
|
|
||||||
wl_resource_set_destructor(pool->resource, destroy_pool);
|
wl_resource_set_implementation(pool->resource,
|
||||||
|
&shm_pool_interface,
|
||||||
|
pool, destroy_pool);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
@ -229,8 +232,8 @@ bind_shm(struct wl_client *client,
|
||||||
{
|
{
|
||||||
struct wl_resource *resource;
|
struct wl_resource *resource;
|
||||||
|
|
||||||
resource = wl_client_add_object(client, &wl_shm_interface,
|
resource = wl_resource_create(client, &wl_shm_interface, 1, id);
|
||||||
&shm_interface, id, data);
|
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_ARGB8888);
|
||||||
wl_shm_send_format(resource, WL_SHM_FORMAT_XRGB8888);
|
wl_shm_send_format(resource, WL_SHM_FORMAT_XRGB8888);
|
||||||
|
|
@ -271,11 +274,11 @@ wl_shm_buffer_create(struct wl_client *client,
|
||||||
buffer->offset = 0;
|
buffer->offset = 0;
|
||||||
buffer->pool = NULL;
|
buffer->pool = NULL;
|
||||||
|
|
||||||
|
buffer->resource =
|
||||||
buffer->resource = wl_client_add_object(client, &wl_buffer_interface,
|
wl_resource_create(client, &wl_buffer_interface, 1, id);
|
||||||
&shm_buffer_interface,
|
wl_resource_set_implementation(buffer->resource,
|
||||||
id, buffer);
|
&shm_buffer_interface,
|
||||||
wl_resource_set_destructor(buffer->resource, destroy_buffer);
|
buffer, destroy_buffer);
|
||||||
|
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue