mirror of
https://gitlab.freedesktop.org/wayland/wayland.git
synced 2025-11-05 13:29:50 -05:00
wayland-client: add wl_display_get_error()
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>
This commit is contained in:
parent
36e29df2cb
commit
66e4aa98cf
2 changed files with 37 additions and 3 deletions
|
|
@ -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",
|
||||
int err;
|
||||
|
||||
wl_log("%s@%u: error %d: %s\n",
|
||||
object->interface->name, object->id, code, message);
|
||||
abort();
|
||||
|
||||
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
|
||||
|
|
@ -782,6 +801,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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue