From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48435) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bpz4v-0003db-CJ for qemu-devel@nongnu.org; Fri, 30 Sep 2016 10:46:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bpz4u-0002y8-2I for qemu-devel@nongnu.org; Fri, 30 Sep 2016 10:46:21 -0400 From: "Daniel P. Berrange" Date: Fri, 30 Sep 2016 15:45:31 +0100 Message-Id: <1475246744-29302-9-git-send-email-berrange@redhat.com> In-Reply-To: <1475246744-29302-1-git-send-email-berrange@redhat.com> References: <1475246744-29302-1-git-send-email-berrange@redhat.com> Subject: [Qemu-devel] [PATCH v14 08/21] qapi: allow QObjectInputVisitor to be created with QemuOpts List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Markus Armbruster , Max Reitz , Paolo Bonzini , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Eric Blake , "Daniel P. Berrange" 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. NB, at this point it is only supporting opts syntax which explicitly matches the QAPI schema structure, so is not yet a true drop-in replacement for OptsVisitor. The patches that follow will add the special cases requird for full backwards compatibility with OptsVisitor. Signed-off-by: Daniel P. Berrange --- include/qapi/qobject-input-visitor.h | 15 +++++++++++++++ include/qemu/option.h | 2 +- qapi/qobject-input-visitor.c | 25 +++++++++++++++++++++++++ util/qemu-option.c | 2 +- 4 files changed, 42 insertions(+), 2 deletions(-) diff --git a/include/qapi/qobject-input-visitor.h b/include/qapi/qobject-input-visitor.h index 5022297..f134d90 100644 --- a/include/qapi/qobject-input-visitor.h +++ b/include/qapi/qobject-input-visitor.h @@ -51,4 +51,19 @@ Visitor *qobject_input_visitor_new(QObject *obj, bool strict); */ Visitor *qobject_input_visitor_new_autocast(QObject *obj); + +/** + * 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, Error **errp); + #endif diff --git a/include/qemu/option.h b/include/qemu/option.h index 2a5266f..29f3f18 100644 --- a/include/qemu/option.h +++ b/include/qemu/option.h @@ -125,7 +125,7 @@ void qemu_opts_set_defaults(QemuOptsList *list, const char *params, int permit_abbrev); QemuOpts *qemu_opts_from_qdict(QemuOptsList *list, const QDict *qdict, Error **errp); -QDict *qemu_opts_to_qdict(QemuOpts *opts, QDict *qdict); +QDict *qemu_opts_to_qdict(const QemuOpts *opts, QDict *qdict); void qemu_opts_absorb_qdict(QemuOpts *opts, QDict *qdict, Error **errp); typedef int (*qemu_opts_loopfunc)(void *opaque, QemuOpts *opts, Error **errp); diff --git a/qapi/qobject-input-visitor.c b/qapi/qobject-input-visitor.c index cf41df6..d9269c9 100644 --- a/qapi/qobject-input-visitor.c +++ b/qapi/qobject-input-visitor.c @@ -545,3 +545,28 @@ Visitor *qobject_input_visitor_new_autocast(QObject *obj) return &v->visitor; } + + +Visitor *qobject_input_visitor_new_opts(const QemuOpts *opts, + Error **errp) +{ + QDict *pdict; + QObject *pobj = NULL; + Visitor *v = NULL; + + pdict = qemu_opts_to_qdict(opts, NULL); + if (!pdict) { + goto cleanup; + } + + pobj = qdict_crumple(pdict, true, errp); + if (!pobj) { + goto cleanup; + } + + v = qobject_input_visitor_new_autocast(pobj); + cleanup: + qobject_decref(pobj); + QDECREF(pdict); + return v; +} diff --git a/util/qemu-option.c b/util/qemu-option.c index 41b356c..418cbb6 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) { QemuOpt *opt; QObject *val; -- 2.7.4