19e7dac7cSPeter Lieven /* 29e7dac7cSPeter Lieven * QAPI util functions 39e7dac7cSPeter Lieven * 49e7dac7cSPeter Lieven * Copyright Fujitsu, Inc. 2014 59e7dac7cSPeter Lieven * 69e7dac7cSPeter Lieven * This work is licensed under the terms of the GNU LGPL, version 2.1 or later. 79e7dac7cSPeter Lieven * See the COPYING.LIB file in the top-level directory. 89e7dac7cSPeter Lieven * 99e7dac7cSPeter Lieven */ 109e7dac7cSPeter Lieven 119e7dac7cSPeter Lieven #ifndef QAPI_UTIL_H 129e7dac7cSPeter Lieven #define QAPI_UTIL_H 139e7dac7cSPeter Lieven 14*c67db1edSMarkus Armbruster typedef enum { 15*c67db1edSMarkus Armbruster QAPI_DEPRECATED, 16*c67db1edSMarkus Armbruster } QapiSpecialFeature; 17*c67db1edSMarkus Armbruster 18aa237044SMarkus Armbruster /* QEnumLookup flags */ 19aa237044SMarkus Armbruster #define QAPI_ENUM_DEPRECATED 1 20aa237044SMarkus Armbruster 21f7abe0ecSMarc-André Lureau typedef struct QEnumLookup { 22f7abe0ecSMarc-André Lureau const char *const *array; 23aa237044SMarkus Armbruster const unsigned char *const flags; 24aa237044SMarkus Armbruster const int size; 25f7abe0ecSMarc-André Lureau } QEnumLookup; 26f7abe0ecSMarc-André Lureau 27f7abe0ecSMarc-André Lureau const char *qapi_enum_lookup(const QEnumLookup *lookup, int val); 28f7abe0ecSMarc-André Lureau int qapi_enum_parse(const QEnumLookup *lookup, const char *buf, 2906c60b6cSMarkus Armbruster int def, Error **errp); 30372bcb25SPaolo Bonzini bool qapi_bool_parse(const char *name, const char *value, bool *obj, 31372bcb25SPaolo Bonzini Error **errp); 329e7dac7cSPeter Lieven 33069b64e3SMarkus Armbruster int parse_qapi_name(const char *name, bool complete); 34069b64e3SMarkus Armbruster 359812e712SEric Blake /* 369812e712SEric Blake * For any GenericList @list, insert @element at the front. 379812e712SEric Blake * 389812e712SEric Blake * Note that this macro evaluates @element exactly once, so it is safe 399812e712SEric Blake * to have side-effects with that argument. 409812e712SEric Blake */ 419812e712SEric Blake #define QAPI_LIST_PREPEND(list, element) do { \ 429812e712SEric Blake typeof(list) _tmp = g_malloc(sizeof(*(list))); \ 439812e712SEric Blake _tmp->value = (element); \ 449812e712SEric Blake _tmp->next = (list); \ 459812e712SEric Blake (list) = _tmp; \ 469812e712SEric Blake } while (0) 479812e712SEric Blake 48dc13f40cSEric Blake /* 49dc13f40cSEric Blake * For any pointer to a GenericList @tail (usually the 'next' member of a 50dc13f40cSEric Blake * list element), insert @element at the back and update the tail. 51dc13f40cSEric Blake * 52dc13f40cSEric Blake * Note that this macro evaluates @element exactly once, so it is safe 53dc13f40cSEric Blake * to have side-effects with that argument. 54dc13f40cSEric Blake */ 55dc13f40cSEric Blake #define QAPI_LIST_APPEND(tail, element) do { \ 56dc13f40cSEric Blake *(tail) = g_malloc0(sizeof(**(tail))); \ 57dc13f40cSEric Blake (*(tail))->value = (element); \ 58dc13f40cSEric Blake (tail) = &(*(tail))->next; \ 59dc13f40cSEric Blake } while (0) 60dc13f40cSEric Blake 619e7dac7cSPeter Lieven #endif 62