From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47741) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YoBdG-0004Fh-Qd for qemu-devel@nongnu.org; Fri, 01 May 2015 10:09:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YoBdB-0007qg-EK for qemu-devel@nongnu.org; Fri, 01 May 2015 10:09:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46669) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YoBdB-0007qV-6w for qemu-devel@nongnu.org; Fri, 01 May 2015 10:09:29 -0400 From: Eduardo Habkost Date: Fri, 1 May 2015 11:09:06 -0300 Message-Id: <1430489347-13772-2-git-send-email-ehabkost@redhat.com> In-Reply-To: <1430489347-13772-1-git-send-email-ehabkost@redhat.com> References: <1430489347-13772-1-git-send-email-ehabkost@redhat.com> Subject: [Qemu-devel] [PATCH v2 1/2] qom: Implement object_property_add_const_link() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, peter.crosthwaite@xilinx.com, mimu@linux.vnet.ibm.com, bharata@linux.vnet.ibm.com, agraf@suse.de, borntraeger@de.ibm.com, Paolo Bonzini , cornelia.huck@de.ibm.com, Igor Mammedov , =?UTF-8?q?Andreas=20F=C3=A4rber?= , david@gibson.dropbear.id.au It can be used in simpler cases where a read-only property is needed. Signed-off-by: Eduardo Habkost --- include/qom/object.h | 23 +++++++++++++++++++++++ qom/object.c | 15 +++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/include/qom/object.h b/include/qom/object.h index d2d7748..78bb941 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -1123,6 +1123,8 @@ void object_property_add_child(Object *obj, const char *name, typedef enum { /* Unref the link pointer when the property is deleted */ OBJ_PROP_LINK_UNREF_ON_RELEASE = 0x1, + /* Free the child pointer passed to object_property_add_link() */ + OBJ_PROP_LINK_FREE_CHILD_POINTER = 0x2, } ObjectPropertyLinkFlags; /** @@ -1162,6 +1164,8 @@ void object_property_allow_set_link(Object *, const char *, * property is deleted with object_property_del(). If the * @flags OBJ_PROP_LINK_UNREF_ON_RELEASE bit is set, * the reference count is decremented when the property is deleted. + * If the OBJ_PROP_LINK_FREE_CHILD_POINTER bit is set, + * @child is freed when the property is deleted. */ void object_property_add_link(Object *obj, const char *name, const char *type, Object **child, @@ -1170,6 +1174,25 @@ void object_property_add_link(Object *obj, const char *name, ObjectPropertyLinkFlags flags, Error **errp); + +/** + * object_property_add_const_link: + * @obj: the object to add a property to + * @name: the name of the property + * @type: the qobj type of the link + * @child: pointer to the linked object + * @flags: additional options for the link + * @errp: if an error occurs, a pointer to an area to store the error + * + * Like object_property_add_link(), but adds a link property that will + * always point to the same object. + */ +void object_property_add_const_link(Object *obj, const char *name, + const char *type, Object *child, + ObjectPropertyLinkFlags flags, + Error **errp); + + /** * object_property_add_str: * @obj: the object to add a property to diff --git a/qom/object.c b/qom/object.c index b8dff43..7d4a46d 100644 --- a/qom/object.c +++ b/qom/object.c @@ -1227,6 +1227,9 @@ static void object_release_link_property(Object *obj, const char *name, if ((prop->flags & OBJ_PROP_LINK_UNREF_ON_RELEASE) && *prop->child) { object_unref(*prop->child); } + if (prop->flags & OBJ_PROP_LINK_FREE_CHILD_POINTER) { + g_free(prop->child); + } g_free(prop); } @@ -1266,6 +1269,18 @@ out: g_free(full_type); } +void object_property_add_const_link(Object *obj, const char *name, + const char *type, Object *child, + ObjectPropertyLinkFlags flags, + Error **errp) +{ + Object **childp = g_new0(Object*, 1); + + *childp = child; + object_property_add_link(obj, name, type, childp, NULL, + flags | OBJ_PROP_LINK_FREE_CHILD_POINTER, errp); +} + gchar *object_get_canonical_path_component(Object *obj) { ObjectProperty *prop = NULL; -- 2.1.0