<div dir="ltr"><div>Thanks for reviewing :) English is my weakness (not the only though :D). Fixed patch is coming...<br><br></div><div>Marek<br></div><div><div><div class="gmail_extra"><br><br><div class="gmail_quote">On 19 June 2014 04:24, Bryce W. Harrington <span dir="ltr"><<a href="mailto:b.harrington@samsung.com" target="_blank">b.harrington@samsung.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">On Mon, May 26, 2014 at 04:57:23PM +0200, Marek Chalupa wrote:<br>
> When an error occurs, wl_display_get_error() does not<br>
> provide any way of getting know if it was a local error or if it was<br>
> an error event, respectively what object caused the error and what<br>
> the error was.<br>
><br>
> This patch introduces a new function wl_display_get_protocol_error()<br>
> which will return error code, interface and id of the object that<br>
> generated the error.<br>
> wl_display_get_error() will work the same way as before.<br>
><br>
> wl_display_get_protocol_error() DOES NOT indicate that a non-protocol<br>
> error happened. It returns valid information only in that case that<br>
> (protocol) error occurred, so it should be used after calling<br>
> wl_display_get_error() with positive result.<br>
><br>
> Thanks to Pekka Paalanen <<a href="mailto:ppaalanen@gmail.com">ppaalanen@gmail.com</a>> for pointing out<br>
> issues in the first versions of this patch.<br>
><br>
> Reviewed-by: Pekka Paalanen <<a href="mailto:ppaalanen@gmail.com">ppaalanen@gmail.com</a>><br>
<br>
</div>Some copyedits below. Otherwise LGTM.<br>
<br>
Reviewed-by: Bryce Harrington <<a href="mailto:b.harrington@samsung.com">b.harrington@samsung.com</a>><br>
<div><div class="h5"><br>
> ---<br>
> src/wayland-client.c | 138 ++++++++++++++++++++++++++++++++++++++++++++-------<br>
> src/wayland-client.h | 3 ++<br>
> 2 files changed, 123 insertions(+), 18 deletions(-)<br>
><br>
> diff --git a/src/wayland-client.c b/src/wayland-client.c<br>
> index e8aab7e..ee2215d 100644<br>
> --- a/src/wayland-client.c<br>
> +++ b/src/wayland-client.c<br>
> @@ -78,7 +78,24 @@ struct wl_event_queue {<br>
> struct wl_display {<br>
> struct wl_proxy proxy;<br>
> struct wl_connection *connection;<br>
> +<br>
> + /* errno of the last wl_display error */<br>
> int last_error;<br>
> +<br>
> + /* When display gets an error event from some object, it stores<br>
> + * information about it here, so that client can get this<br>
> + * information afterwards */<br>
> + struct {<br>
> + /* Code of the error. It can be compared to<br>
> + * the interface's errors enumeration. */<br>
> + uint32_t code;<br>
> + /* interface (protocol) in which the error occurred */<br>
> + const struct wl_interface *interface;<br>
> + /* id of the proxy that caused the error. There's no warranty<br>
> + * that the proxy is still valid. It's up to client how it will<br>
> + * use it */<br>
> + uint32_t id;<br>
> + } protocol_error;<br>
> int fd;<br>
> pthread_t display_thread;<br>
> struct wl_map objects;<br>
> @@ -96,6 +113,14 @@ struct wl_display {<br>
><br>
> static int debug_client = 0;<br>
><br>
> +/**<br>
> + * This function is called for local errors (no memory, server hung up)<br>
> + *<br>
> + * \param display<br>
> + * \param error error value (EINVAL, EFAULT, ...)<br>
> + *<br>
> + * \note this function is called with display mutex locked<br>
> + */<br>
> static void<br>
> display_fatal_error(struct wl_display *display, int error)<br>
> {<br>
> @@ -105,7 +130,7 @@ display_fatal_error(struct wl_display *display, int error)<br>
> return;<br>
><br>
> if (!error)<br>
> - error = 1;<br>
> + error = EFAULT;<br>
><br>
> display->last_error = error;<br>
><br>
> @@ -113,11 +138,56 @@ display_fatal_error(struct wl_display *display, int error)<br>
> pthread_cond_broadcast(&iter->cond);<br>
> }<br>
><br>
> +/**<br>
> + * This function is called for error events<br>
> + * and idicates that in some object occured an error.<br>
<br>
</div></div>indicates<br>
<br>
"in some object an error occurred" might be grammatically better.<br>
<div class=""><br>
> + * Difference between this function and display_fatal_error()<br>
> + * is that this one handles errors that will come in wire, whereas<br>
<br>
</div>"come by wire" or "come in by wire" might be clearer<br>
<div><div class="h5"><br>
> + * display_fatal_error() is called for local errors.<br>
> + *<br>
> + * \param display<br>
> + * \param code error code<br>
> + * \param id id of the object that generated the error<br>
> + * \param intf protocol interface<br>
> + */<br>
> static void<br>
> -wl_display_fatal_error(struct wl_display *display, int error)<br>
> +display_protocol_error(struct wl_display *display, uint32_t code,<br>
> + uint32_t id, const struct wl_interface *intf)<br>
> {<br>
> + struct wl_event_queue *iter;<br>
> + int err;<br>
> +<br>
> + if (display->last_error)<br>
> + return;<br>
> +<br>
> + /* set correct errno */<br>
> + if (wl_interface_equal(intf, &wl_display_interface)) {<br>
> + switch (code) {<br>
> + case WL_DISPLAY_ERROR_INVALID_OBJECT:<br>
> + case WL_DISPLAY_ERROR_INVALID_METHOD:<br>
> + err = EINVAL;<br>
> + break;<br>
> + case WL_DISPLAY_ERROR_NO_MEMORY:<br>
> + err = ENOMEM;<br>
> + break;<br>
> + default:<br>
> + err = EFAULT;<br>
> + }<br>
> + } else {<br>
> + err = EPROTO;<br>
> + }<br>
> +<br>
> pthread_mutex_lock(&display->mutex);<br>
> - display_fatal_error(display, error);<br>
> +<br>
> + display->last_error = err;<br>
> +<br>
> + display->protocol_error.code = code;<br>
> + display-><a href="http://protocol_error.id" target="_blank">protocol_error.id</a> = id;<br>
> + display->protocol_error.interface = intf;<br>
> +<br>
> + wl_list_for_each(iter, &display->event_queue_list, link)<br>
> + pthread_cond_broadcast(&iter->cond);<br>
> +<br>
> pthread_mutex_unlock(&display->mutex);<br>
> }<br>
><br>
> @@ -579,25 +649,12 @@ display_handle_error(void *data,<br>
> uint32_t code, const char *message)<br>
> {<br>
> struct wl_proxy *proxy = object;<br>
> - int err;<br>
><br>
> wl_log("%s@%u: error %d: %s\n",<br>
> proxy->object.interface->name, proxy-><a href="http://object.id" target="_blank">object.id</a>, code, message);<br>
><br>
> - switch (code) {<br>
> - case WL_DISPLAY_ERROR_INVALID_OBJECT:<br>
> - case WL_DISPLAY_ERROR_INVALID_METHOD:<br>
> - err = EINVAL;<br>
> - break;<br>
> - case WL_DISPLAY_ERROR_NO_MEMORY:<br>
> - err = ENOMEM;<br>
> - break;<br>
> - default:<br>
> - err = EFAULT;<br>
> - break;<br>
> - }<br>
> -<br>
> - wl_display_fatal_error(display, err);<br>
> + display_protocol_error(display, code, proxy-><a href="http://object.id" target="_blank">object.id</a>,<br>
> + proxy->object.interface);<br>
> }<br>
><br>
> static void<br>
> @@ -1486,6 +1543,51 @@ wl_display_get_error(struct wl_display *display)<br>
> return ret;<br>
> }<br>
><br>
> +/**<br>
> + * Retrieve the information about a protocol error<br>
> + *<br>
> + * \param display display<br>
> + * \param interface if not NULL, store there an interface on which the error<br>
> + * occured<br>
> + * \param id if not NULL, store there the id of the object that generated<br>
> + * the error. There's no warranty that the object is still valid.<br>
> + * Client must know if he deleted the object or not.<br>
> + * \return The error code as defined in the interface specification.<br>
<br>
<br>
</div></div>+ * Retrieves the information about a protocol error:<br>
+ *<br>
+ * \param display The Wayland display<br>
+ * \param interface if not NULL, stores the interface where the error occurred<br>
+ * \param id if not NULL, stores the object id that generated<br>
+ * the error. There's no guarantee the object is<br>
+ * still valid; the client must know if it deleted the object.<br>
<div><div class="h5">+ * \return The error code as defined in the interface specification.<br>
<br>
<br>
> + *<br>
> + * \code<br>
> + * int err = wl_display_get_error(display);<br>
> + *<br>
> + * if (err == EPROTO) {<br>
> + * code = wl_display_get_protocol_error(display, &interface, &id);<br>
> + * handle_error(code, interface, id);<br>
> + * }<br>
> + *<br>
> + * ...<br>
> + *<br>
> + * \endcode<br>
> + */<br>
> +WL_EXPORT uint32_t<br>
> +wl_display_get_protocol_error(struct wl_display *display,<br>
> + const struct wl_interface **interface,<br>
> + uint32_t *id)<br>
> +{<br>
> + uint32_t ret;<br>
> +<br>
> + pthread_mutex_lock(&display->mutex);<br>
> +<br>
> + ret = display->protocol_error.code;<br>
> +<br>
> + if (interface)<br>
> + *interface = display->protocol_error.interface;<br>
> + if (id)<br>
> + *id = display-><a href="http://protocol_error.id" target="_blank">protocol_error.id</a>;<br>
> +<br>
> + pthread_mutex_unlock(&display->mutex);<br>
> +<br>
> + return ret;<br>
> +}<br>
> +<br>
> +<br>
> /** Send all buffered requests on the display to the server<br>
> *<br>
> * \param display The display context object<br>
> diff --git a/src/wayland-client.h b/src/wayland-client.h<br>
> index 2a32785..dc4df53 100644<br>
> --- a/src/wayland-client.h<br>
> +++ b/src/wayland-client.h<br>
> @@ -161,6 +161,9 @@ int wl_display_dispatch_queue_pending(struct wl_display *display,<br>
> struct wl_event_queue *queue);<br>
> int wl_display_dispatch_pending(struct wl_display *display);<br>
> int wl_display_get_error(struct wl_display *display);<br>
> +uint32_t wl_display_get_protocol_error(struct wl_display *display,<br>
> + const struct wl_interface **interface,<br>
> + uint32_t *id);<br>
><br>
> int wl_display_flush(struct wl_display *display);<br>
> int wl_display_roundtrip(struct wl_display *display);<br>
> --<br>
> 1.9.1<br>
><br>
</div></div>> _______________________________________________<br>
> wayland-devel mailing list<br>
> <a href="mailto:wayland-devel@lists.freedesktop.org">wayland-devel@lists.freedesktop.org</a><br>
> <a href="http://lists.freedesktop.org/mailman/listinfo/wayland-devel" target="_blank">http://lists.freedesktop.org/mailman/listinfo/wayland-devel</a></blockquote></div><br></div></div></div></div>