From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:47305) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SFklL-00020V-Lv for qemu-devel@nongnu.org; Thu, 05 Apr 2012 07:22:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SFklF-0004l8-ED for qemu-devel@nongnu.org; Thu, 05 Apr 2012 07:21:59 -0400 Received: from cantor2.suse.de ([195.135.220.15]:52077 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SFklF-0004kx-4s for qemu-devel@nongnu.org; Thu, 05 Apr 2012 07:21:53 -0400 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Thu, 5 Apr 2012 13:21:46 +0200 Message-Id: <1333624906-7870-1-git-send-email-afaerber@suse.de> In-Reply-To: <4F732C0F.8030005@redhat.com> References: <4F732C0F.8030005@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH] qom: Refine container_get() to allow using a custom root List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Paolo Bonzini , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Anthony Liguori 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=C3=A4rber Cc: Paolo Bonzini Cc: Anthony Liguori --- 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; =20 if (dev =3D=3D NULL) { - dev =3D container_get("/machine/peripheral"); + dev =3D container_get(qdev_get_machine(), "/peripheral"); } =20 return dev; @@ -191,7 +191,7 @@ static Object *qdev_get_peripheral_anon(void) static Object *dev; =20 if (dev =3D=3D NULL) { - dev =3D container_get("/machine/peripheral-anon"); + dev =3D container_get(qdev_get_machine(), "/peripheral-anon"); } =20 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 =3D 0; gchar *name =3D g_strdup_printf("device[%d]", unattached_count++= ); =20 - 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); } =20 @@ -673,7 +674,7 @@ Object *qdev_get_machine(void) static Object *dev; =20 if (dev =3D=3D NULL) { - dev =3D container_get("/machine"); + dev =3D container_get(object_get_root(), "/machine"); } =20 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, =20 /** * 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 container= s @@ -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); =20 =20 #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); } =20 -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) =20 parts =3D g_strsplit(path, "/", 0); assert(parts !=3D NULL && parts[0] !=3D NULL && !parts[0][0]); - obj =3D object_get_root(); + obj =3D root; =20 for (i =3D 1; parts[i] !=3D NULL; i++, obj =3D child) { child =3D object_resolve_path_component(obj, parts[i]); --=20 1.7.7