qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Daniel P. Berrange" <berrange@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Markus Armbruster" <armbru@redhat.com>,
	"Max Reitz" <mreitz@redhat.com>,
	"Marc-André Lureau" <marcandre.lureau@gmail.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Andreas Färber" <afaerber@suse.de>,
	"Eric Blake" <eblake@redhat.com>,
	"Daniel P. Berrange" <berrange@redhat.com>
Subject: [Qemu-devel] [PATCH v10 11/11] qmp: add support for mixed typed input visitor
Date: Mon, 15 Aug 2016 15:22:25 +0100	[thread overview]
Message-ID: <1471270945-19975-12-git-send-email-berrange@redhat.com> (raw)
In-Reply-To: <1471270945-19975-1-git-send-email-berrange@redhat.com>

Add a qmp_mixed_input_visitor_new() method which returns
a QMP input visitor that accepts either strings or the
native data types.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
---
 include/qapi/qobject-input-visitor.h | 22 ++++++++
 qapi/qobject-input-visitor.c         | 98 ++++++++++++++++++++++++++++++++++++
 2 files changed, 120 insertions(+)

diff --git a/include/qapi/qobject-input-visitor.h b/include/qapi/qobject-input-visitor.h
index aa911cb..d9fe1d4 100644
--- a/include/qapi/qobject-input-visitor.h
+++ b/include/qapi/qobject-input-visitor.h
@@ -60,4 +60,26 @@ Visitor *qobject_input_visitor_new(QObject *obj, bool strict);
  */
 Visitor *qobject_string_input_visitor_new(QObject *obj);
 
+/**
+ * qobject_mixed_input_visitor_new:
+ * @obj: the input object to visit
+ * @strict: whether to require that all input keys are consumed
+ *
+ * Create a new input visitor that converts a QObject to a QAPI object.
+ *
+ * Any scalar values in the @obj input data structure can either be
+ * represented as the native data type, or as strings. ie if visiting
+ * a boolean, the value can be a QBoolean or a QString whose contents
+ * represent a valid boolean.
+ *
+ * If @strict is set to true, then an error will be reported if any
+ * dict keys are not consumed during visitation.
+ *
+ * The returned input visitor should be released by calling
+ * visit_free() when no longer required.
+ *
+ * Returns: a new input visitor
+ */
+Visitor *qobject_mixed_input_visitor_new(QObject *obj, bool strict);
+
 #endif
diff --git a/qapi/qobject-input-visitor.c b/qapi/qobject-input-visitor.c
index b79c229..d71c195 100644
--- a/qapi/qobject-input-visitor.c
+++ b/qapi/qobject-input-visitor.c
@@ -276,6 +276,19 @@ static void qobject_input_type_int64_str(Visitor *v, const char *name,
     *obj = ret;
 }
 
