<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Apr 24, 2014 at 4:37 PM, Jonathon Jongsma <span dir="ltr"><<a href="mailto:jjongsma@redhat.com" target="_blank">jjongsma@redhat.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div id=":4qy" class="a3s" style="overflow:hidden">Perhaps there should be a g_warning here to aid debugging? Or alternately in the function that calls this one?<br>
<div><div class="h5"><br></div></div></div></blockquote><div><br></div><div>The spice_usb_device_manager_get() will return NULL , with a GError. Since this function is called many times by spice-gtk or the client, I think it's preferable to let the application print a warning or a dialog (once) instead of flooding with warnings. However, I added a SPICE_DEBUG.<br>
</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div id=":4qy" class="a3s" style="overflow:hidden"><div><div class="h5">
> return FALSE;<br>
> - }<br>
> #endif<br>
><br>
> /* Initialize libusb */<br>
> diff --git a/<span class="il">gtk</span>/win-usb-driver-install.c b/<span class="il">gtk</span>/win-usb-driver-install.c<br>
> index bb18ae4..71b51d7 100644<br>
> --- a/<span class="il">gtk</span>/win-usb-driver-install.c<br>
> +++ b/<span class="il">gtk</span>/win-usb-driver-install.c<br>
> @@ -53,14 +53,42 @@ struct _SpiceWinUsbDriverPrivate {<br>
> };<br>
><br>
><br>
> +static void spice_win_usb_driver_initable_iface_init(GInitableIface *iface);<br>
><br>
> -G_DEFINE_TYPE(SpiceWinUsbDriver, spice_win_usb_driver, G_TYPE_OBJECT);<br>
> +G_DEFINE_TYPE_WITH_CODE(SpiceWinUsbDriver, spice_win_usb_driver,<br>
> G_TYPE_OBJECT,<br>
> + G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,<br>
> spice_win_usb_driver_initable_iface_init));<br>
><br>
> static void spice_win_usb_driver_init(SpiceWinUsbDriver *self)<br>
> {<br>
> self->priv = SPICE_WIN_USB_DRIVER_GET_PRIVATE(self);<br>
> }<br>
><br>
> +static gboolean spice_win_usb_driver_initable_init(GInitable *initable,<br>
> + GCancellable<br>
> *cancellable,<br>
> + GError **err)<br>
> +{<br>
> + SpiceWinUsbDriver *self = SPICE_WIN_USB_DRIVER(initable);<br>
> + SpiceWinUsbDriverPrivate *priv = self->priv;<br>
> +<br>
> + SPICE_DEBUG("win-usb-driver-install: connecting to usbclerk named<br>
> pipe");<br>
> + priv->handle = CreateFile(USB_CLERK_PIPE_NAME,<br>
> + GENERIC_READ | GENERIC_WRITE,<br>
> + 0, NULL,<br>
> + OPEN_EXISTING,<br>
> + FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,<br>
> + NULL);<br>
> + if (priv->handle == INVALID_HANDLE_VALUE) {<br>
> + DWORD errval = GetLastError();<br>
> + gchar *errstr = g_win32_error_message(errval);<br>
> + g_set_error(err, SPICE_CLIENT_ERROR, SPICE_CLIENT_ERROR_USB_SERVICE,<br>
> + "Failed to create service named pipe (%ld) %s", errval,<br>
> errstr);<br>
> + g_free(errstr);<br>
> + return FALSE;<br>
> + }<br>
> +<br>
> + return TRUE;<br>
> +}<br>
> +<br>
> static void spice_win_usb_driver_finalize(GObject *gobject)<br>
> {<br>
> SpiceWinUsbDriver *self = SPICE_WIN_USB_DRIVER(gobject);<br>
> @@ -68,6 +96,7 @@ static void spice_win_usb_driver_finalize(GObject *gobject)<br>
><br>
> if (priv->handle)<br>
> CloseHandle(priv->handle);<br>
> +<br>
> g_clear_object(&priv->result);<br>
> }<br>
><br>
> @@ -80,6 +109,11 @@ static void<br>
> spice_win_usb_driver_class_init(SpiceWinUsbDriverClass *klass)<br>
> g_type_class_add_private(klass, sizeof(SpiceWinUsbDriverPrivate));<br>
> }<br>
><br>
> +static void spice_win_usb_driver_initable_iface_init(GInitableIface *iface)<br>
> +{<br>
> + iface->init = spice_win_usb_driver_initable_init;<br>
> +}<br>
> +<br>
> /* ------------------------------------------------------------------ */<br>
> /* callbacks */<br>
><br>
> @@ -244,13 +278,15 @@ void<br>
> spice_win_usb_driver_read_reply_async(SpiceWinUsbDriver *self)<br>
><br>
><br>
> G_GNUC_INTERNAL<br>
> -SpiceWinUsbDriver *spice_win_usb_driver_new(void)<br>
> +SpiceWinUsbDriver *spice_win_usb_driver_new(GError **err)<br>
> {<br>
> - GObject *obj;<br>
> + GObject *self;<br>
> +<br>
> + g_return_val_if_fail(err == NULL || *err == NULL, FALSE);<br>
><br>
> - obj = g_object_new(SPICE_TYPE_WIN_USB_DRIVER, NULL);<br>
> + self = g_initable_new(SPICE_TYPE_WIN_USB_DRIVER, NULL, err, NULL);<br>
><br>
> - return SPICE_WIN_USB_DRIVER(obj);<br>
> + return SPICE_WIN_USB_DRIVER(self);<br>
> }<br>
><br>
> static<br>
> @@ -286,26 +322,6 @@ void spice_win_usb_driver_op(SpiceWinUsbDriver *self,<br>
> vid = spice_usb_device_get_vid(device);<br>
> pid = spice_usb_device_get_pid(device);<br>
><br>
> - if (! priv->handle ) {<br>
> - SPICE_DEBUG("win-usb-driver-install: connecting to usbclerk named<br>
> pipe");<br>
> - priv->handle = CreateFile(USB_CLERK_PIPE_NAME,<br>
> - GENERIC_READ | GENERIC_WRITE,<br>
> - 0, NULL,<br>
> - OPEN_EXISTING,<br>
> - FILE_ATTRIBUTE_NORMAL |<br>
> FILE_FLAG_OVERLAPPED,<br>
> - NULL);<br>
> - if (priv->handle == INVALID_HANDLE_VALUE) {<br>
> - DWORD errval = GetLastError();<br>
> - gchar *errstr = g_win32_error_message(errval);<br>
> - g_warning("failed to create a named pipe to usbclerk (%ld) %s",<br>
> - errval,errstr);<br>
> - g_simple_async_result_set_error(result,<br>
> - G_IO_ERROR, G_IO_ERROR_FAILED,<br>
> - "Failed to create named pipe (%ld) %s", errval,<br>
> errstr);<br>
> - goto failed_request;<br>
> - }<br>
> - }<br>
> -<br>
<br>
</div></div>One behavioral change to note here: with the old code, if we failed to create the usbclerk pipe, we would re-try to do it again the next time spice_win_usb_driver_op() was called. With the new code, we try it once at the beginning and then never try again. I suspect that re-trying isn't really useful (if it failed the first time, it will likely fail again the next time), but I thought it was worth mentioning the change in behavior.</div>
</blockquote></div><br></div><div class="gmail_extra">Yes, that's correct. I added a comment in the commit message (now it retries every time UsbDeviceManager is initialized).<br></div><div class="gmail_extra"><br clear="all">
<br>-- <br>Marc-André Lureau
</div></div>