[RFC wayland 01/12] wayland-client: add wl_display_get_error()

David Herrmann dh.herrmann at googlemail.com
Thu Oct 11 14:37:42 PDT 2012


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 at googlemail.com>
---
 src/wayland-client.c | 39 ++++++++++++++++++++++++++++++++++++---
 src/wayland-client.h |  1 +
 2 files changed, 37 insertions(+), 3 deletions(-)

diff --git a/src/wayland-client.c b/src/wayland-client.c
index 625cd76..2e9681c 100644
--- a/src/wayland-client.c
+++ b/src/wayland-client.c
@@ -65,6 +65,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;
@@ -235,9 +236,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
@@ -594,6 +613,20 @@ wl_display_dispatch(struct wl_display *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;
diff --git a/src/wayland-client.h b/src/wayland-client.h
index cb1be9c..6fae273 100644
--- a/src/wayland-client.h
+++ b/src/wayland-client.h
@@ -60,6 +60,7 @@ int wl_display_get_fd(struct wl_display *display);
 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_get_error(struct wl_display *display);
 
 int wl_display_flush(struct wl_display *display);
 void wl_display_roundtrip(struct wl_display *display);
-- 
1.7.12.2



More information about the wayland-devel mailing list