2 * Core Definitions for QAPI Visitor Classes
4 * Copyright IBM, Corp. 2011
7 * Anthony Liguori <aliguori@us.ibm.com>
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/qapi-visit-core.h"
16 #include "qapi/qapi-visit-impl.h"
18 void visit_start_handle(Visitor *v, void **obj, const char *kind,
19 const char *name, Error **errp)
21 if (!error_is_set(errp) && v->start_handle) {
22 v->start_handle(v, obj, kind, name, errp);
26 void visit_end_handle(Visitor *v, Error **errp)
28 if (!error_is_set(errp) && v->end_handle) {
29 v->end_handle(v, errp);
33 void visit_start_struct(Visitor *v, void **obj, const char *kind,
34 const char *name, size_t size, Error **errp)
36 if (!error_is_set(errp)) {
37 v->start_struct(v, obj, kind, name, size, errp);
41 void visit_end_struct(Visitor *v, Error **errp)
43 assert(!error_is_set(errp));
44 v->end_struct(v, errp);
47 void visit_start_list(Visitor *v, const char *name, Error **errp)
49 if (!error_is_set(errp)) {
50 v->start_list(v, name, errp);
54 GenericList *visit_next_list(Visitor *v, GenericList **list, Error **errp)
56 if (!error_is_set(errp)) {
57 return v->next_list(v, list, errp);
63 void visit_end_list(Visitor *v, Error **errp)
65 assert(!error_is_set(errp));
69 void visit_start_optional(Visitor *v, bool *present, const char *name,
72 if (!error_is_set(errp) && v->start_optional) {
73 v->start_optional(v, present, name, errp);
77 void visit_end_optional(Visitor *v, Error **errp)
79 if (!error_is_set(errp) && v->end_optional) {
80 v->end_optional(v, errp);
84 void visit_type_enum(Visitor *v, int *obj, const char *strings[],
85 const char *kind, const char *name, Error **errp)
87 if (!error_is_set(errp)) {
88 v->type_enum(v, obj, strings, kind, name, errp);
92 void visit_type_int(Visitor *v, int64_t *obj, const char *name, Error **errp)
94 if (!error_is_set(errp)) {
95 v->type_int(v, obj, name, errp);
99 void visit_type_uint8(Visitor *v, uint8_t *obj, const char *name, Error **errp)
102 if (!error_is_set(errp)) {
104 v->type_uint8(v, obj, name, errp);
107 v->type_int(v, &value, name, errp);
108 if (value < 0 || value > UINT8_MAX) {
109 error_set(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null",
118 void visit_type_uint16(Visitor *v, uint16_t *obj, const char *name, Error **errp)
121 if (!error_is_set(errp)) {
122 if (v->type_uint16) {
123 v->type_uint16(v, obj, name, errp);
126 v->type_int(v, &value, name, errp);
127 if (value < 0 || value > UINT16_MAX) {
128 error_set(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null",
137 void visit_type_uint32(Visitor *v, uint32_t *obj, const char *name, Error **errp)
140 if (!error_is_set(errp)) {
141 if (v->type_uint32) {
142 v->type_uint32(v, obj, name, errp);
145 v->type_int(v, &value, name, errp);
146 if (value < 0 || value > UINT32_MAX) {
147 error_set(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null",
156 void visit_type_uint64(Visitor *v, uint64_t *obj, const char *name, Error **errp)
159 if (!error_is_set(errp)) {
160 if (v->type_uint64) {
161 v->type_uint64(v, obj, name, errp);
164 v->type_int(v, &value, name, errp);
170 void visit_type_int8(Visitor *v, int8_t *obj, const char *name, Error **errp)
173 if (!error_is_set(errp)) {
175 v->type_int8(v, obj, name, errp);
178 v->type_int(v, &value, name, errp);
179 if (value < INT8_MIN || value > INT8_MAX) {
180 error_set(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null",
189 void visit_type_int16(Visitor *v, int16_t *obj, const char *name, Error **errp)
192 if (!error_is_set(errp)) {
194 v->type_int16(v, obj, name, errp);
197 v->type_int(v, &value, name, errp);
198 if (value < INT16_MIN || value > INT16_MAX) {
199 error_set(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null",
208 void visit_type_int32(Visitor *v, int32_t *obj, const char *name, Error **errp)
211 if (!error_is_set(errp)) {
213 v->type_int32(v, obj, name, errp);
216 v->type_int(v, &value, name, errp);
217 if (value < INT32_MIN || value > INT32_MAX) {
218 error_set(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null",
227 void visit_type_int64(Visitor *v, int64_t *obj, const char *name, Error **errp)
229 if (!error_is_set(errp)) {
231 v->type_int64(v, obj, name, errp);
233 v->type_int(v, obj, name, errp);
238 void visit_type_size(Visitor *v, uint64_t *obj, const char *name, Error **errp)
240 if (!error_is_set(errp)) {
241 (v->type_size ? v->type_size : v->type_uint64)(v, obj, name, errp);
245 void visit_type_bool(Visitor *v, bool *obj, const char *name, Error **errp)
247 if (!error_is_set(errp)) {
248 v->type_bool(v, obj, name, errp);
252 void visit_type_str(Visitor *v, char **obj, const char *name, Error **errp)
254 if (!error_is_set(errp)) {
255 v->type_str(v, obj, name, errp);
259 void visit_type_number(Visitor *v, double *obj, const char *name, Error **errp)
261 if (!error_is_set(errp)) {
262 v->type_number(v, obj, name, errp);
266 void output_type_enum(Visitor *v, int *obj, const char *strings[],
267 const char *kind, const char *name,
275 while (strings[i++] != NULL);
276 if (value < 0 || value >= i - 1) {
277 error_set(errp, QERR_INVALID_PARAMETER, name ? name : "null");
281 enum_str = (char *)strings[value];
282 visit_type_str(v, &enum_str, name, errp);
285 void input_type_enum(Visitor *v, int *obj, const char *strings[],
286 const char *kind, const char *name,
294 visit_type_str(v, &enum_str, name, errp);
295 if (error_is_set(errp)) {
299 while (strings[value] != NULL) {
300 if (strcmp(strings[value], enum_str) == 0) {
306 if (strings[value] == NULL) {
307 error_set(errp, QERR_INVALID_PARAMETER, enum_str);