diff options
author | Andreas Färber <afaerber@suse.de> | 2012-04-05 13:21:46 +0200 |
---|---|---|
committer | Anthony Liguori <aliguori@us.ibm.com> | 2012-04-24 09:50:31 -0500 |
commit | dfe47e7029e117f65a14c0948021654f7f7d5d05 (patch) | |
tree | 9831f047090bf7bb7c58959741aad546221cb862 | |
parent | 7f3bf92fad79dff1edcb796a875b5c0d57666162 (diff) |
qom: Refine container_get() to allow using a custom root
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 <afaerber@suse.de>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Anthony Liguori <anthony@codemonkey.ws>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
-rw-r--r-- | hw/qdev-monitor.c | 4 | ||||
-rw-r--r-- | hw/qdev.c | 7 | ||||
-rw-r--r-- | include/qemu/object.h | 3 | ||||
-rw-r--r-- | qom/container.c | 4 |
4 files changed, 10 insertions, 8 deletions
diff --git a/hw/qdev-monitor.c b/hw/qdev-monitor.c index 81d654827f..dc4e4e1b84 100644 --- a/hw/qdev-monitor.c +++ b/hw/qdev-monitor.c @@ -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; @@ -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; diff --git a/include/qemu/object.h b/include/qemu/object.h index a675937da1..ca1649c918 100644 --- a/include/qemu/object.h +++ b/include/qemu/object.h @@ -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 diff --git a/qom/container.c b/qom/container.c index 67e9e8a6f8..c9940ab2e1 100644 --- a/qom/container.c +++ b/qom/container.c @@ -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]); |