2 * Core Definitions for QAPI Visitor Classes
4 * Copyright IBM, Corp. 2011
9 * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
10 * See the COPYING.LIB file in the top-level directory.
14 #include "qemu-common.h"
15 #include "qapi/qmp/qerror.h"
16 #include "qapi/visitor.h"
17 #include "qapi/visitor-impl.h"
19 void visit_start_handle(Visitor *v, void **obj, const char *kind,
20 const char *name, Error **errp)
22 if (!error_is_set(errp) && v->start_handle) {
23 v->start_handle(v, obj, kind, name, errp);
27 void visit_end_handle(Visitor *v, Error **errp)
29 if (!error_is_set(errp) && v->end_handle) {
30 v->end_handle(v, errp);
34 void visit_start_struct(Visitor *v, void **obj, const char *kind,
35 const char *name, size_t size, Error **errp)
37 if (!error_is_set(errp)) {
38 v->start_struct(v, obj, kind, name, size, errp);
42 void visit_end_struct(Visitor *v, Error **errp)
44 assert(!error_is_set(errp));
45 v->end_struct(v, errp);
48 void visit_start_implicit_struct(Visitor *v, void **obj, size_t size,
51 if (!error_is_set(errp) && v->start_implicit_struct) {
52 v->start_implicit_struct(v, obj, size, errp);
56 void visit_end_implicit_struct(Visitor *v, Error **errp)
58 assert(!error_is_set(errp));
59 if (v->end_implicit_struct) {
60 v->end_implicit_struct(v, errp);
64 void visit_start_list(Visitor *v, const char *name, Error **errp)
66 if (!error_is_set(errp)) {
67 v->start_list(v, name, errp);
71 GenericList *visit_next_list(Visitor *v, GenericList **list, Error **errp)
73 if (!error_is_set(errp)) {
74 return v->next_list(v, list, errp);
80 void visit_end_list(Visitor *v, Error **errp)
82 assert(!error_is_set(errp));
86 void visit_start_optional(Visitor *v, bool *present, const char *name,
89 if (!error_is_set(errp) && v->start_optional) {
90 v->start_optional(v, present, name, errp);
94 void visit_end_optional(Visitor *v, Error **errp)
96 if (!error_is_set(errp) && v->end_optional) {
97 v->end_optional(v, errp);
101 void visit_type_enum(Visitor *v, int *obj, const char *strings[],
102 const char *kind, const char *name, Error **errp)
104 if (!error_is_set(errp)) {
105 v->type_enum(v, obj, strings, kind, name, errp);
109 void visit_type_int(Visitor *v, int64_t *obj, const char *name, Error **errp)
111 if (!error_is_set(errp)) {
112 v->type_int(v, obj, name, errp);
116 void visit_type_uint8(Visitor *v, uint8_t *obj, const char *name, Error **errp)
119 if (!error_is_set(errp)) {
121 v->type_uint8(v, obj, name, errp);
124 v->type_int(v, &value, name, errp);
125 if (value < 0 || value > UINT8_MAX) {
126 error_set(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null",
135 void visit_type_uint16(Visitor *v, uint16_t *obj, const char *name, Error **errp)
138 if (!error_is_set(errp)) {
139 if (v->type_uint16) {
140 v->type_uint16(v, obj, name, errp);
143 v->type_int(v, &value, name, errp);
144 if (value < 0 || value > UINT16_MAX) {
145 error_set(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null",
154 void visit_type_uint32(Visitor *v, uint32_t *obj, const char *name, Error **errp)
157 if (!error_is_set(errp)) {
158 if (v->type_uint32) {
159 v->type_uint32(v, obj, name, errp);
162 v->type_int(v, &value, name, errp);
163 if (value < 0 || value > UINT32_MAX) {
164 error_set(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null",
173 void visit_type_uint64(Visitor *v, uint64_t *obj, const char *name, Error **errp)
176 if (!error_is_set(errp)) {
177 if (v->type_uint64) {
178 v->type_uint64(v, obj, name, errp);
181 v->type_int(v, &value, name, errp);
187 void visit_type_int8(Visitor *v, int8_t *obj, const char *name, Error **errp)
190 if (!error_is_set(errp)) {
192 v->type_int8(v, obj, name, errp);
195 v->type_int(v, &value, name, errp);
196 if (value < INT8_MIN || value > INT8_MAX) {
197 error_set(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null",
206 void visit_type_int16(Visitor *v, int16_t *obj, const char *name, Error **errp)
209 if (!error_is_set(errp)) {
211 v->type_int16(v, obj, name, errp);
214 v->type_int(v, &value, name, errp);
215 if (value < INT16_MIN || value > INT16_MAX) {
216 error_set(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null",
225 void visit_type_int32(Visitor *v, int32_t *obj, const char *name, Error **errp)
228 if (!error_is_set(errp)) {
230 v->type_int32(v, obj, name, errp);
233 v->type_int(v, &value, name, errp);
234 if (value < INT32_MIN || value > INT32_MAX) {
235 error_set(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null",
244 void visit_type_int64(Visitor *v, int64_t *obj, const char *name, Error **errp)
246 if (!error_is_set(errp)) {
248 v->type_int64(v, obj, name, errp);
250 v->type_int(v, obj, name, errp);
255 void visit_type_size(Visitor *v, uint64_t *obj, const char *name, Error **errp)
257 if (!error_is_set(errp)) {
258 (v->type_size ? v->type_size : v->type_uint64)(v, obj, name, errp);
262 void visit_type_bool(Visitor *v, bool *obj, const char *name, Error **errp)
264 if (!error_is_set(errp)) {
265 v->type_bool(v, obj, name, errp);
269 void visit_type_str(Visitor *v, char **obj, const char *name, Error **errp)
271 if (!error_is_set(errp)) {
272 v->type_str(v, obj, name, errp);
276 void visit_type_number(Visitor *v, double *obj, const char *name, Error **errp)
278 if (!error_is_set(errp)) {
279 v->type_number(v, obj, name, errp);
283 void output_type_enum(Visitor *v, int *obj, const char *strings[],
284 const char *kind, const char *name,
292 while (strings[i++] != NULL);
293 if (value < 0 || value >= i - 1) {
294 error_set(errp, QERR_INVALID_PARAMETER, name ? name : "null");
298 enum_str = (char *)strings[value];
299 visit_type_str(v, &enum_str, name, errp);
302 void input_type_enum(Visitor *v, int *obj, const char *strings[],
303 const char *kind, const char *name,
311 visit_type_str(v, &enum_str, name, errp);
312 if (error_is_set(errp)) {
316 while (strings[value] != NULL) {
317 if (strcmp(strings[value], enum_str) == 0) {
323 if (strings[value] == NULL) {
324 error_set(errp, QERR_INVALID_PARAMETER, enum_str);