190
* gusb_devices_sort_by_platform_id_cb:
193
gusb_devices_sort_by_platform_id_cb (gconstpointer a, gconstpointer b)
195
GUsbDevice *device_a = *((GUsbDevice **) a);
196
GUsbDevice *device_b = *((GUsbDevice **) b);
197
return g_strcmp0 (g_usb_device_get_platform_id (device_a),
198
g_usb_device_get_platform_id (device_b));
202
moo_cb (GNode *node, gpointer data)
204
GUsbDevice *device = G_USB_DEVICE (node->data);
208
gchar *product = NULL;
209
gchar *vendor = NULL;
212
if (device == NULL) {
213
g_print ("Root Device\n");
218
str = g_string_new ("");
219
for (n = node; n->data != NULL; n = n->parent)
220
g_string_append (str, " ");
222
/* add bus:address */
223
g_string_append_printf (str, "%02x:%02x [%04x:%04x]",
224
g_usb_device_get_bus (device),
225
g_usb_device_get_address (device),
226
g_usb_device_get_vid (device),
227
g_usb_device_get_pid (device));
230
for (i = str->len; i < 30; i++)
231
g_string_append (str, " ");
233
/* We don't error check these as not all devices have these
234
(and the device_open may have failed). */
235
g_usb_device_open (device, NULL);
236
vendor = g_usb_device_get_string_descriptor (device,
237
g_usb_device_get_manufacturer_index (device),
239
product = g_usb_device_get_string_descriptor (device,
240
g_usb_device_get_product_index (device),
243
/* lookup from usb.ids */
244
if (vendor == NULL) {
245
tmp = g_usb_device_get_vid_as_str (device);
247
vendor = g_strdup (tmp);
250
if (product == NULL) {
251
tmp = g_usb_device_get_pid_as_str (device);
253
product = g_strdup (tmp);
257
if (g_usb_device_get_device_class (device) == 0x09 && product == NULL) {
258
product = g_strdup ("USB HUB");
261
/* fall back to the VID/PID */
263
product = g_strdup ("Unknown");
266
vendor = g_strdup ("Unknown");
268
/* add bus:address */
269
g_string_append_printf (str, "%s - %s", vendor, product);
273
g_print ("%s\n", str->str);
274
g_string_free (str, TRUE);
193
283
gusb_cmd_show (GUsbCmdPrivate *priv, gchar **values, GError **error)
198
288
GUsbDevice *device;
290
GPtrArray *devices = NULL;
200
293
devices = g_usb_context_get_devices (priv->usb_ctx);
294
g_ptr_array_sort (devices, gusb_devices_sort_by_platform_id_cb);
296
/* make a tree of the devices */
297
node = g_node_new (NULL);
201
298
for (i = 0; i < devices->len; i++) {
202
299
device = g_ptr_array_index (devices, i);
203
g_print ("device present %x:%x\n",
204
g_usb_device_get_bus (device),
205
g_usb_device_get_address (device));
301
parent = g_usb_device_get_parent (device);
302
if (parent == NULL) {
303
g_node_append_data (node, device);
306
n = g_node_find (node, G_PRE_ORDER, G_TRAVERSE_ALL, parent);
308
g_set_error (error, 1, 0,
309
"no parent node for %s",
310
g_usb_device_get_platform_id (device));
313
g_node_append_data (n, device);
207
317
g_ptr_array_unref (devices);
318
g_node_traverse (node, G_PRE_ORDER, G_TRAVERSE_ALL, -1, moo_cb, priv);