aboutsummaryrefslogtreecommitdiff
path: root/qapi/qmp-input-visitor.c
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2012-02-09 09:11:52 +0100
committerPaolo Bonzini <pbonzini@redhat.com>2012-02-21 10:21:05 +0100
commit0f71a1e0c8d64b84edd5ac5abdce70a4fb9357a9 (patch)
treeed0d41c8d49750ac961afb7c9d120f6e2912148d /qapi/qmp-input-visitor.c
parent99c7f87826337fa81f2f0f9baa9ca0a44faf90e9 (diff)
downloadqemu-0f71a1e0c8d64b84edd5ac5abdce70a4fb9357a9.zip
qemu-0f71a1e0c8d64b84edd5ac5abdce70a4fb9357a9.tar.gz
qemu-0f71a1e0c8d64b84edd5ac5abdce70a4fb9357a9.tar.bz2
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-input-visitor.c')
-rw-r--r--qapi/qmp-input-visitor.c34
1 files changed, 2 insertions, 32 deletions
diff --git a/qapi/qmp-input-visitor.c b/qapi/qmp-input-visitor.c
index c78022b..012cd0a 100644
--- a/qapi/qmp-input-visitor.c
+++ b/qapi/qmp-input-visitor.c
@@ -12,6 +12,7 @@
*/
#include "qmp-input-visitor.h"
+#include "qapi/qapi-visit-impl.h"
#include "qemu-queue.h"
#include "qemu-common.h"
#include "qemu-objects.h"
@@ -217,37 +218,6 @@ static void qmp_input_type_number(Visitor *v, double *obj, const char *name,
*obj = qfloat_get_double(qobject_to_qfloat(qobj));
}
-static void qmp_input_type_enum(Visitor *v, int *obj, const char *strings[],
- const char *kind, const char *name,
- Error **errp)
-{
- int64_t value = 0;
- char *enum_str;
-
- assert(strings);
-
- qmp_input_type_str(v, &enum_str, name, errp);
- if (error_is_set(errp)) {
- return;
- }
-
- while (strings[value] != NULL) {
- if (strcmp(strings[value], enum_str) == 0) {
- break;
- }
- value++;
- }
-
- if (strings[value] == NULL) {
- error_set(errp, QERR_INVALID_PARAMETER, name ? name : "null");
- g_free(enum_str);
- return;
- }
-
- g_free(enum_str);
- *obj = value;
-}
-
static void qmp_input_start_optional(Visitor *v, bool *present,
const char *name, Error **errp)
{
@@ -288,7 +258,7 @@ QmpInputVisitor *qmp_input_visitor_new(QObject *obj)
v->visitor.start_list = qmp_input_start_list;
v->visitor.next_list = qmp_input_next_list;
v->visitor.end_list = qmp_input_end_list;
- v->visitor.type_enum = qmp_input_type_enum;
+ v->visitor.type_enum = input_type_enum;
v->visitor.type_int = qmp_input_type_int;
v->visitor.type_bool = qmp_input_type_bool;
v->visitor.type_str = qmp_input_type_str;