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/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_list(Visitor
*v
, const char *name
, Error
**errp
)
50 if (!error_is_set(errp
)) {
51 v
->start_list(v
, name
, errp
);
55 GenericList
*visit_next_list(Visitor
*v
, GenericList
**list
, Error
**errp
)
57 if (!error_is_set(errp
)) {
58 return v
->next_list(v
, list
, errp
);
64 void visit_end_list(Visitor
*v
, Error
**errp
)
66 assert(!error_is_set(errp
));
70 void visit_start_optional(Visitor
*v
, bool *present
, const char *name
,
73 if (!error_is_set(errp
) && v
->start_optional
) {
74 v
->start_optional(v
, present
, name
, errp
);
78 void visit_end_optional(Visitor
*v
, Error
**errp
)
80 if (!error_is_set(errp
) && v
->end_optional
) {
81 v
->end_optional(v
, errp
);
85 void visit_type_enum(Visitor
*v
, int *obj
, const char *strings
[],
86 const char *kind
, const char *name
, Error
**errp
)
88 if (!error_is_set(errp
)) {
89 v
->type_enum(v
, obj
, strings
, kind
, name
, errp
);
93 void visit_type_int(Visitor
*v
, int64_t *obj
, const char *name
, Error
**errp
)
95 if (!error_is_set(errp
)) {
96 v
->type_int(v
, obj
, name
, errp
);
100 void visit_type_uint8(Visitor
*v
, uint8_t *obj
, const char *name
, Error
**errp
)
103 if (!error_is_set(errp
)) {
105 v
->type_uint8(v
, obj
, name
, errp
);
108 v
->type_int(v
, &value
, name
, errp
);
109 if (value
< 0 || value
> UINT8_MAX
) {
110 error_set(errp
, QERR_INVALID_PARAMETER_VALUE
, name
? name
: "null",
119 void visit_type_uint16(Visitor
*v
, uint16_t *obj
, const char *name
, Error
**errp
)
122 if (!error_is_set(errp
)) {
123 if (v
->type_uint16
) {
124 v
->type_uint16(v
, obj
, name
, errp
);
127 v
->type_int(v
, &value
, name
, errp
);
128 if (value
< 0 || value
> UINT16_MAX
) {
129 error_set(errp
, QERR_INVALID_PARAMETER_VALUE
, name
? name
: "null",
138 void visit_type_uint32(Visitor
*v
, uint32_t *obj
, const char *name
, Error
**errp
)
141 if (!error_is_set(errp
)) {
142 if (v
->type_uint32
) {
143 v
->type_uint32(v
, obj
, name
, errp
);
146 v
->type_int(v
, &value
, name
, errp
);
147 if (value
< 0 || value
> UINT32_MAX
) {
148 error_set(errp
, QERR_INVALID_PARAMETER_VALUE
, name
? name
: "null",
157 void visit_type_uint64(Visitor
*v
, uint64_t *obj
, const char *name
, Error
**errp
)
160 if (!error_is_set(errp
)) {
161 if (v
->type_uint64
) {
162 v
->type_uint64(v
, obj
, name
, errp
);
165 v
->type_int(v
, &value
, name
, errp
);
171 void visit_type_int8(Visitor
*v
, int8_t *obj
, const char *name
, Error
**errp
)
174 if (!error_is_set(errp
)) {
176 v
->type_int8(v
, obj
, name
, errp
);
179 v
->type_int(v
, &value
, name
, errp
);
180 if (value
< INT8_MIN
|| value
> INT8_MAX
) {
181 error_set(errp
, QERR_INVALID_PARAMETER_VALUE
, name
? name
: "null",
190 void visit_type_int16(Visitor
*v
, int16_t *obj
, const char *name
, Error
**errp
)
193 if (!error_is_set(errp
)) {
195 v
->type_int16(v
, obj
, name
, errp
);
198 v
->type_int(v
, &value
, name
, errp
);
199 if (value
< INT16_MIN
|| value
> INT16_MAX
) {
200 error_set(errp
, QERR_INVALID_PARAMETER_VALUE
, name
? name
: "null",
209 void visit_type_int32(Visitor
*v
, int32_t *obj
, const char *name
, Error
**errp
)
212 if (!error_is_set(errp
)) {
214 v
->type_int32(v
, obj
, name
, errp
);
217 v
->type_int(v
, &value
, name
, errp
);
218 if (value
< INT32_MIN
|| value
> INT32_MAX
) {
219 error_set(errp
, QERR_INVALID_PARAMETER_VALUE
, name
? name
: "null",
228 void visit_type_int64(Visitor
*v
, int64_t *obj
, const char *name
, Error
**errp
)
230 if (!error_is_set(errp
)) {
232 v
->type_int64(v
, obj
, name
, errp
);
234 v
->type_int(v
, obj
, name
, errp
);
239 void visit_type_size(Visitor
*v
, uint64_t *obj
, const char *name
, Error
**errp
)
241 if (!error_is_set(errp
)) {
242 (v
->type_size
? v
->type_size
: v
->type_uint64
)(v
, obj
, name
, errp
);
246 void visit_type_bool(Visitor
*v
, bool *obj
, const char *name
, Error
**errp
)
248 if (!error_is_set(errp
)) {
249 v
->type_bool(v
, obj
, name
, errp
);
253 void visit_type_str(Visitor
*v
, char **obj
, const char *name
, Error
**errp
)
255 if (!error_is_set(errp
)) {
256 v
->type_str(v
, obj
, name
, errp
);
260 void visit_type_number(Visitor
*v
, double *obj
, const char *name
, Error
**errp
)
262 if (!error_is_set(errp
)) {
263 v
->type_number(v
, obj
, name
, errp
);
267 void output_type_enum(Visitor
*v
, int *obj
, const char *strings
[],
268 const char *kind
, const char *name
,
276 while (strings
[i
++] != NULL
);
277 if (value
< 0 || value
>= i
- 1) {
278 error_set(errp
, QERR_INVALID_PARAMETER
, name
? name
: "null");
282 enum_str
= (char *)strings
[value
];
283 visit_type_str(v
, &enum_str
, name
, errp
);
286 void input_type_enum(Visitor
*v
, int *obj
, const char *strings
[],
287 const char *kind
, const char *name
,
295 visit_type_str(v
, &enum_str
, name
, errp
);
296 if (error_is_set(errp
)) {
300 while (strings
[value
] != NULL
) {
301 if (strcmp(strings
[value
], enum_str
) == 0) {
307 if (strings
[value
] == NULL
) {
308 error_set(errp
, QERR_INVALID_PARAMETER
, enum_str
);