Patchwork [08/11] qdev: Add usb_bus_dev_info

login
register
mail settings
Submitter Nathan Baum
Date Dec. 26, 2009, 9:19 p.m.
Message ID <1261862362-2530-9-git-send-email-nathan@parenthephobia.org.uk>
Download mbox | patch
Permalink /patch/41815/
State New
Headers show

Comments

Nathan Baum - Dec. 26, 2009, 9:19 p.m.
Returns a QObject with information about a USB device.

Signed-off-by: Nathan Baum <nathan@parenthephobia.org.uk>
---
 hw/usb-bus.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)

Patch

diff --git a/hw/usb-bus.c b/hw/usb-bus.c
index 54027df..6d02807 100644
--- a/hw/usb-bus.c
+++ b/hw/usb-bus.c
@@ -3,6 +3,7 @@ 
 #include "qdev.h"
 #include "sysemu.h"
 #include "monitor.h"
+#include "qjson.h"
 
 static void usb_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent);
 
@@ -232,6 +233,18 @@  static void usb_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent)
                    dev->attached ? ", attached" : "");
 }
 
+static QObject *usb_bus_dev_info(Monitor *mon, DeviceState *qdev)
+{
+    USBDevice *dev = DO_UPCAST(USBDevice, qdev, qdev);
+    USBBus *bus = usb_bus_from_device(dev);
+    return qobject_from_jsonf("{'busnr': %d, 'addr':%d, 'speed': %s, 'desc': %s, 'attached': %i}",
+                              bus->busnr,
+                              dev->addr,
+                              usb_speed(dev->speed),
+                              dev->product_desc,
+                              dev->attached);
+}
+
 void usb_info(Monitor *mon)
 {
     USBBus *bus;