diff mbox series

[25/26] qapi/qmp: add ObjectPropertyInfo.default-value

Message ID 20191201111531.1136947-26-marcandre.lureau@redhat.com
State New
Headers show
Series Make QDev use class properties | expand

Commit Message

Marc-André Lureau Dec. 1, 2019, 11:15 a.m. UTC
Report the default value associated with a property.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 qapi/qom.json      | 7 ++++++-
 qom/qom-qmp-cmds.c | 4 ++++
 2 files changed, 10 insertions(+), 1 deletion(-)

Comments

Eric Blake Dec. 11, 2019, 4:06 p.m. UTC | #1
On 12/1/19 5:15 AM, Marc-André Lureau wrote:
> Report the default value associated with a property.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>   qapi/qom.json      | 7 ++++++-
>   qom/qom-qmp-cmds.c | 4 ++++
>   2 files changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/qapi/qom.json b/qapi/qom.json
> index 32db96ffc4..471e4b484b 100644
> --- a/qapi/qom.json
> +++ b/qapi/qom.json
> @@ -26,10 +26,15 @@
>   #
>   # @description: if specified, the description of the property.
>   #
> +# @default-value: the default value, if any (since 5.0)
> +#
>   # Since: 1.2
>   ##
>   { 'struct': 'ObjectPropertyInfo',
> -  'data': { 'name': 'str', 'type': 'str', '*description': 'str' } }
> +  'data': { 'name': 'str',
> +            'type': 'str',
> +            '*description': 'str',
> +            '*default-value': 'str' } }

Do we always want to output the stringized value, or would it be wise to 
make this 'any' and output integers where that makes sense?
Marc-André Lureau Dec. 11, 2019, 5:41 p.m. UTC | #2
Hi

On Wed, Dec 11, 2019 at 8:12 PM Eric Blake <eblake@redhat.com> wrote:
>
> On 12/1/19 5:15 AM, Marc-André Lureau wrote:
> > Report the default value associated with a property.
> >
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> >   qapi/qom.json      | 7 ++++++-
> >   qom/qom-qmp-cmds.c | 4 ++++
> >   2 files changed, 10 insertions(+), 1 deletion(-)
> >
> > diff --git a/qapi/qom.json b/qapi/qom.json
> > index 32db96ffc4..471e4b484b 100644
> > --- a/qapi/qom.json
> > +++ b/qapi/qom.json
> > @@ -26,10 +26,15 @@
> >   #
> >   # @description: if specified, the description of the property.
> >   #
> > +# @default-value: the default value, if any (since 5.0)
> > +#
> >   # Since: 1.2
> >   ##
> >   { 'struct': 'ObjectPropertyInfo',
> > -  'data': { 'name': 'str', 'type': 'str', '*description': 'str' } }
> > +  'data': { 'name': 'str',
> > +            'type': 'str',
> > +            '*description': 'str',
> > +            '*default-value': 'str' } }
>
> Do we always want to output the stringized value, or would it be wise to
> make this 'any' and output integers where that makes sense?

Good point, it should work with 'any', I'll give it a try.

thanks
diff mbox series

Patch

diff --git a/qapi/qom.json b/qapi/qom.json
index 32db96ffc4..471e4b484b 100644
--- a/qapi/qom.json
+++ b/qapi/qom.json
@@ -26,10 +26,15 @@ 
 #
 # @description: if specified, the description of the property.
 #
+# @default-value: the default value, if any (since 5.0)
+#
 # Since: 1.2
 ##
 { 'struct': 'ObjectPropertyInfo',
-  'data': { 'name': 'str', 'type': 'str', '*description': 'str' } }
+  'data': { 'name': 'str',
+            'type': 'str',
+            '*description': 'str',
+            '*default-value': 'str' } }
 
 ##
 # @qom-list:
diff --git a/qom/qom-qmp-cmds.c b/qom/qom-qmp-cmds.c
index 8785816c1f..68f0a41bca 100644
--- a/qom/qom-qmp-cmds.c
+++ b/qom/qom-qmp-cmds.c
@@ -177,6 +177,10 @@  ObjectPropertyInfoList *qmp_device_list_properties(const char *typename,
         info->type = g_strdup(prop->type);
         info->has_description = !!prop->description;
         info->description = g_strdup(prop->description);
+        if (prop->get_default) {
+            info->default_value = prop->get_default(prop);
+            info->has_default_value = !!info->default_value;
+        }
 
         entry = g_malloc0(sizeof(*entry));
         entry->value = info;