[Spice-devel] [PATCH v6 04/10] win-usbredir: Move installer interaction logic to separate functions

Dmitry Fleytman dmitry at daynix.com
Thu Feb 11 13:56:15 UTC 2016


> On 29 Jan 2016, at 14:40 PM, Dmitry Fleytman <dmitry at daynix.com> wrote:
> 
>> 
>> On 29 Jan 2016, at 24:42 AM, Jonathon Jongsma <jjongsma at redhat.com> wrote:
>> 
>> On Thu, 2015-10-29 at 17:26 +0200, Dmitry Fleytman wrote:
>>> Signed-off-by: Dmitry Fleytman <dmitry at daynix.com>
>>> ---
>>> spice-common             |   2 +-
>>> src/usb-device-manager.c | 108 ++++++++++++++++++++++++++++------------------
>>> -
>>> 2 files changed, 66 insertions(+), 44 deletions(-)
>>> 
>>> diff --git a/spice-common b/spice-common
>>> index f7ec855..2d054e0 160000
>>> --- a/spice-common
>>> +++ b/spice-common
>>> @@ -1 +1 @@
>>> -Subproject commit f7ec855af3deff18aeb43ddbf2467c565f4bf346
>>> +Subproject commit 2d054e0e6901a1cfbe396f30d9899da46ff533d9
>> 
>> It looks like this submodule update can be removed.
> 
> Right, it should not be there.

Ditched.
Thanks!


> 
>> 
>> In general I don't see a huge need to move these to separate functions, since
>> they're not used elsewhere. But OK.
> 
> These functions needed to make next patches of the same series simpler.
> Probably this should be stated in the commit message.

I added an explanation to the commit message.

