]> Git Repo - qemu.git/blame - include/qapi/visitor.h
qmp-input: Refactor when list is advanced
[qemu.git] / include / qapi / visitor.h
CommitLineData
2345c77c
MR
1/*
2 * Core Definitions for QAPI Visitor Classes
3 *
08f9541d 4 * Copyright (C) 2012-2016 Red Hat, Inc.
2345c77c
MR
5 * Copyright IBM, Corp. 2011
6 *
7 * Authors:
8 * Anthony Liguori <[email protected]>
9 *
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.
12 *
13 */
14#ifndef QAPI_VISITOR_CORE_H
15#define QAPI_VISITOR_CORE_H
16
69dd62df 17#include "qapi/qmp/qobject.h"
2345c77c 18
e65d89bf
EB
19/* This struct is layout-compatible with all other *List structs
20 * created by the qapi generator. It is used as a typical
21 * singly-linked list. */
22typedef struct GenericList {
2345c77c 23 struct GenericList *next;
e65d89bf 24 char padding[];
2345c77c
MR
25} GenericList;
26
dbf11922
EB
27/* This struct is layout-compatible with all Alternate types
28 * created by the qapi generator. */
29typedef struct GenericAlternate {
30 QType type;
31 char padding[];
32} GenericAlternate;
33
51e72bc1 34void visit_start_struct(Visitor *v, const char *name, void **obj,
337283df 35 size_t size, Error **errp);
2345c77c 36void visit_end_struct(Visitor *v, Error **errp);
08f9541d 37
2345c77c 38void visit_start_list(Visitor *v, const char *name, Error **errp);
e65d89bf 39GenericList *visit_next_list(Visitor *v, GenericList **list, size_t size);
08f9541d 40void visit_end_list(Visitor *v);
5cdc8831 41
dbf11922
EB
42/*
43 * Start the visit of an alternate @obj with the given @size.
44 *
45 * @name specifies the relationship to the containing struct (ignored
46 * for a top level visit, the name of the key if this alternate is
47 * part of an object, or NULL if this alternate is part of a list).
48 *
49 * @obj must not be NULL. Input visitors will allocate @obj and
50 * determine the qtype of the next thing to be visited, stored in
51 * (*@obj)->type. Other visitors will leave @obj unchanged.
52 *
53 * If @promote_int, treat integers as QTYPE_FLOAT.
54 *
55 * If successful, this must be paired with visit_end_alternate(), even
56 * if visiting the contents of the alternate fails.
57 */
58void visit_start_alternate(Visitor *v, const char *name,
59 GenericAlternate **obj, size_t size,
60 bool promote_int, Error **errp);
61
62/*
63 * Finish visiting an alternate type.
64 *
65 * Must be called after a successful visit_start_alternate(), even if
66 * an error occurred in the meantime.
67 *
68 * TODO: Should all the visit_end_* interfaces take obj parameter, so
69 * that dealloc visitor need not track what was passed in visit_start?
70 */
71void visit_end_alternate(Visitor *v);
72
5cdc8831
EB
73/**
74 * Check if an optional member @name of an object needs visiting.
75 * For input visitors, set *@present according to whether the
76 * corresponding visit_type_*() needs calling; for other visitors,
29637a6e 77 * leave *@present unchanged. Return *@present for convenience.
5cdc8831 78 */
51e72bc1 79bool visit_optional(Visitor *v, const char *name, bool *present);
0426d53c 80
983f52d4
EB
81/*
82 * Visit an enum value.
83 *
84 * @strings expresses the mapping between C enum values and QAPI enum
85 * names; it should be the ENUM_lookup array from visit-types.h.
86 *
87 * May call visit_type_str() under the hood, and the enum visit may
88 * fail even if the corresponding string visit succeeded; this implies
89 * that visit_type_str() must have no unwelcome side effects.
90 */
51e72bc1 91void visit_type_enum(Visitor *v, const char *name, int *obj,
337283df 92 const char *const strings[], Error **errp);
983f52d4 93
51e72bc1
EB
94void visit_type_int(Visitor *v, const char *name, int64_t *obj, Error **errp);
95void visit_type_uint8(Visitor *v, const char *name, uint8_t *obj,
96 Error **errp);
97void visit_type_uint16(Visitor *v, const char *name, uint16_t *obj,
98 Error **errp);
99void visit_type_uint32(Visitor *v, const char *name, uint32_t *obj,
100 Error **errp);
101void visit_type_uint64(Visitor *v, const char *name, uint64_t *obj,
102 Error **errp);
103void visit_type_int8(Visitor *v, const char *name, int8_t *obj, Error **errp);
104void visit_type_int16(Visitor *v, const char *name, int16_t *obj,
105 Error **errp);
106void visit_type_int32(Visitor *v, const char *name, int32_t *obj,
107 Error **errp);
108void visit_type_int64(Visitor *v, const char *name, int64_t *obj,
109 Error **errp);
110void visit_type_size(Visitor *v, const char *name, uint64_t *obj,
111 Error **errp);
112void visit_type_bool(Visitor *v, const char *name, bool *obj, Error **errp);
113void visit_type_str(Visitor *v, const char *name, char **obj, Error **errp);
114void visit_type_number(Visitor *v, const char *name, double *obj,
115 Error **errp);
116void visit_type_any(Visitor *v, const char *name, QObject **obj, Error **errp);
2345c77c
MR
117
118#endif
This page took 0.311541 seconds and 4 git commands to generate.