From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40385) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WKQ8u-00043t-QQ for qemu-devel@nongnu.org; Mon, 03 Mar 2014 05:30:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WKQ8p-0000NP-Uj for qemu-devel@nongnu.org; Mon, 03 Mar 2014 05:30:40 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35471) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WKQ8p-0000MP-4k for qemu-devel@nongnu.org; Mon, 03 Mar 2014 05:30:35 -0500 From: Stefan Hajnoczi Date: Mon, 3 Mar 2014 11:30:02 +0100 Message-Id: <1393842608-17795-2-git-send-email-stefanha@redhat.com> In-Reply-To: <1393842608-17795-1-git-send-email-stefanha@redhat.com> References: <1393842608-17795-1-git-send-email-stefanha@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH v6 1/7] object: add object_get_canonical_path_component() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Fam Zheng , "Shergill, Gurinder" , Michael Roth , Paolo Bonzini , "Vinod, Chegu" , Andreas Faerber It is often useful to find an object's child property name. Also use this new function to simplify the implementation of object_get_canonical_path(). Cc: "Andreas F=C3=A4rber" Signed-off-by: Stefan Hajnoczi --- include/qom/object.h | 8 ++++++++ qom/object.c | 54 +++++++++++++++++++++++++++++++---------------= ------ 2 files changed, 40 insertions(+), 22 deletions(-) diff --git a/include/qom/object.h b/include/qom/object.h index 9c7c361..4cd7704 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -974,6 +974,14 @@ const char *object_property_get_type(Object *obj, co= nst char *name, Object *object_get_root(void); =20 /** + * object_get_canonical_path_component: + * + * Returns: The final component in the object's canonical path. The can= onical + * path is the path within the composition tree starting from the root. + */ +gchar *object_get_canonical_path_component(Object *obj); + +/** * object_get_canonical_path: * * Returns: The canonical path for a object. This is the path within th= e diff --git a/qom/object.c b/qom/object.c index 660859c..3290375 100644 --- a/qom/object.c +++ b/qom/object.c @@ -1102,39 +1102,49 @@ void object_property_add_link(Object *obj, const = char *name, g_free(full_type); } =20 +gchar *object_get_canonical_path_component(Object *obj) +{ + ObjectProperty *prop =3D NULL; + + g_assert(obj); + g_assert(obj->parent !=3D NULL); + + QTAILQ_FOREACH(prop, &obj->parent->properties, node) { + if (!object_property_is_child(prop)) { + continue; + } + + if (prop->opaque =3D=3D obj) { + return g_strdup(prop->name); + } + } + + /* obj had a parent but was not a child, should never happen */ + g_assert_not_reached(); + return NULL; +} + gchar *object_get_canonical_path(Object *obj) { Object *root =3D object_get_root(); - char *newpath =3D NULL, *path =3D NULL; + char *newpath, *path =3D NULL; =20 while (obj !=3D root) { - ObjectProperty *prop =3D NULL; - - g_assert(obj->parent !=3D NULL); - - QTAILQ_FOREACH(prop, &obj->parent->properties, node) { - if (!object_property_is_child(prop)) { - continue; - } + char *component =3D object_get_canonical_path_component(obj); =20 - if (prop->opaque =3D=3D obj) { - if (path) { - newpath =3D g_strdup_printf("%s/%s", prop->name, pat= h); - g_free(path); - path =3D newpath; - } else { - path =3D g_strdup(prop->name); - } - break; - } + if (path) { + newpath =3D g_strdup_printf("%s/%s", component, path); + g_free(component); + g_free(path); + path =3D newpath; + } else { + path =3D component; } =20 - g_assert(prop !=3D NULL); - obj =3D obj->parent; } =20 - newpath =3D g_strdup_printf("/%s", path); + newpath =3D g_strdup_printf("/%s", path ? path : ""); g_free(path); =20 return newpath; --=20 1.8.5.3