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 14f7abe0ecSMarc-André Lureau typedef struct QEnumLookup { 15f7abe0ecSMarc-André Lureau const char *const *array; 16f7abe0ecSMarc-André Lureau int size; 17f7abe0ecSMarc-André Lureau } QEnumLookup; 18f7abe0ecSMarc-André Lureau 19f7abe0ecSMarc-André Lureau const char *qapi_enum_lookup(const QEnumLookup *lookup, int val); 20f7abe0ecSMarc-André Lureau int qapi_enum_parse(const QEnumLookup *lookup, const char *buf, 2106c60b6cSMarkus Armbruster int def, Error **errp); 22*372bcb25SPaolo Bonzini bool qapi_bool_parse(const char *name, const char *value, bool *obj, 23*372bcb25SPaolo Bonzini Error **errp); 249e7dac7cSPeter Lieven 25069b64e3SMarkus Armbruster int parse_qapi_name(const char *name, bool complete); 26069b64e3SMarkus Armbruster 279812e712SEric Blake /* 289812e712SEric Blake * For any GenericList @list, insert @element at the front. 299812e712SEric Blake * 309812e712SEric Blake * Note that this macro evaluates @element exactly once, so it is safe 319812e712SEric Blake * to have side-effects with that argument. 329812e712SEric Blake */ 339812e712SEric Blake #define QAPI_LIST_PREPEND(list, element) do { \ 349812e712SEric Blake typeof(list) _tmp = g_malloc(sizeof(*(list))); \ 359812e712SEric Blake _tmp->value = (element); \ 369812e712SEric Blake _tmp->next = (list); \ 379812e712SEric Blake (list) = _tmp; \ 389812e712SEric Blake } while (0) 399812e712SEric Blake 409e7dac7cSPeter Lieven #endif 41