server: Make wl_object and wl_resource opaque structs

With the work to add wl_resource accessors and port weston to use them,
we're ready to make wl_resource and wl_object opaque structs.  We keep
wl_buffer in the header for EGL stacks to use, but don't expose it by
default.  In time we'll remove it completely, but for now it provides a
transition paths for code that still uses wl_buffer.

Reviewed-by: Jason Ekstrand<jason@jlekstrand.net>
This commit is contained in:
Kristian Høgsberg 2013-06-27 20:09:18 -05:00
parent 2e07587443
commit d94a8722cb
11 changed files with 57 additions and 42 deletions

View file

@ -34,8 +34,8 @@
#include <sys/timerfd.h> #include <sys/timerfd.h>
#include <unistd.h> #include <unistd.h>
#include <assert.h> #include <assert.h>
#include "wayland-server.h"
#include "wayland-private.h" #include "wayland-private.h"
#include "wayland-server.h"
#include "wayland-os.h" #include "wayland-os.h"
struct wl_event_loop { struct wl_event_loop {

View file

@ -829,7 +829,7 @@ emit_structs(struct wl_list *message_list, struct interface *interface)
else if (is_interface && a->type == NEW_ID && a->interface_name == NULL) else if (is_interface && a->type == NEW_ID && a->interface_name == NULL)
printf("const char *interface, uint32_t version, uint32_t "); printf("const char *interface, uint32_t version, uint32_t ");
else if (!is_interface && a->type == OBJECT && a->interface_name == NULL) else if (!is_interface && a->type == OBJECT && a->interface_name == NULL)
printf("struct wl_object *"); printf("void *");
else if (!is_interface && a->type == NEW_ID) else if (!is_interface && a->type == NEW_ID)
printf("struct %s *", a->interface_name); printf("struct %s *", a->interface_name);

View file

@ -388,13 +388,14 @@ wl_proxy_marshal(struct wl_proxy *proxy, uint32_t opcode, ...)
static void static void
display_handle_error(void *data, display_handle_error(void *data,
struct wl_display *display, struct wl_object *object, struct wl_display *display, void *object,
uint32_t code, const char *message) uint32_t code, const char *message)
{ {
struct wl_proxy *proxy = object;
int err; int err;
wl_log("%s@%u: error %d: %s\n", wl_log("%s@%u: error %d: %s\n",
object->interface->name, object->id, code, message); proxy->object.interface->name, proxy->object.id, code, message);
switch (code) { switch (code) {
case WL_DISPLAY_ERROR_INVALID_OBJECT: case WL_DISPLAY_ERROR_INVALID_OBJECT:

View file

@ -26,6 +26,9 @@
#define WAYLAND_PRIVATE_H #define WAYLAND_PRIVATE_H
#include <stdarg.h> #include <stdarg.h>
#define WL_HIDE_DEPRECATED 1
#include "wayland-util.h" #include "wayland-util.h"
#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0]) #define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
@ -39,6 +42,12 @@
#define WL_SERVER_ID_START 0xff000000 #define WL_SERVER_ID_START 0xff000000
#define WL_CLOSURE_MAX_ARGS 20 #define WL_CLOSURE_MAX_ARGS 20
struct wl_object {
const struct wl_interface *interface;
const void *implementation;
uint32_t id;
};
extern struct wl_object global_zombie_object; extern struct wl_object global_zombie_object;
#define WL_ZOMBIE_OBJECT ((void*)&global_zombie_object) #define WL_ZOMBIE_OBJECT ((void*)&global_zombie_object)

View file

@ -102,6 +102,15 @@ struct wl_global {
struct wl_list link; struct wl_list link;
}; };
struct wl_resource {
struct wl_object object;
wl_resource_destroy_func_t destroy;
struct wl_list link;
struct wl_signal destroy_signal;
struct wl_client *client;
void *data;
};
static int wl_debug = 0; static int wl_debug = 0;
static void static void
@ -373,6 +382,10 @@ wl_client_get_credentials(struct wl_client *client,
*gid = client->ucred.gid; *gid = client->ucred.gid;
} }
uint32_t
wl_client_add_resource(struct wl_client *client,
struct wl_resource *resource) WL_DEPRECATED;
WL_EXPORT uint32_t WL_EXPORT uint32_t
wl_client_add_resource(struct wl_client *client, wl_client_add_resource(struct wl_client *client,
struct wl_resource *resource) struct wl_resource *resource)
@ -996,9 +1009,15 @@ wl_client_add_object(struct wl_client *client,
return NULL; return NULL;
} }
wl_resource_init(resource, interface, implementation, id, data); resource->object.id = id;
resource->client = client; resource->object.interface = interface;
resource->object.implementation = implementation;
wl_signal_init(&resource->destroy_signal);
resource->destroy = NULL; resource->destroy = NULL;
resource->client = client;
resource->data = data;
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,

View file

@ -181,12 +181,14 @@ wl_signal_emit(struct wl_signal *signal, void *data)
typedef void (*wl_resource_destroy_func_t)(struct wl_resource *resource); typedef void (*wl_resource_destroy_func_t)(struct wl_resource *resource);
/* The wl_resource structure has be deprecated as a transparent structure. #ifndef WL_HIDE_DEPRECATED
* 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 struct wl_object {
* wl_client_add_object and wl_client_new_object and only accessed by the const struct wl_interface *interface;
* accessor functions provided. const void *implementation;
*/ uint32_t id;
};
struct wl_resource { struct wl_resource {
struct wl_object object; struct wl_object object;
wl_resource_destroy_func_t destroy; wl_resource_destroy_func_t destroy;
@ -196,27 +198,17 @@ struct wl_resource {
void *data; 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_buffer {
struct wl_resource resource; struct wl_resource resource;
int32_t width, height; int32_t width, height;
uint32_t busy_count; uint32_t busy_count;
}; } WL_DEPRECATED;
uint32_t
wl_client_add_resource(struct wl_client *client,
struct wl_resource *resource) WL_DEPRECATED;
#endif
/* /*
* Post an event to the client's object referred to by 'resource'. * Post an event to the client's object referred to by 'resource'.
@ -247,10 +239,6 @@ void wl_resource_post_no_memory(struct wl_resource *resource);
#include "wayland-server-protocol.h" #include "wayland-server-protocol.h"
uint32_t
wl_client_add_resource(struct wl_client *client,
struct wl_resource *resource) WL_DEPRECATED;
struct wl_display * struct wl_display *
wl_client_get_display(struct wl_client *client); wl_client_get_display(struct wl_client *client);

View file

@ -283,6 +283,9 @@ wl_shm_buffer_create(struct wl_client *client,
WL_EXPORT struct wl_shm_buffer * WL_EXPORT struct wl_shm_buffer *
wl_shm_buffer_get(struct wl_resource *resource) wl_shm_buffer_get(struct wl_resource *resource)
{ {
if (resource == NULL)
return NULL;
if (wl_resource_instance_of(resource, &wl_buffer_interface, if (wl_resource_instance_of(resource, &wl_buffer_interface,
&shm_buffer_interface)) &shm_buffer_interface))
return wl_resource_get_user_data(resource); return wl_resource_get_user_data(resource);

View file

@ -61,12 +61,6 @@ struct wl_interface {
const struct wl_message *events; const struct wl_message *events;
}; };
struct wl_object {
const struct wl_interface *interface;
const void *implementation;
uint32_t id;
};
/** /**
* wl_list - linked list * wl_list - linked list
* *

View file

@ -31,8 +31,8 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include "wayland-server.h"
#include "wayland-private.h" #include "wayland-private.h"
#include "wayland-server.h"
#include "test-runner.h" #include "test-runner.h"
struct client_destroy_listener { struct client_destroy_listener {

View file

@ -32,8 +32,8 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include "wayland-server.h"
#include "wayland-private.h" #include "wayland-private.h"
#include "wayland-server.h"
#include "test-runner.h" #include "test-runner.h"
struct display_destroy_listener { struct display_destroy_listener {

View file

@ -25,8 +25,9 @@
#include <assert.h> #include <assert.h>
#include <unistd.h> #include <unistd.h>
#include <signal.h> #include <signal.h>
#include "wayland-server.h"
#include "wayland-private.h" #include "wayland-private.h"
#include "wayland-server.h"
#include "test-runner.h" #include "test-runner.h"
static int static int