[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 03/17] qapi: add visitor interfaces for arrays
From: |
Michael Roth |
Subject: |
[Qemu-devel] [PATCH 03/17] qapi: add visitor interfaces for arrays |
Date: |
Mon, 4 Jun 2012 20:00:04 -0500 |
Signed-off-by: Michael Roth <address@hidden>
---
qapi/qapi-visit-core.c | 25 +++++++++++++++++++++++++
qapi/qapi-visit-core.h | 8 ++++++++
scripts/qapi-visit.py | 26 ++++++++++++++++++++++++++
3 files changed, 59 insertions(+), 0 deletions(-)
diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c
index 9a29674..482bab6 100644
--- a/qapi/qapi-visit-core.c
+++ b/qapi/qapi-visit-core.c
@@ -306,3 +306,28 @@ void input_type_enum(Visitor *v, int *obj, const char
*strings[],
g_free(enum_str);
*obj = value;
}
+
+void visit_start_array(Visitor *v, void **obj, const char *name,
+ size_t elem_count, size_t elem_size, Error **errp)
+{
+ g_assert(v->start_array);
+ if (!error_is_set(errp)) {
+ v->start_array(v, obj, name, elem_count, elem_size, errp);
+ }
+}
+
+void visit_next_array(Visitor *v, Error **errp)
+{
+ g_assert(v->next_array);
+ if (!error_is_set(errp)) {
+ v->next_array(v, errp);
+ }
+}
+
+void visit_end_array(Visitor *v, Error **errp)
+{
+ g_assert(v->end_array);
+ if (!error_is_set(errp)) {
+ v->end_array(v, errp);
+ }
+}
diff --git a/qapi/qapi-visit-core.h b/qapi/qapi-visit-core.h
index a19d70c..19de382 100644
--- a/qapi/qapi-visit-core.h
+++ b/qapi/qapi-visit-core.h
@@ -43,6 +43,10 @@ struct Visitor
void (*type_str)(Visitor *v, char **obj, const char *name, Error **errp);
void (*type_number)(Visitor *v, double *obj, const char *name,
Error **errp);
+ void (*start_array)(Visitor *v, void **obj, const char *name,
+ size_t elem_count, size_t elem_size, Error **errp);
+ void (*next_array)(Visitor *v, Error **errp);
+ void (*end_array)(Visitor *v, Error **errp);
/* May be NULL */
void (*start_optional)(Visitor *v, bool *present, const char *name,
@@ -88,5 +92,9 @@ void visit_type_int64(Visitor *v, int64_t *obj, const char
*name, Error **errp);
void visit_type_bool(Visitor *v, bool *obj, const char *name, Error **errp);
void visit_type_str(Visitor *v, char **obj, const char *name, Error **errp);
void visit_type_number(Visitor *v, double *obj, const char *name, Error
**errp);
+void visit_start_array(Visitor *v, void **obj, const char *name,
+ size_t elem_count, size_t elem_size, Error **errp);
+void visit_next_array(Visitor *v, Error **errp);
+void visit_end_array(Visitor *v, Error **errp);
#endif
diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
index 8d4e94a..3a03537 100644
--- a/scripts/qapi-visit.py
+++ b/scripts/qapi-visit.py
@@ -17,6 +17,32 @@ import os
import getopt
import errno
+def generate_visit_array_body(name, info):
+ if info.has_key('array_capacity'):
+ array_capacity = info['array_capacity']
+ else:
+ array_capacity = info['array_size']
+
+ if info['array_size'].isdigit():
+ array_size = info['array_size']
+ else:
+ array_size = "(*obj)->%s" % info['array_size']
+
+ ret = mcgen('''
+visit_start_array(m, (void **)obj, "%(name)s", %(array_capacity)s,
sizeof(%(type)s), errp);
+int %(name)s_i;
+for (%(name)s_i = 0; %(name)s_i < %(array_size)s; %(name)s_i++) {
+ visit_type_%(type_short)s(m, &(*obj)->%(name)s[%(name)s_i], NULL, errp);
+ visit_next_array(m, errp);
+}
+visit_end_array(m, errp);
+''',
+ name=name, type=c_type(info['type'][0]),
+ type_short=info['type'][0],
+ array_size=array_size,
+ array_capacity=array_capacity)
+ return ret
+
def generate_visit_struct_body(field_prefix, members):
ret = ""
if len(field_prefix):
--
1.7.4.1
[Qemu-devel] [PATCH 04/17] qapi: QmpOutputVisitor, implement array handling, Michael Roth, 2012/06/04
[Qemu-devel] [PATCH 03/17] qapi: add visitor interfaces for arrays,
Michael Roth <=
[Qemu-devel] [PATCH 01/17] qidl: add QEMU IDL processor, Michael Roth, 2012/06/04
- Re: [Qemu-devel] [PATCH 01/17] qidl: add QEMU IDL processor, Anthony Liguori, 2012/06/04
- Re: [Qemu-devel] [PATCH 01/17] qidl: add QEMU IDL processor, Kevin Wolf, 2012/06/05
- Re: [Qemu-devel] [PATCH 01/17] qidl: add QEMU IDL processor, Michael Roth, 2012/06/05
- Re: [Qemu-devel] [PATCH 01/17] qidl: add QEMU IDL processor, Paolo Bonzini, 2012/06/05
- Re: [Qemu-devel] [PATCH 01/17] qidl: add QEMU IDL processor, Anthony Liguori, 2012/06/05
- Re: [Qemu-devel] [PATCH 01/17] qidl: add QEMU IDL processor, Paolo Bonzini, 2012/06/06
- Re: [Qemu-devel] [PATCH 01/17] qidl: add QEMU IDL processor, Anthony Liguori, 2012/06/06