diff mbox

[v3,4/7] qom: add description field in ObjectProperty struct

Message ID 1411794841-9672-5-git-send-email-arei.gonglei@huawei.com
State New
Headers show

Commit Message

Gonglei (Arei) Sept. 27, 2014, 5:13 a.m. UTC
From: Gonglei <arei.gonglei@huawei.com>

The descriptions can serve as documentation in the code,
and they can be used to provide better help.

Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Michael S. Tsirkin <mst@redhat.com>
Cc: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Gonglei <arei.gonglei@huawei.com>
---
 include/qom/object.h | 15 +++++++++++++++
 qom/object.c         | 14 ++++++++++++++
 2 files changed, 29 insertions(+)

Comments

Paolo Bonzini Sept. 29, 2014, 1:35 p.m. UTC | #1
Il 27/09/2014 07:13, arei.gonglei@huawei.com ha scritto:
> +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;
> +    }

The old description is leaked here if it is not NULL.

Since you are doing v4, please move the object_property_add_alias change
here, too.

Paolo

> +    op->description = description ? g_strdup(description) : NULL;
> +}
> +
Gonglei (Arei) Sept. 30, 2014, 1:45 a.m. UTC | #2
Hi,

> Subject: Re: [PATCH v3 4/7] qom: add description field in ObjectProperty struct
> 
> Il 27/09/2014 07:13, arei.gonglei@huawei.com ha scritto:
> > +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;
> > +    }
> 
> The old description is leaked here if it is not NULL.
> 
Good catch.

> Since you are doing v4, please move the object_property_add_alias change
> here, too.
> 
OK. Thanks !

Best regards,
-Gonglei

> Paolo
> 
> > +    op->description = description ? g_strdup(description) : NULL;
> > +}
> > +
diff mbox

Patch

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);