This is the first step towards making wl_resource an opaque pointer type.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
{
if (resource->object.id == 0) {
resource->object.id =
- wl_map_insert_new(&client->objects, 0, resource);
- } else if (wl_map_insert_at(&client->objects, 0,
+ wl_map_insert_new(&client->objects,
+ WL_MAP_ENTRY_LEGACY, resource);
+ } else if (wl_map_insert_at(&client->objects, WL_MAP_ENTRY_LEGACY,
resource->object.id, resource) < 0) {
wl_resource_post_error(client->display_resource,
WL_DISPLAY_ERROR_INVALID_OBJECT,
}
}
+WL_EXPORT struct wl_list *
+wl_resource_get_link(struct wl_resource *resource)
+{
+ return &resource->link;
+}
+
+WL_EXPORT struct wl_client *
+wl_resource_get_client(struct wl_resource *resource)
+{
+ return resource->client;
+}
+
+WL_EXPORT void *
+wl_resource_get_user_data(struct wl_resource *resource)
+{
+ return resource->data;
+}
+
+WL_EXPORT void
+wl_resource_set_destructor(struct wl_resource *resource,
+ wl_resource_destroy_func_t destroy)
+{
+ resource->destroy = destroy;
+}
+
+WL_EXPORT void
+wl_resource_add_destroy_listener(struct wl_resource *resource,
+ struct wl_listener * listener)
+{
+ wl_signal_add(&resource->destroy_signal, listener);
+}
+
+WL_EXPORT struct wl_listener *
+wl_resource_get_destroy_listener(struct wl_resource *resource,
+ wl_notify_func_t notify)
+{
+ return wl_signal_get(&resource->destroy_signal, notify);
+}
+
WL_EXPORT void
wl_client_add_destroy_listener(struct wl_client *client,
struct wl_listener *listener)
struct wl_client;
struct wl_display;
struct wl_listener;
+struct wl_resource;
+struct wl_global;
typedef void (*wl_notify_func_t)(struct wl_listener *listener, void *data);
void wl_event_loop_add_destroy_listener(struct wl_event_loop *loop,
l->notify(l, data);
}
+typedef void (*wl_resource_destroy_func_t)(struct wl_resource *resource);
+
+/* The wl_resource structure has be deprecated as a transparent structure.
+ * While wl_resource will still exist, it will, in the future, be an opaque
+ * pointer. Instead of accessing wl_resource directly, it should be created by
+ * wl_client_add_object and wl_client_new_object and only accessed by the
+ * accessor functions provided.
+ */
struct wl_resource {
struct wl_object object;
- void (*destroy)(struct wl_resource *resource);
+ wl_resource_destroy_func_t destroy;
struct wl_list link;
struct wl_signal destroy_signal;
struct wl_client *client;
uint32_t
wl_client_add_resource(struct wl_client *client,
- struct wl_resource *resource);
+ struct wl_resource *resource) WL_DEPRECATED;
struct wl_display *
wl_client_get_display(struct wl_client *client);
void
wl_resource_destroy(struct wl_resource *resource);
+struct wl_list *
+wl_resource_get_link(struct wl_resource *resource);
+struct wl_client *
+wl_resource_get_client(struct wl_resource *resource);
+void *
+wl_resource_get_user_data(struct wl_resource *resource);
+void
+wl_resource_set_destructor(struct wl_resource *resource,
+ wl_resource_destroy_func_t destroy);
+void
+wl_resource_add_destroy_listener(struct wl_resource *resource,
+ struct wl_listener * listener);
+struct wl_listener *
+wl_resource_get_destroy_listener(struct wl_resource *resource,
+ wl_notify_func_t notify);
void *
wl_shm_buffer_get_data(struct wl_buffer *buffer);
#include "wayland-server.h"
struct wl_shm_pool {
- struct wl_resource resource;
+ struct wl_resource *resource;
int refcount;
char *data;
int size;
static void
destroy_buffer(struct wl_resource *resource)
{
- struct wl_shm_buffer *buffer =
- container_of(resource, struct wl_shm_buffer, buffer.resource);
+ struct wl_shm_buffer *buffer = wl_resource_get_user_data(resource);
if (buffer->pool)
shm_pool_unref(buffer->pool);
int32_t width, int32_t height,
int32_t stride, uint32_t format)
{
- struct wl_shm_pool *pool = resource->data;
+ struct wl_shm_pool *pool = wl_resource_get_user_data(resource);
struct wl_shm_buffer *buffer;
switch (format) {
buffer->pool = pool;
pool->refcount++;
- wl_resource_init(&buffer->buffer.resource, &wl_buffer_interface,
- &shm_buffer_interface, id, buffer);
- buffer->buffer.resource.client = resource->client;
+ buffer->buffer.resource.object.id = id;
+ buffer->buffer.resource.object.interface = &wl_buffer_interface;
+ buffer->buffer.resource.object.implementation = &shm_buffer_interface;
+ buffer->buffer.resource.data = buffer;
+ buffer->buffer.resource.client = client;
buffer->buffer.resource.destroy = destroy_buffer;
wl_client_add_resource(client, &buffer->buffer.resource);
static void
destroy_pool(struct wl_resource *resource)
{
- struct wl_shm_pool *pool = resource->data;
+ struct wl_shm_pool *pool = wl_resource_get_user_data(resource);
shm_pool_unref(pool);
}
shm_pool_resize(struct wl_client *client, struct wl_resource *resource,
int32_t size)
{
- struct wl_shm_pool *pool = resource->data;
+ struct wl_shm_pool *pool = wl_resource_get_user_data(resource);
void *data;
data = mremap(pool->data, pool->size, size, MREMAP_MAYMOVE);
}
close(fd);
- wl_resource_init(&pool->resource, &wl_shm_pool_interface,
- &shm_pool_interface, id, pool);
- pool->resource.client = client;
- pool->resource.destroy = destroy_pool;
+ pool->resource = wl_client_add_object(client, &wl_shm_pool_interface,
+ &shm_pool_interface, id, pool);
+ if (!pool->resource)
+ goto err_free;
- wl_client_add_resource(client, &pool->resource);
+ wl_resource_set_destructor(pool->resource, destroy_pool);
return;
buffer->offset = 0;
buffer->pool = NULL;
- wl_resource_init(&buffer->buffer.resource, &wl_buffer_interface,
- &shm_buffer_interface, id, buffer);
+ buffer->buffer.resource.object.id = id;
+ buffer->buffer.resource.object.interface = &wl_buffer_interface;
+ buffer->buffer.resource.object.implementation = &shm_buffer_interface;
+ buffer->buffer.resource.data = buffer;
buffer->buffer.resource.client = client;
buffer->buffer.resource.destroy = destroy_buffer;
#define WL_EXPORT
#endif
+/* Deprecated attribute */
+#if defined(__GNUC__) && __GNUC__ >= 4
+#define WL_DEPRECATED __attribute__ ((deprecated))
+#else
+#define WL_DEPRECATED
+#endif
+
struct wl_message {
const char *name;
const char *signature;