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 v
->start_struct(v
, obj
, kind
, name
, size
, errp
);
26 void visit_end_struct(Visitor
*v
, Error
**errp
)
28 v
->end_struct(v
, errp
);
31 void visit_start_implicit_struct(Visitor
*v
, void **obj
, size_t size
,
34 if (v
->start_implicit_struct
) {
35 v
->start_implicit_struct(v
, obj
, size
, errp
);
39 void visit_end_implicit_struct(Visitor
*v
, Error
**errp
)
41 if (v
->end_implicit_struct
) {
42 v
->end_implicit_struct(v
, errp
);
46 void visit_start_list(Visitor
*v
, const char *name
, Error
**errp
)
48 v
->start_list(v
, name
, errp
);
51 GenericList
*visit_next_list(Visitor
*v
, GenericList
**list
, Error
**errp
)
53 return v
->next_list(v
, list
, errp
);
56 void visit_end_list(Visitor
*v
, Error
**errp
)
61 bool visit_start_union(Visitor
*v
, bool data_present
, Error
**errp
)
64 return v
->start_union(v
, data_present
, errp
);
69 void visit_end_union(Visitor
*v
, bool data_present
, Error
**errp
)
72 v
->end_union(v
, data_present
, errp
);
76 bool visit_optional(Visitor
*v
, bool *present
, const char *name
)
79 v
->optional(v
, present
, name
);
84 void visit_get_next_type(Visitor
*v
, QType
*type
, bool promote_int
,
85 const char *name
, Error
**errp
)
87 if (v
->get_next_type
) {
88 v
->get_next_type(v
, type
, promote_int
, name
, errp
);
92 void visit_type_enum(Visitor
*v
, int *obj
, const char * const strings
[],
93 const char *kind
, const char *name
, Error
**errp
)
95 v
->type_enum(v
, obj
, strings
, kind
, name
, errp
);
98 void visit_type_int(Visitor
*v
, int64_t *obj
, const char *name
, Error
**errp
)
100 v
->type_int(v
, obj
, name
, errp
);
103 void visit_type_uint8(Visitor
*v
, uint8_t *obj
, const char *name
, Error
**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_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
114 name
? name
: "null", "uint8_t");
121 void visit_type_uint16(Visitor
*v
, uint16_t *obj
, const char *name
, Error
**errp
)
125 if (v
->type_uint16
) {
126 v
->type_uint16(v
, obj
, name
, errp
);
129 v
->type_int(v
, &value
, name
, errp
);
130 if (value
< 0 || value
> UINT16_MAX
) {
131 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
132 name
? name
: "null", "uint16_t");
139 void visit_type_uint32(Visitor
*v
, uint32_t *obj
, const char *name
, Error
**errp
)
143 if (v
->type_uint32
) {
144 v
->type_uint32(v
, obj
, name
, errp
);
147 v
->type_int(v
, &value
, name
, errp
);
148 if (value
< 0 || value
> UINT32_MAX
) {
149 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
150 name
? name
: "null", "uint32_t");
157 void visit_type_uint64(Visitor
*v
, uint64_t *obj
, const char *name
, Error
**errp
)
161 if (v
->type_uint64
) {
162 v
->type_uint64(v
, obj
, name
, errp
);
165 v
->type_int(v
, &value
, name
, errp
);
170 void visit_type_int8(Visitor
*v
, int8_t *obj
, const char *name
, Error
**errp
)
175 v
->type_int8(v
, obj
, name
, errp
);
178 v
->type_int(v
, &value
, name
, errp
);
179 if (value
< INT8_MIN
|| value
> INT8_MAX
) {
180 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
181 name
? name
: "null", "int8_t");
188 void visit_type_int16(Visitor
*v
, int16_t *obj
, const char *name
, Error
**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_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
199 name
? name
: "null", "int16_t");
206 void visit_type_int32(Visitor
*v
, int32_t *obj
, const char *name
, Error
**errp
)
211 v
->type_int32(v
, obj
, name
, errp
);
214 v
->type_int(v
, &value
, name
, errp
);
215 if (value
< INT32_MIN
|| value
> INT32_MAX
) {
216 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
217 name
? name
: "null", "int32_t");
224 void visit_type_int64(Visitor
*v
, int64_t *obj
, const char *name
, Error
**errp
)
227 v
->type_int64(v
, obj
, name
, errp
);
229 v
->type_int(v
, obj
, name
, errp
);
233 void visit_type_size(Visitor
*v
, uint64_t *obj
, const char *name
, Error
**errp
)
238 v
->type_size(v
, obj
, name
, errp
);
239 } else if (v
->type_uint64
) {
240 v
->type_uint64(v
, obj
, name
, errp
);
243 v
->type_int(v
, &value
, name
, errp
);
248 void visit_type_bool(Visitor
*v
, bool *obj
, const char *name
, Error
**errp
)
250 v
->type_bool(v
, obj
, name
, errp
);
253 void visit_type_str(Visitor
*v
, char **obj
, const char *name
, Error
**errp
)
255 v
->type_str(v
, obj
, name
, errp
);
258 void visit_type_number(Visitor
*v
, double *obj
, const char *name
, Error
**errp
)
260 v
->type_number(v
, obj
, name
, errp
);
263 void visit_type_any(Visitor
*v
, QObject
**obj
, const char *name
,
266 v
->type_any(v
, obj
, name
, errp
);
269 void output_type_enum(Visitor
*v
, int *obj
, const char * const strings
[],
270 const char *kind
, const char *name
,
278 while (strings
[i
++] != NULL
);
279 if (value
< 0 || value
>= i
- 1) {
280 error_setg(errp
, QERR_INVALID_PARAMETER
, name
? name
: "null");
284 enum_str
= (char *)strings
[value
];
285 visit_type_str(v
, &enum_str
, name
, errp
);
288 void input_type_enum(Visitor
*v
, int *obj
, const char * const strings
[],
289 const char *kind
, const char *name
,
292 Error
*local_err
= NULL
;
298 visit_type_str(v
, &enum_str
, name
, &local_err
);
300 error_propagate(errp
, local_err
);
304 while (strings
[value
] != NULL
) {
305 if (strcmp(strings
[value
], enum_str
) == 0) {
311 if (strings
[value
] == NULL
) {
312 error_setg(errp
, QERR_INVALID_PARAMETER
, enum_str
);