qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Andreas Färber" <afaerber@suse.de>
To: qemu-devel@nongnu.org
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
	"Andreas Färber" <afaerber@suse.de>,
	"Anthony Liguori" <anthony@codemonkey.ws>
Subject: [Qemu-devel] [PATCH] qom: Refine container_get() to allow using a custom root
Date: Thu,  5 Apr 2012 13:21:46 +0200	[thread overview]
Message-ID: <1333624906-7870-1-git-send-email-afaerber@suse.de> (raw)
In-Reply-To: <4F732C0F.8030005@redhat.com>

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>
---
 hw/qdev-monitor.c     |    4 ++--
 hw/qdev.c             |    7 ++++---
 include/qemu/object.h |    3 ++-
 qom/container.c       |    4 ++--
 4 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/hw/qdev-monitor.c b/hw/qdev-monitor.c
index 4783366..67f296b 100644
--- a/hw/qdev-monitor.c
+++ b/hw/qdev-monitor.c
@@ -180,7 +180,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;
@@ -191,7 +191,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;
diff --git a/hw/qdev.c b/hw/qdev.c
index 0d3c0fc..efa4c5d 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -157,8 +157,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);
     }
 
@@ -673,7 +674,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 a675937..ca1649c 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 67e9e8a..c9940ab 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]);
-- 
1.7.7

  reply	other threads:[~2012-04-05 11:22 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-27 16:38 [Qemu-devel] [PATCH 0/4] qdev: give all devices a canonical QOM path Paolo Bonzini
2012-03-27 16:38 ` [Qemu-devel] [PATCH 1/4] qom: add container_get Paolo Bonzini
2012-03-27 21:07   ` Anthony Liguori
2012-03-27 16:38 ` [Qemu-devel] [PATCH 2/4] qdev: add children before qdev_init Paolo Bonzini
2012-03-27 21:08   ` Anthony Liguori
2012-03-27 16:38 ` [Qemu-devel] [PATCH 3/4] qdev: give all devices a canonical path Paolo Bonzini
2012-03-27 21:12   ` Anthony Liguori
2012-03-27 16:38 ` [Qemu-devel] [PATCH 4/4] qdev: put all devices under /machine Paolo Bonzini
2012-03-27 21:11   ` Anthony Liguori
2012-03-28 14:01     ` Andreas Färber
2012-03-28 14:34       ` [Qemu-devel] [PATCH v2 " Paolo Bonzini
2012-03-28 15:10         ` Andreas Färber
2012-03-28 15:19           ` Paolo Bonzini
2012-04-05 11:21             ` Andreas Färber [this message]
2012-04-05 11:30               ` [Qemu-devel] [PATCH] qom: Refine container_get() to allow using a custom root Paolo Bonzini
2012-03-27 16:42 ` [Qemu-devel] [PATCH 0/4] qdev: give all devices a canonical QOM path Anthony Liguori
2012-04-02 21:21 ` Anthony Liguori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1333624906-7870-1-git-send-email-afaerber@suse.de \
    --to=afaerber@suse.de \
    --cc=anthony@codemonkey.ws \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).