Pass struct wl_resource as the first argument to server side stubs

This commit is contained in:
Kristian Høgsberg 2011-08-23 16:40:39 -04:00
parent 5dc90adc19
commit 8cbc5482b1
4 changed files with 58 additions and 57 deletions

View file

@ -514,9 +514,10 @@ emit_structs(struct wl_list *message_list, struct interface *interface)
n = strlen(m->name) + 17; n = strlen(m->name) + 17;
if (is_interface) { if (is_interface) {
printf("struct wl_client *client,\n" printf("struct wl_resource *resource,\n"
"%sstruct wl_resource *resource", "%sstruct %s *%s",
indent(n)); indent(n),
interface->name, interface->name);
} else { } else {
printf("void *data,\n"), printf("void *data,\n"),
printf("%sstruct %s *%s", printf("%sstruct %s *%s",

View file

@ -108,8 +108,8 @@ wl_resource_post_event(struct wl_resource *resource, uint32_t opcode, ...)
} }
WL_EXPORT void WL_EXPORT void
wl_client_post_error(struct wl_client *client, struct wl_object *object, wl_resource_post_error(struct wl_resource *resource,
uint32_t code, const char *msg, ...) uint32_t code, const char *msg, ...)
{ {
char buffer[128]; char buffer[128];
va_list ap; va_list ap;
@ -118,8 +118,9 @@ wl_client_post_error(struct wl_client *client, struct wl_object *object,
vsnprintf(buffer, sizeof buffer, msg, ap); vsnprintf(buffer, sizeof buffer, msg, ap);
va_end(ap); va_end(ap);
wl_resource_post_event(client->display_resource, wl_resource_post_event(resource->client->display_resource,
WL_DISPLAY_ERROR, object, code, buffer); WL_DISPLAY_ERROR,
&resource->object, code, buffer);
} }
static int static int
@ -155,9 +156,9 @@ wl_client_connection_data(int fd, uint32_t mask, void *data)
resource = wl_map_lookup(&client->objects, p[0]); resource = wl_map_lookup(&client->objects, p[0]);
if (resource == NULL) { if (resource == NULL) {
wl_client_post_error(client, &resource->object, wl_resource_post_error(resource,
WL_DISPLAY_ERROR_INVALID_OBJECT, WL_DISPLAY_ERROR_INVALID_OBJECT,
"invalid object %d", p[0]); "invalid object %d", p[0]);
wl_connection_consume(connection, size); wl_connection_consume(connection, size);
len -= size; len -= size;
continue; continue;
@ -165,11 +166,11 @@ wl_client_connection_data(int fd, uint32_t mask, void *data)
object = &resource->object; object = &resource->object;
if (opcode >= object->interface->method_count) { if (opcode >= object->interface->method_count) {
wl_client_post_error(client, &resource->object, wl_resource_post_error(resource,
WL_DISPLAY_ERROR_INVALID_METHOD, WL_DISPLAY_ERROR_INVALID_METHOD,
"invalid method %d, object %s@%d", "invalid method %d, object %s@%d",
object->interface->name, object->interface->name,
object->id, opcode); object->id, opcode);
wl_connection_consume(connection, size); wl_connection_consume(connection, size);
len -= size; len -= size;
continue; continue;
@ -181,12 +182,12 @@ wl_client_connection_data(int fd, uint32_t mask, void *data)
len -= size; len -= size;
if (closure == NULL && errno == EINVAL) { if (closure == NULL && errno == EINVAL) {
wl_client_post_error(client, &resource->object, wl_resource_post_error(resource,
WL_DISPLAY_ERROR_INVALID_METHOD, WL_DISPLAY_ERROR_INVALID_METHOD,
"invalid arguments for %s@%d.%s", "invalid arguments for %s@%d.%s",
object->interface->name, object->interface->name,
object->id, object->id,
message->name); message->name);
continue; continue;
} else if (closure == NULL && errno == ENOMEM) { } else if (closure == NULL && errno == ENOMEM) {
wl_client_post_no_memory(client); wl_client_post_no_memory(client);
@ -197,8 +198,8 @@ wl_client_connection_data(int fd, uint32_t mask, void *data)
if (wl_debug) if (wl_debug)
wl_closure_print(closure, object, false); wl_closure_print(closure, object, false);
wl_closure_invoke(closure, object, wl_closure_invoke(closure, resource->data,
object->implementation[opcode], client); object->implementation[opcode], resource);
wl_closure_destroy(closure); wl_closure_destroy(closure);
} }
@ -287,8 +288,8 @@ wl_client_add_resource(struct wl_client *client,
WL_EXPORT void WL_EXPORT void
wl_client_post_no_memory(struct wl_client *client) wl_client_post_no_memory(struct wl_client *client)
{ {
wl_client_post_error(client, &client->display_resource->object, wl_resource_post_error(client->display_resource,
WL_DISPLAY_ERROR_NO_MEMORY, "no memory"); WL_DISPLAY_ERROR_NO_MEMORY, "no memory");
} }
static void static void
@ -510,32 +511,31 @@ wl_input_device_update_grab(struct wl_input_device *device,
} }
static void static void
display_bind(struct wl_client *client, display_bind(struct wl_resource *resource,
struct wl_resource *resource, uint32_t name, struct wl_display *display, uint32_t name,
const char *interface, uint32_t version, uint32_t id) const char *interface, uint32_t version, uint32_t id)
{ {
struct wl_global *global; struct wl_global *global;
struct wl_display *display = resource->data;
wl_list_for_each(global, &display->global_list, link) wl_list_for_each(global, &display->global_list, link)
if (global->name == name) if (global->name == name)
break; break;
if (&global->link == &display->global_list) if (&global->link == &display->global_list)
wl_client_post_error(client, &resource->object, wl_resource_post_error(resource,
WL_DISPLAY_ERROR_INVALID_OBJECT, WL_DISPLAY_ERROR_INVALID_OBJECT,
"invalid global %d", name); "invalid global %d", name);
else else
global->bind(client, global->data, version, id); global->bind(resource->client, global->data, version, id);
} }
static void static void
display_sync(struct wl_client *client, display_sync(struct wl_resource *resource,
struct wl_resource *resource, uint32_t id) struct wl_display *display, uint32_t id)
{ {
struct wl_resource *callback; struct wl_resource *callback;
callback = wl_client_add_object(client, callback = wl_client_add_object(resource->client,
&wl_callback_interface, NULL, id, NULL); &wl_callback_interface, NULL, id, NULL);
wl_resource_post_event(callback, WL_CALLBACK_DONE, 0); wl_resource_post_event(callback, WL_CALLBACK_DONE, 0);
wl_resource_destroy(callback, 0); wl_resource_destroy(callback, 0);

View file

@ -98,8 +98,6 @@ void wl_display_remove_global(struct wl_display *display,
struct wl_client *wl_client_create(struct wl_display *display, int fd); struct wl_client *wl_client_create(struct wl_display *display, int fd);
void wl_client_destroy(struct wl_client *client); void wl_client_destroy(struct wl_client *client);
void wl_client_post_error(struct wl_client *client, struct wl_object *object,
uint32_t code, const char *msg, ...);
void wl_client_post_no_memory(struct wl_client *client); void wl_client_post_no_memory(struct wl_client *client);
void wl_client_flush(struct wl_client *client); void wl_client_flush(struct wl_client *client);
@ -226,6 +224,9 @@ struct wl_selection {
struct wl_listener selection_focus_listener; struct wl_listener selection_focus_listener;
}; };
void
wl_resource_post_error(struct wl_resource *resource,
uint32_t code, const char *msg, ...);
void void
wl_resource_post_event(struct wl_resource *resource, uint32_t opcode, ...); wl_resource_post_event(struct wl_resource *resource, uint32_t opcode, ...);

View file

@ -58,17 +58,18 @@ destroy_buffer(struct wl_resource *resource)
} }
static void static void
shm_buffer_damage(struct wl_client *client, struct wl_resource *resource, shm_buffer_damage(struct wl_resource *resource, struct wl_buffer *base,
int32_t x, int32_t y, int32_t width, int32_t height) int32_t x, int32_t y, int32_t width, int32_t height)
{ {
struct wl_shm_buffer *buffer = resource->data; struct wl_shm_buffer *buffer =
container_of(base, struct wl_shm_buffer, buffer);
buffer->shm->callbacks->buffer_damaged(&buffer->buffer, x, y, buffer->shm->callbacks->buffer_damaged(&buffer->buffer, x, y,
width, height); width, height);
} }
static void static void
shm_buffer_destroy(struct wl_client *client, struct wl_resource *resource) shm_buffer_destroy(struct wl_resource *resource, struct wl_buffer *buffer)
{ {
wl_resource_destroy(resource, 0); wl_resource_destroy(resource, 0);
} }
@ -113,27 +114,26 @@ wl_shm_buffer_init(struct wl_shm *shm, struct wl_client *client, uint32_t id,
} }
static void static void
shm_create_buffer(struct wl_client *client, struct wl_resource *resource, shm_create_buffer(struct wl_resource *resource, struct wl_shm *shm,
uint32_t id, int fd, int32_t width, int32_t height, uint32_t id, int fd, int32_t width, int32_t height,
uint32_t stride, struct wl_visual *visual) uint32_t stride, struct wl_visual *visual)
{ {
struct wl_shm *shm = resource->data;
struct wl_shm_buffer *buffer; struct wl_shm_buffer *buffer;
void *data; void *data;
if (!visual || visual->object.interface != &wl_visual_interface) { if (!visual || visual->object.interface != &wl_visual_interface) {
wl_client_post_error(client, &resource->object, wl_resource_post_error(resource,
WL_SHM_ERROR_INVALID_VISUAL, WL_SHM_ERROR_INVALID_VISUAL,
"invalid visual"); "invalid visual");
close(fd); close(fd);
return; return;
} }
if (width < 0 || height < 0 || stride < width) { if (width < 0 || height < 0 || stride < width) {
wl_client_post_error(client, &resource->object, wl_resource_post_error(resource,
WL_SHM_ERROR_INVALID_STRIDE, WL_SHM_ERROR_INVALID_STRIDE,
"invalid width, height or stride (%dx%d, %u)", "invalid width, height or stride (%dx%d, %u)",
width, height, stride); width, height, stride);
close(fd); close(fd);
return; return;
} }
@ -143,22 +143,21 @@ shm_create_buffer(struct wl_client *client, struct wl_resource *resource,
close(fd); close(fd);
if (data == MAP_FAILED) { if (data == MAP_FAILED) {
wl_client_post_error(client, &resource->object, wl_resource_post_error(resource,
WL_SHM_ERROR_INVALID_FD, WL_SHM_ERROR_INVALID_FD,
"failed mmap fd %d", fd); "failed mmap fd %d", fd);
return; return;
} }
buffer = wl_shm_buffer_init(shm, client, id, buffer = wl_shm_buffer_init(shm, resource->client, id,
width, height, stride, visual, width, height, stride, visual, data);
data);
if (buffer == NULL) { if (buffer == NULL) {
munmap(data, stride * height); munmap(data, stride * height);
wl_client_post_no_memory(client); wl_client_post_no_memory(resource->client);
return; return;
} }
wl_client_add_resource(client, &buffer->buffer.resource); wl_client_add_resource(resource->client, &buffer->buffer.resource);
} }
const static struct wl_shm_interface shm_interface = { const static struct wl_shm_interface shm_interface = {