[Spice-devel] [PATCH 2/5] WinUsbDev: add redirecting state to GUdevClientPrivate
Dmitry Fleytman
dmitry at daynix.com
Fri Jul 3 06:05:40 PDT 2015
> On Jul 3, 2015, at 15:56 PM, Christophe Fergeau <cfergeau at redhat.com> wrote:
>
> On Thu, Jul 02, 2015 at 04:41:32PM +0300, Kirill Moizik wrote:
>> we need to add redirecting state to singleton since wnd_proc callback should not query usb devices
>> in the middle of redirecting flow.
>
> Why ?
Because in the middle of redirecting flow caller may get inconsistent enumeration results (due to device resets performed by UsbDk and Windows mechanisms handling those resets),
UsbDk API intentionally returns error when enumeration is called during start/stop redirection flows.
>
>
>> GUdevClient is the only context exist in the cb, so we should add a stateand update it accordingly.
>>
>> Signed-off-by: Kirill Moizik <kirill at daynix.com>
>> ---
>> src/map-file | 2 ++
>> src/win-usb-dev.c | 15 +++++++++++++++
>> src/win-usb-dev.h | 2 ++
>> 3 files changed, 19 insertions(+)
>>
>> diff --git a/src/map-file b/src/map-file
>> index d3a079e..f9883b2 100644
>> --- a/src/map-file
>> +++ b/src/map-file
>> @@ -117,6 +117,8 @@ spice_uri_to_string;
>> spice_usb_device_get_description;
>> spice_usb_device_get_libusb_device;
>> spice_usb_device_get_type;
>> +spice_g_udev_set_redirecting;
>> +spice_g_udev_handle_device_change;
>> spice_usb_device_manager_set_redirecting;
>> spice_usb_device_manager_get_redirecting;
>> spice_usb_device_manager_can_redirect_device;
>> diff --git a/src/win-usb-dev.c b/src/win-usb-dev.c
>> index 1e4b2d6..23bea42 100644
>> --- a/src/win-usb-dev.c
>> +++ b/src/win-usb-dev.c
>> @@ -37,6 +37,7 @@ struct _GUdevClientPrivate {
>> gssize udev_list_size;
>> GList *udev_list;
>> HWND hwnd;
>> + gboolean redirecting;
>> };
>>
>> #define G_UDEV_CLIENT_WINCLASS_NAME TEXT("G_UDEV_CLIENT")
>> @@ -186,6 +187,7 @@ g_udev_client_initable_init(GInitable *initable, GCancellable *cancellable,
>> self = G_UDEV_CLIENT(initable);
>> priv = self->priv;
>>
>> + priv->redirecting = FALSE;
>> rc = libusb_init(&priv->ctx);
>> if (rc < 0) {
>> const char *errstr = spice_usbutil_libusb_strerror(rc);
>> @@ -334,6 +336,11 @@ static gboolean gudev_devices_are_equal(GUdevDevice *a, GUdevDevice *b)
>> return (same_pid && same_vid);
>> }
>>
>> +void spice_g_udev_set_redirecting (gboolean val)
>> +{
>> + GUdevClientPrivate *priv = singleton->priv;
>> + priv->redirecting = val;
>> +}
>>
>> /* Assumes each event stands for a single device change (at most) */
>> static void handle_dev_change(GUdevClient *self)
>> @@ -347,6 +354,9 @@ static void handle_dev_change(GUdevClient *self)
>> GList *llist, *slist; /* long-list and short-list*/
>> GList *lit, *sit; /* iterators for long-list and short-list */
>> GUdevDevice *ldev, *sdev; /* devices on long-list and short-list */
>> + if (priv->redirecting == TRUE) {
>
>
> if (priv->redirecting) {
>
> }
>
>
>> + return;
>> + }
>>
>> dev_count = g_udev_client_list_devices(self, &now_devs, &err,
>> __FUNCTION__);
>> @@ -409,6 +419,11 @@ leave:
>> priv->udev_list_size = dev_count;
>> }
>>
>> +void spice_g_udev_handle_device_change(void)
>> +{
>> + handle_dev_change(singleton);
>> +}
>> +
>> static LRESULT CALLBACK wnd_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
>> {
>> /* Only DBT_DEVNODES_CHANGED recieved */
>> diff --git a/src/win-usb-dev.h b/src/win-usb-dev.h
>> index b5c4fce..080c89f 100644
>> --- a/src/win-usb-dev.h
>> +++ b/src/win-usb-dev.h
>> @@ -86,6 +86,8 @@ GType g_udev_device_get_type(void) G_GNUC_CONST;
>> const gchar *g_udev_device_get_property(GUdevDevice *udev, const gchar *property);
>> const gchar *g_udev_device_get_sysfs_attr(GUdevDevice *udev, const gchar *attr);
>>
>> +void spice_g_udev_set_redirecting(gboolean val);
>> +void spice_g_udev_handle_device_change(void);
>> GQuark g_udev_client_error_quark(void);
>> #define G_UDEV_CLIENT_ERROR g_udev_client_error_quark()
>>
>> --
>> 2.1.0
>>
>> _______________________________________________
>> Spice-devel mailing list
>> Spice-devel at lists.freedesktop.org
>> http://lists.freedesktop.org/mailman/listinfo/spice-devel
> _______________________________________________
> Spice-devel mailing list
> Spice-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/spice-devel
More information about the Spice-devel
mailing list