xref: /openbmc/qemu/include/qapi/visitor-impl.h (revision 51e72bc1)
1 /*
2  * Core Definitions for QAPI Visitor implementations
3  *
4  * Copyright (C) 2012-2016 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     /* Must be set. */
40     void (*type_int64)(Visitor *v, int64_t *obj, const char *name,
41                        Error **errp);
42     /* Must be set. */
43     void (*type_uint64)(Visitor *v, uint64_t *obj, const char *name,
44                         Error **errp);
45     /* Optional; fallback is type_uint64().  */
46     void (*type_size)(Visitor *v, uint64_t *obj, const char *name,
47                       Error **errp);
48     /* Must be set. */
49     void (*type_bool)(Visitor *v, bool *obj, const char *name, Error **errp);
50     void (*type_str)(Visitor *v, char **obj, const char *name, Error **errp);
51     void (*type_number)(Visitor *v, double *obj, const char *name,
52                         Error **errp);
53     void (*type_any)(Visitor *v, QObject **obj, const char *name,
54                      Error **errp);
55 
56     /* May be NULL; most useful for input visitors. */
57     void (*optional)(Visitor *v, bool *present, const char *name);
58 
59     bool (*start_union)(Visitor *v, bool data_present, Error **errp);
60 };
61 
62 void input_type_enum(Visitor *v, int *obj, const char * const strings[],
63                      const char *kind, const char *name, Error **errp);
64 void output_type_enum(Visitor *v, int *obj, const char * const strings[],
65                       const char *kind, const char *name, Error **errp);
66 
67 #endif
68