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_struct(Visitor
*v
, void **obj
, const char *kind
,
21 const char *name
, size_t size
, Error
**errp
)
23 if (!error_is_set(errp
)) {
24 v
->start_struct(v
, obj
, kind
, name
, size
, errp
);
28 void visit_end_struct(Visitor
*v
, Error
**errp
)
30 assert(!error_is_set(errp
));
31 v
->end_struct(v
, errp
);
34 void visit_start_implicit_struct(Visitor
*v
, void **obj
, size_t size
,
37 if (!error_is_set(errp
) && v
->start_implicit_struct
) {
38 v
->start_implicit_struct(v
, obj
, size
, errp
);
42 void visit_end_implicit_struct(Visitor
*v
, Error
**errp
)
44 assert(!error_is_set(errp
));
45 if (v
->end_implicit_struct
) {
46 v
->end_implicit_struct(v
, errp
);
50 void visit_start_list(Visitor
*v
, const char *name
, Error
**errp
)
52 if (!error_is_set(errp
)) {
53 v
->start_list(v
, name
, errp
);
57 GenericList
*visit_next_list(Visitor
*v
, GenericList
**list
, Error
**errp
)
59 if (!error_is_set(errp
)) {
60 return v
->next_list(v
, list
, errp
);
66 void visit_end_list(Visitor
*v
, Error
**errp
)
68 assert(!error_is_set(errp
));
72 void visit_optional(Visitor
*v
, bool *present
, const char *name
,
75 if (!error_is_set(errp
) && v
->optional
) {
76 v
->optional(v
, present
, name
, errp
);
80 void visit_get_next_type(Visitor
*v
, int *obj
, const int *qtypes
,
81 const char *name
, Error
**errp
)
83 if (!error_is_set(errp
) && v
->get_next_type
) {
84 v
->get_next_type(v
, obj
, qtypes
, name
, errp
);
88 void visit_type_enum(Visitor
*v
, int *obj
, const char *strings
[],
89 const char *kind
, const char *name
, Error
**errp
)
91 if (!error_is_set(errp
)) {
92 v
->type_enum(v
, obj
, strings
, kind
, name
, errp
);
96 void visit_type_int(Visitor
*v
, int64_t *obj
, const char *name
, Error
**errp
)
98 if (!error_is_set(errp
)) {
99 v
->type_int(v
, obj
, name
, errp
);
103 void visit_type_uint8(Visitor
*v
, uint8_t *obj
, const char *name
, Error
**errp
)
106 if (!error_is_set(errp
)) {
108 v
->type_uint8(v
, obj
, name
, errp
);
111 v
->type_int(v
, &value
, name
, errp
);
112 if (value
< 0 || value
> UINT8_MAX
) {
113 error_set(errp
, QERR_INVALID_PARAMETER_VALUE
, name
? name
: "null",
122 void visit_type_uint16(Visitor
*v
, uint16_t *obj
, const char *name
, Error
**errp
)
125 if (!error_is_set(errp
)) {
126 if (v
->type_uint16
) {
127 v
->type_uint16(v
, obj
, name
, errp
);
130 v
->type_int(v
, &value
, name
, errp
);
131 if (value
< 0 || value
> UINT16_MAX
) {
132 error_set(errp
, QERR_INVALID_PARAMETER_VALUE
, name
? name
: "null",
141 void visit_type_uint32(Visitor
*v
, uint32_t *obj
, const char *name
, Error
**errp
)
144 if (!error_is_set(errp
)) {
145 if (v
->type_uint32
) {
146 v
->type_uint32(v
, obj
, name
, errp
);
149 v
->type_int(v
, &value
, name
, errp
);
150 if (value
< 0 || value
> UINT32_MAX
) {
151 error_set(errp
, QERR_INVALID_PARAMETER_VALUE
, name
? name
: "null",
160 void visit_type_uint64(Visitor
*v
, uint64_t *obj
, const char *name
, Error
**errp
)
163 if (!error_is_set(errp
)) {
164 if (v
->type_uint64
) {
165 v
->type_uint64(v
, obj
, name
, errp
);
168 v
->type_int(v
, &value
, name
, errp
);
174 void visit_type_int8(Visitor
*v
, int8_t *obj
, const char *name
, Error
**errp
)
177 if (!error_is_set(errp
)) {
179 v
->type_int8(v
, obj
, name
, errp
);
182 v
->type_int(v
, &value
, name
, errp
);
183 if (value
< INT8_MIN
|| value
> INT8_MAX
) {
184 error_set(errp
, QERR_INVALID_PARAMETER_VALUE
, name
? name
: "null",
193 void visit_type_int16(Visitor
*v
, int16_t *obj
, const char *name
, Error
**errp
)
196 if (!error_is_set(errp
)) {
198 v
->type_int16(v
, obj
, name
, errp
);
201 v
->type_int(v
, &value
, name
, errp
);
202 if (value
< INT16_MIN
|| value
> INT16_MAX
) {
203 error_set(errp
, QERR_INVALID_PARAMETER_VALUE
, name
? name
: "null",
212 void visit_type_int32(Visitor
*v
, int32_t *obj
, const char *name
, Error
**errp
)
215 if (!error_is_set(errp
)) {
217 v
->type_int32(v
, obj
, name
, errp
);
220 v
->type_int(v
, &value
, name
, errp
);
221 if (value
< INT32_MIN
|| value
> INT32_MAX
) {
222 error_set(errp
, QERR_INVALID_PARAMETER_VALUE
, name
? name
: "null",
231 void visit_type_int64(Visitor
*v
, int64_t *obj
, const char *name
, Error
**errp
)
233 if (!error_is_set(errp
)) {
235 v
->type_int64(v
, obj
, name
, errp
);
237 v
->type_int(v
, obj
, name
, errp
);
242 void visit_type_size(Visitor
*v
, uint64_t *obj
, const char *name
, Error
**errp
)
245 if (!error_is_set(errp
)) {
247 v
->type_size(v
, obj
, name
, errp
);
248 } else if (v
->type_uint64
) {
249 v
->type_uint64(v
, obj
, name
, errp
);
252 v
->type_int(v
, &value
, name
, errp
);
258 void visit_type_bool(Visitor
*v
, bool *obj
, const char *name
, Error
**errp
)
260 if (!error_is_set(errp
)) {
261 v
->type_bool(v
, obj
, name
, errp
);
265 void visit_type_str(Visitor
*v
, char **obj
, const char *name
, Error
**errp
)
267 if (!error_is_set(errp
)) {
268 v
->type_str(v
, obj
, name
, errp
);
272 void visit_type_number(Visitor
*v
, double *obj
, const char *name
, Error
**errp
)
274 if (!error_is_set(errp
)) {
275 v
->type_number(v
, obj
, name
, errp
);
279 void output_type_enum(Visitor
*v
, int *obj
, const char *strings
[],
280 const char *kind
, const char *name
,
288 while (strings
[i
++] != NULL
);
289 if (value
< 0 || value
>= i
- 1) {
290 error_set(errp
, QERR_INVALID_PARAMETER
, name
? name
: "null");
294 enum_str
= (char *)strings
[value
];
295 visit_type_str(v
, &enum_str
, name
, errp
);
298 void input_type_enum(Visitor
*v
, int *obj
, const char *strings
[],
299 const char *kind
, const char *name
,
307 visit_type_str(v
, &enum_str
, name
, errp
);
308 if (error_is_set(errp
)) {
312 while (strings
[value
] != NULL
) {
313 if (strcmp(strings
[value
], enum_str
) == 0) {
319 if (strings
[value
] == NULL
) {
320 error_set(errp
, QERR_INVALID_PARAMETER
, enum_str
);