From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56413) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yv6Hl-00052i-Rf for qemu-devel@nongnu.org; Wed, 20 May 2015 11:51:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yv6Hk-00012K-Ct for qemu-devel@nongnu.org; Wed, 20 May 2015 11:51:57 -0400 Received: from cantor2.suse.de ([195.135.220.15]:58237 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yv6Hk-00011V-7n for qemu-devel@nongnu.org; Wed, 20 May 2015 11:51:56 -0400 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Wed, 20 May 2015 17:51:46 +0200 Message-Id: <1432137106-8295-13-git-send-email-afaerber@suse.de> In-Reply-To: <1432137106-8295-1-git-send-email-afaerber@suse.de> References: <1432137106-8295-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL 12/12] qom: Add object_property_add_const_link() 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?= From: Paolo Bonzini This helper adds a read-only link<> property. Suggested-by: Eduardo Habkost Signed-off-by: Paolo Bonzini Reviewed-by: Eduardo Habkost Signed-off-by: Andreas F=C3=A4rber --- include/qom/object.h | 18 ++++++++++++++++++ qom/object.c | 16 ++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/include/qom/object.h b/include/qom/object.h index 270a3ef..e8fb863 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -1449,6 +1449,24 @@ void object_property_add_alias(Object *obj, const = char *name, Error **errp); =20 /** + * object_property_add_const_link: + * @obj: the object to add a property to + * @name: the name of the property + * @target: the object to be referred by the link + * @errp: if an error occurs, a pointer to an area to store the error + * + * Add an unmodifiable link for a property on an object. This function = will + * add a property of type link where TYPE is the type of @target. + * + * The caller must ensure that @target stays alive as long as + * this property exists. In the case @target is a child of @obj, + * this will be the case. Otherwise, the caller is responsible for + * taking a reference. + */ +void object_property_add_const_link(Object *obj, const char *name, + Object *target, Error **errp); + +/** * object_property_set_description: * @obj: the object owning the property * @name: the name of the property diff --git a/qom/object.c b/qom/object.c index f1b289c..8f0d8a7 100644 --- a/qom/object.c +++ b/qom/object.c @@ -1386,6 +1386,22 @@ out: g_free(full_type); } =20 +void object_property_add_const_link(Object *obj, const char *name, + Object *target, Error **errp) +{ + char *link_type; + ObjectProperty *op; + + link_type =3D g_strdup_printf("link<%s>", object_get_typename(target= )); + op =3D object_property_add(obj, name, link_type, + object_get_child_property, NULL, + NULL, target, errp); + if (op !=3D NULL) { + op->resolve =3D object_resolve_child_property; + } + g_free(link_type); +} + gchar *object_get_canonical_path_component(Object *obj) { ObjectProperty *prop =3D NULL; --=20 2.1.4