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/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
,
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
);
81 void visit_end_list(Visitor
*v
, Error
**errp
)
83 assert(!error_is_set(errp
));
87 void visit_start_optional(Visitor
*v
, bool *present
, const char *name
,
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
)
128 if (!error_is_set(errp
)) {
130 v
->type_uint8(v
, obj
, name
, errp
);
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",
144 void visit_type_uint16(Visitor
*v
, uint16_t *obj
, const char *name
, Error
**errp
)
147 if (!error_is_set(errp
)) {
148 if (v
->type_uint16
) {
149 v
->type_uint16(v
, obj
, name
, errp
);
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",
163 void visit_type_uint32(Visitor
*v
, uint32_t *obj
, const char *name
, Error
**errp
)
166 if (!error_is_set(errp
)) {
167 if (v
->type_uint32
) {
168 v
->type_uint32(v
, obj
, name
, errp
);
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",
182 void visit_type_uint64(Visitor
*v
, uint64_t *obj
, const char *name
, Error
**errp
)
185 if (!error_is_set(errp
)) {
186 if (v
->type_uint64
) {
187 v
->type_uint64(v
, obj
, name
, errp
);
190 v
->type_int(v
, &value
, name
, errp
);
196 void visit_type_int8(Visitor
*v
, int8_t *obj
, const char *name
, Error
**errp
)
199 if (!error_is_set(errp
)) {
201 v
->type_int8(v
, obj
, name
, errp
);
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",
215 void visit_type_int16(Visitor
*v
, int16_t *obj
, const char *name
, Error
**errp
)
218 if (!error_is_set(errp
)) {
220 v
->type_int16(v
, obj
, name
, errp
);
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",
234 void visit_type_int32(Visitor
*v
, int32_t *obj
, const char *name
, Error
**errp
)
237 if (!error_is_set(errp
)) {
239 v
->type_int32(v
, obj
, name
, errp
);
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",
253 void visit_type_int64(Visitor
*v
, int64_t *obj
, const char *name
, Error
**errp
)
255 if (!error_is_set(errp
)) {
257 v
->type_int64(v
, obj
, name
, errp
);
259 v
->type_int(v
, obj
, name
, errp
);
264 void visit_type_size(Visitor
*v
, uint64_t *obj
, const char *name
, Error
**errp
)
267 if (!error_is_set(errp
)) {
269 v
->type_size(v
, obj
, name
, errp
);
270 } else if (v
->type_uint64
) {
271 v
->type_uint64(v
, obj
, name
, errp
);
274 v
->type_int(v
, &value
, name
, errp
);
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
,
310 while (strings
[i
++] != NULL
);
311 if (value
< 0 || value
>= i
- 1) {
312 error_set(errp
, QERR_INVALID_PARAMETER
, name
? name
: "null");
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
,
329 visit_type_str(v
, &enum_str
, name
, errp
);
330 if (error_is_set(errp
)) {
334 while (strings
[value
] != NULL
) {
335 if (strcmp(strings
[value
], enum_str
) == 0) {
341 if (strings
[value
] == NULL
) {
342 error_set(errp
, QERR_INVALID_PARAMETER
, enum_str
);