qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 5/7] qdev: add qdev_foreach()


From: Mark McLoughlin
Subject: [Qemu-devel] [PATCH 5/7] qdev: add qdev_foreach()
Date: Thu, 12 Nov 2009 20:29:00 +0000

No doubt this is the worst idea ever, but the requirement is simple -
some way to iterate all NICs in the system.

Signed-off-by: Mark McLoughlin <address@hidden>
---
 hw/qdev.c |   20 ++++++++++++++++++++
 hw/qdev.h |    3 +++
 2 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/hw/qdev.c b/hw/qdev.c
index b8ab449..d6e3184 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -401,6 +401,26 @@ BusState *qdev_get_child_bus(DeviceState *dev, const char 
*name)
     return NULL;
 }
 
+static void qdev_foreach_recursive(BusState *bus, qdev_foreach_func func, void 
*opaque)
+{
+    DeviceState *dev;
+
+    QLIST_FOREACH(dev, &bus->children, sibling) {
+        BusState *child;
+
+        func(dev, opaque);
+
+        QLIST_FOREACH(child, &dev->child_bus, sibling) {
+            qdev_foreach_recursive(child, func, opaque);
+        }
+    }
+}
+
+void qdev_foreach(qdev_foreach_func func, void *opaque)
+{
+    qdev_foreach_recursive(main_system_bus, func, opaque);
+}
+
 static BusState *qbus_find_recursive(BusState *bus, const char *name,
                                      const BusInfo *info)
 {
diff --git a/hw/qdev.h b/hw/qdev.h
index 26e372c..712ae3b 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -153,6 +153,9 @@ CharDriverState *qdev_init_chardev(DeviceState *dev);
 
 BusState *qdev_get_parent_bus(DeviceState *dev);
 
+typedef void (*qdev_foreach_func)(DeviceState *dev, void *opaque);
+void qdev_foreach(qdev_foreach_func func, void *opaque);
+
 /* Convert from a base type to a parent type, with compile time checking.  */
 #ifdef __GNUC__
 #define DO_UPCAST(type, field, dev) ( __extension__ ( { \
-- 
1.6.2.5





reply via email to

[Prev in Thread] Current Thread [Next in Thread]