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/visitor.h" 16 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 29 /* 30 * There are three classes of visitors; setting the class determines 31 * how QAPI enums are visited, as well as what additional restrictions 32 * can be asserted. 33 */ 34 typedef enum VisitorType { 35 VISITOR_INPUT, 36 VISITOR_OUTPUT, 37 VISITOR_DEALLOC, 38 } VisitorType; 39 40 struct Visitor 41 { 42 /* Must be set to visit structs */ 43 void (*start_struct)(Visitor *v, const char *name, void **obj, 44 size_t size, Error **errp); 45 46 /* Must be set to visit structs */ 47 void (*end_struct)(Visitor *v, Error **errp); 48 49 /* Must be set */ 50 void (*start_list)(Visitor *v, const char *name, Error **errp); 51 52 /* Must be set */ 53 GenericList *(*next_list)(Visitor *v, GenericList **list, size_t size); 54 55 /* Must be set */ 56 void (*end_list)(Visitor *v); 57 58 /* Must be set by input and dealloc visitors to visit alternates; 59 * optional for output visitors. */ 60 void (*start_alternate)(Visitor *v, const char *name, 61 GenericAlternate **obj, size_t size, 62 bool promote_int, Error **errp); 63 64 /* Optional, needed for dealloc visitor */ 65 void (*end_alternate)(Visitor *v); 66 67 /* Must be set */ 68 void (*type_int64)(Visitor *v, const char *name, int64_t *obj, 69 Error **errp); 70 71 /* Must be set */ 72 void (*type_uint64)(Visitor *v, const char *name, uint64_t *obj, 73 Error **errp); 74 75 /* Optional; fallback is type_uint64() */ 76 void (*type_size)(Visitor *v, const char *name, uint64_t *obj, 77 Error **errp); 78 79 /* Must be set */ 80 void (*type_bool)(Visitor *v, const char *name, bool *obj, Error **errp); 81 82 /* Must be set */ 83 void (*type_str)(Visitor *v, const char *name, char **obj, Error **errp); 84 85 /* Must be set to visit numbers */ 86 void (*type_number)(Visitor *v, const char *name, double *obj, 87 Error **errp); 88 89 /* Must be set to visit arbitrary QTypes */ 90 void (*type_any)(Visitor *v, const char *name, QObject **obj, 91 Error **errp); 92 93 /* Must be set for input visitors, optional otherwise. The core 94 * takes care of the return type in the public interface. */ 95 void (*optional)(Visitor *v, const char *name, bool *present); 96 97 /* Must be set */ 98 VisitorType type; 99 }; 100 101 #endif 102