1 /* 2 * QAPI util functions 3 * 4 * Copyright Fujitsu, Inc. 2014 5 * 6 * This work is licensed under the terms of the GNU LGPL, version 2.1 or later. 7 * See the COPYING.LIB file in the top-level directory. 8 * 9 */ 10 11 #ifndef QAPI_UTIL_H 12 #define QAPI_UTIL_H 13 14 typedef enum { 15 QAPI_DEPRECATED, 16 } QapiSpecialFeature; 17 18 /* QEnumLookup flags */ 19 #define QAPI_ENUM_DEPRECATED 1 20 21 typedef struct QEnumLookup { 22 const char *const *array; 23 const unsigned char *const flags; 24 const int size; 25 } QEnumLookup; 26 27 const char *qapi_enum_lookup(const QEnumLookup *lookup, int val); 28 int qapi_enum_parse(const QEnumLookup *lookup, const char *buf, 29 int def, Error **errp); 30 bool qapi_bool_parse(const char *name, const char *value, bool *obj, 31 Error **errp); 32 33 int parse_qapi_name(const char *name, bool complete); 34 35 /* 36 * For any GenericList @list, insert @element at the front. 37 * 38 * Note that this macro evaluates @element exactly once, so it is safe 39 * to have side-effects with that argument. 40 */ 41 #define QAPI_LIST_PREPEND(list, element) do { \ 42 typeof(list) _tmp = g_malloc(sizeof(*(list))); \ 43 _tmp->value = (element); \ 44 _tmp->next = (list); \ 45 (list) = _tmp; \ 46 } while (0) 47 48 /* 49 * For any pointer to a GenericList @tail (usually the 'next' member of a 50 * list element), insert @element at the back and update the tail. 51 * 52 * Note that this macro evaluates @element exactly once, so it is safe 53 * to have side-effects with that argument. 54 */ 55 #define QAPI_LIST_APPEND(tail, element) do { \ 56 *(tail) = g_malloc0(sizeof(**(tail))); \ 57 (*(tail))->value = (element); \ 58 (tail) = &(*(tail))->next; \ 59 } while (0) 60 61 #endif 62