<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Jul 16, 2014 at 4:49 PM, Marc-André Lureau <span dir="ltr"><<a href="mailto:mlureau@redhat.com" target="_blank">mlureau@redhat.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Hi<br>
<div class=""><br>
----- Original Message -----<br>
> This function allows the applications to get USB devices filtered by the<br>
> devices' classes. The applications that are going to use this function<br>
> should do:<br>
> - Create a list of SpiceUsbDeviceFilter and set, for each<br>
>   SpiceUsbDeviceFilter:<br>
>     - the device class code based on<br>
>       <a href="http://www.usb.org/developers/defined_class" target="_blank">http://www.usb.org/developers/defined_class</a><br>
>     - whether the device is allowed or not to auto connect<br>
> The function will create a string in the expcted format, representing the<br>
> filter, based on the list provided by the user and then call<br>
> spice_usb_device_manager_get_devices_with_filter()<br>
<br>
</div>I am not sure this kind of utility function belongs in spice-gtk. It doesn't bring much to the existing call.<br>
<br>
Why is this change needed for?<br></blockquote><div><br></div><div>Basically because the filter rule seems a bit cryptic and would be better if we could do that only by the device class code.</div><div>Please, take a look on <a href="https://bugs.freedesktop.org/show_bug.cgi?id=63807#c2">https://bugs.freedesktop.org/show_bug.cgi?id=63807#c2</a> for more info.</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div><div class="h5">
> ---<br>
>  doc/reference/spice-gtk-sections.txt |  1 +<br>
>  gtk/map-file                         |  1 +<br>
>  gtk/spice-glib-sym-file              |  1 +<br>
>  gtk/usb-device-manager.c             | 47<br>
>  +++++++++++++++++++++++++++++++++++-<br>
>  gtk/usb-device-manager.h             | 13 ++++++++++<br>
>  5 files changed, 62 insertions(+), 1 deletion(-)<br>
><br>
> diff --git a/doc/reference/spice-gtk-sections.txt<br>
> b/doc/reference/spice-gtk-sections.txt<br>
> index caaa92c..03dcec3 100644<br>
> --- a/doc/reference/spice-gtk-sections.txt<br>
> +++ b/doc/reference/spice-gtk-sections.txt<br>
> @@ -298,6 +298,7 @@ SpiceUsbDeviceManagerClass<br>
>  spice_usb_device_manager_get<br>
>  spice_usb_device_manager_get_devices<br>
>  spice_usb_device_manager_get_devices_with_filter<br>
> +spice_usb_device_manager_get_devices_by_classes<br>
>  spice_usb_device_manager_is_device_connected<br>
>  spice_usb_device_manager_disconnect_device<br>
>  spice_usb_device_manager_can_redirect_device<br>
> diff --git a/gtk/map-file b/gtk/map-file<br>
> index 90f14f1..0a31dc0 100644<br>
> --- a/gtk/map-file<br>
> +++ b/gtk/map-file<br>
> @@ -110,6 +110,7 @@ spice_usb_device_manager_connect_device_finish;<br>
>  spice_usb_device_manager_disconnect_device;<br>
>  spice_usb_device_manager_get;<br>
>  spice_usb_device_manager_get_devices;<br>
> +spice_usb_device_manager_get_devices_by_classes;<br>
>  spice_usb_device_manager_get_devices_with_filter;<br>
>  spice_usb_device_manager_get_type;<br>
>  spice_usb_device_manager_is_device_connected;<br>
> diff --git a/gtk/spice-glib-sym-file b/gtk/spice-glib-sym-file<br>
> index 878dd12..3c5a785 100644<br>
> --- a/gtk/spice-glib-sym-file<br>
> +++ b/gtk/spice-glib-sym-file<br>
> @@ -85,6 +85,7 @@ spice_usb_device_manager_connect_device_finish<br>
>  spice_usb_device_manager_disconnect_device<br>
>  spice_usb_device_manager_get<br>
>  spice_usb_device_manager_get_devices<br>
> +spice_usb_device_manager_get_devices_by_classes<br>
>  spice_usb_device_manager_get_devices_with_filter<br>
>  spice_usb_device_manager_get_type<br>
>  spice_usb_device_manager_is_device_connected<br>
> diff --git a/gtk/usb-device-manager.c b/gtk/usb-device-manager.c<br>
> index 5013b6c..71bffe4 100644<br>
> --- a/gtk/usb-device-manager.c<br>
> +++ b/gtk/usb-device-manager.c<br>
> @@ -154,7 +154,6 @@ typedef struct _SpiceUsbDeviceInfo {<br>
>      gint    ref;<br>
>  } SpiceUsbDeviceInfo;<br>
><br>
> -<br>
>  static void channel_new(SpiceSession *session, SpiceChannel *channel,<br>
>                          gpointer user_data);<br>
>  static void channel_destroy(SpiceSession *session, SpiceChannel *channel,<br>
> @@ -1379,6 +1378,52 @@ GPtrArray*<br>
> spice_usb_device_manager_get_devices(SpiceUsbDeviceManager *self)<br>
>  }<br>
><br>
>  /**<br>
> + * spice_usb_device_manager_get_devices_by_classes:<br>
> + * @manager: the #SpiceUsbDeviceManager manager<br>
> + * @classes: (element-type SpiceUsbDeviceFilter) (allow-none): a %GList of<br>
> classes for selecting<br>
> + * which devices to return or %NULL to use the default filter, that filters<br>
> out HID (class 0x03)<br>
> + * USB devices from auto connect and auto connects anything else.<br>
> + *<br>
> + * Returns: (element-type SpiceUsbDevice) (transfer full): a %GPtrArray<br>
> array of %SpiceUsbDevice<br>
> + */<br>
<br>
</div></div>missing Since:<br>
<div class=""><br>
> +GPtrArray*<br>
> spice_usb_device_manager_get_devices_by_classes(SpiceUsbDeviceManager *self,<br>
> +                                                           GList *classes)<br>
<br>
</div>I am not convinced using GList of structs make this function easier to use,<br>
a string or a valist could do. Aee also below for my question about struct content.<br></blockquote><div><br></div><div>Maybe a GList of device codes? That would be exactly what I need, considering I don't have to set the allow field.</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div><div class="h5">
> +{<br>
> +    GPtrArray *devices;<br>
> +    GList *l;<br>
> +    gchar *filter = NULL;<br>
> +<br>
> +    /* Builds the filter based on the USB classes received from the user. As<br>
> this function<br>
> +       filters only by the device class, another fields as vendor id,<br>
> product id and device<br>
> +       version bcd are automatically set to match any id/version.<br>
> +<br>
> +       A filter rule has the form of @class,@vendor,@product,@version,@allow<br>
> and the rules,<br>
> +       themselves, are concatenated like @rule1|@rule2|@rule3 */<br>
> +    for (l = classes; l != NULL; l = l->next) {<br>
> +        SpiceUsbDeviceFilter *device_filter = l->data;<br>
> +        if (filter == NULL) {<br>
> +            filter = g_strdup_printf(<br>
> +                    "0x%02x,-1,-1,-1,%d",<br>
> +                    device_filter->code, device_filter->allow);<br>
> +        } else {<br>
> +            gchar *tmp_filter = NULL;<br>
> +<br>
> +            tmp_filter = g_strdup_printf(<br>
> +                    "%s|0x%02x,-1,-1,-1,%d",<br>
> +                    filter, device_filter->code, device_filter->allow);<br>
> +<br>
> +            g_free(filter);<br>
> +            filter = tmp_filter;<br>
> +        }<br>
> +    }<br>
> +<br>
> +    devices = spice_usb_device_manager_get_devices_with_filter(self,<br>
> filter);<br>
> +    g_free(filter);<br>
> +<br>
> +    return devices;<br>
> +}<br>
> +<br>
> +/**<br>
>   * spice_usb_device_manager_is_device_connected:<br>
>   * @manager: the #SpiceUsbDeviceManager manager<br>
>   * @device: a #SpiceUsbDevice<br>
> diff --git a/gtk/usb-device-manager.h b/gtk/usb-device-manager.h<br>
> index a7e3515..7a048be 100644<br>
> --- a/gtk/usb-device-manager.h<br>
> +++ b/gtk/usb-device-manager.h<br>
> @@ -40,6 +40,7 @@ typedef struct _SpiceUsbDeviceManagerClass<br>
> SpiceUsbDeviceManagerClass;<br>
>  typedef struct _SpiceUsbDeviceManagerPrivate SpiceUsbDeviceManagerPrivate;<br>
><br>
>  typedef struct _SpiceUsbDevice SpiceUsbDevice;<br>
> +typedef struct _SpiceUsbDeviceFilter SpiceUsbDeviceFilter;<br>
><br>
>  /**<br>
>   * SpiceUsbDeviceManager:<br>
> @@ -85,6 +86,16 @@ struct _SpiceUsbDeviceManagerClass<br>
>      gchar _spice_reserved[SPICE_RESERVED_PADDING];<br>
>  };<br>
><br>
> +/**<br>
> + * SpiceUsbDeviceFilter:<br>
> + * @code: the USB Class Code<br>
> + * @allow: whether the device is allowed or not to auto connect<br>
<br>
</div></div>I don't get why "allow" is necessary here. It make sense for auto-connect-filter, but to query a list of devices?<br></blockquote><div><br></div><div>Hmmm. I'm not sure if "allow" is necessary. Thinking a bit, probably not.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class=""><div class="h5"><br>
> + */<br>
> +struct _SpiceUsbDeviceFilter {<br>
> +    guint code;<br>
> +    gboolean allow;<br>
> +};<br>
> +<br>
>  GType spice_usb_device_get_type(void);<br>
>  GType spice_usb_device_manager_get_type(void);<br>
><br>
> @@ -96,6 +107,8 @@ SpiceUsbDeviceManager<br>
> *spice_usb_device_manager_get(SpiceSession *session,<br>
>  GPtrArray *spice_usb_device_manager_get_devices(SpiceUsbDeviceManager<br>
>  *manager);<br>
>  GPtrArray* spice_usb_device_manager_get_devices_with_filter(<br>
>      SpiceUsbDeviceManager *manager, const gchar *filter);<br>
> +GPtrArray* spice_usb_device_manager_get_devices_by_classes(<br>
> +    SpiceUsbDeviceManager *manager, GList *classes);<br>
><br>
>  gboolean spice_usb_device_manager_is_device_connected(SpiceUsbDeviceManager<br>
>  *manager,<br>
>                                                        SpiceUsbDevice<br>
>                                                        *device);<br>
> --<br>
> 1.9.3<br>
><br>
> _______________________________________________<br>
> Spice-devel mailing list<br>
> <a href="mailto:Spice-devel@lists.freedesktop.org">Spice-devel@lists.freedesktop.org</a><br>
> <a href="http://lists.freedesktop.org/mailman/listinfo/spice-devel" target="_blank">http://lists.freedesktop.org/mailman/listinfo/spice-devel</a><br>
><br>
_______________________________________________<br>
Spice-devel mailing list<br>
<a href="mailto:Spice-devel@lists.freedesktop.org">Spice-devel@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/spice-devel" target="_blank">http://lists.freedesktop.org/mailman/listinfo/spice-devel</a><br>
</div></div></blockquote></div><br><div><br></div>-- <br><div>Fabiano Fidênciou</div>
</div></div>