+static void qobject_input_type_int64_mixed(Visitor *v, const char *name,
+                                           int64_t *obj, Error **errp)
+{
+    QObjectInputVisitor *qiv = to_qiv(v);
+    QObject *qobj = qobject_input_get_object(qiv, name, true);
+
+    if (qobj && qobj->type == QTYPE_QSTRING) {
+        qobject_input_type_int64_str(v, name, obj, errp);
+    } else {
+        qobject_input_type_int64(v, name, obj, errp);
+    }
+}
+
 static void qobject_input_type_uint64(Visitor *v, const char *name,
                                       uint64_t *obj, Error **errp)
 {
@@ -302,6 +315,19 @@ static void qobject_input_type_uint64_str(Visitor *v, const char *name,
     parse_option_number(name, qstr ? qstr->string : NULL, obj, errp);
 }
 
+static void qobject_input_type_uint64_mixed(Visitor *v, const char *name,
+                                            uint64_t *obj, Error **errp)
+{
+    QObjectInputVisitor *qiv = to_qiv(v);
+    QObject *qobj = qobject_input_get_object(qiv, name, true);
+
+    if (qobj && qobj->type == QTYPE_QSTRING) {
+        qobject_input_type_uint64_str(v, name, obj, errp);
+    } else {
+        qobject_input_type_uint64(v, name, obj, errp);
+    }
+}
+
 static void qobject_input_type_bool(Visitor *v, const char *name, bool *obj,
                                     Error **errp)
 {
@@ -327,6 +353,19 @@ static void qobject_input_type_bool_str(Visitor *v, const char *name, bool *obj,
     parse_option_bool(name, qstr ? qstr->string : NULL, obj, errp);
 }
 
+static void qobject_input_type_bool_mixed(Visitor *v, const char *name,
+                                          bool *obj, Error **errp)
+{
+    QObjectInputVisitor *qiv = to_qiv(v);
+    QObject *qobj = qobject_input_get_object(qiv, name, true);
+
+    if (qobj && qobj->type == QTYPE_QSTRING) {
+        qobject_input_type_bool_str(v, name, obj, errp);
+    } else {
+        qobject_input_type_bool(v, name, obj, errp);
+    }
+}
+
 static void qobject_input_type_str(Visitor *v, const char *name, char **obj,
                                    Error **errp)
 {
@@ -388,6 +427,19 @@ static void qobject_input_type_number_str(Visitor *v, const char *name,
                "number");
 }
 
+static void qobject_input_type_number_mixed(Visitor *v, const char *name,
+                                            double *obj, Error **errp)
+{
+    QObjectInputVisitor *qiv = to_qiv(v);
+    QObject *qobj = qobject_input_get_object(qiv, name, true);
+
+    if (qobj && qobj->type == QTYPE_QSTRING) {
+        qobject_input_type_number_str(v, name, obj, errp);
+    } else {
+        qobject_input_type_number(v, name, obj, errp);
+    }
+}
+
 static void qobject_input_type_any(Visitor *v, const char *name, QObject **obj,
                                    Error **errp)
 {
@@ -435,6 +487,20 @@ static void qobject_input_type_size_str(Visitor *v, const char *name,
                "size");
 }
 
+static void qobject_input_type_size_mixed(Visitor *v, const char *name,
+                                          uint64_t *obj, Error **errp)
+{
+    QObjectInputVisitor *qiv = to_qiv(v);
+    QObject *qobj = qobject_input_get_object(qiv, name, true);
+
+    if (qobj && qobj->type == QTYPE_QSTRING) {
+        qobject_input_type_size_str(v, name, obj, errp);
+    } else {
+        qobject_input_type_uint64(v, name, obj, errp);
+    }
+}
+
+
 static void qobject_input_optional(Visitor *v, const char *name, bool *present)
 {
     QObjectInputVisitor *qiv = to_qiv(v);
@@ -524,3 +590,35 @@ Visitor *qobject_string_input_visitor_new(QObject *obj)
 
     return &v->visitor;
 }
+
+Visitor *qobject_mixed_input_visitor_new(QObject *obj, bool strict)
+{
+    QObjectInputVisitor *v;
+
+    v = g_malloc0(sizeof(*v));
+
+    v->visitor.type = VISITOR_INPUT;
+    v->visitor.start_struct = qobject_input_start_struct;
+    v->visitor.check_struct = qobject_input_check_struct;
+    v->visitor.end_struct = qobject_input_pop;
+    v->visitor.start_list = qobject_input_start_list;
+    v->visitor.next_list = qobject_input_next_list;
+    v->visitor.end_list = qobject_input_pop;
+    v->visitor.start_alternate = qobject_input_start_alternate;
+    v->visitor.type_int64 = qobject_input_type_int64_mixed;
+    v->visitor.type_uint64 = qobject_input_type_uint64_mixed;
+    v->visitor.type_bool = qobject_input_type_bool_mixed;
+    v->visitor.type_str = qobject_input_type_str;
+    v->visitor.type_number = qobject_input_type_number_mixed;
+    v->visitor.type_any = qobject_input_type_any;
+    v->visitor.type_null = qobject_input_type_null;
+    v->visitor.type_size = qobject_input_type_size_mixed;
+    v->visitor.optional = qobject_input_optional;
+    v->visitor.free = qobject_input_free;
+    v->strict = strict;
+
+    v->root = obj;
+    qobject_incref(obj);
+
+    return &v->visitor;
+}
-- 
2.7.4

  parent reply	other threads:[~2016-08-15 14:23 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-15 14:22 [Qemu-devel] [PATCH v10 00/11] Provide a QOM-based authorization API Daniel P. Berrange
2016-08-15 14:22 ` [Qemu-devel] [PATCH v10 01/11] qdict: implement a qdict_crumple method for un-flattening a dict Daniel P. Berrange
2016-08-15 14:22 ` [Qemu-devel] [PATCH v10 02/11] option: make parse_option_bool/number non-static Daniel P. Berrange
2016-08-15 14:22 ` [Qemu-devel] [PATCH v10 03/11] qapi: rename QmpInputVisitor to QObjectInputVisitor Daniel P. Berrange
2016-08-15 14:22 ` [Qemu-devel] [PATCH v10 04/11] qapi: rename QmpOutputVisitor to QObjectOutputVisitor Daniel P. Berrange
2016-08-15 14:22 ` [Qemu-devel] [PATCH v10 05/11] qapi: add a QmpInputVisitor that does string conversion Daniel P. Berrange
2016-08-15 14:22 ` [Qemu-devel] [PATCH v10 06/11] qom: support arbitrary non-scalar properties with -object Daniel P. Berrange
2016-08-15 14:22 ` [Qemu-devel] [PATCH v10 07/11] util: add QAuthZ object as an authorization base class Daniel P. Berrange
2016-08-15 14:22 ` [Qemu-devel] [PATCH v10 08/11] util: add QAuthZSimple object type for a simple access control list Daniel P. Berrange
2016-08-15 14:22 ` [Qemu-devel] [PATCH v10 09/11] acl: delete existing ACL implementation Daniel P. Berrange
2016-08-15 14:22 ` [Qemu-devel] [PATCH v10 10/11] util: add QAuthZPAM object type for authorizing using PAM Daniel P. Berrange
2016-08-15 14:22 ` Daniel P. Berrange [this message]
2016-08-15 14:44 ` [Qemu-devel] [PATCH v10 00/11] Provide a QOM-based authorization API no-reply
2016-08-15 14:46 ` no-reply
2016-08-16  1:21   ` Fam Zheng
2016-08-16  8:29     ` Daniel P. Berrange

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1471270945-19975-12-git-send-email-berrange@redhat.com \
    --to=berrange@redhat.com \
    --cc=afaerber@suse.de \
    --cc=armbru@redhat.com \
    --cc=eblake@redhat.com \
    --cc=marcandre.lureau@gmail.com \
    --cc=mreitz@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).