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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Throw an error when initialization failed.
---
 gtk/spice-client.h       |  2 ++
 gtk/usb-device-manager.c | 23 ++++++++++++++++-------
 2 files changed, 18 insertions(+), 7 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..e941904 100644
--- a/gtk/usb-device-manager.c
+++ b/gtk/usb-device-manager.c
@@ -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

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]