]> git.proxmox.com Git - mirror_qemu.git/blame - include/qapi/visitor-impl.h
minikconf: do not include variables from MINIKCONF_ARGS in config-all-devices.mak
[mirror_qemu.git] / include / qapi / visitor-impl.h
CommitLineData
0f71a1e0
PB
1/*
2 * Core Definitions for QAPI Visitor implementations
3 *
04e070d2 4 * Copyright (C) 2012-2016 Red Hat, Inc.
0f71a1e0
PB
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
7b1b5d19 15#include "qapi/visitor.h"
0f71a1e0 16
adfb264c
EB
17/*
18 * This file describes the callback interface for implementing a QAPI
19 * visitor. For the client interface, see visitor.h. When
20 * implementing the callbacks, it is easiest to declare a struct with
21 * 'Visitor visitor;' as the first member. A callback's contract
22 * matches the corresponding public functions' contract unless stated
23 * otherwise. In the comments below, some callbacks are marked "must
24 * be set for $TYPE visits to work"; if a visitor implementation omits
25 * that callback, it should also document that it is only useful for a
26 * subset of QAPI.
27 */
28
983f52d4 29/*
a15fcc3c 30 * There are four classes of visitors; setting the class determines
983f52d4 31 * how QAPI enums are visited, as well as what additional restrictions
a15fcc3c
EB
32 * can be asserted. The values are intentionally chosen so as to
33 * permit some assertions based on whether a given bit is set (that
34 * is, some assertions apply to input and clone visitors, some
35 * assertions apply to output and clone visitors).
983f52d4
EB
36 */
37typedef enum VisitorType {
a15fcc3c
EB
38 VISITOR_INPUT = 1,
39 VISITOR_OUTPUT = 2,
40 VISITOR_CLONE = 3,
41 VISITOR_DEALLOC = 4,
983f52d4
EB
42} VisitorType;
43
7edd63f1
PB
44struct Visitor
45{
adfb264c 46 /* Must be set to visit structs */
0b2a0d6b 47 void (*start_struct)(Visitor *v, const char *name, void **obj,
337283df 48 size_t size, Error **errp);
adfb264c 49
15c2f669
EB
50 /* Optional; intended for input visitors */
51 void (*check_struct)(Visitor *v, Error **errp);
52
adfb264c 53 /* Must be set to visit structs */
1158bb2a 54 void (*end_struct)(Visitor *v, void **obj);
7edd63f1 55
d9f62dde
EB
56 /* Must be set; implementations may require @list to be non-null,
57 * but must document it. */
58 void (*start_list)(Visitor *v, const char *name, GenericList **list,
59 size_t size, Error **errp);
adfb264c 60
08f9541d 61 /* Must be set */
d9f62dde 62 GenericList *(*next_list)(Visitor *v, GenericList *tail, size_t size);
adfb264c 63
a4a1c70d
MA
64 /* Optional; intended for input visitors */
65 void (*check_list)(Visitor *v, Error **errp);
66
08f9541d 67 /* Must be set */
1158bb2a 68 void (*end_list)(Visitor *v, void **list);
7edd63f1 69
adfb264c
EB
70 /* Must be set by input and dealloc visitors to visit alternates;
71 * optional for output visitors. */
dbf11922
EB
72 void (*start_alternate)(Visitor *v, const char *name,
73 GenericAlternate **obj, size_t size,
60390d2d 74 Error **errp);
dbf11922 75
adfb264c 76 /* Optional, needed for dealloc visitor */
1158bb2a 77 void (*end_alternate)(Visitor *v, void **obj);
dbf11922 78
adfb264c 79 /* Must be set */
0b2a0d6b 80 void (*type_int64)(Visitor *v, const char *name, int64_t *obj,
4c40314a 81 Error **errp);
adfb264c
EB
82
83 /* Must be set */
0b2a0d6b 84 void (*type_uint64)(Visitor *v, const char *name, uint64_t *obj,
f755dea7 85 Error **errp);
adfb264c
EB
86
87 /* Optional; fallback is type_uint64() */
0b2a0d6b 88 void (*type_size)(Visitor *v, const char *name, uint64_t *obj,
f755dea7 89 Error **errp);
adfb264c
EB
90
91 /* Must be set */
0b2a0d6b 92 void (*type_bool)(Visitor *v, const char *name, bool *obj, Error **errp);
adfb264c
EB
93
94 /* Must be set */
0b2a0d6b 95 void (*type_str)(Visitor *v, const char *name, char **obj, Error **errp);
adfb264c
EB
96
97 /* Must be set to visit numbers */
0b2a0d6b 98 void (*type_number)(Visitor *v, const char *name, double *obj,
7edd63f1 99 Error **errp);
adfb264c
EB
100
101 /* Must be set to visit arbitrary QTypes */
0b2a0d6b 102 void (*type_any)(Visitor *v, const char *name, QObject **obj,
28770e05 103 Error **errp);
7edd63f1 104
3bc97fd5 105 /* Must be set to visit explicit null values. */
d2f95f4d
MA
106 void (*type_null)(Visitor *v, const char *name, QNull **obj,
107 Error **errp);
3bc97fd5 108
a8aec6de
MA
109 /* Must be set for input visitors to visit structs, optional otherwise.
110 The core takes care of the return type in the public interface. */
0b2a0d6b 111 void (*optional)(Visitor *v, const char *name, bool *present);
7edd63f1 112
983f52d4
EB
113 /* Must be set */
114 VisitorType type;
2c0ef9f4 115
3b098d56
EB
116 /* Must be set for output visitors, optional otherwise. */
117 void (*complete)(Visitor *v, void *opaque);
118
2c0ef9f4
EB
119 /* Must be set */
120 void (*free)(Visitor *v);
983f52d4 121};
0f71a1e0
PB
122
123#endif