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 struct Visitor 18 { 19 /* Must be set */ 20 void (*start_struct)(Visitor *v, const char *name, void **obj, 21 size_t size, Error **errp); 22 void (*end_struct)(Visitor *v, Error **errp); 23 24 void (*start_list)(Visitor *v, const char *name, Error **errp); 25 /* Must be set */ 26 GenericList *(*next_list)(Visitor *v, GenericList **list, size_t size); 27 /* Must be set */ 28 void (*end_list)(Visitor *v); 29 30 /* Optional, needed for input and dealloc visitors. */ 31 void (*start_alternate)(Visitor *v, const char *name, 32 GenericAlternate **obj, size_t size, 33 bool promote_int, Error **errp); 34 35 /* Optional, needed for dealloc visitor. */ 36 void (*end_alternate)(Visitor *v); 37 38 /* Must be set. */ 39 void (*type_enum)(Visitor *v, const char *name, int *obj, 40 const char *const strings[], Error **errp); 41 42 /* Must be set. */ 43 void (*type_int64)(Visitor *v, const char *name, int64_t *obj, 44 Error **errp); 45 /* Must be set. */ 46 void (*type_uint64)(Visitor *v, const char *name, uint64_t *obj, 47 Error **errp); 48 /* Optional; fallback is type_uint64(). */ 49 void (*type_size)(Visitor *v, const char *name, uint64_t *obj, 50 Error **errp); 51 /* Must be set. */ 52 void (*type_bool)(Visitor *v, const char *name, bool *obj, Error **errp); 53 void (*type_str)(Visitor *v, const char *name, char **obj, Error **errp); 54 void (*type_number)(Visitor *v, const char *name, double *obj, 55 Error **errp); 56 void (*type_any)(Visitor *v, const char *name, QObject **obj, 57 Error **errp); 58 59 /* May be NULL; most useful for input visitors. */ 60 void (*optional)(Visitor *v, const char *name, bool *present); 61 }; 62 63 void input_type_enum(Visitor *v, const char *name, int *obj, 64 const char *const strings[], Error **errp); 65 void output_type_enum(Visitor *v, const char *name, int *obj, 66 const char *const strings[], Error **errp); 67 68 #endif 69