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 "qapi/qapi-visit-core.h"
15 #include "qapi/qapi-visit-impl.h"
17 void visit_start_handle(Visitor
*v
, void **obj
, const char *kind
,
18 const char *name
, Error
**errp
)
20 if (!error_is_set(errp
) && v
->start_handle
) {
21 v
->start_handle(v
, obj
, kind
, name
, errp
);
25 void visit_end_handle(Visitor
*v
, Error
**errp
)
27 if (!error_is_set(errp
) && v
->end_handle
) {
28 v
->end_handle(v
, errp
);
32 void visit_start_struct(Visitor
*v
, void **obj
, const char *kind
,
33 const char *name
, size_t size
, Error
**errp
)
35 if (!error_is_set(errp
)) {
36 v
->start_struct(v
, obj
, kind
, name
, size
, errp
);
40 void visit_end_struct(Visitor
*v
, Error
**errp
)
42 assert(!error_is_set(errp
));
43 v
->end_struct(v
, errp
);
46 void visit_start_list(Visitor
*v
, const char *name
, Error
**errp
)
48 if (!error_is_set(errp
)) {
49 v
->start_list(v
, name
, errp
);
53 GenericList
*visit_next_list(Visitor
*v
, GenericList
**list
, Error
**errp
)
55 if (!error_is_set(errp
)) {
56 return v
->next_list(v
, list
, errp
);
62 void visit_end_list(Visitor
*v
, Error
**errp
)
64 assert(!error_is_set(errp
));
68 void visit_start_optional(Visitor
*v
, bool *present
, const char *name
,
71 if (!error_is_set(errp
) && v
->start_optional
) {
72 v
->start_optional(v
, present
, name
, errp
);
76 void visit_end_optional(Visitor
*v
, Error
**errp
)
78 if (!error_is_set(errp
) && v
->end_optional
) {
79 v
->end_optional(v
, errp
);
83 void visit_type_enum(Visitor
*v
, int *obj
, const char *strings
[],
84 const char *kind
, const char *name
, Error
**errp
)
86 if (!error_is_set(errp
)) {
87 v
->type_enum(v
, obj
, strings
, kind
, name
, errp
);
91 void visit_type_int(Visitor
*v
, int64_t *obj
, const char *name
, Error
**errp
)
93 if (!error_is_set(errp
)) {
94 v
->type_int(v
, obj
, name
, errp
);
98 void visit_type_uint8(Visitor
*v
, uint8_t *obj
, const char *name
, Error
**errp
)
101 if (!error_is_set(errp
)) {
103 v
->type_uint8(v
, obj
, name
, errp
);
106 v
->type_int(v
, &value
, name
, errp
);
107 if (value
< 0 || value
> UINT8_MAX
) {
108 error_set(errp
, QERR_INVALID_PARAMETER_VALUE
, name
? name
: "null",
117 void visit_type_uint16(Visitor
*v
, uint16_t *obj
, const char *name
, Error
**errp
)
120 if (!error_is_set(errp
)) {
121 if (v
->type_uint16
) {
122 v
->type_uint16(v
, obj
, name
, errp
);
125 v
->type_int(v
, &value
, name
, errp
);
126 if (value
< 0 || value
> UINT16_MAX
) {
127 error_set(errp
, QERR_INVALID_PARAMETER_VALUE
, name
? name
: "null",
136 void visit_type_uint32(Visitor
*v
, uint32_t *obj
, const char *name
, Error
**errp
)
139 if (!error_is_set(errp
)) {
140 if (v
->type_uint32
) {
141 v
->type_uint32(v
, obj
, name
, errp
);
144 v
->type_int(v
, &value
, name
, errp
);
145 if (value
< 0 || value
> UINT32_MAX
) {
146 error_set(errp
, QERR_INVALID_PARAMETER_VALUE
, name
? name
: "null",
155 void visit_type_uint64(Visitor
*v
, uint64_t *obj
, const char *name
, Error
**errp
)
158 if (!error_is_set(errp
)) {
159 if (v
->type_uint64
) {
160 v
->type_uint64(v
, obj
, name
, errp
);
163 v
->type_int(v
, &value
, name
, errp
);
169 void visit_type_int8(Visitor
*v
, int8_t *obj
, const char *name
, Error
**errp
)
172 if (!error_is_set(errp
)) {
174 v
->type_int8(v
, obj
, name
, errp
);
177 v
->type_int(v
, &value
, name
, errp
);
178 if (value
< INT8_MIN
|| value
> INT8_MAX
) {
179 error_set(errp
, QERR_INVALID_PARAMETER_VALUE
, name
? name
: "null",
188 void visit_type_int16(Visitor
*v
, int16_t *obj
, const char *name
, Error
**errp
)
191 if (!error_is_set(errp
)) {
193 v
->type_int16(v
, obj
, name
, errp
);
196 v
->type_int(v
, &value
, name
, errp
);
197 if (value
< INT16_MIN
|| value
> INT16_MAX
) {
198 error_set(errp
, QERR_INVALID_PARAMETER_VALUE
, name
? name
: "null",
207 void visit_type_int32(Visitor
*v
, int32_t *obj
, const char *name
, Error
**errp
)
210 if (!error_is_set(errp
)) {
212 v
->type_int32(v
, obj
, name
, errp
);
215 v
->type_int(v
, &value
, name
, errp
);
216 if (value
< INT32_MIN
|| value
> INT32_MAX
) {
217 error_set(errp
, QERR_INVALID_PARAMETER_VALUE
, name
? name
: "null",
226 void visit_type_int64(Visitor
*v
, int64_t *obj
, const char *name
, Error
**errp
)
228 if (!error_is_set(errp
)) {
230 v
->type_int64(v
, obj
, name
, errp
);
232 v
->type_int(v
, obj
, name
, errp
);
237 void visit_type_size(Visitor
*v
, uint64_t *obj
, const char *name
, Error
**errp
)
239 if (!error_is_set(errp
)) {
240 (v
->type_size
? v
->type_size
: v
->type_uint64
)(v
, obj
, name
, errp
);
244 void visit_type_bool(Visitor
*v
, bool *obj
, const char *name
, Error
**errp
)
246 if (!error_is_set(errp
)) {
247 v
->type_bool(v
, obj
, name
, errp
);
251 void visit_type_str(Visitor
*v
, char **obj
, const char *name
, Error
**errp
)
253 if (!error_is_set(errp
)) {
254 v
->type_str(v
, obj
, name
, errp
);
258 void visit_type_number(Visitor
*v
, double *obj
, const char *name
, Error
**errp
)
260 if (!error_is_set(errp
)) {
261 v
->type_number(v
, obj
, name
, errp
);
265 void output_type_enum(Visitor
*v
, int *obj
, const char *strings
[],
266 const char *kind
, const char *name
,
274 while (strings
[i
++] != NULL
);
275 if (value
< 0 || value
>= i
- 1) {
276 error_set(errp
, QERR_INVALID_PARAMETER
, name
? name
: "null");
280 enum_str
= (char *)strings
[value
];
281 visit_type_str(v
, &enum_str
, name
, errp
);
284 void input_type_enum(Visitor
*v
, int *obj
, const char *strings
[],
285 const char *kind
, const char *name
,
293 visit_type_str(v
, &enum_str
, name
, errp
);
294 if (error_is_set(errp
)) {
298 while (strings
[value
] != NULL
) {
299 if (strcmp(strings
[value
], enum_str
) == 0) {
305 if (strings
[value
] == NULL
) {
306 error_set(errp
, QERR_INVALID_PARAMETER
, enum_str
);