qapi: Support downstream events and commands
Enhance the testsuite to cover downstream events and commands. Events worked without more tweaks, but commands needed a few final updates in the generator to mangle names in the appropriate places. In making those tweaks, it was easier to drop type_visitor() and inline its actions instead. Signed-off-by: Eric Blake <eblake@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
This commit is contained in:
parent
d1f07c86c0
commit
e3c4c3d796
@ -20,12 +20,6 @@ import os
|
|||||||
import getopt
|
import getopt
|
||||||
import errno
|
import errno
|
||||||
|
|
||||||
def type_visitor(name):
|
|
||||||
if type(name) == list:
|
|
||||||
return 'visit_type_%sList' % name[0]
|
|
||||||
else:
|
|
||||||
return 'visit_type_%s' % name
|
|
||||||
|
|
||||||
def generate_command_decl(name, args, ret_type):
|
def generate_command_decl(name, args, ret_type):
|
||||||
arglist=""
|
arglist=""
|
||||||
for argname, argtype, optional in parse_args(args):
|
for argname, argtype, optional in parse_args(args):
|
||||||
@ -153,10 +147,10 @@ if (has_%(c_name)s) {
|
|||||||
c_name=c_name(argname))
|
c_name=c_name(argname))
|
||||||
push_indent()
|
push_indent()
|
||||||
ret += mcgen('''
|
ret += mcgen('''
|
||||||
%(visitor)s(v, &%(c_name)s, "%(name)s", %(errp)s);
|
visit_type_%(visitor)s(v, &%(c_name)s, "%(name)s", %(errp)s);
|
||||||
''',
|
''',
|
||||||
c_name=c_name(argname), name=argname, argtype=argtype,
|
c_name=c_name(argname), name=argname, argtype=argtype,
|
||||||
visitor=type_visitor(argtype), errp=errparg)
|
visitor=type_name(argtype), errp=errparg)
|
||||||
ret += gen_err_check(errarg)
|
ret += gen_err_check(errarg)
|
||||||
if optional:
|
if optional:
|
||||||
pop_indent()
|
pop_indent()
|
||||||
@ -184,7 +178,7 @@ static void qmp_marshal_output_%(c_name)s(%(c_ret_type)s ret_in, QObject **ret_o
|
|||||||
Visitor *v;
|
Visitor *v;
|
||||||
|
|
||||||
v = qmp_output_get_visitor(mo);
|
v = qmp_output_get_visitor(mo);
|
||||||
%(visitor)s(v, &ret_in, "unused", &local_err);
|
visit_type_%(visitor)s(v, &ret_in, "unused", &local_err);
|
||||||
if (local_err) {
|
if (local_err) {
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
@ -195,12 +189,12 @@ out:
|
|||||||
qmp_output_visitor_cleanup(mo);
|
qmp_output_visitor_cleanup(mo);
|
||||||
md = qapi_dealloc_visitor_new();
|
md = qapi_dealloc_visitor_new();
|
||||||
v = qapi_dealloc_get_visitor(md);
|
v = qapi_dealloc_get_visitor(md);
|
||||||
%(visitor)s(v, &ret_in, "unused", NULL);
|
visit_type_%(visitor)s(v, &ret_in, "unused", NULL);
|
||||||
qapi_dealloc_visitor_cleanup(md);
|
qapi_dealloc_visitor_cleanup(md);
|
||||||
}
|
}
|
||||||
''',
|
''',
|
||||||
c_ret_type=c_type(ret_type), c_name=c_name(name),
|
c_ret_type=c_type(ret_type), c_name=c_name(name),
|
||||||
visitor=type_visitor(ret_type))
|
visitor=type_name(ret_type))
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
@ -122,3 +122,8 @@
|
|||||||
'data': { '__org.qemu_x-value': '__org.qemu_x-Struct2' } }
|
'data': { '__org.qemu_x-value': '__org.qemu_x-Struct2' } }
|
||||||
{ 'alternate': '__org.qemu_x-Alt',
|
{ 'alternate': '__org.qemu_x-Alt',
|
||||||
'data': { '__org.qemu_x-branch': 'str', 'b': '__org.qemu_x-Base' } }
|
'data': { '__org.qemu_x-branch': 'str', 'b': '__org.qemu_x-Base' } }
|
||||||
|
{ 'event': '__ORG.QEMU_X-EVENT', 'data': '__org.qemu_x-Struct' }
|
||||||
|
{ 'command': '__org.qemu_x-command',
|
||||||
|
'data': { 'a': ['__org.qemu_x-Enum'], 'b': ['__org.qemu_x-Struct'],
|
||||||
|
'c': '__org.qemu_x-Union2', 'd': '__org.qemu_x-Alt' },
|
||||||
|
'returns': '__org.qemu_x-Union1' }
|
||||||
|
@ -29,7 +29,9 @@
|
|||||||
OrderedDict([('union', '__org.qemu_x-Union1'), ('data', OrderedDict([('__org.qemu_x-branch', 'str')]))]),
|
OrderedDict([('union', '__org.qemu_x-Union1'), ('data', OrderedDict([('__org.qemu_x-branch', 'str')]))]),
|
||||||
OrderedDict([('struct', '__org.qemu_x-Struct2'), ('data', OrderedDict([('array', ['__org.qemu_x-Union1'])]))]),
|
OrderedDict([('struct', '__org.qemu_x-Struct2'), ('data', OrderedDict([('array', ['__org.qemu_x-Union1'])]))]),
|
||||||
OrderedDict([('union', '__org.qemu_x-Union2'), ('base', '__org.qemu_x-Base'), ('discriminator', '__org.qemu_x-member1'), ('data', OrderedDict([('__org.qemu_x-value', '__org.qemu_x-Struct2')]))]),
|
OrderedDict([('union', '__org.qemu_x-Union2'), ('base', '__org.qemu_x-Base'), ('discriminator', '__org.qemu_x-member1'), ('data', OrderedDict([('__org.qemu_x-value', '__org.qemu_x-Struct2')]))]),
|
||||||
OrderedDict([('alternate', '__org.qemu_x-Alt'), ('data', OrderedDict([('__org.qemu_x-branch', 'str'), ('b', '__org.qemu_x-Base')]))])]
|
OrderedDict([('alternate', '__org.qemu_x-Alt'), ('data', OrderedDict([('__org.qemu_x-branch', 'str'), ('b', '__org.qemu_x-Base')]))]),
|
||||||
|
OrderedDict([('event', '__ORG.QEMU_X-EVENT'), ('data', '__org.qemu_x-Struct')]),
|
||||||
|
OrderedDict([('command', '__org.qemu_x-command'), ('data', OrderedDict([('a', ['__org.qemu_x-Enum']), ('b', ['__org.qemu_x-Struct']), ('c', '__org.qemu_x-Union2'), ('d', '__org.qemu_x-Alt')])), ('returns', '__org.qemu_x-Union1')])]
|
||||||
[{'enum_name': 'EnumOne', 'enum_values': ['value1', 'value2', 'value3']},
|
[{'enum_name': 'EnumOne', 'enum_values': ['value1', 'value2', 'value3']},
|
||||||
{'enum_name': '__org.qemu_x-Enum', 'enum_values': ['__org.qemu_x-value']},
|
{'enum_name': '__org.qemu_x-Enum', 'enum_values': ['__org.qemu_x-value']},
|
||||||
{'enum_name': 'UserDefAlternateKind', 'enum_values': None},
|
{'enum_name': 'UserDefAlternateKind', 'enum_values': None},
|
||||||
|
@ -51,6 +51,21 @@ int64_t qmp_user_def_cmd3(int64_t a, bool has_b, int64_t b, Error **errp)
|
|||||||
return a + (has_b ? b : 0);
|
return a + (has_b ? b : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__org_qemu_x_Union1 *qmp___org_qemu_x_command(__org_qemu_x_EnumList *a,
|
||||||
|
__org_qemu_x_StructList *b,
|
||||||
|
__org_qemu_x_Union2 *c,
|
||||||
|
__org_qemu_x_Alt *d,
|
||||||
|
Error **errp)
|
||||||
|
{
|
||||||
|
__org_qemu_x_Union1 *ret = g_new0(__org_qemu_x_Union1, 1);
|
||||||
|
|
||||||
|
ret->kind = ORG_QEMU_X_UNION1_KIND___ORG_QEMU_X_BRANCH;
|
||||||
|
ret->__org_qemu_x_branch = strdup("blah1");
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* test commands with no input and no return value */
|
/* test commands with no input and no return value */
|
||||||
static void test_dispatch_cmd(void)
|
static void test_dispatch_cmd(void)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user