qapi: Change visit_start_implicit_struct to visit_start_alternate
[qemu/kevin.git] / include / qapi / visitor.h
blob83cad74c88498714384de05c730a332732c22164
1 /*
2 * Core Definitions for QAPI Visitor Classes
4 * Copyright (C) 2012-2016 Red Hat, Inc.
5 * Copyright IBM, Corp. 2011
7 * Authors:
8 * Anthony Liguori <aliguori@us.ibm.com>
10 * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
11 * See the COPYING.LIB file in the top-level directory.
14 #ifndef QAPI_VISITOR_CORE_H
15 #define QAPI_VISITOR_CORE_H
17 #include "qemu/typedefs.h"
18 #include "qapi/qmp/qobject.h"
19 #include "qapi/error.h"
20 #include <stdlib.h>
22 /* This struct is layout-compatible with all other *List structs
23 * created by the qapi generator. It is used as a typical
24 * singly-linked list. */
25 typedef struct GenericList {
26 struct GenericList *next;
27 char padding[];
28 } GenericList;
30 /* This struct is layout-compatible with all Alternate types
31 * created by the qapi generator. */
32 typedef struct GenericAlternate {
33 QType type;
34 char padding[];
35 } GenericAlternate;
37 void visit_start_struct(Visitor *v, const char *name, void **obj,
38 size_t size, Error **errp);
39 void visit_end_struct(Visitor *v, Error **errp);
41 void visit_start_list(Visitor *v, const char *name, Error **errp);
42 GenericList *visit_next_list(Visitor *v, GenericList **list, size_t size);
43 void visit_end_list(Visitor *v);
46 * Start the visit of an alternate @obj with the given @size.
48 * @name specifies the relationship to the containing struct (ignored
49 * for a top level visit, the name of the key if this alternate is
50 * part of an object, or NULL if this alternate is part of a list).
52 * @obj must not be NULL. Input visitors will allocate @obj and
53 * determine the qtype of the next thing to be visited, stored in
54 * (*@obj)->type. Other visitors will leave @obj unchanged.
56 * If @promote_int, treat integers as QTYPE_FLOAT.
58 * If successful, this must be paired with visit_end_alternate(), even
59 * if visiting the contents of the alternate fails.
61 void visit_start_alternate(Visitor *v, const char *name,
62 GenericAlternate **obj, size_t size,
63 bool promote_int, Error **errp);
66 * Finish visiting an alternate type.
68 * Must be called after a successful visit_start_alternate(), even if
69 * an error occurred in the meantime.
71 * TODO: Should all the visit_end_* interfaces take obj parameter, so
72 * that dealloc visitor need not track what was passed in visit_start?
74 void visit_end_alternate(Visitor *v);
76 /**
77 * Check if an optional member @name of an object needs visiting.
78 * For input visitors, set *@present according to whether the
79 * corresponding visit_type_*() needs calling; for other visitors,
80 * leave *@present unchanged. Return *@present for convenience.
82 bool visit_optional(Visitor *v, const char *name, bool *present);
84 void visit_type_enum(Visitor *v, const char *name, int *obj,
85 const char *const strings[], Error **errp);
86 void visit_type_int(Visitor *v, const char *name, int64_t *obj, Error **errp);
87 void visit_type_uint8(Visitor *v, const char *name, uint8_t *obj,
88 Error **errp);
89 void visit_type_uint16(Visitor *v, const char *name, uint16_t *obj,
90 Error **errp);
91 void visit_type_uint32(Visitor *v, const char *name, uint32_t *obj,
92 Error **errp);
93 void visit_type_uint64(Visitor *v, const char *name, uint64_t *obj,
94 Error **errp);
95 void visit_type_int8(Visitor *v, const char *name, int8_t *obj, Error **errp);
96 void visit_type_int16(Visitor *v, const char *name, int16_t *obj,
97 Error **errp);
98 void visit_type_int32(Visitor *v, const char *name, int32_t *obj,
99 Error **errp);
100 void visit_type_int64(Visitor *v, const char *name, int64_t *obj,
101 Error **errp);
102 void visit_type_size(Visitor *v, const char *name, uint64_t *obj,
103 Error **errp);
104 void visit_type_bool(Visitor *v, const char *name, bool *obj, Error **errp);
105 void visit_type_str(Visitor *v, const char *name, char **obj, Error **errp);
106 void visit_type_number(Visitor *v, const char *name, double *obj,
107 Error **errp);
108 void visit_type_any(Visitor *v, const char *name, QObject **obj, Error **errp);
110 #endif