<arg name="key" type="uint"/>
</request>
- <!-- A request addressed a non-existent object id. This is
- tyipcally a fatal error. -->
- <event name="invalid_object">
- <arg name="object_id" type="uint"/>
+ <!-- A fatal error has occurred. -->
+ <event name="error">
+ <arg name="object_id" type="object" interface="wl_object"/>
+ <arg name="code" type="uint"/>
+ <arg name="message" type="string"/>
</event>
- <!-- A request tried to invoke an opcode out of range. This is
- typically a fatal error. -->
- <event name="invalid_method">
- <arg name="object_id" type="uint"/>
- <arg name="opcode" type="uint"/>
- </event>
-
- <!-- A request has failed due to an out of memory error. -->
- <event name="no_memory"/>
+ <enum name="error">
+ <entry name="invalid_object" value="0"/>
+ <entry name="invalid_method" value="1"/>
+ <entry name="no_memory" value="2"/>
+ </enum>
<!-- Notify the client of global objects. These are objects that
are created by the server. Globals are published on the
</request>
</interface>
-
<!-- Shared memory support -->
<interface name="wl_shm" version="1">
<!-- Transfer a shm buffer to the server. The allocated buffer
}
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();
}
}
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
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)
{
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;
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);
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
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);
/* 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;
}
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;
}