]> Git Repo - qemu.git/commitdiff
qom: Refine container_get() to allow using a custom root
authorAndreas Färber <[email protected]>
Thu, 5 Apr 2012 11:21:46 +0000 (13:21 +0200)
committerAnthony Liguori <[email protected]>
Tue, 24 Apr 2012 14:50:31 +0000 (09:50 -0500)
Specify the root to search from as argument. This avoids hardcoding
"/machine" in some places and makes it more flexible.

Signed-off-by: Andreas Färber <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Anthony Liguori <[email protected]>
Signed-off-by: Anthony Liguori <[email protected]>
hw/qdev-monitor.c
hw/qdev.c
include/qemu/object.h
qom/container.c

index 81d654827f813b7f5a1942660927ef1ba551fb43..dc4e4e1b8446c6a56867a6192fc4ad5b316be4a8 100644 (file)
@@ -181,7 +181,7 @@ static Object *qdev_get_peripheral(void)
     static Object *dev;
 
     if (dev == NULL) {
-        dev = container_get("/machine/peripheral");
+        dev = container_get(qdev_get_machine(), "/peripheral");
     }
 
     return dev;
@@ -192,7 +192,7 @@ static Object *qdev_get_peripheral_anon(void)
     static Object *dev;
 
     if (dev == NULL) {
-        dev = container_get("/machine/peripheral-anon");
+        dev = container_get(qdev_get_machine(), "/peripheral-anon");
     }
 
     return dev;
index afbc975b8f32a10fae3025df2a7e16d90afd7e0f..0bcde20c92a39cf4f43a1cdeb1eeaf907e164c9e 100644 (file)
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -158,8 +158,9 @@ int qdev_init(DeviceState *dev)
         static int unattached_count = 0;
         gchar *name = g_strdup_printf("device[%d]", unattached_count++);
 
-        object_property_add_child(container_get("/machine/unattached"), name,
-                                  OBJECT(dev), NULL);
+        object_property_add_child(container_get(qdev_get_machine(),
+                                                "/unattached"),
+                                  name, OBJECT(dev), NULL);
         g_free(name);
     }
 
@@ -677,7 +678,7 @@ Object *qdev_get_machine(void)
     static Object *dev;
 
     if (dev == NULL) {
-        dev = container_get("/machine");
+        dev = container_get(object_get_root(), "/machine");
     }
 
     return dev;
index a675937da1f7f1e128b4fd5d83e8cc17548e1394..ca1649c9188b56ed29348fa8cf0ee4330aaa310d 100644 (file)
@@ -905,6 +905,7 @@ void object_property_add_str(Object *obj, const char *name,
 
 /**
  * container_get:
+ * @root: root of the #path, e.g., object_get_root()
  * @path: path to the container
  *
  * Return a container object whose path is @path.  Create more containers
@@ -912,7 +913,7 @@ void object_property_add_str(Object *obj, const char *name,
  *
  * Returns: the container object.
  */
-Object *container_get(const char *path);
+Object *container_get(Object *root, const char *path);
 
 
 #endif
index 67e9e8a6f8923978a53c332ca71eeda572f0efb6..c9940ab2e17f04361bc550772c911fe497ba17ea 100644 (file)
@@ -25,7 +25,7 @@ static void container_register_types(void)
     type_register_static(&container_info);
 }
 
-Object *container_get(const char *path)
+Object *container_get(Object *root, const char *path)
 {
     Object *obj, *child;
     gchar **parts;
@@ -33,7 +33,7 @@ Object *container_get(const char *path)
 
     parts = g_strsplit(path, "/", 0);
     assert(parts != NULL && parts[0] != NULL && !parts[0][0]);
-    obj = object_get_root();
+    obj = root;
 
     for (i = 1; parts[i] != NULL; i++, obj = child) {
         child = object_resolve_path_component(obj, parts[i]);
This page took 0.032678 seconds and 4 git commands to generate.