[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 10/12] qapi: AllocVisitor
From: |
Kővágó, Zoltán |
Subject: |
[Qemu-devel] [PATCH 10/12] qapi: AllocVisitor |
Date: |
Fri, 12 Jun 2015 14:33:11 +0200 |
Simple visitor that recursively allocates structures with only optional
variables. Unions are initialized to the first type specified. Other non
optional types are not supported.
Signed-off-by: Kővágó, Zoltán <address@hidden>
---
include/qapi/alloc-visitor.h | 18 +++++++++++++
qapi/Makefile.objs | 1 +
qapi/alloc-visitor.c | 62 ++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 81 insertions(+)
create mode 100644 include/qapi/alloc-visitor.h
create mode 100644 qapi/alloc-visitor.c
diff --git a/include/qapi/alloc-visitor.h b/include/qapi/alloc-visitor.h
new file mode 100644
index 0000000..3d54295
--- /dev/null
+++ b/include/qapi/alloc-visitor.h
@@ -0,0 +1,18 @@
+/*
+ * Alloc Visitor.
+ * Recursively allocates structs, leaving all optional fields unset. In case of
+ * a non-optional field it fails.
+ */
+
+#ifndef ALLOC_VISITOR_H
+#define ALLOC_VISITOR_H
+
+#include "qapi/visitor.h"
+
+typedef struct AllocVisitor AllocVisitor;
+
+AllocVisitor *alloc_visitor_new(void);
+void alloc_visitor_cleanup(AllocVisitor *v);
+Visitor *alloc_visitor_get_visitor(AllocVisitor *v);
+
+#endif
diff --git a/qapi/Makefile.objs b/qapi/Makefile.objs
index 2278970..7bc26a3 100644
--- a/qapi/Makefile.objs
+++ b/qapi/Makefile.objs
@@ -4,3 +4,4 @@ util-obj-y += string-input-visitor.o string-output-visitor.o
util-obj-y += opts-visitor.o
util-obj-y += qmp-event.o
util-obj-y += qapi-util.o
+util-obj-y += alloc-visitor.o
diff --git a/qapi/alloc-visitor.c b/qapi/alloc-visitor.c
new file mode 100644
index 0000000..dbb83af
--- /dev/null
+++ b/qapi/alloc-visitor.c
@@ -0,0 +1,62 @@
+#include "qapi/alloc-visitor.h"
+#include "qemu-common.h"
+#include "qapi/visitor-impl.h"
+
+struct AllocVisitor {
+ Visitor visitor;
+};
+
+static void alloc_start_struct(Visitor *v, void **obj, const char* kind,
+ const char *name, size_t size, Error **errp)
+{
+ if (obj) {
+ *obj = g_malloc0(size);
+ }
+}
+
+static void alloc_end_struct(Visitor *v, Error **errp)
+{
+}
+
+static void alloc_start_implicit_struct(Visitor *v, void **obj, size_t size,
+ Error **errp)
+{
+ if (obj) {
+ *obj = g_malloc0(size);
+ }
+}
+
+static void alloc_end_implicit_struct(Visitor *v, Error **errp)
+{
+}
+
+static void alloc_type_enum(Visitor *v, int *obj, const char *strings[],
+ const char *kind, const char *name, Error **errp)
+{
+ assert(*strings); /* there is at least one valid enum value... */
+ *obj = 0;
+}
+
+AllocVisitor *alloc_visitor_new(void)
+{
+ AllocVisitor *v = g_malloc0(sizeof(AllocVisitor));
+
+ v->visitor.start_struct = alloc_start_struct;
+ v->visitor.end_struct = alloc_end_struct;
+ v->visitor.start_implicit_struct = alloc_start_implicit_struct;
+ v->visitor.end_implicit_struct = alloc_end_implicit_struct;
+
+ v->visitor.type_enum = alloc_type_enum;
+
+ return v;
+}
+
+void alloc_visitor_cleanup(AllocVisitor *v)
+{
+ g_free(v);
+}
+
+Visitor *alloc_visitor_get_visitor(AllocVisitor *v)
+{
+ return &v->visitor;
+}
--
2.4.2
- [Qemu-devel] [PATCH 01/12] audio: remove LOG_TO_MONITOR along with default_mon, (continued)
- [Qemu-devel] [PATCH 01/12] audio: remove LOG_TO_MONITOR along with default_mon, Kővágó, Zoltán, 2015/06/12
- [Qemu-devel] [PATCH 02/12] audio: remove plive, Kővágó, Zoltán, 2015/06/12
- [Qemu-devel] [PATCH 03/12] dsoundaudio: remove *_retries kludges, Kővágó, Zoltán, 2015/06/12
- [Qemu-devel] [PATCH 04/12] dsoundaudio: remove primary buffer, Kővágó, Zoltán, 2015/06/12
- [Qemu-devel] [PATCH 06/12] ossaudio: use trace events instead of debug config flag, Kővágó, Zoltán, 2015/06/12
- [Qemu-devel] [PATCH 05/12] alsaaudio: use trace events instead of verbose, Kővágó, Zoltán, 2015/06/12
- [Qemu-devel] [PATCH 09/12] opts: do not print separator before first item in qemu_opts_print, Kővágó, Zoltán, 2015/06/12
- [Qemu-devel] [PATCH 07/12] qapi: qapi for audio backends, Kővágó, Zoltán, 2015/06/12
- [Qemu-devel] [PATCH 10/12] qapi: AllocVisitor,
Kővágó, Zoltán <=
- [Qemu-devel] [PATCH 08/12] qapi: support nested structs in OptsVisitor, Kővágó, Zoltán, 2015/06/12
- [Qemu-devel] [PATCH 11/12] audio: use qapi AudioFormat instead of audfmt_e, Kővágó, Zoltán, 2015/06/12
- [Qemu-devel] [PATCH 12/12] audio: -audiodev command line option, Kővágó, Zoltán, 2015/06/12
- Re: [Qemu-devel] [PATCH 00/12] -audiodev option, Gerd Hoffmann, 2015/06/15