218e99
From a2a326f0a6b544335c49432248201fb811f1fc2b Mon Sep 17 00:00:00 2001
218e99
From: Kevin Wolf <kwolf@redhat.com>
218e99
Date: Mon, 9 Sep 2013 14:28:11 +0200
218e99
Subject: [PATCH 20/38] qapi: Add visitor for implicit structs
218e99
218e99
RH-Author: Kevin Wolf <kwolf@redhat.com>
218e99
Message-id: <1378736903-18489-21-git-send-email-kwolf@redhat.com>
218e99
Patchwork-id: 54207
218e99
O-Subject: [RHEL-7.0 qemu-kvm PATCH 20/32] qapi: Add visitor for implicit structs
218e99
Bugzilla: 1005818
218e99
RH-Acked-by: Fam Zheng <famz@redhat.com>
218e99
RH-Acked-by: Max Reitz <mreitz@redhat.com>
218e99
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
218e99
218e99
Bugzilla: 1005818
218e99
218e99
These can be used when an embedded struct is parsed and members not
218e99
belonging to the struct may be present in the input (e.g. parsing a
218e99
flat namespace QMP union, where fields from both the base and one
218e99
of the alternative types are mixed in the JSON object)
218e99
218e99
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
218e99
Reviewed-by: Eric Blake <eblake@redhat.com>
218e99
(cherry picked from commit 761d524dbcc5bb41213dd0f238f43c273bc2b077)
218e99
218e99
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
218e99
---
218e99
 include/qapi/visitor-impl.h |  4 ++++
218e99
 include/qapi/visitor.h      |  3 +++
218e99
 qapi/qapi-visit-core.c      | 16 ++++++++++++++++
218e99
 qapi/qmp-input-visitor.c    | 14 ++++++++++++++
218e99
 4 files changed, 37 insertions(+)
218e99
218e99
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
218e99
---
218e99
 include/qapi/visitor-impl.h |    4 ++++
218e99
 include/qapi/visitor.h      |    3 +++
218e99
 qapi/qapi-visit-core.c      |   16 ++++++++++++++++
218e99
 qapi/qmp-input-visitor.c    |   14 ++++++++++++++
218e99
 4 files changed, 37 insertions(+), 0 deletions(-)
218e99
218e99
diff --git a/include/qapi/visitor-impl.h b/include/qapi/visitor-impl.h
218e99
index 5159964..5c1297f 100644
218e99
--- a/include/qapi/visitor-impl.h
218e99
+++ b/include/qapi/visitor-impl.h
218e99
@@ -22,6 +22,10 @@ struct Visitor
218e99
                          const char *name, size_t size, Error **errp);
218e99
     void (*end_struct)(Visitor *v, Error **errp);
218e99
 
218e99
+    void (*start_implicit_struct)(Visitor *v, void **obj, size_t size,
218e99
+                                  Error **errp);
218e99
+    void (*end_implicit_struct)(Visitor *v, Error **errp);
218e99
+
218e99
     void (*start_list)(Visitor *v, const char *name, Error **errp);
218e99
     GenericList *(*next_list)(Visitor *v, GenericList **list, Error **errp);
218e99
     void (*end_list)(Visitor *v, Error **errp);
218e99
diff --git a/include/qapi/visitor.h b/include/qapi/visitor.h
218e99
index 1fef18c..a1cdd81 100644
218e99
--- a/include/qapi/visitor.h
218e99
+++ b/include/qapi/visitor.h
218e99
@@ -30,6 +30,9 @@ void visit_end_handle(Visitor *v, Error **errp);
218e99
 void visit_start_struct(Visitor *v, void **obj, const char *kind,
218e99
                         const char *name, size_t size, Error **errp);
218e99
 void visit_end_struct(Visitor *v, Error **errp);
218e99
+void visit_start_implicit_struct(Visitor *v, void **obj, size_t size,
218e99
+                                 Error **errp);
218e99
+void visit_end_implicit_struct(Visitor *v, Error **errp);
218e99
 void visit_start_list(Visitor *v, const char *name, Error **errp);
218e99
 GenericList *visit_next_list(Visitor *v, GenericList **list, Error **errp);
218e99
 void visit_end_list(Visitor *v, Error **errp);
218e99
diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c
218e99
index 401ee6e..9b4d51b 100644
218e99
--- a/qapi/qapi-visit-core.c
218e99
+++ b/qapi/qapi-visit-core.c
218e99
@@ -45,6 +45,22 @@ void visit_end_struct(Visitor *v, Error **errp)
218e99
     v->end_struct(v, errp);
218e99
 }
218e99
 
218e99
+void visit_start_implicit_struct(Visitor *v, void **obj, size_t size,
218e99
+                                 Error **errp)
218e99
+{
218e99
+    if (!error_is_set(errp) && v->start_implicit_struct) {
218e99
+        v->start_implicit_struct(v, obj, size, errp);
218e99
+    }
218e99
+}
218e99
+
218e99
+void visit_end_implicit_struct(Visitor *v, Error **errp)
218e99
+{
218e99
+    assert(!error_is_set(errp));
218e99
+    if (v->end_implicit_struct) {
218e99
+        v->end_implicit_struct(v, errp);
218e99
+    }
218e99
+}
218e99
+
218e99
 void visit_start_list(Visitor *v, const char *name, Error **errp)
218e99
 {
218e99
     if (!error_is_set(errp)) {
218e99
diff --git a/qapi/qmp-input-visitor.c b/qapi/qmp-input-visitor.c
218e99
index 67fb127..59c5cac 100644
218e99
--- a/qapi/qmp-input-visitor.c
218e99
+++ b/qapi/qmp-input-visitor.c
218e99
@@ -144,6 +144,18 @@ static void qmp_input_end_struct(Visitor *v, Error **errp)
218e99
     qmp_input_pop(qiv, errp);
218e99
 }
218e99
 
218e99
+static void qmp_input_start_implicit_struct(Visitor *v, void **obj,
218e99
+                                            size_t size, Error **errp)
218e99
+{
218e99
+    if (obj) {
218e99
+        *obj = g_malloc0(size);
218e99
+    }
218e99
+}
218e99
+
218e99
+static void qmp_input_end_implicit_struct(Visitor *v, Error **errp)
218e99
+{
218e99
+}
218e99
+
218e99
 static void qmp_input_start_list(Visitor *v, const char *name, Error **errp)
218e99
 {
218e99
     QmpInputVisitor *qiv = to_qiv(v);
218e99
@@ -293,6 +305,8 @@ QmpInputVisitor *qmp_input_visitor_new(QObject *obj)
218e99
 
218e99
     v->visitor.start_struct = qmp_input_start_struct;
218e99
     v->visitor.end_struct = qmp_input_end_struct;
218e99
+    v->visitor.start_implicit_struct = qmp_input_start_implicit_struct;
218e99
+    v->visitor.end_implicit_struct = qmp_input_end_implicit_struct;
218e99
     v->visitor.start_list = qmp_input_start_list;
218e99
     v->visitor.next_list = qmp_input_next_list;
218e99
     v->visitor.end_list = qmp_input_end_list;
218e99
-- 
218e99
1.7.1
218e99