block/iscsi: allow cluster_size of 4K and greater
[qemu.git] / qapi / qapi-visit-core.c
blob6451a21a2880fdcb31cba3ca87328fd12aa72c3a
1 /*
2 * Core Definitions for QAPI Visitor Classes
4 * Copyright IBM, Corp. 2011
6 * Authors:
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/qmp/qobject.h"
16 #include "qapi/qmp/qerror.h"
17 #include "qapi/visitor.h"
18 #include "qapi/visitor-impl.h"
20 void visit_start_handle(Visitor *v, void **obj, const char *kind,
21 const char *name, Error **errp)
23 if (!error_is_set(errp) && v->start_handle) {
24 v->start_handle(v, obj, kind, name, errp);
28 void visit_end_handle(Visitor *v, Error **errp)
30 if (!error_is_set(errp) && v->end_handle) {
31 v->end_handle(v, errp);
35 void visit_start_struct(Visitor *v, void **obj, const char *kind,
36 const char *name, size_t size, Error **errp)
38 if (!error_is_set(errp)) {
39 v->start_struct(v, obj, kind, name, size, errp);
43 void visit_end_struct(Visitor *v, Error **errp)
45 assert(!error_is_set(errp));
46 v->end_struct(v, errp);
49 void visit_start_implicit_struct(Visitor *v, void **obj, size_t size,
50 Error **errp)
52 if (!error_is_set(errp) && v->start_implicit_struct) {
53 v->start_implicit_struct(v, obj, size, errp);
57 void visit_end_implicit_struct(Visitor *v, Error **errp)
59 assert(!error_is_set(errp));
60 if (v->end_implicit_struct) {
61 v->end_implicit_struct(v, errp);
65 void visit_start_list(Visitor *v, const char *name, Error **errp)
67 if (!error_is_set(errp)) {
68 v->start_list(v, name, errp);
72 GenericList *visit_next_list(Visitor *v, GenericList **list, Error **errp)
74 if (!error_is_set(errp)) {
75 return v->next_list(v, list, errp);
78 return 0;
81 void visit_end_list(Visitor *v, Error **errp)
83 assert(!error_is_set(errp));
84 v->end_list(v, errp);
87 void visit_start_optional(Visitor *v, bool *present, const char *name,
88 Error **errp)
90 if (!error_is_set(errp) && v->start_optional) {
91 v->start_optional(v, present, name, errp);
95 void visit_end_optional(Visitor *v, Error **errp)
97 if (!error_is_set(errp) && v->end_optional) {
98 v->end_optional(v, errp);
102 void visit_get_next_type(Visitor *v, int *obj, const int *qtypes,
103 const char *name, Error **errp)
105 if (!error_is_set(errp) && v->get_next_type) {
106 v->get_next_type(v, obj, qtypes, name, errp);
110 void visit_type_enum(Visitor *v, int *obj, const char *strings[],
111 const char *kind, const char *name, Error **errp)
113 if (!error_is_set(errp)) {
114 v->type_enum(v, obj, strings, kind, name, errp);
118 void visit_type_int(Visitor *v, int64_t *obj, const char *name, Error **errp)
120 if (!error_is_set(errp)) {
121 v->type_int(v, obj, name, errp);
125 void visit_type_uint8(Visitor *v, uint8_t *obj, const char *name, Error **errp)
127 int64_t value;
128 if (!error_is_set(errp)) {
129 if (v->type_uint8) {
130 v->type_uint8(v, obj, name, errp);
131 } else {
132 value = *obj;
133 v->type_int(v, &value, name, errp);
134 if (value < 0 || value > UINT8_MAX) {
135 error_set(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null",
136 "uint8_t");
137 return;
139 *obj = value;
144 void visit_type_uint16(Visitor *v, uint16_t *obj, const char *name, Error **errp)
146 int64_t value;
147 if (!error_is_set(errp)) {
148 if (v->type_uint16) {
149 v->type_uint16(v, obj, name, errp);
150 } else {
151 value = *obj;
152 v->type_int(v, &value, name, errp);
153 if (value < 0 || value > UINT16_MAX) {
154 error_set(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null",
155 "uint16_t");
156 return;
158 *obj = value;
163 void visit_type_uint32(Visitor *v, uint32_t *obj, const char *name, Error **errp)
165 int64_t value;
166 if (!error_is_set(errp)) {
167 if (v->type_uint32) {
168 v->type_uint32(v, obj, name, errp);
169 } else {
170 value = *obj;
171 v->type_int(v, &value, name, errp);
172 if (value < 0 || value > UINT32_MAX) {
173 error_set(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null",
174 "uint32_t");
175 return;
177 *obj = value;
182 void visit_type_uint64(Visitor *v, uint64_t *obj, const char *name, Error **errp)
184 int64_t value;
185 if (!error_is_set(errp)) {
186 if (v->type_uint64) {
187 v->type_uint64(v, obj, name, errp);
188 } else {
189 value = *obj;
190 v->type_int(v, &value, name, errp);
191 *obj = value;
196 void visit_type_int8(Visitor *v, int8_t *obj, const char *name, Error **errp)
198 int64_t value;
199 if (!error_is_set(errp)) {
200 if (v->type_int8) {
201 v->type_int8(v, obj, name, errp);
202 } else {
203 value = *obj;
204 v->type_int(v, &value, name, errp);
205 if (value < INT8_MIN || value > INT8_MAX) {
206 error_set(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null",
207 "int8_t");
208 return;
210 *obj = value;
215 void visit_type_int16(Visitor *v, int16_t *obj, const char *name, Error **errp)
217 int64_t value;
218 if (!error_is_set(errp)) {
219 if (v->type_int16) {
220 v->type_int16(v, obj, name, errp);
221 } else {
222 value = *obj;
223 v->type_int(v, &value, name, errp);
224 if (value < INT16_MIN || value > INT16_MAX) {
225 error_set(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null",
226 "int16_t");
227 return;
229 *obj = value;
234 void visit_type_int32(Visitor *v, int32_t *obj, const char *name, Error **errp)
236 int64_t value;
237 if (!error_is_set(errp)) {
238 if (v->type_int32) {
239 v->type_int32(v, obj, name, errp);
240 } else {
241 value = *obj;
242 v->type_int(v, &value, name, errp);
243 if (value < INT32_MIN || value > INT32_MAX) {
244 error_set(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null",
245 "int32_t");
246 return;
248 *obj = value;
253 void visit_type_int64(Visitor *v, int64_t *obj, const char *name, Error **errp)
255 if (!error_is_set(errp)) {
256 if (v->type_int64) {
257 v->type_int64(v, obj, name, errp);
258 } else {
259 v->type_int(v, obj, name, errp);
264 void visit_type_size(Visitor *v, uint64_t *obj, const char *name, Error **errp)
266 int64_t value;
267 if (!error_is_set(errp)) {
268 if (v->type_size) {
269 v->type_size(v, obj, name, errp);
270 } else if (v->type_uint64) {
271 v->type_uint64(v, obj, name, errp);
272 } else {
273 value = *obj;
274 v->type_int(v, &value, name, errp);
275 *obj = value;
280 void visit_type_bool(Visitor *v, bool *obj, const char *name, Error **errp)
282 if (!error_is_set(errp)) {
283 v->type_bool(v, obj, name, errp);
287 void visit_type_str(Visitor *v, char **obj, const char *name, Error **errp)
289 if (!error_is_set(errp)) {
290 v->type_str(v, obj, name, errp);
294 void visit_type_number(Visitor *v, double *obj, const char *name, Error **errp)
296 if (!error_is_set(errp)) {
297 v->type_number(v, obj, name, errp);
301 void output_type_enum(Visitor *v, int *obj, const char *strings[],
302 const char *kind, const char *name,
303 Error **errp)
305 int i = 0;
306 int value = *obj;
307 char *enum_str;
309 assert(strings);
310 while (strings[i++] != NULL);
311 if (value < 0 || value >= i - 1) {
312 error_set(errp, QERR_INVALID_PARAMETER, name ? name : "null");
313 return;
316 enum_str = (char *)strings[value];
317 visit_type_str(v, &enum_str, name, errp);
320 void input_type_enum(Visitor *v, int *obj, const char *strings[],
321 const char *kind, const char *name,
322 Error **errp)
324 int64_t value = 0;
325 char *enum_str;
327 assert(strings);
329 visit_type_str(v, &enum_str, name, errp);
330 if (error_is_set(errp)) {
331 return;
334 while (strings[value] != NULL) {
335 if (strcmp(strings[value], enum_str) == 0) {
336 break;
338 value++;
341 if (strings[value] == NULL) {
342 error_set(errp, QERR_INVALID_PARAMETER, enum_str);
343 g_free(enum_str);
344 return;
347 g_free(enum_str);
348 *obj = value;