<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Jul 17, 2014 at 11:43 AM, Fabiano Fidêncio <span dir="ltr"><<a href="mailto:fidencio@redhat.com" target="_blank">fidencio@redhat.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">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 provide a list of USB devices class code (based on<br>
<a href="http://www.usb.org/developers/defined_class" target="_blank">http://www.usb.org/developers/defined_class</a>), then the function will<br>
create a string in the expcted format, representing the filter, and call<br>
spice_usb_device_manager_get_devices_with_filter()<br></blockquote><div><br></div><div>This doesn't bring significant improvement to the string  get_devices_with_filter(). I disagree with adding this utility function, which can be implemented by apps.<br>
</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
---<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             | 45 ++++++++++++++++++++++++++++++++++++<br>
 gtk/usb-device-manager.h             |  2 ++<br>
 5 files changed, 50 insertions(+)<br>
<br>
diff --git a/doc/reference/spice-gtk-sections.txt 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..7e65991 100644<br>
--- a/gtk/usb-device-manager.c<br>
+++ b/gtk/usb-device-manager.c<br>
@@ -1379,6 +1379,51 @@ GPtrArray* 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 gint) (allow-none): a %GList of classes for selecting<br>
+ *           which devices to return or %NULL<br></blockquote><div><br></div><div>Again, I'd prefer a regular C array here. A GList is overkill<br><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">

+ *<br>
+ * Returns: (element-type SpiceUsbDevice) (transfer full): a %GPtrArray array of %SpiceUsbDevice<br>
+ *<br>
+ * Since: 0.26<br>
+ */<br>
+GPtrArray* spice_usb_device_manager_get_devices_by_classes(SpiceUsbDeviceManager *self,<br>
+                                                           GList *classes)<br>
+{<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 this function<br>
+       filters only by the device class, another fields as vendor id, product id and device<br>
+       version bcd are automatically set to match any id/version and allow is always set to<br>
+       "allows redir for this device" (actually, it doesn't matter when we are just querying<br>
+       a list of devices).<br>
+<br>
+       A filter rule has the form of @class,@vendor,@product,@version,@allow and the rules,<br>
+       themselves, are concatenated like @rule1|@rule2|@rule3 */<br>
+    for (l = classes; l != NULL; l = l->next) {<br>
+        enum libusb_class_code code = GPOINTER_TO_INT(l->data);<br>
+        if (filter == NULL) {<br>
+            filter = g_strdup_printf("0x%02x,-1,-1,-1,1", code);<br>
+        } else {<br>
+            gchar *tmp_filter = NULL;<br>
+<br>
+            tmp_filter = g_strdup_printf("%s|0x%02x,-1,-1,-1,1", filter, code);<br>
+<br>
+            g_free(filter);<br>
+            filter = tmp_filter;<br>
+        }<br>
+    }<br>
+<br>
+    devices = spice_usb_device_manager_get_devices_with_filter(self, 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..e6db56f 100644<br>
--- a/gtk/usb-device-manager.h<br>
+++ b/gtk/usb-device-manager.h<br>
@@ -96,6 +96,8 @@ SpiceUsbDeviceManager *spice_usb_device_manager_get(SpiceSession *session,<br>
 GPtrArray *spice_usb_device_manager_get_devices(SpiceUsbDeviceManager *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 *manager,<br>
                                                       SpiceUsbDevice *device);<br>
<span class=""><font color="#888888">--<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>
</font></span></blockquote></div><br><br clear="all"><br>-- <br>Marc-André Lureau
</div></div>