Instead of requiring all callers to go through the mutli-step process of turning QemuOpts into a suitable QObject for visiting, add a new constructor that encapsulates this logic. This will allow QObjectInputVisitor to be a drop-in replacement for the existing OptsVisitor with minimal code changes for callers.
Signed-off-by: Daniel P. Berrange <berra...@redhat.com> --- include/qapi/qobject-input-visitor.h | 19 +++++++++++++++++++ include/qemu/option.h | 2 +- qapi/qobject-input-visitor.c | 29 +++++++++++++++++++++++++++++ util/qemu-option.c | 2 +- 4 files changed, 50 insertions(+), 2 deletions(-) diff --git a/include/qapi/qobject-input-visitor.h b/include/qapi/qobject-input-visitor.h index 63f3782..242b767 100644 --- a/include/qapi/qobject-input-visitor.h +++ b/include/qapi/qobject-input-visitor.h @@ -102,4 +102,23 @@ Visitor *qobject_input_visitor_new_autocast(QObject *obj, size_t autocreate_struct_levels, bool permit_int_ranges); + +/** + * Create a new input visitor that converts @opts to a QAPI object. + * + * The QemuOpts will be converted into a QObject using the + * qdict_crumple() method to automatically create structs + * and lists. The resulting QDict will then be passed to the + * qobject_input_visitor_new_autocast() method. See the docs + * of that method for further details on processing behaviour. + * + * The returned input visitor should be released by calling + * visit_free() when no longer required. + */ +Visitor *qobject_input_visitor_new_opts(const QemuOpts *opts, + bool autocreate_list, + size_t autocreate_struct_levels, + bool permit_int_ranges, + Error **errp); + #endif diff --git a/include/qemu/option.h b/include/qemu/option.h index 328c468..bf1f078 100644 --- a/include/qemu/option.h +++ b/include/qemu/option.h @@ -130,7 +130,7 @@ typedef enum { QEMU_OPTS_REPEAT_POLICY_LIST, } QemuOptsRepeatPolicy; -QDict *qemu_opts_to_qdict(QemuOpts *opts, QDict *qdict, +QDict *qemu_opts_to_qdict(const QemuOpts *opts, QDict *qdict, QemuOptsRepeatPolicy repeatPolicy); void qemu_opts_absorb_qdict(QemuOpts *opts, QDict *qdict, Error **errp); diff --git a/qapi/qobject-input-visitor.c b/qapi/qobject-input-visitor.c index a38e779..0aef20e 100644 --- a/qapi/qobject-input-visitor.c +++ b/qapi/qobject-input-visitor.c @@ -747,3 +747,32 @@ Visitor *qobject_input_visitor_new_autocast(QObject *obj, return &v->visitor; } + + +Visitor *qobject_input_visitor_new_opts(const QemuOpts *opts, + bool autocreate_list, + size_t autocreate_struct_levels, + bool permit_int_ranges, + Error **errp) +{ + QDict *pdict; + QObject *pobj; + Visitor *v = NULL; + + pdict = qemu_opts_to_qdict(opts, NULL, + QEMU_OPTS_REPEAT_POLICY_LIST); + + pobj = qdict_crumple(pdict, true, errp); + if (!pobj) { + goto cleanup; + } + + v = qobject_input_visitor_new_autocast(pobj, + autocreate_list, + autocreate_struct_levels, + permit_int_ranges); + cleanup: + qobject_decref(pobj); + QDECREF(pdict); + return v; +} diff --git a/util/qemu-option.c b/util/qemu-option.c index ad28d4e..db0fef2 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -1058,7 +1058,7 @@ void qemu_opts_absorb_qdict(QemuOpts *opts, QDict *qdict, Error **errp) * TODO We'll want to use types appropriate for opt->desc->type, but * this is enough for now. */ -QDict *qemu_opts_to_qdict(QemuOpts *opts, QDict *qdict, +QDict *qemu_opts_to_qdict(const QemuOpts *opts, QDict *qdict, QemuOptsRepeatPolicy repeatPolicy) { QemuOpt *opt; -- 2.7.4