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