wayland-client: add wl_display_get_error()
authorDavid Herrmann <dh.herrmann@googlemail.com>
Thu, 11 Oct 2012 21:37:42 +0000 (23:37 +0200)
committerKristian Høgsberg <krh@bitplanet.net>
Mon, 15 Oct 2012 20:06:00 +0000 (16:06 -0400)
A server may asynchronously send errors via wl_display.error() events.
Instead of aborting we now the a "last_error" flag inside of wl_display
objects. The user can retrieve these via wl_display_get_error().

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
src/wayland-client.c
src/wayland-client.h

index c0caa7b..751ce70 100644 (file)
@@ -68,6 +68,7 @@ struct wl_event_queue {
 struct wl_display {
        struct wl_proxy proxy;
        struct wl_connection *connection;
+       int last_error;
        int fd;
        int close_fd;
        pthread_t display_thread;
@@ -327,9 +328,27 @@ display_handle_error(void *data,
                     struct wl_display *display, struct wl_object *object,
                     uint32_t code, const char *message)
 {
-       fprintf(stderr, "%s@%u: error %d: %s\n",
-               object->interface->name, object->id, code, message);
-       abort();
+       int err;
+
+       wl_log("%s@%u: error %d: %s\n",
+              object->interface->name, object->id, code, message);
+
+       switch (code) {
+       case WL_DISPLAY_ERROR_INVALID_OBJECT:
+       case WL_DISPLAY_ERROR_INVALID_METHOD:
+               err = -EINVAL;
+               break;
+       case WL_DISPLAY_ERROR_NO_MEMORY:
+               err = -ENOMEM;
+               break;
+       default:
+               err = -EFAULT;
+               break;
+       }
+
+       pthread_mutex_lock(&display->mutex);
+       display->last_error = err;
+       pthread_mutex_unlock(&display->mutex);
 }
 
 static void
@@ -783,6 +802,20 @@ wl_display_dispatch_pending(struct wl_display *display)
  * \memberof wl_display
  */
 WL_EXPORT int
+wl_display_get_error(struct wl_display *display)
+{
+       int ret;
+
+       pthread_mutex_lock(&display->mutex);
+
+       ret = display->last_error;
+
+       pthread_mutex_unlock(&display->mutex);
+
+       return ret;
+}
+
+WL_EXPORT int
 wl_display_flush(struct wl_display *display)
 {
        int ret;
index cb21d70..82e7cc9 100644 (file)
@@ -118,6 +118,7 @@ int wl_display_dispatch(struct wl_display *display);
 int wl_display_dispatch_queue(struct wl_display *display,
                              struct wl_event_queue *queue);
 int wl_display_dispatch_pending(struct wl_display *display);
+int wl_display_get_error(struct wl_display *display);
 
 int wl_display_flush(struct wl_display *display);
 void wl_display_roundtrip(struct wl_display *display);