Peter Lieven | 9e7dac7 | 2014-08-13 19:20:17 +0200 | [diff] [blame] | 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 | |
Marc-André Lureau | f7abe0e | 2017-08-24 10:46:10 +0200 | [diff] [blame] | 14 | typedef struct QEnumLookup { |
| 15 | const char *const *array; |
| 16 | int size; |
| 17 | } QEnumLookup; |
| 18 | |
| 19 | const char *qapi_enum_lookup(const QEnumLookup *lookup, int val); |
| 20 | int qapi_enum_parse(const QEnumLookup *lookup, const char *buf, |
Markus Armbruster | 06c60b6 | 2017-08-24 10:45:57 +0200 | [diff] [blame] | 21 | int def, Error **errp); |
Paolo Bonzini | 372bcb2 | 2020-11-03 11:13:39 -0500 | [diff] [blame] | 22 | bool qapi_bool_parse(const char *name, const char *value, bool *obj, |
| 23 | Error **errp); |
Peter Lieven | 9e7dac7 | 2014-08-13 19:20:17 +0200 | [diff] [blame] | 24 | |
Markus Armbruster | 069b64e | 2017-02-28 22:27:04 +0100 | [diff] [blame] | 25 | int parse_qapi_name(const char *name, bool complete); |
| 26 | |
Eric Blake | 9812e71 | 2020-10-27 00:05:47 -0500 | [diff] [blame] | 27 | /* |
| 28 | * For any GenericList @list, insert @element at the front. |
| 29 | * |
| 30 | * Note that this macro evaluates @element exactly once, so it is safe |
| 31 | * to have side-effects with that argument. |
| 32 | */ |
| 33 | #define QAPI_LIST_PREPEND(list, element) do { \ |
| 34 | typeof(list) _tmp = g_malloc(sizeof(*(list))); \ |
| 35 | _tmp->value = (element); \ |
| 36 | _tmp->next = (list); \ |
| 37 | (list) = _tmp; \ |
| 38 | } while (0) |
| 39 | |
Eric Blake | dc13f40 | 2021-01-13 16:10:11 -0600 | [diff] [blame] | 40 | /* |
| 41 | * For any pointer to a GenericList @tail (usually the 'next' member of a |
| 42 | * list element), insert @element at the back and update the tail. |
| 43 | * |
| 44 | * Note that this macro evaluates @element exactly once, so it is safe |
| 45 | * to have side-effects with that argument. |
| 46 | */ |
| 47 | #define QAPI_LIST_APPEND(tail, element) do { \ |
| 48 | *(tail) = g_malloc0(sizeof(**(tail))); \ |
| 49 | (*(tail))->value = (element); \ |
| 50 | (tail) = &(*(tail))->next; \ |
| 51 | } while (0) |
| 52 | |
Peter Lieven | 9e7dac7 | 2014-08-13 19:20:17 +0200 | [diff] [blame] | 53 | #endif |