qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] qdev: keep track of property types, print properties.
@ 2009-05-28 15:38 Gerd Hoffmann
  0 siblings, 0 replies; only message in thread
From: Gerd Hoffmann @ 2009-05-28 15:38 UTC (permalink / raw)
  To: qemu-devel@nongnu.org

[-- Attachment #1: Type: text/plain, Size: 251 bytes --]

   Hi,

This patch makes qemu keep track od property types.  Types are checked 
when reading them and the information is also used to print them.  The 
patch depends on the "info qtree" monitor command patch sent earlier today.

please apply,
   Gerd

[-- Attachment #2: 0001-qdev-keep-track-of-property-types-print-properties.patch --]
[-- Type: text/plain, Size: 2606 bytes --]

>From a74479d447f79582eb624bcdcc6ffc9f53d38252 Mon Sep 17 00:00:00 2001
From: Gerd Hoffmann <kraxel@redhat.com>
Date: Thu, 28 May 2009 17:33:54 +0200
Subject: [PATCH] qdev: keep track of property types, print properties.


Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/qdev.c |   23 +++++++++++++++++++++--
 1 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/hw/qdev.c b/hw/qdev.c
index d2eeb9a..f271b7f 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -33,6 +33,10 @@
 
 struct DeviceProperty {
     const char *name;
+    enum {
+        PROP_INT,
+        PROP_PTR,
+    } type;
     union {
         uint64_t i;
         void *ptr;
@@ -138,6 +142,7 @@ void qdev_set_prop_int(DeviceState *dev, const char *name, uint64_t value)
     DeviceProperty *prop;
 
     prop = create_prop(dev, name);
+    prop->type = PROP_INT;
     prop->value.i = value;
 }
 
@@ -146,6 +151,7 @@ void qdev_set_prop_ptr(DeviceState *dev, const char *name, void *value)
     DeviceProperty *prop;
 
     prop = create_prop(dev, name);
+    prop->type = PROP_PTR;
     prop->value.ptr = value;
 }
 
@@ -191,7 +197,7 @@ uint64_t qdev_get_prop_int(DeviceState *dev, const char *name, uint64_t def)
     DeviceProperty *prop;
 
     prop = find_prop(dev, name);
-    if (!prop)
+    if (!prop || prop->type != PROP_INT)
         return def;
 
     return prop->value.i;
@@ -203,6 +209,7 @@ void *qdev_get_prop_ptr(DeviceState *dev, const char *name)
 
     prop = find_prop(dev, name);
     assert(prop);
+    assert(prop->type == PROP_PTR);
     return prop->value.ptr;
 }
 
@@ -318,11 +325,23 @@ void qbus_print(Monitor *mon, BusState *bus, int indent)
 {
     struct DeviceState *dev;
     struct BusState *child;
+    struct DeviceProperty *prop;
 
     monitor_printf(mon, "%*sbus: name %s, type %d\n", indent, "",
                    bus->name, bus->type);
     LIST_FOREACH(dev, &bus->children, sibling) {
-        monitor_printf(mon, "%*sdev: %s\n", indent+2, "", dev->type->name);
+        monitor_printf(mon, "%*sdev: %s", indent+2, "", dev->type->name);
+        for (prop = dev->props; prop; prop = prop->next) {
+            switch (prop->type) {
+            case PROP_INT:
+                monitor_printf(mon, ", %s=%" PRId64, prop->name, prop->value.i);
+                break;
+            case PROP_PTR:
+                monitor_printf(mon, ", %s=%p", prop->name, prop->value.ptr);
+                break;
+            }
+        }
+        monitor_printf(mon, "\n");
         LIST_FOREACH(child, &dev->child_bus, sibling) {
             qbus_print(mon, child, indent+4);
         }
-- 
1.6.2.2


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2009-05-28 15:38 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-05-28 15:38 [Qemu-devel] [PATCH] qdev: keep track of property types, print properties Gerd Hoffmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).