ObjectPropertyInfo member @type is "child<T>" for a child property of QOM type T, and "link<T>" for a link property of QOM type T. Such encoding of information in strings should be avoided in QMP, because it requires clients to parse the strings in addition to parse JSON. Turn ObjectPropertyInfo into a union with discriminator @kind and a variant member @qom-type in branches "child" and "link". This provides the same information unencoded. A later commit will deprecate @type. Signed-off-by: Markus Armbruster <armbru@redhat.com> --- qapi/qom.json | 48 +++++++++++++++++++++++++++++++++++++++------- qom/qom-qmp-cmds.c | 9 +++++++++ 2 files changed, 50 insertions(+), 7 deletions(-) diff --git a/qapi/qom.json b/qapi/qom.json index cc642c7ba97..ca74b652a0d 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -15,11 +15,33 @@ # *********************** ## +## +# @ObjectPropertyKind: +# +# @child: TODO +# +# @link: TODO +# +# @other: TODO +## +{ 'enum': 'ObjectPropertyKind', + 'data': [ 'child', 'link', 'other' ] } + +## +# @ObjectPropertyQomType: +# +# @qom-type: TODO +## +{ 'struct': 'ObjectPropertyQomType', + 'data': { 'qom-type': 'str' } } + ## # @ObjectPropertyInfo: # # @name: the name of the property # +# @kind: TODO +# # @type: the type of the property. This will typically come in one of # four forms: # @@ -48,12 +70,16 @@ # # Since: 1.2 ## -{ 'struct': 'ObjectPropertyInfo', - 'data': { 'name': 'str', +{ 'union': 'ObjectPropertyInfo', + 'base': { 'name': 'str', + 'kind': 'ObjectPropertyKind', 'type': 'str', 'qapi-type': { 'type': 'str', 'features': [ 'unstable' ] }, '*description': 'str', - '*default-value': 'any' } } + '*default-value': 'any' }, + 'discriminator': 'kind', + 'data': { 'child': 'ObjectPropertyQomType', + 'link': 'ObjectPropertyQomType' } } ## # @ObjectPropertyValue: @@ -106,10 +132,18 @@ # # -> { "execute": "qom-list", # "arguments": { "path": "/chardevs" } } -# <- { "return": [ { "name": "type", "type": "string" }, -# { "name": "parallel0", "type": "child<chardev-vc>" }, -# { "name": "serial0", "type": "child<chardev-vc>" }, -# { "name": "mon0", "type": "child<chardev-stdio>" } ] } +# <- {"return": [ +# {"name": "type", "kind": "other", "qapi-type": "str", +# "type": "string"}, +# {"name": "parallel0", "kind": "child", "qapi-type": "str", +# "type": "child<chardev-vc>", +# "qom-type": "chardev-vc"}, +# {"name": "compat_monitor0", "kind": "child", "qapi-type": "str", +# "type": "child<chardev-stdio>", +# "qom-type": "chardev-stdio"}, +# {"name": "serial0", "kind": "child", "qapi-type": "str", +# "type": "child<chardev-vc>", +# "qom-type": "chardev-vc"}]} ## { 'command': 'qom-list', 'data': { 'path': 'str' }, diff --git a/qom/qom-qmp-cmds.c b/qom/qom-qmp-cmds.c index 84a29590514..2b491caaf7a 100644 --- a/qom/qom-qmp-cmds.c +++ b/qom/qom-qmp-cmds.c @@ -34,6 +34,15 @@ static ObjectPropertyInfo *qom_property_info(ObjectProperty *prop) ObjectPropertyInfo *info = g_new0(ObjectPropertyInfo, 1); info->name = g_strdup(prop->name); + if (object_property_is_child(prop)) { + info->kind = OBJECT_PROPERTY_KIND_CHILD; + info->u.child.qom_type = g_strdup(prop->qom_type); + } else if (object_property_is_link(prop)) { + info->kind = OBJECT_PROPERTY_KIND_LINK; + info->u.link.qom_type = g_strdup(prop->qom_type); + } else { + info->kind = OBJECT_PROPERTY_KIND_OTHER; + } info->type = g_strdup(prop->type); info->description = g_strdup(prop->description); info->default_value = qobject_ref(prop->defval); -- 2.55.0