diff options
author | Paolo Bonzini <pbonzini@redhat.com> | 2012-02-09 09:11:52 +0100 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2012-02-21 10:21:05 +0100 |
commit | 0f71a1e0c8d64b84edd5ac5abdce70a4fb9357a9 (patch) | |
tree | ed0d41c8d49750ac961afb7c9d120f6e2912148d /qapi/qmp-output-visitor.c | |
parent | 99c7f87826337fa81f2f0f9baa9ca0a44faf90e9 (diff) |
qapi: allow sharing enum implementation across visitors
Most visitors will use the same code for enum parsing. Move it to
the core.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'qapi/qmp-output-visitor.c')
-rw-r--r-- | qapi/qmp-output-visitor.c | 22 |
1 files changed, 2 insertions, 20 deletions
diff --git a/qapi/qmp-output-visitor.c b/qapi/qmp-output-visitor.c index f76d0159cd..e0697b0d0f 100644 --- a/qapi/qmp-output-visitor.c +++ b/qapi/qmp-output-visitor.c @@ -12,6 +12,7 @@ */ #include "qmp-output-visitor.h" +#include "qapi/qapi-visit-impl.h" #include "qemu-queue.h" #include "qemu-common.h" #include "qemu-objects.h" @@ -180,25 +181,6 @@ static void qmp_output_type_number(Visitor *v, double *obj, const char *name, qmp_output_add(qov, name, qfloat_from_double(*obj)); } -static void qmp_output_type_enum(Visitor *v, int *obj, const char *strings[], - const char *kind, const char *name, - Error **errp) -{ - int i = 0; - int value = *obj; - char *enum_str; - - assert(strings); - while (strings[i++] != NULL); - if (value < 0 || value >= i - 1) { - error_set(errp, QERR_INVALID_PARAMETER, name ? name : "null"); - return; - } - - enum_str = (char *)strings[value]; - qmp_output_type_str(v, &enum_str, name, errp); -} - QObject *qmp_output_get_qobject(QmpOutputVisitor *qov) { QObject *obj = qmp_output_first(qov); @@ -239,7 +221,7 @@ QmpOutputVisitor *qmp_output_visitor_new(void) v->visitor.start_list = qmp_output_start_list; v->visitor.next_list = qmp_output_next_list; v->visitor.end_list = qmp_output_end_list; - v->visitor.type_enum = qmp_output_type_enum; + v->visitor.type_enum = output_type_enum; v->visitor.type_int = qmp_output_type_int; v->visitor.type_bool = qmp_output_type_bool; v->visitor.type_str = qmp_output_type_str; |