Received: from eggs.gnu.org ([2001:4830:134:3::10]:57862) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XXkLu-0006oV-DX for qemu-devel@nongnu.org; Sat, 27 Sep 2014 01:15:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XXkLn-0007Wt-QF for qemu-devel@nongnu.org; Sat, 27 Sep 2014 01:15:26 -0400 Received: from szxga03-in.huawei.com ([119.145.14.66]:3785) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XXkLm-0007W2-Ue for qemu-devel@nongnu.org; Sat, 27 Sep 2014 01:15:19 -0400 From: Date: Sat, 27 Sep 2014 13:13:58 +0800 Message-ID: <1411794841-9672-5-git-send-email-arei.gonglei@huawei.com> In-Reply-To: <1411794841-9672-1-git-send-email-arei.gonglei@huawei.com> References: <1411794841-9672-1-git-send-email-arei.gonglei@huawei.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Qemu-devel] [PATCH v3 4/7] qom: add description field in ObjectProperty struct List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: weidong.huang@huawei.com, aliguori@amazon.com, mst@redhat.com, armbru@redhat.com, luonengjun@huawei.com, peter.huangpeng@huawei.com, lcapitulino@redhat.com, Gonglei , stefanha@redhat.com, pbonzini@redhat.com, afaerber@suse.de From: Gonglei The descriptions can serve as documentation in the code, and they can be used to provide better help. Cc: Paolo Bonzini Cc: Michael S. Tsirkin Cc: Markus Armbruster Signed-off-by: Gonglei --- include/qom/object.h | 15 +++++++++++++++ qom/object.c | 14 ++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/include/qom/object.h b/include/qom/object.h index 8a05a81..ddc600d 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -338,6 +338,7 @@ typedef struct ObjectProperty { gchar *name; gchar *type; + gchar *description; ObjectPropertyAccessor *get; ObjectPropertyAccessor *set; ObjectPropertyResolve *resolve; @@ -1274,6 +1275,20 @@ void object_property_add_alias(Object *obj, const char *name, Object *target_obj, const char *target_name, Error **errp); + +/** + * object_property_set_description: + * @obj: the object to set a property's description to + * @name: the name of the property + * @description: the description of the property on the object + * @errp: if an error occurs, a pointer to an area to store the error + * + * Set an object property's description. + * + */ +void object_property_set_description(Object *obj, const char *name, + const char *description, Error **errp); + /** * object_child_foreach: * @obj: the object whose children will be navigated diff --git a/qom/object.c b/qom/object.c index 575291f..c9b67cf 100644 --- a/qom/object.c +++ b/qom/object.c @@ -369,6 +369,7 @@ static void object_property_del_all(Object *obj) g_free(prop->name); g_free(prop->type); + g_free(prop->description); g_free(prop); } } @@ -803,6 +804,7 @@ void object_property_del(Object *obj, const char *name, Error **errp) g_free(prop->name); g_free(prop->type); + g_free(prop->description); g_free(prop); } @@ -1676,6 +1678,18 @@ out: g_free(prop_type); } +void object_property_set_description(Object *obj, const char *name, + const char *description, Error **errp) +{ + ObjectProperty *op; + + op = object_property_find(obj, name, errp); + if (!op) { + return; + } + op->description = description ? g_strdup(description) : NULL; +} + static void object_instance_init(Object *obj) { object_property_add_str(obj, "type", qdev_get_type, NULL, NULL); -- 1.7.12.4