> 
>> 
>> 
>>> diff --git a/src/usb-device-manager.c b/src/usb-device-manager.c
>>> index 4930613..78f038e 100644
>>> --- a/src/usb-device-manager.c
>>> +++ b/src/usb-device-manager.c
>>> @@ -1396,6 +1396,68 @@ gboolean
>>> spice_usb_device_manager_is_device_connected(SpiceUsbDeviceManager *sel
>>>    return !!spice_usb_device_manager_get_channel_for_dev(self, device);
>>> }
>>> 
>>> +#if defined(USE_USBREDIR) && defined(G_OS_WIN32)
>>> +
>>> +static void
>>> +_spice_usb_device_manager_install_driver_async(SpiceUsbDeviceManager *self,
>>> +                                               SpiceUsbDevice *device,
>>> +                                               GCancellable *cancellable,
>>> +                                               GAsyncReadyCallback callback,
>>> +                                               gpointer user_data)
>>> +{
>>> +    SpiceWinUsbDriver *installer;
>>> +    UsbInstallCbInfo *cbinfo;
>>> +
>>> +    g_return_if_fail(self->priv->installer);
>>> +
>>> +    spice_usb_device_set_state(device, SPICE_USB_DEVICE_STATE_INSTALLING);
>>> +
>>> +    installer = self->priv->installer;
>>> +    cbinfo = g_new0(UsbInstallCbInfo, 1);
>>> +    cbinfo->manager     = self;
>>> +    cbinfo->device      = spice_usb_device_ref(device);
>>> +    cbinfo->installer   = installer;
>>> +    cbinfo->cancellable = cancellable;
>>> +    cbinfo->callback    = callback;
>>> +    cbinfo->user_data   = user_data;
>>> +
>>> +    spice_win_usb_driver_install_async(installer, device, cancellable,
>>> +                                      
>>> spice_usb_device_manager_drv_install_cb,
>>> +                                       cbinfo);
>>> +}
>>> +
>>> +static void
>>> +_spice_usb_device_manager_uninstall_driver_async(SpiceUsbDeviceManager *self,
>>> +                                                 SpiceUsbDevice *device)
>>> +{
>>> +    SpiceWinUsbDriver *installer;
>>> +    UsbInstallCbInfo *cbinfo;
>>> +    guint8 state;
>>> +
>>> +    g_warn_if_fail(device != NULL);
>>> +    g_return_if_fail(self->priv->installer);
>>> +
>>> +    state = spice_usb_device_get_state(device);
>>> +    if ((state != SPICE_USB_DEVICE_STATE_INSTALLED) &&
>>> +        (state != SPICE_USB_DEVICE_STATE_CONNECTED)) {
>>> +        return;
>>> +    }
>>> +
>>> +    spice_usb_device_set_state(device, SPICE_USB_DEVICE_STATE_UNINSTALLING);
>>> +
>>> +    installer = self->priv->installer;
>>> +    cbinfo = g_new0(UsbInstallCbInfo, 1);
>>> +    cbinfo->manager     = self;
>>> +    cbinfo->device      = spice_usb_device_ref(device);
>>> +    cbinfo->installer   = installer;
>>> +
>>> +    spice_win_usb_driver_uninstall_async(installer, device, NULL,
>>> +                                        
>>> spice_usb_device_manager_drv_uninstall_cb,
>>> +                                         cbinfo);
>>> +}
>>> +
>>> +#endif
>>> +
>>> static void
>>> _spice_usb_device_manager_connect_device_async(SpiceUsbDeviceManager *self,
>>>                                               SpiceUsbDevice *device,
>>> @@ -1491,25 +1553,8 @@ void
>>> spice_usb_device_manager_connect_device_async(SpiceUsbDeviceManager *self,
>>> {
>>> 
>>> #if defined(USE_USBREDIR) && defined(G_OS_WIN32)
>>> -    SpiceWinUsbDriver *installer;
>>> -    UsbInstallCbInfo *cbinfo;
>>> -
>>> -    g_return_if_fail(self->priv->installer);
>>> -
>>> -    spice_usb_device_set_state(device, SPICE_USB_DEVICE_STATE_INSTALLING);
>>> -
>>> -    installer = self->priv->installer;
>>> -    cbinfo = g_new0(UsbInstallCbInfo, 1);
>>> -    cbinfo->manager     = self;
>>> -    cbinfo->device      = spice_usb_device_ref(device);
>>> -    cbinfo->installer   = installer;
>>> -    cbinfo->cancellable = cancellable;
>>> -    cbinfo->callback    = callback;
>>> -    cbinfo->user_data   = user_data;
>>> -
>>> -    spice_win_usb_driver_install_async(installer, device, cancellable,
>>> -                                      
>>> spice_usb_device_manager_drv_install_cb,
>>> -                                       cbinfo);
>>> +    _spice_usb_device_manager_install_driver_async(self, device, cancellable,
>>> +                                                   callback, user_data);
>>> #else
>>>    _spice_usb_device_manager_connect_device_async(self,
>>>                                                   device,
>>> @@ -1569,30 +1614,7 @@ void
>>> spice_usb_device_manager_disconnect_device(SpiceUsbDeviceManager *self,
>>>        spice_usbredir_channel_disconnect_device(channel);
>>> 
>>> #ifdef G_OS_WIN32
>>> -    SpiceWinUsbDriver *installer;
>>> -    UsbInstallCbInfo *cbinfo;
>>> -    guint8 state;
>>> -
>>> -    g_warn_if_fail(device != NULL);
>>> -    g_return_if_fail(self->priv->installer);
>>> -
>>> -    state = spice_usb_device_get_state(device);
>>> -    if ((state != SPICE_USB_DEVICE_STATE_INSTALLED) &&
>>> -        (state != SPICE_USB_DEVICE_STATE_CONNECTED)) {
>>> -        return;
>>> -    }
>>> -
>>> -    spice_usb_device_set_state(device, SPICE_USB_DEVICE_STATE_UNINSTALLING);
>>> -
>>> -    installer = self->priv->installer;
>>> -    cbinfo = g_new0(UsbInstallCbInfo, 1);
>>> -    cbinfo->manager     = self;
>>> -    cbinfo->device      = spice_usb_device_ref(device);
>>> -    cbinfo->installer   = installer;
>>> -
>>> -    spice_win_usb_driver_uninstall_async(installer, device, NULL,
>>> -                                        
>>> spice_usb_device_manager_drv_uninstall_cb,
>>> -                                         cbinfo);
>>> +    _spice_usb_device_manager_uninstall_driver_async(self, device);
>>> #endif
>>> 
>>> #endif

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20160211/75755a5f/attachment-0001.html>


More information about the Spice-devel mailing list