提交 c3944f8f 编写于 作者: P Peter Krempa

qemu: qapi: Use declarative approach for meta-type parsers in virQEMUQAPISchemaTraverse

Introduce an array of callbacks for given 'meta-type' of the QAPI schema
structure rather than using code to select it. This will simplify
extension for the other meta-types which are not handled yet.
Signed-off-by: NPeter Krempa <pkrempa@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 0b49f891
......@@ -164,12 +164,30 @@ virQEMUQAPISchemaTraverseCommand(virJSONValuePtr cur,
}
typedef int (*virQEMUQAPISchemaTraverseFunc)(virJSONValuePtr cur,
struct virQEMUQAPISchemaTraverseContext *ctxt);
struct virQEMUQAPISchemaTraverseMetaType {
const char *metatype;
virQEMUQAPISchemaTraverseFunc func;
};
static const struct virQEMUQAPISchemaTraverseMetaType traverseMetaType[] = {
{ "object", virQEMUQAPISchemaTraverseObject },
{ "array", virQEMUQAPISchemaTraverseArray },
{ "command", virQEMUQAPISchemaTraverseCommand },
{ "event", virQEMUQAPISchemaTraverseCommand },
};
static int
virQEMUQAPISchemaTraverse(const char *baseName,
struct virQEMUQAPISchemaTraverseContext *ctxt)
{
virJSONValuePtr cur;
const char *metatype;
size_t i;
if (!(cur = virHashLookup(ctxt->schema, baseName)))
return 0;
......@@ -182,16 +200,9 @@ virQEMUQAPISchemaTraverse(const char *baseName,
if (!(metatype = virJSONValueObjectGetString(cur, "meta-type")))
return 0;
if (STREQ(metatype, "array")) {
return virQEMUQAPISchemaTraverseArray(cur, ctxt);
} else if (STREQ(metatype, "object")) {
return virQEMUQAPISchemaTraverseObject(cur, ctxt);
} else if (STREQ(metatype, "command") ||
STREQ(metatype, "event")) {
return virQEMUQAPISchemaTraverseCommand(cur, ctxt);
} else {
/* alternates, basic types and enums can't be entered */
return 0;
for (i = 0; i < ARRAY_CARDINALITY(traverseMetaType); i++) {
if (STREQ(metatype, traverseMetaType[i].metatype))
return traverseMetaType[i].func(cur, ctxt);
}
return 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册