[Spice-devel] [PATCH spice-gtk 11/14] usb: call win_usb_driver_new() during initable_init()

Marc-André Lureau marcandre.lureau at gmail.com
Wed Apr 23 11:09:16 PDT 2014


Throw an error when initialization failed.
---
 gtk/spice-client.h       |  2 ++
 gtk/usb-device-manager.c | 27 ++++++++++++++++++---------
 2 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/gtk/spice-client.h b/gtk/spice-client.h
index e734cca..39765db 100644
--- a/gtk/spice-client.h
+++ b/gtk/spice-client.h
@@ -58,6 +58,7 @@ G_BEGIN_DECLS
  * @SPICE_CLIENT_ERROR_FAILED: generic error code
  * @SPICE_CLIENT_ERROR_USB_DEVICE_REJECTED: device redirection rejected by host
  * @SPICE_CLIENT_ERROR_USB_DEVICE_LOST: device disconnected (fatal IO error)
+ * @SPICE_CLIENT_ERROR_USB_SERVICE: USB service error
  *
  * Error codes returned by spice-client API.
  */
@@ -66,6 +67,7 @@ typedef enum
     SPICE_CLIENT_ERROR_FAILED,
     SPICE_CLIENT_ERROR_USB_DEVICE_REJECTED,
     SPICE_CLIENT_ERROR_USB_DEVICE_LOST,
+    SPICE_CLIENT_ERROR_USB_SERVICE,
 } SpiceClientError;
 
 #ifndef SPICE_DISABLE_DEPRECATED
diff --git a/gtk/usb-device-manager.c b/gtk/usb-device-manager.c
index c87efd5..81e3c80 100644
--- a/gtk/usb-device-manager.c
+++ b/gtk/usb-device-manager.c
@@ -227,8 +227,8 @@ static void spice_usb_device_manager_init(SpiceUsbDeviceManager *self)
 }
 
 static gboolean spice_usb_device_manager_initable_init(GInitable  *initable,
-                                                    GCancellable  *cancellable,
-                                                    GError        **err)
+                                                       GCancellable  *cancellable,
+                                                       GError        **err)
 {
     SpiceUsbDeviceManager *self;
     SpiceUsbDeviceManagerPrivate *priv;
@@ -260,6 +260,17 @@ static gboolean spice_usb_device_manager_initable_init(GInitable  *initable,
     }
 
 #ifdef USE_USBREDIR
+
+#ifdef G_OS_WIN32
+    priv->installer = spice_win_usb_driver_new();
+    if (!priv->installer) {
+        g_warn_if_reached();
+        g_set_error_literal(err, SPICE_CLIENT_ERROR, SPICE_CLIENT_ERROR_USB_SERVICE,
+                            "Failed to initialize USB device installer service");
+        return FALSE;
+    }
+#endif
+
     /* Initialize libusb */
     rc = libusb_init(&priv->context);
     if (rc < 0) {
@@ -1480,10 +1491,10 @@ void spice_usb_device_manager_connect_device_async(SpiceUsbDeviceManager *self,
     SpiceWinUsbDriver *installer;
     UsbInstallCbInfo *cbinfo;
 
+    g_return_if_fail(self->priv->installer);
+
     spice_usb_device_set_state(device, SPICE_USB_DEVICE_STATE_INSTALLING);
-    if (! self->priv->installer) {
-        self->priv->installer = spice_win_usb_driver_new();
-    }
+
     installer = self->priv->installer;
     cbinfo = g_new0(UsbInstallCbInfo, 1);
     cbinfo->manager     = self;
@@ -1548,7 +1559,7 @@ void spice_usb_device_manager_disconnect_device(SpiceUsbDeviceManager *self,
     guint8 state;
 
     g_warn_if_fail(device != NULL);
-    g_warn_if_fail(self->priv->installer != NULL);
+    g_return_if_fail(self->priv->installer);
 
     state = spice_usb_device_get_state(device);
     if ((state != SPICE_USB_DEVICE_STATE_INSTALLED) &&
@@ -1557,9 +1568,7 @@ void spice_usb_device_manager_disconnect_device(SpiceUsbDeviceManager *self,
     }
 
     spice_usb_device_set_state(device, SPICE_USB_DEVICE_STATE_UNINSTALLING);
-    if (! self->priv->installer) {
-        self->priv->installer = spice_win_usb_driver_new();
-    }
+
     installer = self->priv->installer;
     cbinfo = g_new0(UsbInstallCbInfo, 1);
     cbinfo->manager     = self;
-- 
1.8.5.3



More information about the Spice-devel mailing list