mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-21 20:15:17 +00:00
qemu: qapi: Implement worker for introspecting builtin types
Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
8bfb615b4b
commit
b82f2d837a
@ -121,7 +121,7 @@ virQEMUQAPISchemaTraverseObject(virJSONValuePtr cur,
|
|||||||
query++;
|
query++;
|
||||||
|
|
||||||
/* exit on modifers for other types */
|
/* exit on modifers for other types */
|
||||||
if (modifier == '^')
|
if (modifier == '^' || modifier == '!')
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (modifier == '+') {
|
if (modifier == '+') {
|
||||||
@ -203,6 +203,31 @@ virQEMUQAPISchemaTraverseEnum(virJSONValuePtr cur,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
virQEMUQAPISchemaTraverseBuiltin(virJSONValuePtr cur,
|
||||||
|
struct virQEMUQAPISchemaTraverseContext *ctxt)
|
||||||
|
{
|
||||||
|
const char *query = virQEMUQAPISchemaTraverseContextNextQuery(ctxt);
|
||||||
|
const char *jsontype;
|
||||||
|
|
||||||
|
if (query[0] != '!')
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (virQEMUQAPISchemaTraverseContextHasNextQuery(ctxt))
|
||||||
|
return -3;
|
||||||
|
|
||||||
|
query++;
|
||||||
|
|
||||||
|
if (!(jsontype = virJSONValueObjectGetString(cur, "json-type")))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (STREQ(jsontype, query))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* The function must return 1 on successful query, 0 if the query was not found
|
/* The function must return 1 on successful query, 0 if the query was not found
|
||||||
* -1 when a libvirt error is reported, -2 if the schema is invalid and -3 if
|
* -1 when a libvirt error is reported, -2 if the schema is invalid and -3 if
|
||||||
* the query component is malformed. */
|
* the query component is malformed. */
|
||||||
@ -221,6 +246,7 @@ static const struct virQEMUQAPISchemaTraverseMetaType traverseMetaType[] = {
|
|||||||
{ "command", virQEMUQAPISchemaTraverseCommand },
|
{ "command", virQEMUQAPISchemaTraverseCommand },
|
||||||
{ "event", virQEMUQAPISchemaTraverseCommand },
|
{ "event", virQEMUQAPISchemaTraverseCommand },
|
||||||
{ "enum", virQEMUQAPISchemaTraverseEnum },
|
{ "enum", virQEMUQAPISchemaTraverseEnum },
|
||||||
|
{ "builtin", virQEMUQAPISchemaTraverseBuiltin },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -280,6 +306,9 @@ virQEMUQAPISchemaTraverse(const char *baseName,
|
|||||||
*
|
*
|
||||||
* - Boolean queries - @entry remains NULL, return value indicates success:
|
* - Boolean queries - @entry remains NULL, return value indicates success:
|
||||||
* '^enumval': returns true if the previously selected enum contains 'enumval'
|
* '^enumval': returns true if the previously selected enum contains 'enumval'
|
||||||
|
* '!basictype': returns true if previously selected type is of 'basictype'
|
||||||
|
* JSON type. Spported are 'null', 'string', 'number', 'value',
|
||||||
|
* 'int' and 'boolean.
|
||||||
*
|
*
|
||||||
* If the name of any (sub)attribute starts with non-alphabetical symbols it
|
* If the name of any (sub)attribute starts with non-alphabetical symbols it
|
||||||
* needs to be prefixed by a single space.
|
* needs to be prefixed by a single space.
|
||||||
|
@ -3092,12 +3092,14 @@ mymain(void)
|
|||||||
DO_TEST_QAPI_QUERY("variant", "blockdev-add/arg-type/+file", 1, true);
|
DO_TEST_QAPI_QUERY("variant", "blockdev-add/arg-type/+file", 1, true);
|
||||||
DO_TEST_QAPI_QUERY("variant property", "blockdev-add/arg-type/+file/filename", 1, true);
|
DO_TEST_QAPI_QUERY("variant property", "blockdev-add/arg-type/+file/filename", 1, true);
|
||||||
DO_TEST_QAPI_QUERY("enum value", "query-status/ret-type/status/^debug", 1, false);
|
DO_TEST_QAPI_QUERY("enum value", "query-status/ret-type/status/^debug", 1, false);
|
||||||
|
DO_TEST_QAPI_QUERY("builtin type", "query-qmp-schema/ret-type/name/!string", 1, false);
|
||||||
|
|
||||||
DO_TEST_QAPI_QUERY("nonexistent command", "nonexistent", 0, false);
|
DO_TEST_QAPI_QUERY("nonexistent command", "nonexistent", 0, false);
|
||||||
DO_TEST_QAPI_QUERY("nonexistent attr", "screendump/arg-type/nonexistent", 0, false);
|
DO_TEST_QAPI_QUERY("nonexistent attr", "screendump/arg-type/nonexistent", 0, false);
|
||||||
DO_TEST_QAPI_QUERY("nonexistent variant", "blockdev-add/arg-type/+nonexistent", 0, false);
|
DO_TEST_QAPI_QUERY("nonexistent variant", "blockdev-add/arg-type/+nonexistent", 0, false);
|
||||||
DO_TEST_QAPI_QUERY("nonexistent enum value", "query-status/ret-type/status/^nonexistentdebug", 0, false);
|
DO_TEST_QAPI_QUERY("nonexistent enum value", "query-status/ret-type/status/^nonexistentdebug", 0, false);
|
||||||
DO_TEST_QAPI_QUERY("broken query for enum value", "query-status/ret-type/status/^debug/test", -1, false);
|
DO_TEST_QAPI_QUERY("broken query for enum value", "query-status/ret-type/status/^debug/test", -1, false);
|
||||||
|
DO_TEST_QAPI_QUERY("builtin type", "query-qmp-schema/ret-type/name/!number", 0, false);
|
||||||
|
|
||||||
#undef DO_TEST_QAPI_QUERY
|
#undef DO_TEST_QAPI_QUERY
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user