Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/src/wayland-client.c b/src/wayland-client.c
- index bd40313..28c2848 100644
- --- a/src/wayland-client.c
- +++ b/src/wayland-client.c
- @@ -78,7 +78,21 @@ struct wl_event_queue {
- struct wl_display {
- struct wl_proxy proxy;
- struct wl_connection *connection;
- - int last_error;
- + struct {
- + /* Code of the error. If the object that caused the error is
- + * wl_display, than it contains appropriately set error value
- + * (i. e. EINVAL, ENOMEM). Otherwise it contains code of
- + * error that can be compared to interface's errors enumeration.
- + * This code 'duality' is due to backward compatibility with
- + * old behaviour of wl_display_get_error() */
- + int code;
- + /* interface (protocol) in wich the error occured */
- + const struct wl_interface *interface;
- + /* id of the proxy that caused the error. There's no warranty
- + * that the proxy is still valid. It's up to client how it will
- + * use it */
- + unsigned int id;
- + } error;
- int fd;
- pthread_t display_thread;
- struct wl_map objects;
- @@ -97,27 +111,38 @@ struct wl_display {
- static int debug_client = 0;
- static void
- -display_fatal_error(struct wl_display *display, int error)
- +object_fatal_error(struct wl_display *display, int error,
- + unsigned int id, const struct wl_interface *intf)
- {
- struct wl_event_queue *iter;
- - if (display->last_error)
- + if (display->error.code)
- return;
- if (!error)
- error = 1;
- - display->last_error = error;
- + display->error.code = error;
- + display->error.id = id;
- + display->error.interface = intf;
- wl_list_for_each(iter, &display->event_queue_list, link)
- pthread_cond_broadcast(&iter->cond);
- }
- static void
- -wl_display_fatal_error(struct wl_display *display, int error)
- +display_fatal_error(struct wl_display *display, int error)
- +{
- + struct wl_object *obj = &display->proxy.object;
- + object_fatal_error(display, error, obj->id, obj->interface);
- +}
- +
- +static void
- +wl_display_fatal_error(struct wl_display *display, int error,
- + unsigned int id, const struct wl_interface *intf)
- {
- pthread_mutex_lock(&display->mutex);
- - display_fatal_error(display, error);
- + object_fatal_error(display, error, id, intf);
- pthread_mutex_unlock(&display->mutex);
- }
- @@ -584,20 +609,24 @@ display_handle_error(void *data,
- wl_log("%s@%u: error %d: %s\n",
- proxy->object.interface->name, proxy->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;
- - }
- + if (wl_interface_equal(proxy->object.interface, &wl_display_interface))
- + 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;
- + }
- + else
- + err = code;
- - wl_display_fatal_error(display, err);
- + wl_display_fatal_error(display, err, proxy->object.id,
- + proxy->object.interface);
- }
- static void
- @@ -1147,20 +1176,20 @@ dispatch_queue(struct wl_display *display, struct wl_event_queue *queue)
- {
- int count;
- - if (display->last_error)
- + if (display->error.code)
- goto err;
- count = 0;
- while (!wl_list_empty(&display->display_queue.event_list)) {
- dispatch_event(display, &display->display_queue);
- - if (display->last_error)
- + if (display->error.code)
- goto err;
- count++;
- }
- while (!wl_list_empty(&queue->event_list)) {
- dispatch_event(display, queue);
- - if (display->last_error)
- + if (display->error.code)
- goto err;
- count++;
- }
- @@ -1168,7 +1197,7 @@ dispatch_queue(struct wl_display *display, struct wl_event_queue *queue)
- return count;
- err:
- - errno = display->last_error;
- + errno = display->error.code;
- return -1;
- }
- @@ -1482,13 +1511,50 @@ wl_display_get_error(struct wl_display *display)
- pthread_mutex_lock(&display->mutex);
- - ret = display->last_error;
- + ret = display->error.code;
- pthread_mutex_unlock(&display->mutex);
- return ret;
- }
- +/** Retrieve the last error that occurred along with additional information
- + *
- + * \param display The display context object
- + * \param interface Store the interface that caused the error there (if not NULL)
- + * \param interface Store the id of object that caused the error there (if not NULL)
- + * \return The last error that occurred on \c display or 0 if no error occurred
- + *
- + * Return the last error that occurred on the display. This may be an error sent
- + * by the server or caused by the local client.
- + *
- + * \note Errors are \b fatal. If this function returns non-zero the display
- + * can no longer be used.
- + *
- + * \memberof wl_display
- + */
- +WL_EXPORT int
- +wl_display_get_error_full(struct wl_display *display,
- + const struct wl_interface **interface,
- + unsigned int *id)
- +{
- + int ret;
- +
- + pthread_mutex_lock(&display->mutex);
- +
- + ret = display->error.code;
- +
- + if (interface)
- + *interface = display->error.interface;
- + if (id)
- + *id = display->error.id;
- +
- + pthread_mutex_unlock(&display->mutex);
- +
- + return ret;
- +}
- +
- +
- /** Send all buffered requests on the display to the server
- *
- * \param display The display context object
- @@ -1513,8 +1579,8 @@ wl_display_flush(struct wl_display *display)
- pthread_mutex_lock(&display->mutex);
- - if (display->last_error) {
- - errno = display->last_error;
- + if (display->error.code) {
- + errno = display->error.code;
- ret = -1;
- } else {
- ret = wl_connection_flush(display->connection);
- diff --git a/src/wayland-client.h b/src/wayland-client.h
- index 2a32785..d6b0c4e 100644
- --- a/src/wayland-client.h
- +++ b/src/wayland-client.h
- @@ -161,6 +161,9 @@ int wl_display_dispatch_queue_pending(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_get_error_full(struct wl_display *display,
- + const struct wl_interface **interface,
- + unsigned int *id);
- int wl_display_flush(struct wl_display *display);
- int wl_display_roundtrip(struct wl_display *display);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement