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