xref: /openbmc/qemu/include/qapi/visitor-impl.h (revision d00341af)
1 /*
2  * Core Definitions for QAPI Visitor implementations
3  *
4  * Copyright (C) 2012 Red Hat, Inc.
5  *
6  * Author: Paolo Bonizni <pbonzini@redhat.com>
7  *
8  * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
9  * See the COPYING.LIB file in the top-level directory.
10  *
11  */
12 #ifndef QAPI_VISITOR_IMPL_H
13 #define QAPI_VISITOR_IMPL_H
14 
15 #include "qapi/error.h"
16 #include "qapi/visitor.h"
17 
18 struct Visitor
19 {
20     /* Must be set */
21     void (*start_struct)(Visitor *v, void **obj, const char *kind,
22                          const char *name, size_t size, Error **errp);
23     void (*end_struct)(Visitor *v, Error **errp);
24 
25     void (*start_implicit_struct)(Visitor *v, void **obj, size_t size,
26                                   Error **errp);
27     void (*end_implicit_struct)(Visitor *v, Error **errp);
28 
29     void (*start_list)(Visitor *v, const char *name, Error **errp);
30     GenericList *(*next_list)(Visitor *v, GenericList **list, Error **errp);
31     void (*end_list)(Visitor *v, Error **errp);
32 
33     void (*type_enum)(Visitor *v, int *obj, const char * const strings[],
34                       const char *kind, const char *name, Error **errp);
35     /* May be NULL; only needed for input visitors. */
36     void (*get_next_type)(Visitor *v, QType *type, bool promote_int,
37                           const char *name, Error **errp);
38 
39     void (*type_int)(Visitor *v, int64_t *obj, const char *name, Error **errp);
40     void (*type_bool)(Visitor *v, bool *obj, const char *name, Error **errp);
41     void (*type_str)(Visitor *v, char **obj, const char *name, Error **errp);
42     void (*type_number)(Visitor *v, double *obj, const char *name,
43                         Error **errp);
44     void (*type_any)(Visitor *v, QObject **obj, const char *name,
45                      Error **errp);
46 
47     /* May be NULL */
48     void (*optional)(Visitor *v, bool *present, const char *name,
49                      Error **errp);
50 
51     void (*type_uint8)(Visitor *v, uint8_t *obj, const char *name, Error **errp);
52     void (*type_uint16)(Visitor *v, uint16_t *obj, const char *name, Error **errp);
53     void (*type_uint32)(Visitor *v, uint32_t *obj, const char *name, Error **errp);
54     void (*type_uint64)(Visitor *v, uint64_t *obj, const char *name, Error **errp);
55     void (*type_int8)(Visitor *v, int8_t *obj, const char *name, Error **errp);
56     void (*type_int16)(Visitor *v, int16_t *obj, const char *name, Error **errp);
57     void (*type_int32)(Visitor *v, int32_t *obj, const char *name, Error **errp);
58     void (*type_int64)(Visitor *v, int64_t *obj, const char *name, Error **errp);
59     /* visit_type_size() falls back to (*type_uint64)() if type_size is unset */
60     void (*type_size)(Visitor *v, uint64_t *obj, const char *name, Error **errp);
61     bool (*start_union)(Visitor *v, bool data_present, Error **errp);
62     void (*end_union)(Visitor *v, bool data_present, Error **errp);
63 };
64 
65 void input_type_enum(Visitor *v, int *obj, const char * const strings[],
66                      const char *kind, const char *name, Error **errp);
67 void output_type_enum(Visitor *v, int *obj, const char * const strings[],
68                       const char *kind, const char *name, Error **errp);
69 
70 #endif
71