Commit 8cbc5482 authored by Kristian Høgsberg's avatar Kristian Høgsberg
Browse files

Pass struct wl_resource as the first argument to server side stubs

parent 5dc90adc
......@@ -514,9 +514,10 @@ emit_structs(struct wl_list *message_list, struct interface *interface)
n = strlen(m->name) + 17;
if (is_interface) {
printf("struct wl_client *client,\n"
"%sstruct wl_resource *resource",
indent(n));
printf("struct wl_resource *resource,\n"
"%sstruct %s *%s",
indent(n),
interface->name, interface->name);
} else {
printf("void *data,\n"),
printf("%sstruct %s *%s",
......
......@@ -108,8 +108,8 @@ wl_resource_post_event(struct wl_resource *resource, uint32_t opcode, ...)
}
WL_EXPORT void
wl_client_post_error(struct wl_client *client, struct wl_object *object,
uint32_t code, const char *msg, ...)
wl_resource_post_error(struct wl_resource *resource,
uint32_t code, const char *msg, ...)
{
char buffer[128];
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);
va_end(ap);
wl_resource_post_event(client->display_resource,
WL_DISPLAY_ERROR, object, code, buffer);
wl_resource_post_event(resource->client->display_resource,
WL_DISPLAY_ERROR,
&resource->object, code, buffer);
}
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]);
if (resource == NULL) {
wl_client_post_error(client, &resource->object,
WL_DISPLAY_ERROR_INVALID_OBJECT,
"invalid object %d", p[0]);
wl_resource_post_error(resource,
WL_DISPLAY_ERROR_INVALID_OBJECT,
"invalid object %d", p[0]);
wl_connection_consume(connection, size);
len -= size;
continue;
......@@ -165,11 +166,11 @@ wl_client_connection_data(int fd, uint32_t mask, void *data)
object = &resource->object;
if (opcode >= object->interface->method_count) {
wl_client_post_error(client, &resource->object,
WL_DISPLAY_ERROR_INVALID_METHOD,
"invalid method %d, object %s@%d",
object->interface->name,
object->id, opcode);
wl_resource_post_error(resource,
WL_DISPLAY_ERROR_INVALID_METHOD,
"invalid method %d, object %s@%d",
object->interface->name,
object->id, opcode);
wl_connection_consume(connection, size);
len -= size;
continue;
......@@ -181,12 +182,12 @@ wl_client_connection_data(int fd, uint32_t mask, void *data)
len -= size;
if (closure == NULL && errno == EINVAL) {
wl_client_post_error(client, &resource->object,
WL_DISPLAY_ERROR_INVALID_METHOD,
"invalid arguments for %s@%d.%s",
object->interface->name,
object->id,
message->name);
wl_resource_post_error(resource,
WL_DISPLAY_ERROR_INVALID_METHOD,
"invalid arguments for %s@%d.%s",
object->interface->name,
object->id,
message->name);
continue;
} else if (closure == NULL && errno == ENOMEM) {
wl_client_post_no_memory(client);
......@@ -197,8 +198,8 @@ wl_client_connection_data(int fd, uint32_t mask, void *data)
if (wl_debug)
wl_closure_print(closure, object, false);
wl_closure_invoke(closure, object,
object->implementation[opcode], client);
wl_closure_invoke(closure, resource->data,
object->implementation[opcode], resource);
wl_closure_destroy(closure);
}
......@@ -287,8 +288,8 @@ wl_client_add_resource(struct wl_client *client,
WL_EXPORT void
wl_client_post_no_memory(struct wl_client *client)
{
wl_client_post_error(client, &client->display_resource->object,
WL_DISPLAY_ERROR_NO_MEMORY, "no memory");
wl_resource_post_error(client->display_resource,
WL_DISPLAY_ERROR_NO_MEMORY, "no memory");
}
static void
......@@ -510,32 +511,31 @@ wl_input_device_update_grab(struct wl_input_device *device,
}
static void
display_bind(struct wl_client *client,
struct wl_resource *resource, uint32_t name,
display_bind(struct wl_resource *resource,
struct wl_display *display, uint32_t name,
const char *interface, uint32_t version, uint32_t id)
{
struct wl_global *global;
struct wl_display *display = resource->data;
wl_list_for_each(global, &display->global_list, link)
if (global->name == name)
break;
if (&global->link == &display->global_list)
wl_client_post_error(client, &resource->object,
WL_DISPLAY_ERROR_INVALID_OBJECT,
"invalid global %d", name);
wl_resource_post_error(resource,
WL_DISPLAY_ERROR_INVALID_OBJECT,
"invalid global %d", name);
else
global->bind(client, global->data, version, id);
global->bind(resource->client, global->data, version, id);
}
static void
display_sync(struct wl_client *client,
struct wl_resource *resource, uint32_t id)
display_sync(struct wl_resource *resource,
struct wl_display *display, uint32_t id)
{
struct wl_resource *callback;
callback = wl_client_add_object(client,
callback = wl_client_add_object(resource->client,
&wl_callback_interface, NULL, id, NULL);
wl_resource_post_event(callback, WL_CALLBACK_DONE, 0);
wl_resource_destroy(callback, 0);
......
......@@ -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);
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_flush(struct wl_client *client);
......@@ -226,6 +224,9 @@ struct wl_selection {
struct wl_listener selection_focus_listener;
};
void
wl_resource_post_error(struct wl_resource *resource,
uint32_t code, const char *msg, ...);
void
wl_resource_post_event(struct wl_resource *resource, uint32_t opcode, ...);
......
......@@ -58,17 +58,18 @@ destroy_buffer(struct wl_resource *resource)
}
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)
{
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,
width, height);
}
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);
}
......@@ -113,27 +114,26 @@ wl_shm_buffer_init(struct wl_shm *shm, struct wl_client *client, uint32_t id,
}
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 stride, struct wl_visual *visual)
{
struct wl_shm *shm = resource->data;
struct wl_shm_buffer *buffer;
void *data;
if (!visual || visual->object.interface != &wl_visual_interface) {
wl_client_post_error(client, &resource->object,
WL_SHM_ERROR_INVALID_VISUAL,
"invalid visual");
wl_resource_post_error(resource,
WL_SHM_ERROR_INVALID_VISUAL,
"invalid visual");
close(fd);
return;
}
if (width < 0 || height < 0 || stride < width) {
wl_client_post_error(client, &resource->object,
WL_SHM_ERROR_INVALID_STRIDE,
"invalid width, height or stride (%dx%d, %u)",
width, height, stride);
wl_resource_post_error(resource,
WL_SHM_ERROR_INVALID_STRIDE,
"invalid width, height or stride (%dx%d, %u)",
width, height, stride);
close(fd);
return;
}
......@@ -143,22 +143,21 @@ shm_create_buffer(struct wl_client *client, struct wl_resource *resource,
close(fd);
if (data == MAP_FAILED) {
wl_client_post_error(client, &resource->object,
WL_SHM_ERROR_INVALID_FD,
"failed mmap fd %d", fd);
wl_resource_post_error(resource,
WL_SHM_ERROR_INVALID_FD,
"failed mmap fd %d", fd);
return;
}
buffer = wl_shm_buffer_init(shm, client, id,
width, height, stride, visual,
data);
buffer = wl_shm_buffer_init(shm, resource->client, id,
width, height, stride, visual, data);
if (buffer == NULL) {
munmap(data, stride * height);
wl_client_post_no_memory(client);
wl_client_post_no_memory(resource->client);
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 = {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment