Re: [spice-gtk 03/13] usb-redir: reuse libusb context under Windows

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

 



On Sun, Mar 10, 2019 at 04:46:02PM +0200, Yuri Benditovich wrote:
> Do not create own libusb context in usb-device-manager.
> Reuse existing context created by win-usb-dev instead.

I'd rephrase this slightly
« On Windows, do not create a new libusb context in
usb-device-manager.c, but reuse the existing one created by
win-usb-dev.c » + an explanation why we want to do that.
Iirc, we need a shared libusb_context if we want to share libusb_device
between the 2 files, so I'd add that to the commit log.

Apart from this, 

Acked-by: Christophe Fergeau <cfergeau@xxxxxxxxxx>

> 
> Signed-off-by: Yuri Benditovich <yuri.benditovich@xxxxxxxxxx>
> ---
>  src/usb-device-manager.c | 11 +++++------
>  src/win-usb-dev.c        |  4 ++++
>  src/win-usb-dev.h        |  1 +
>  3 files changed, 10 insertions(+), 6 deletions(-)
> 
> diff --git a/src/usb-device-manager.c b/src/usb-device-manager.c
> index 6435be8..debba4d 100644
> --- a/src/usb-device-manager.c
> +++ b/src/usb-device-manager.c
> @@ -282,8 +282,9 @@ static gboolean spice_usb_device_manager_initable_init(GInitable  *initable,
>      SpiceUsbDeviceManagerPrivate *priv = self->priv;
>      GList *list;
>      GList *it;
> -    int rc;
>  
> +#ifndef G_OS_WIN32
> +    int rc;
>      /* Initialize libusb */
>      rc = libusb_init(&priv->context);
>      if (rc < 0) {
> @@ -293,11 +294,6 @@ static gboolean spice_usb_device_manager_initable_init(GInitable  *initable,
>                      "Error initializing USB support: %s [%i]", desc, rc);
>          return FALSE;
>      }
> -
> -#ifdef G_OS_WIN32
> -#if LIBUSB_API_VERSION >= 0x01000106
> -    libusb_set_option(priv->context, LIBUSB_OPTION_USE_USBDK);
> -#endif
>  #endif
>  
>      /* Start listening for usb devices plug / unplug */
> @@ -307,6 +303,7 @@ static gboolean spice_usb_device_manager_initable_init(GInitable  *initable,
>          g_warning("Error initializing GUdevClient");
>          return FALSE;
>      }
> +    priv->context = g_udev_client_get_context(priv->udev);
>      g_signal_connect(G_OBJECT(priv->udev), "uevent",
>                       G_CALLBACK(spice_usb_device_manager_uevent_cb), self);
>      /* Do coldplug (detection of already connected devices) */
> @@ -402,8 +399,10 @@ static void spice_usb_device_manager_finalize(GObject *gobject)
>      g_clear_object(&priv->udev);
>  #endif
>      g_return_if_fail(priv->event_thread == NULL);
> +#ifndef G_OS_WIN32
>      if (priv->context)
>          libusb_exit(priv->context);
> +#endif
>      free(priv->auto_conn_filter_rules);
>      free(priv->redirect_on_connect_rules);
>  #ifdef G_OS_WIN32
> diff --git a/src/win-usb-dev.c b/src/win-usb-dev.c
> index d0eae06..a8d922f 100644
> --- a/src/win-usb-dev.c
> +++ b/src/win-usb-dev.c
> @@ -113,6 +113,10 @@ GUdevClient *g_udev_client_new(void)
>      return singleton;
>  }
>  
> +libusb_context *g_udev_client_get_context(GUdevClient *client)
> +{
> +    return client->priv->ctx;
> +}
>  
>  /*
>   * devs [in,out] an empty devs list in, full devs list out
> diff --git a/src/win-usb-dev.h b/src/win-usb-dev.h
> index 0f34a01..f3c7466 100644
> --- a/src/win-usb-dev.h
> +++ b/src/win-usb-dev.h
> @@ -80,6 +80,7 @@ struct _GUdevClientClass
>  
>  GType g_udev_client_get_type(void) G_GNUC_CONST;
>  GUdevClient *g_udev_client_new(void);
> +libusb_context *g_udev_client_get_context(GUdevClient *client);
>  GList *g_udev_client_query_by_subsystem(GUdevClient *client, const gchar *subsystem);
>  
>  GType g_udev_device_get_type(void) G_GNUC_CONST;
> -- 
> 2.17.1
> 
> _______________________________________________
> Spice-devel mailing list
> Spice-devel@xxxxxxxxxxxxxxxxxxxxx
> https://lists.freedesktop.org/mailman/listinfo/spice-devel

Attachment: signature.asc
Description: PGP signature

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

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