Unify error events

Consolidate the different error events into one.  This event will also be
usable for other interaces.
This commit is contained in:
Kristian Høgsberg 2011-05-11 10:57:06 -04:00
parent 2d27f3b6e9
commit 1db0525572
5 changed files with 57 additions and 57 deletions

View file

@ -258,27 +258,12 @@ wl_display_get_global(struct wl_display *display,
}
static void
display_handle_invalid_object(void *data,
struct wl_display *display, uint32_t id)
display_handle_error(void *data,
struct wl_display *display, struct wl_object *object,
uint32_t code, const char *message)
{
fprintf(stderr, "sent request to invalid object\n");
abort();
}
static void
display_handle_invalid_method(void *data,
struct wl_display *display,
uint32_t id, uint32_t opcode)
{
fprintf(stderr, "sent invalid request opcode\n");
abort();
}
static void
display_handle_no_memory(void *data,
struct wl_display *display)
{
fprintf(stderr, "server out of memory\n");
fprintf(stderr, "%s@%d: error %d: %s\n",
object->interface->name, object->id, code, message);
abort();
}
@ -345,9 +330,7 @@ display_handle_key(void *data,
}
static const struct wl_display_listener display_listener = {
display_handle_invalid_object,
display_handle_invalid_method,
display_handle_no_memory,
display_handle_error,
display_handle_global,
display_handle_range,
display_handle_key

View file

@ -113,6 +113,21 @@ wl_client_post_event(struct wl_client *client, struct wl_object *sender,
wl_closure_destroy(closure);
}
WL_EXPORT void
wl_client_post_error(struct wl_client *client, struct wl_object *object,
uint32_t code, const char *msg, ...)
{
char buffer[128];
va_list ap;
va_start(ap, msg);
vsnprintf(buffer, sizeof buffer, msg, ap);
va_end(ap);
wl_client_post_event(client, &client->display->object,
WL_DISPLAY_ERROR, object, code, buffer);
}
static int
wl_client_connection_data(int fd, uint32_t mask, void *data)
{
@ -145,16 +160,20 @@ wl_client_connection_data(int fd, uint32_t mask, void *data)
object = wl_hash_table_lookup(client->display->objects, p[0]);
if (object == NULL) {
wl_client_post_event(client, &client->display->object,
WL_DISPLAY_INVALID_OBJECT, p[0]);
wl_client_post_error(client, &client->display->object,
WL_DISPLAY_ERROR_INVALID_OBJECT,
"invalid object %d", p[0]);
wl_connection_consume(connection, size);
len -= size;
continue;
}
if (opcode >= object->interface->method_count) {
wl_client_post_event(client, &client->display->object,
WL_DISPLAY_INVALID_METHOD, p[0], opcode);
wl_client_post_error(client, &client->display->object,
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;
@ -167,9 +186,11 @@ wl_client_connection_data(int fd, uint32_t mask, void *data)
len -= size;
if (closure == NULL && errno == EINVAL) {
wl_client_post_event(client, &client->display->object,
WL_DISPLAY_INVALID_METHOD,
p[0], opcode);
wl_client_post_error(client, &client->display->object,
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);
@ -270,9 +291,8 @@ wl_client_add_resource(struct wl_client *client,
WL_EXPORT void
wl_client_post_no_memory(struct wl_client *client)
{
wl_client_post_event(client,
&client->display->object,
WL_DISPLAY_NO_MEMORY);
wl_client_post_error(client, &client->display->object,
WL_DISPLAY_ERROR_NO_MEMORY, "no memory");
}
WL_EXPORT void

View file

@ -95,6 +95,8 @@ int wl_display_add_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_post_global(struct wl_client *client, struct wl_object *object);

View file

@ -124,18 +124,17 @@ shm_create_buffer(struct wl_client *client, struct wl_shm *shm,
/* FIXME: Define a real exception event instead of abusing the
* display.invalid_object error */
if (visual->object.interface != &wl_visual_interface) {
wl_client_post_event(client, (struct wl_object *) display,
WL_DISPLAY_INVALID_OBJECT, 0);
fprintf(stderr, "invalid visual in create_buffer\n");
wl_client_post_error(client, (struct wl_object *) display,
WL_DISPLAY_ERROR_INVALID_OBJECT,
"invalid visual in create_buffer\n");
close(fd);
return;
}
if (width < 0 || height < 0 || stride < width) {
wl_client_post_event(client, (struct wl_object *) display,
WL_DISPLAY_INVALID_OBJECT, 0);
fprintf(stderr,
"invalid width, height or stride in create_buffer\n");
wl_client_post_error(client, (struct wl_object *) display,
WL_DISPLAY_ERROR_INVALID_OBJECT,
"invalid width, height or stride in create_buffer\n");
close(fd);
return;
}
@ -147,9 +146,9 @@ shm_create_buffer(struct wl_client *client, struct wl_shm *shm,
if (data == MAP_FAILED) {
/* FIXME: Define a real exception event instead of
* abusing this one */
wl_client_post_event(client, (struct wl_object *) display,
WL_DISPLAY_INVALID_OBJECT, 0);
fprintf(stderr, "failed to create image for fd %d\n", fd);
wl_client_post_error(client, (struct wl_object *) display,
WL_DISPLAY_ERROR_INVALID_OBJECT,
"failed to create image for fd %d\n");
return;
}