[Spice-commits] 14 commits - gtk/channel-usbredir.c gtk/spice-client.h gtk/usb-device-manager.c gtk/win-usb-driver-install.c gtk/win-usb-driver-install.h

Marc-André Lureau elmarco at kemper.freedesktop.org
Fri Jun 5 04:47:30 PDT 2015


 gtk/channel-usbredir.c       |    4 -
 gtk/spice-client.h           |   15 +++-
 gtk/usb-device-manager.c     |  123 +++++++++++++++----------------------
 gtk/win-usb-driver-install.c |  140 +++++++++++++++++++++++++------------------
 gtk/win-usb-driver-install.h |   28 ++++----
 5 files changed, 161 insertions(+), 149 deletions(-)

New commits:
commit 47abb9549c067aa0f523725ad44997f6c92121f4
Author: Marc-André Lureau <marcandre.lureau at gmail.com>
Date:   Thu Jun 26 15:55:43 2014 +0200

    usb: remove useless assignments
    
    The struct is g_new0() already.

diff --git a/gtk/usb-device-manager.c b/gtk/usb-device-manager.c
index 67d9919..d700dcd 100644
--- a/gtk/usb-device-manager.c
+++ b/gtk/usb-device-manager.c
@@ -1556,9 +1556,6 @@ void spice_usb_device_manager_disconnect_device(SpiceUsbDeviceManager *self,
     cbinfo->manager     = self;
     cbinfo->device      = spice_usb_device_ref(device);
     cbinfo->installer   = installer;
-    cbinfo->cancellable = NULL;
-    cbinfo->callback    = NULL;
-    cbinfo->user_data   = NULL;
 
     spice_win_usb_driver_uninstall_async(installer, device, NULL,
                                          spice_usb_device_manager_drv_uninstall_cb,
commit 534afdf899b6f9af93598d795027d5cbb8e59346
Author: Marc-André Lureau <marcandre.lureau at gmail.com>
Date:   Thu Apr 24 17:51:02 2014 +0200

    win-usb: try to connect to usbclerk during init
    
    Fail early during initialization if the usbclerk service can't be
    reached.
    
    This changes the current behaviour that would retry to connect to
    usbclerk every time to perform an operation. Now, it will try each time
    the UsbDeviceManager is initialized.

diff --git a/gtk/usb-device-manager.c b/gtk/usb-device-manager.c
index 81d6872..67d9919 100644
--- a/gtk/usb-device-manager.c
+++ b/gtk/usb-device-manager.c
@@ -241,11 +241,9 @@ static gboolean spice_usb_device_manager_initable_init(GInitable  *initable,
 #endif
 
 #ifdef G_OS_WIN32
-    priv->installer = spice_win_usb_driver_new();
+    priv->installer = spice_win_usb_driver_new(err);
     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");
+        SPICE_DEBUG("failed to initialize winusb driver");
         return FALSE;
     }
 #endif
diff --git a/gtk/win-usb-driver-install.c b/gtk/win-usb-driver-install.c
index 65bb58c..54e9b14 100644
--- a/gtk/win-usb-driver-install.c
+++ b/gtk/win-usb-driver-install.c
@@ -51,14 +51,42 @@ struct _SpiceWinUsbDriverPrivate {
 };
 
 
+static void spice_win_usb_driver_initable_iface_init(GInitableIface *iface);
 
-G_DEFINE_TYPE(SpiceWinUsbDriver, spice_win_usb_driver, G_TYPE_OBJECT);
+G_DEFINE_TYPE_WITH_CODE(SpiceWinUsbDriver, spice_win_usb_driver, G_TYPE_OBJECT,
+    G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, spice_win_usb_driver_initable_iface_init));
 
 static void spice_win_usb_driver_init(SpiceWinUsbDriver *self)
 {
     self->priv = SPICE_WIN_USB_DRIVER_GET_PRIVATE(self);
 }
 
+static gboolean spice_win_usb_driver_initable_init(GInitable     *initable,
+                                                   GCancellable  *cancellable,
+                                                   GError        **err)
+{
+    SpiceWinUsbDriver *self = SPICE_WIN_USB_DRIVER(initable);
+    SpiceWinUsbDriverPrivate *priv = self->priv;
+
+    SPICE_DEBUG("win-usb-driver-install: connecting to usbclerk named pipe");
+    priv->handle = CreateFile(USB_CLERK_PIPE_NAME,
+                              GENERIC_READ | GENERIC_WRITE,
+                              0, NULL,
+                              OPEN_EXISTING,
+                              FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
+                              NULL);
+    if (priv->handle == INVALID_HANDLE_VALUE) {
+        DWORD errval  = GetLastError();
+        gchar *errstr = g_win32_error_message(errval);
+        g_set_error(err, SPICE_CLIENT_ERROR, SPICE_CLIENT_ERROR_USB_SERVICE,
+                    "Failed to create service named pipe (%ld) %s", errval, errstr);
+        g_free(errstr);
+        return FALSE;
+    }
+
+    return TRUE;
+}
+
 static void spice_win_usb_driver_finalize(GObject *gobject)
 {
     SpiceWinUsbDriver *self = SPICE_WIN_USB_DRIVER(gobject);
@@ -66,6 +94,7 @@ static void spice_win_usb_driver_finalize(GObject *gobject)
 
     if (priv->handle)
         CloseHandle(priv->handle);
+
     g_clear_object(&priv->result);
 
     if (G_OBJECT_CLASS(spice_win_usb_driver_parent_class)->finalize)
@@ -81,6 +110,11 @@ static void spice_win_usb_driver_class_init(SpiceWinUsbDriverClass *klass)
     g_type_class_add_private(klass, sizeof(SpiceWinUsbDriverPrivate));
 }
 
+static void spice_win_usb_driver_initable_iface_init(GInitableIface *iface)
+{
+    iface->init = spice_win_usb_driver_initable_init;
+}
+
 /* ------------------------------------------------------------------ */
 /* callbacks                                                          */
 
@@ -244,13 +278,15 @@ void spice_win_usb_driver_read_reply_async(SpiceWinUsbDriver *self)
 
 
 G_GNUC_INTERNAL
-SpiceWinUsbDriver *spice_win_usb_driver_new(void)
+SpiceWinUsbDriver *spice_win_usb_driver_new(GError **err)
 {
-    GObject *obj;
+    GObject *self;
+
+    g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
 
-    obj = g_object_new(SPICE_TYPE_WIN_USB_DRIVER, NULL);
+    self = g_initable_new(SPICE_TYPE_WIN_USB_DRIVER, NULL, err, NULL);
 
-    return SPICE_WIN_USB_DRIVER(obj);
+    return SPICE_WIN_USB_DRIVER(self);
 }
 
 static
@@ -286,26 +322,6 @@ void spice_win_usb_driver_op(SpiceWinUsbDriver *self,
     vid = spice_usb_device_get_vid(device);
     pid = spice_usb_device_get_pid(device);
 
-    if (! priv->handle ) {
-        SPICE_DEBUG("win-usb-driver-install: connecting to usbclerk named pipe");
-        priv->handle = CreateFile(USB_CLERK_PIPE_NAME,
-                                  GENERIC_READ | GENERIC_WRITE,
-                                  0, NULL,
-                                  OPEN_EXISTING,
-                                  FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
-                                  NULL);
-        if (priv->handle == INVALID_HANDLE_VALUE) {
-            DWORD errval  = GetLastError();
-            gchar *errstr = g_win32_error_message(errval);
-            g_warning("failed to create a named pipe to usbclerk (%ld) %s",
-                      errval,errstr);
-            g_simple_async_result_set_error(result,
-                      G_IO_ERROR, G_IO_ERROR_FAILED,
-                      "Failed to create named pipe (%ld) %s", errval, errstr);
-            goto failed_request;
-        }
-    }
-
     if (!spice_win_usb_driver_send_request(self, op_type,
                                            vid, pid, &err)) {
         g_warning("failed to send a request to usbclerk %s", err->message);
diff --git a/gtk/win-usb-driver-install.h b/gtk/win-usb-driver-install.h
index b9eadcd..f9afedc 100644
--- a/gtk/win-usb-driver-install.h
+++ b/gtk/win-usb-driver-install.h
@@ -61,7 +61,7 @@ struct _SpiceWinUsbDriverClass
 
 GType spice_win_usb_driver_get_type(void);
 
-SpiceWinUsbDriver *spice_win_usb_driver_new(void);
+SpiceWinUsbDriver *spice_win_usb_driver_new(GError **err);
 
 
 void spice_win_usb_driver_install_async(SpiceWinUsbDriver *self,
commit 4839fb4ff51a0803d573b13b3cad0e14bac9850f
Author: Marc-André Lureau <marcandre.lureau at gmail.com>
Date:   Thu Apr 24 17:51:01 2014 +0200

    usb: do not return GError on programmer pre-condition checks
    
    Use regular g_return precondition checks.

diff --git a/gtk/usb-device-manager.c b/gtk/usb-device-manager.c
index f83023b..81d6872 100644
--- a/gtk/usb-device-manager.c
+++ b/gtk/usb-device-manager.c
@@ -230,8 +230,8 @@ static gboolean spice_usb_device_manager_initable_init(GInitable  *initable,
                                                        GCancellable  *cancellable,
                                                        GError        **err)
 {
-    SpiceUsbDeviceManager *self;
-    SpiceUsbDeviceManagerPrivate *priv;
+    SpiceUsbDeviceManager *self = SPICE_USB_DEVICE_MANAGER(initable);
+    SpiceUsbDeviceManagerPrivate *priv = self->priv;
 #ifdef USE_USBREDIR
     GList *list;
     GList *it;
@@ -239,27 +239,6 @@ static gboolean spice_usb_device_manager_initable_init(GInitable  *initable,
 #ifdef USE_GUDEV
     const gchar *const subsystems[] = {"usb", NULL};
 #endif
-#endif
-
-    g_return_val_if_fail(SPICE_IS_USB_DEVICE_MANAGER(initable), FALSE);
-    g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
-
-    if (cancellable != NULL) {
-        g_set_error_literal(err, SPICE_CLIENT_ERROR, SPICE_CLIENT_ERROR_FAILED,
-                            "Cancellable initialization not supported");
-        return FALSE;
-    }
-
-    self = SPICE_USB_DEVICE_MANAGER(initable);
-    priv = self->priv;
-
-    if (!priv->session) {
-        g_set_error_literal(err, SPICE_CLIENT_ERROR, SPICE_CLIENT_ERROR_FAILED,
-                "SpiceUsbDeviceManager constructed without a session");
-        return FALSE;
-    }
-
-#ifdef USE_USBREDIR
 
 #ifdef G_OS_WIN32
     priv->installer = spice_win_usb_driver_new();
commit dced5f9e259bc4906d0a7a25a942e82e183637c3
Author: Marc-André Lureau <marcandre.lureau at gmail.com>
Date:   Thu Apr 24 17:51:00 2014 +0200

    win-usb: remove useless function

diff --git a/gtk/win-usb-driver-install.c b/gtk/win-usb-driver-install.c
index 05bd8ed..65bb58c 100644
--- a/gtk/win-usb-driver-install.c
+++ b/gtk/win-usb-driver-install.c
@@ -59,20 +59,13 @@ static void spice_win_usb_driver_init(SpiceWinUsbDriver *self)
     self->priv = SPICE_WIN_USB_DRIVER_GET_PRIVATE(self);
 }
 
-static void spice_win_usb_driver_close(SpiceWinUsbDriver *self)
-{
-    if (self->priv->handle) {
-        CloseHandle(self->priv->handle);
-        self->priv->handle = 0;
-    }
-}
-
 static void spice_win_usb_driver_finalize(GObject *gobject)
 {
     SpiceWinUsbDriver *self = SPICE_WIN_USB_DRIVER(gobject);
     SpiceWinUsbDriverPrivate *priv = self->priv;
 
-    spice_win_usb_driver_close(self);
+    if (priv->handle)
+        CloseHandle(priv->handle);
     g_clear_object(&priv->result);
 
     if (G_OBJECT_CLASS(spice_win_usb_driver_parent_class)->finalize)
commit 638116cea12b2d859277cf526ba4c3823dbdcee2
Author: Marc-André Lureau <marcandre.lureau at gmail.com>
Date:   Thu Apr 24 17:50:59 2014 +0200

    usb: misc code formatting

diff --git a/gtk/usb-device-manager.c b/gtk/usb-device-manager.c
index 0a0576d..f83023b 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;
commit 2e1a5ead1f8cc0c5d032a6cf1ceb5c285941c3dd
Author: Marc-André Lureau <marcandre.lureau at gmail.com>
Date:   Thu Apr 24 17:50:58 2014 +0200

    usb: call win_usb_driver_new() during initable_init()
    
    Throw an error when initialization failed.

diff --git a/gtk/spice-client.h b/gtk/spice-client.h
index 8250dd5..e4e1763 100644
--- a/gtk/spice-client.h
+++ b/gtk/spice-client.h
@@ -60,6 +60,7 @@ G_BEGIN_DECLS
  * @SPICE_CLIENT_ERROR_USB_DEVICE_LOST: device disconnected (fatal IO error)
  * @SPICE_CLIENT_ERROR_AUTH_NEEDS_PASSWORD: password is required
  * @SPICE_CLIENT_ERROR_AUTH_NEEDS_PASSWORD_AND_USERNAME: password and username are required
+ * @SPICE_CLIENT_ERROR_USB_SERVICE: USB service error
  *
  * Error codes returned by spice-client API.
  */
@@ -70,6 +71,7 @@ typedef enum
     SPICE_CLIENT_ERROR_USB_DEVICE_LOST,
     SPICE_CLIENT_ERROR_AUTH_NEEDS_PASSWORD,
     SPICE_CLIENT_ERROR_AUTH_NEEDS_PASSWORD_AND_USERNAME,
+    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 ba33ccb..0a0576d 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) {
@@ -1485,10 +1496,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;
@@ -1553,7 +1564,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) &&
@@ -1562,9 +1573,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;
commit b875d4ef34109f2daf177b70c4780b58e4548f23
Author: Marc-André Lureau <marcandre.lureau at gmail.com>
Date:   Thu Apr 24 17:50:57 2014 +0200

    usb: use SPICE_CLIENT_ERROR_ prefix
    
    To be consistent with GLib idioms, the code should use a common prefix for errors.

diff --git a/gtk/channel-usbredir.c b/gtk/channel-usbredir.c
index d974434..292b82f 100644
--- a/gtk/channel-usbredir.c
+++ b/gtk/channel-usbredir.c
@@ -654,12 +654,12 @@ static void usbredir_handle_msg(SpiceChannel *c, SpiceMsgIn *in)
             break;
         case usbredirhost_read_device_rejected:
             err = g_error_new(SPICE_CLIENT_ERROR,
-                              SPICE_CLIENT_USB_DEVICE_REJECTED,
+                              SPICE_CLIENT_ERROR_USB_DEVICE_REJECTED,
                               _("%s rejected by host"), desc);
             break;
         case usbredirhost_read_device_lost:
             err = g_error_new(SPICE_CLIENT_ERROR,
-                              SPICE_CLIENT_USB_DEVICE_LOST,
+                              SPICE_CLIENT_ERROR_USB_DEVICE_LOST,
                               _("%s disconnected (fatal IO error)"), desc);
             break;
         default:
diff --git a/gtk/spice-client.h b/gtk/spice-client.h
index c2474d1..8250dd5 100644
--- a/gtk/spice-client.h
+++ b/gtk/spice-client.h
@@ -56,8 +56,8 @@ G_BEGIN_DECLS
 /**
  * SpiceClientError:
  * @SPICE_CLIENT_ERROR_FAILED: generic error code
- * @SPICE_CLIENT_USB_DEVICE_REJECTED: usb device rejected by host
- * @SPICE_CLIENT_USB_DEVICE_LOST: usb device disconnected (fatal IO error)
+ * @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_AUTH_NEEDS_PASSWORD: password is required
  * @SPICE_CLIENT_ERROR_AUTH_NEEDS_PASSWORD_AND_USERNAME: password and username are required
  *
@@ -66,12 +66,17 @@ G_BEGIN_DECLS
 typedef enum
 {
     SPICE_CLIENT_ERROR_FAILED,
-    SPICE_CLIENT_USB_DEVICE_REJECTED,
-    SPICE_CLIENT_USB_DEVICE_LOST,
+    SPICE_CLIENT_ERROR_USB_DEVICE_REJECTED,
+    SPICE_CLIENT_ERROR_USB_DEVICE_LOST,
     SPICE_CLIENT_ERROR_AUTH_NEEDS_PASSWORD,
     SPICE_CLIENT_ERROR_AUTH_NEEDS_PASSWORD_AND_USERNAME,
 } SpiceClientError;
 
+#ifndef SPICE_DISABLE_DEPRECATED
+#define SPICE_CLIENT_USB_DEVICE_REJECTED SPICE_CLIENT_ERROR_USB_DEVICE_REJECTED
+#define SPICE_CLIENT_USB_DEVICE_LOST SPICE_CLIENT_ERROR_USB_DEVICE_LOST
+#endif
+
 GQuark spice_client_error_quark(void);
 
 G_END_DECLS
commit a09e84de032330a9e414b3acb03058d7730341d9
Author: Marc-André Lureau <marcandre.lureau at gmail.com>
Date:   Thu Jun 26 15:37:05 2014 +0200

    usb: unref the device when it is no longer needed
    
    The current code unref() the device too early, it must be unref
    after it is no longer needed.

diff --git a/gtk/usb-device-manager.c b/gtk/usb-device-manager.c
index fb312dd..ba33ccb 100644
--- a/gtk/usb-device-manager.c
+++ b/gtk/usb-device-manager.c
@@ -1128,7 +1128,6 @@ static void spice_usb_device_manager_drv_install_cb(GObject *gobject,
         g_error_free(err);
     }
 
-    spice_usb_device_unref(device);
     spice_usb_device_set_state(device, SPICE_USB_DEVICE_STATE_INSTALLED);
 
     /* device is already ref'ed */
@@ -1138,6 +1137,7 @@ static void spice_usb_device_manager_drv_install_cb(GObject *gobject,
                                                    callback,
                                                    user_data);
 
+    spice_usb_device_unref(device);
 }
 
 static void spice_usb_device_manager_drv_uninstall_cb(GObject *gobject,
@@ -1156,9 +1156,9 @@ static void spice_usb_device_manager_drv_uninstall_cb(GObject *gobject,
         g_clear_error(&err);
     }
 
-    spice_usb_device_unref(cbinfo->device);
     spice_usb_device_set_state(cbinfo->device, SPICE_USB_DEVICE_STATE_NONE);
 
+    spice_usb_device_unref(cbinfo->device);
     g_free(cbinfo);
 }
 
commit 692d88b141940d0c63ee5121d0291435885fc0bf
Author: Marc-André Lureau <marcandre.lureau at gmail.com>
Date:   Thu Apr 24 17:50:54 2014 +0200

    win-usb: get rid of status code return in async ops

diff --git a/gtk/usb-device-manager.c b/gtk/usb-device-manager.c
index b7da246..fb312dd 100644
--- a/gtk/usb-device-manager.c
+++ b/gtk/usb-device-manager.c
@@ -1099,7 +1099,6 @@ static void spice_usb_device_manager_drv_install_cb(GObject *gobject,
 {
     SpiceUsbDeviceManager *self;
     SpiceWinUsbDriver *installer;
-    gint status;
     GError *err = NULL;
     SpiceUsbDevice *device;
     UsbInstallCbInfo *cbinfo;
@@ -1124,17 +1123,11 @@ static void spice_usb_device_manager_drv_install_cb(GObject *gobject,
 
     SPICE_DEBUG("Win USB driver install finished");
 
-    status = spice_win_usb_driver_install_finish(installer, res, &err);
-
-    if (err) {
+    if (!spice_win_usb_driver_install_finish(installer, res, &err)) {
         g_warning("win usb driver install failed -- %s", err->message);
         g_error_free(err);
     }
 
-    if (!status) {
-        g_warning("failed to install win usb driver (status=0)");
-    }
-
     spice_usb_device_unref(device);
     spice_usb_device_set_state(device, SPICE_USB_DEVICE_STATE_INSTALLED);
 
@@ -1154,21 +1147,15 @@ static void spice_usb_device_manager_drv_uninstall_cb(GObject *gobject,
     UsbInstallCbInfo *cbinfo = user_data;
     SpiceUsbDeviceManager *self = cbinfo->manager;
     GError *err = NULL;
-    gint status;
 
     SPICE_DEBUG("Win USB driver uninstall finished");
     g_return_if_fail(SPICE_IS_USB_DEVICE_MANAGER(self));
 
-    status = spice_win_usb_driver_uninstall_finish(cbinfo->installer, res, &err);
-    if (err) {
+    if (!spice_win_usb_driver_uninstall_finish(cbinfo->installer, res, &err)) {
         g_warning("win usb driver uninstall failed -- %s", err->message);
         g_clear_error(&err);
     }
 
-    if (!status) {
-        g_warning("failed to uninstall win usb driver (status=0)");
-    }
-
     spice_usb_device_unref(cbinfo->device);
     spice_usb_device_set_state(cbinfo->device, SPICE_USB_DEVICE_STATE_NONE);
 
diff --git a/gtk/win-usb-driver-install.c b/gtk/win-usb-driver-install.c
index 1bdf10f..05bd8ed 100644
--- a/gtk/win-usb-driver-install.c
+++ b/gtk/win-usb-driver-install.c
@@ -338,7 +338,7 @@ void spice_win_usb_driver_op(SpiceWinUsbDriver *self,
  * Returns: currently returns 0 (failure) and 1 (success)
  * possibly later we'll add error-codes
  */
-static gint
+static gboolean
 spice_win_usb_driver_op_finish(SpiceWinUsbDriver *self,
                                GAsyncResult *res, GError **err)
 {
@@ -349,9 +349,9 @@ spice_win_usb_driver_op_finish(SpiceWinUsbDriver *self,
                                                         spice_win_usb_driver_op),
                          FALSE);
     if (g_simple_async_result_propagate_error(result, err))
-        return 0;
+        return FALSE;
 
-    return self->priv->reply.status;
+    return TRUE;
 }
 
 /**
@@ -390,14 +390,14 @@ void spice_win_usb_driver_uninstall_async(SpiceWinUsbDriver *self,
 }
 
 G_GNUC_INTERNAL
-gint spice_win_usb_driver_install_finish(SpiceWinUsbDriver *self,
+gboolean spice_win_usb_driver_install_finish(SpiceWinUsbDriver *self,
                                           GAsyncResult *res, GError **err)
 {
     return spice_win_usb_driver_op_finish(self, res, err);
 }
 
 G_GNUC_INTERNAL
-gint spice_win_usb_driver_uninstall_finish(SpiceWinUsbDriver *self,
+gboolean spice_win_usb_driver_uninstall_finish(SpiceWinUsbDriver *self,
                                            GAsyncResult *res, GError **err)
 {
     return spice_win_usb_driver_op_finish(self, res, err);
diff --git a/gtk/win-usb-driver-install.h b/gtk/win-usb-driver-install.h
index bac41f1..b9eadcd 100644
--- a/gtk/win-usb-driver-install.h
+++ b/gtk/win-usb-driver-install.h
@@ -69,16 +69,16 @@ void spice_win_usb_driver_install_async(SpiceWinUsbDriver *self,
                                         GCancellable *cancellable,
                                         GAsyncReadyCallback callback,
                                         gpointer user_data);
-gint spice_win_usb_driver_install_finish(SpiceWinUsbDriver *self,
-                                         GAsyncResult *res, GError **err);
+gboolean spice_win_usb_driver_install_finish(SpiceWinUsbDriver *self,
+                                             GAsyncResult *res, GError **err);
 
 void spice_win_usb_driver_uninstall_async(SpiceWinUsbDriver *self,
                                           SpiceUsbDevice *device,
                                           GCancellable *cancellable,
                                           GAsyncReadyCallback callback,
                                           gpointer user_data);
-gint spice_win_usb_driver_uninstall_finish(SpiceWinUsbDriver *self,
-                                           GAsyncResult *res, GError **err);
+gboolean spice_win_usb_driver_uninstall_finish(SpiceWinUsbDriver *self,
+                                               GAsyncResult *res, GError **err);
 
 
 
commit d0501a6710c3d3c3030620140ad48e3fbc23c158
Author: Marc-André Lureau <marcandre.lureau at gmail.com>
Date:   Thu Apr 24 17:50:53 2014 +0200

    win-usb: throw an error if reply.status == 0

diff --git a/gtk/win-usb-driver-install.c b/gtk/win-usb-driver-install.c
index 6d01b91..1bdf10f 100644
--- a/gtk/win-usb-driver-install.c
+++ b/gtk/win-usb-driver-install.c
@@ -176,6 +176,14 @@ void win_usb_driver_handle_reply_cb(GObject *gobject,
         goto failed_reply;
     }
 
+    if (priv->reply.status == 0) {
+        g_simple_async_result_set_error(priv->result,
+                                        SPICE_WIN_USB_DRIVER_ERROR,
+                                        SPICE_WIN_USB_DRIVER_ERROR_MESSAGE,
+                                        "usbclerk error reply");
+        goto failed_reply;
+    }
+
  failed_reply:
     g_simple_async_result_complete_in_idle(priv->result);
     g_clear_object(&priv->result);
commit a3b0faf968f61f45bf5de51fdf963415d7971b14
Author: Marc-André Lureau <marcandre.lureau at gmail.com>
Date:   Thu Apr 24 17:50:52 2014 +0200

    usb: use win-usb uninstall_finish()

diff --git a/gtk/usb-device-manager.c b/gtk/usb-device-manager.c
index d192750..b7da246 100644
--- a/gtk/usb-device-manager.c
+++ b/gtk/usb-device-manager.c
@@ -1077,7 +1077,6 @@ typedef struct _UsbInstallCbInfo {
     GCancellable          *cancellable;
     GAsyncReadyCallback   callback;
     gpointer              user_data;
-    gboolean              is_install;
 } UsbInstallCbInfo;
 
 /**
@@ -1106,8 +1105,6 @@ static void spice_usb_device_manager_drv_install_cb(GObject *gobject,
     UsbInstallCbInfo *cbinfo;
     GCancellable *cancellable;
     GAsyncReadyCallback callback;
-    gboolean is_install;
-    const gchar *opstr;
 
     g_return_if_fail(user_data != NULL);
 
@@ -1118,7 +1115,6 @@ static void spice_usb_device_manager_drv_install_cb(GObject *gobject,
     cancellable = cbinfo->cancellable;
     callback    = cbinfo->callback;
     user_data   = cbinfo->user_data;
-    is_install  = cbinfo->is_install;
 
     g_free(cbinfo);
 
@@ -1126,31 +1122,21 @@ static void spice_usb_device_manager_drv_install_cb(GObject *gobject,
     g_return_if_fail(SPICE_IS_WIN_USB_DRIVER(installer));
     g_return_if_fail(device!= NULL);
 
-    opstr = is_install ? "install" : "uninstall";
-    SPICE_DEBUG("Win USB driver %s finished", opstr);
+    SPICE_DEBUG("Win USB driver install finished");
 
     status = spice_win_usb_driver_install_finish(installer, res, &err);
 
-    spice_usb_device_unref(device);
-
-    if (is_install) {
-        spice_usb_device_set_state(device, SPICE_USB_DEVICE_STATE_INSTALLED);
-    } else {
-        spice_usb_device_set_state(device, SPICE_USB_DEVICE_STATE_NONE);
-    }
-
     if (err) {
-        g_warning("win usb driver %s failed -- %s", opstr, err->message);
+        g_warning("win usb driver install failed -- %s", err->message);
         g_error_free(err);
     }
 
     if (!status) {
-        g_warning("failed to %s win usb driver (status=0)", opstr);
+        g_warning("failed to install win usb driver (status=0)");
     }
 
-    if (! is_install) {
-        return;
-    }
+    spice_usb_device_unref(device);
+    spice_usb_device_set_state(device, SPICE_USB_DEVICE_STATE_INSTALLED);
 
     /* device is already ref'ed */
     _spice_usb_device_manager_connect_device_async(self,
@@ -1160,6 +1146,35 @@ static void spice_usb_device_manager_drv_install_cb(GObject *gobject,
                                                    user_data);
 
 }
+
+static void spice_usb_device_manager_drv_uninstall_cb(GObject *gobject,
+                                                      GAsyncResult *res,
+                                                      gpointer user_data)
+{
+    UsbInstallCbInfo *cbinfo = user_data;
+    SpiceUsbDeviceManager *self = cbinfo->manager;
+    GError *err = NULL;
+    gint status;
+
+    SPICE_DEBUG("Win USB driver uninstall finished");
+    g_return_if_fail(SPICE_IS_USB_DEVICE_MANAGER(self));
+
+    status = spice_win_usb_driver_uninstall_finish(cbinfo->installer, res, &err);
+    if (err) {
+        g_warning("win usb driver uninstall failed -- %s", err->message);
+        g_clear_error(&err);
+    }
+
+    if (!status) {
+        g_warning("failed to uninstall win usb driver (status=0)");
+    }
+
+    spice_usb_device_unref(cbinfo->device);
+    spice_usb_device_set_state(cbinfo->device, SPICE_USB_DEVICE_STATE_NONE);
+
+    g_free(cbinfo);
+}
+
 #endif
 
 /* ------------------------------------------------------------------ */
@@ -1495,7 +1510,6 @@ void spice_usb_device_manager_connect_device_async(SpiceUsbDeviceManager *self,
     cbinfo->cancellable = cancellable;
     cbinfo->callback    = callback;
     cbinfo->user_data   = user_data;
-    cbinfo->is_install  = TRUE;
 
     spice_win_usb_driver_install_async(installer, device, cancellable,
                                        spice_usb_device_manager_drv_install_cb,
@@ -1572,10 +1586,9 @@ void spice_usb_device_manager_disconnect_device(SpiceUsbDeviceManager *self,
     cbinfo->cancellable = NULL;
     cbinfo->callback    = NULL;
     cbinfo->user_data   = NULL;
-    cbinfo->is_install  = FALSE;
 
     spice_win_usb_driver_uninstall_async(installer, device, NULL,
-                                         spice_usb_device_manager_drv_install_cb,
+                                         spice_usb_device_manager_drv_uninstall_cb,
                                          cbinfo);
 #endif
 
diff --git a/gtk/win-usb-driver-install.c b/gtk/win-usb-driver-install.c
index 91aa075..6d01b91 100644
--- a/gtk/win-usb-driver-install.c
+++ b/gtk/win-usb-driver-install.c
@@ -389,6 +389,13 @@ gint spice_win_usb_driver_install_finish(SpiceWinUsbDriver *self,
 }
 
 G_GNUC_INTERNAL
+gint spice_win_usb_driver_uninstall_finish(SpiceWinUsbDriver *self,
+                                           GAsyncResult *res, GError **err)
+{
+    return spice_win_usb_driver_op_finish(self, res, err);
+}
+
+G_GNUC_INTERNAL
 SpiceUsbDevice *spice_win_usb_driver_get_device(SpiceWinUsbDriver *self)
 {
     g_return_val_if_fail(SPICE_IS_WIN_USB_DRIVER(self), 0);
diff --git a/gtk/win-usb-driver-install.h b/gtk/win-usb-driver-install.h
index b3ca4bf..bac41f1 100644
--- a/gtk/win-usb-driver-install.h
+++ b/gtk/win-usb-driver-install.h
@@ -77,6 +77,10 @@ void spice_win_usb_driver_uninstall_async(SpiceWinUsbDriver *self,
                                           GCancellable *cancellable,
                                           GAsyncReadyCallback callback,
                                           gpointer user_data);
+gint spice_win_usb_driver_uninstall_finish(SpiceWinUsbDriver *self,
+                                           GAsyncResult *res, GError **err);
+
+
 
 SpiceUsbDevice *spice_win_usb_driver_get_device(SpiceWinUsbDriver *self);
 
commit faffab3c0f4603f3bc805b2332ed92fc3fdd643a
Author: Marc-André Lureau <marcandre.lureau at gmail.com>
Date:   Thu Apr 24 17:50:51 2014 +0200

    win-usb: rename async functions

diff --git a/gtk/usb-device-manager.c b/gtk/usb-device-manager.c
index 1aee83a..d192750 100644
--- a/gtk/usb-device-manager.c
+++ b/gtk/usb-device-manager.c
@@ -1497,9 +1497,9 @@ void spice_usb_device_manager_connect_device_async(SpiceUsbDeviceManager *self,
     cbinfo->user_data   = user_data;
     cbinfo->is_install  = TRUE;
 
-    spice_win_usb_driver_install(installer, device, cancellable,
-                                 spice_usb_device_manager_drv_install_cb,
-                                 cbinfo);
+    spice_win_usb_driver_install_async(installer, device, cancellable,
+                                       spice_usb_device_manager_drv_install_cb,
+                                       cbinfo);
 #else
     _spice_usb_device_manager_connect_device_async(self,
                                                    device,
@@ -1574,9 +1574,9 @@ void spice_usb_device_manager_disconnect_device(SpiceUsbDeviceManager *self,
     cbinfo->user_data   = NULL;
     cbinfo->is_install  = FALSE;
 
-    spice_win_usb_driver_uninstall(installer, device, NULL,
-                                   spice_usb_device_manager_drv_install_cb,
-                                   cbinfo);
+    spice_win_usb_driver_uninstall_async(installer, device, NULL,
+                                         spice_usb_device_manager_drv_install_cb,
+                                         cbinfo);
 #endif
 
 #endif
diff --git a/gtk/win-usb-driver-install.c b/gtk/win-usb-driver-install.c
index 5bb623a..91aa075 100644
--- a/gtk/win-usb-driver-install.c
+++ b/gtk/win-usb-driver-install.c
@@ -347,7 +347,7 @@ spice_win_usb_driver_op_finish(SpiceWinUsbDriver *self,
 }
 
 /**
- * spice_win_usb_driver_install:
+ * spice_win_usb_driver_install_async:
  * Start libusb driver installation for @device
  *
  * A new NamedPipe is created for each request.
@@ -356,11 +356,11 @@ spice_win_usb_driver_op_finish(SpiceWinUsbDriver *self,
  *          FALSE upon failure to send a request.
  */
 G_GNUC_INTERNAL
-void spice_win_usb_driver_install(SpiceWinUsbDriver *self,
-                                  SpiceUsbDevice *device,
-                                  GCancellable *cancellable,
-                                  GAsyncReadyCallback callback,
-                                  gpointer user_data)
+void spice_win_usb_driver_install_async(SpiceWinUsbDriver *self,
+                                        SpiceUsbDevice *device,
+                                        GCancellable *cancellable,
+                                        GAsyncReadyCallback callback,
+                                        gpointer user_data)
 {
     SPICE_DEBUG("Win usb driver installation started");
 
@@ -369,11 +369,11 @@ void spice_win_usb_driver_install(SpiceWinUsbDriver *self,
 }
 
 G_GNUC_INTERNAL
-void spice_win_usb_driver_uninstall(SpiceWinUsbDriver *self,
-                                    SpiceUsbDevice *device,
-                                    GCancellable *cancellable,
-                                    GAsyncReadyCallback callback,
-                                    gpointer user_data)
+void spice_win_usb_driver_uninstall_async(SpiceWinUsbDriver *self,
+                                          SpiceUsbDevice *device,
+                                          GCancellable *cancellable,
+                                          GAsyncReadyCallback callback,
+                                          gpointer user_data)
 {
     SPICE_DEBUG("Win usb driver uninstall operation started");
 
diff --git a/gtk/win-usb-driver-install.h b/gtk/win-usb-driver-install.h
index 034abf9..b3ca4bf 100644
--- a/gtk/win-usb-driver-install.h
+++ b/gtk/win-usb-driver-install.h
@@ -64,21 +64,19 @@ GType spice_win_usb_driver_get_type(void);
 SpiceWinUsbDriver *spice_win_usb_driver_new(void);
 
 
-void spice_win_usb_driver_install(SpiceWinUsbDriver *self,
-                                  SpiceUsbDevice *device,
-                                  GCancellable *cancellable,
-                                  GAsyncReadyCallback callback,
-                                  gpointer user_data);
-
-void spice_win_usb_driver_uninstall(SpiceWinUsbDriver *self,
-                                    SpiceUsbDevice *device,
-                                    GCancellable *cancellable,
-                                    GAsyncReadyCallback callback,
-                                    gpointer user_data);
-
+void spice_win_usb_driver_install_async(SpiceWinUsbDriver *self,
+                                        SpiceUsbDevice *device,
+                                        GCancellable *cancellable,
+                                        GAsyncReadyCallback callback,
+                                        gpointer user_data);
 gint spice_win_usb_driver_install_finish(SpiceWinUsbDriver *self,
                                          GAsyncResult *res, GError **err);
 
+void spice_win_usb_driver_uninstall_async(SpiceWinUsbDriver *self,
+                                          SpiceUsbDevice *device,
+                                          GCancellable *cancellable,
+                                          GAsyncReadyCallback callback,
+                                          gpointer user_data);
 
 SpiceUsbDevice *spice_win_usb_driver_get_device(SpiceWinUsbDriver *self);
 
commit 1c43d7e586155f7498e71484f878d52668cb43f9
Author: Marc-André Lureau <marcandre.lureau at gmail.com>
Date:   Thu Apr 24 17:50:50 2014 +0200

    win-usb: introduce a spice_win_usb_driver_op_finish
    
    We want the exported functions to follow the gio async idom. Currently,
    both install() and uninstall() are paired with install_finish(). In the
    following patch we introduce uninstall_async() uninstall_finish() using
    that common internal op_finish() function. Then we correctly pair
    associated async/finish() calls.

diff --git a/gtk/win-usb-driver-install.c b/gtk/win-usb-driver-install.c
index 674a7c6..5bb623a 100644
--- a/gtk/win-usb-driver-install.c
+++ b/gtk/win-usb-driver-install.c
@@ -326,7 +326,25 @@ void spice_win_usb_driver_op(SpiceWinUsbDriver *self,
     g_clear_object(&result);
 }
 
+/**
+ * Returns: currently returns 0 (failure) and 1 (success)
+ * possibly later we'll add error-codes
+ */
+static gint
+spice_win_usb_driver_op_finish(SpiceWinUsbDriver *self,
+                               GAsyncResult *res, GError **err)
+{
+    GSimpleAsyncResult *result = G_SIMPLE_ASYNC_RESULT(res);
 
+    g_return_val_if_fail(SPICE_IS_WIN_USB_DRIVER(self), 0);
+    g_return_val_if_fail(g_simple_async_result_is_valid(res, G_OBJECT(self),
+                                                        spice_win_usb_driver_op),
+                         FALSE);
+    if (g_simple_async_result_propagate_error(result, err))
+        return 0;
+
+    return self->priv->reply.status;
+}
 
 /**
  * spice_win_usb_driver_install:
@@ -363,25 +381,11 @@ void spice_win_usb_driver_uninstall(SpiceWinUsbDriver *self,
                             callback, user_data);
 }
 
-
-/**
- * Returns: currently returns 0 (failure) and 1 (success)
- * possibly later we'll add error-codes
- */
 G_GNUC_INTERNAL
 gint spice_win_usb_driver_install_finish(SpiceWinUsbDriver *self,
                                           GAsyncResult *res, GError **err)
 {
-    GSimpleAsyncResult *result = G_SIMPLE_ASYNC_RESULT(res);
-
-    g_return_val_if_fail(SPICE_IS_WIN_USB_DRIVER(self), 0);
-    g_return_val_if_fail(g_simple_async_result_is_valid(res, G_OBJECT(self),
-                                                        spice_win_usb_driver_op),
-                         FALSE);
-    if (g_simple_async_result_propagate_error(result, err))
-        return 0;
-
-    return self->priv->reply.status;
+    return spice_win_usb_driver_op_finish(self, res, err);
 }
 
 G_GNUC_INTERNAL
commit a5747389cdb13ba2ef98a2c70b963328fdfa5cb7
Author: Marc-André Lureau <marcandre.lureau at gmail.com>
Date:   Thu Apr 24 17:50:49 2014 +0200

    usb: remove useless declaration

diff --git a/gtk/usb-device-manager.c b/gtk/usb-device-manager.c
index 7aa60c4..1aee83a 100644
--- a/gtk/usb-device-manager.c
+++ b/gtk/usb-device-manager.c
@@ -207,14 +207,6 @@ G_DEFINE_BOXED_TYPE(SpiceUsbDevice, spice_usb_device, g_object_ref, g_object_unr
 
 static void spice_usb_device_manager_initable_iface_init(GInitableIface *iface);
 
-#ifdef USE_USBREDIR
-#ifdef G_OS_WIN32
-static void spice_usb_device_manager_drv_install_cb(GObject *gobject,
-                                                    GAsyncResult *res,
-                                                    gpointer user_data);
-#endif
-#endif
-
 static guint signals[LAST_SIGNAL] = { 0, };
 
 G_DEFINE_TYPE_WITH_CODE(SpiceUsbDeviceManager, spice_usb_device_manager, G_TYPE_OBJECT,


More information about the Spice-commits mailing list