Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Core Definitions for QAPI/QMP Command Registry |
| 3 | * |
Eric Blake | 08f9541 | 2016-01-29 06:48:59 -0700 | [diff] [blame] | 4 | * Copyright (C) 2012-2016 Red Hat, Inc. |
Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 5 | * Copyright IBM, Corp. 2011 |
| 6 | * |
| 7 | * Authors: |
| 8 | * Anthony Liguori <aliguori@us.ibm.com> |
| 9 | * |
| 10 | * This work is licensed under the terms of the GNU LGPL, version 2.1 or later. |
| 11 | * See the COPYING.LIB file in the top-level directory. |
| 12 | * |
| 13 | */ |
| 14 | |
Peter Maydell | cbf2115 | 2016-01-29 17:49:57 +0000 | [diff] [blame] | 15 | #include "qemu/osdep.h" |
Daniel P. Berrange | b3db211 | 2016-09-30 15:45:27 +0100 | [diff] [blame] | 16 | #include "qapi/qobject-output-visitor.h" |
Paolo Bonzini | 7b1b5d1 | 2012-12-17 18:19:43 +0100 | [diff] [blame] | 17 | #include "qapi/visitor-impl.h" |
Paolo Bonzini | 1de7afc | 2012-12-17 18:20:00 +0100 | [diff] [blame] | 18 | #include "qemu/queue.h" |
Markus Armbruster | 6b67395 | 2018-02-01 12:18:35 +0100 | [diff] [blame] | 19 | #include "qapi/qmp/qbool.h" |
Markus Armbruster | 452fcdb | 2018-02-01 12:18:39 +0100 | [diff] [blame] | 20 | #include "qapi/qmp/qdict.h" |
Markus Armbruster | 47e6b29 | 2018-02-01 12:18:38 +0100 | [diff] [blame] | 21 | #include "qapi/qmp/qlist.h" |
Markus Armbruster | 15280c3 | 2018-02-01 12:18:36 +0100 | [diff] [blame] | 22 | #include "qapi/qmp/qnull.h" |
| 23 | #include "qapi/qmp/qnum.h" |
Markus Armbruster | 6b67395 | 2018-02-01 12:18:35 +0100 | [diff] [blame] | 24 | #include "qapi/qmp/qstring.h" |
Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 25 | |
Daniel P. Berrange | 7d5e199 | 2016-09-30 15:45:28 +0100 | [diff] [blame] | 26 | typedef struct QStackEntry { |
Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 27 | QObject *value; |
Eric Blake | 1158bb2 | 2016-06-09 10:48:34 -0600 | [diff] [blame] | 28 | void *qapi; /* sanity check that caller uses same pointer */ |
Paolo Bonzini | fc76ae8 | 2016-07-07 17:53:17 +0200 | [diff] [blame] | 29 | QSLIST_ENTRY(QStackEntry) node; |
Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 30 | } QStackEntry; |
| 31 | |
Daniel P. Berrange | 7d5e199 | 2016-09-30 15:45:28 +0100 | [diff] [blame] | 32 | struct QObjectOutputVisitor { |
Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 33 | Visitor visitor; |
Paolo Bonzini | fc76ae8 | 2016-07-07 17:53:17 +0200 | [diff] [blame] | 34 | QSLIST_HEAD(, QStackEntry) stack; /* Stack of unfinished containers */ |
Eric Blake | 455ba08 | 2016-01-29 06:49:01 -0700 | [diff] [blame] | 35 | QObject *root; /* Root of the output visit */ |
Eric Blake | 3b098d5 | 2016-06-09 10:48:43 -0600 | [diff] [blame] | 36 | QObject **result; /* User's storage location for result */ |
Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 37 | }; |
| 38 | |
Daniel P. Berrange | 7d5e199 | 2016-09-30 15:45:28 +0100 | [diff] [blame] | 39 | #define qobject_output_add(qov, name, value) \ |
| 40 | qobject_output_add_obj(qov, name, QOBJECT(value)) |
| 41 | #define qobject_output_push(qov, value, qapi) \ |
| 42 | qobject_output_push_obj(qov, QOBJECT(value), qapi) |
Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 43 | |
Daniel P. Berrange | 7d5e199 | 2016-09-30 15:45:28 +0100 | [diff] [blame] | 44 | static QObjectOutputVisitor *to_qov(Visitor *v) |
Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 45 | { |
Daniel P. Berrange | 7d5e199 | 2016-09-30 15:45:28 +0100 | [diff] [blame] | 46 | return container_of(v, QObjectOutputVisitor, visitor); |
Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 47 | } |
| 48 | |
Eric Blake | a861564 | 2016-01-29 06:49:00 -0700 | [diff] [blame] | 49 | /* Push @value onto the stack of current QObjects being built */ |
Daniel P. Berrange | 7d5e199 | 2016-09-30 15:45:28 +0100 | [diff] [blame] | 50 | static void qobject_output_push_obj(QObjectOutputVisitor *qov, QObject *value, |
| 51 | void *qapi) |
Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 52 | { |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 53 | QStackEntry *e = g_malloc0(sizeof(*e)); |
Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 54 | |
Eric Blake | 455ba08 | 2016-01-29 06:49:01 -0700 | [diff] [blame] | 55 | assert(qov->root); |
Eric Blake | a861564 | 2016-01-29 06:49:00 -0700 | [diff] [blame] | 56 | assert(value); |
Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 57 | e->value = value; |
Eric Blake | 1158bb2 | 2016-06-09 10:48:34 -0600 | [diff] [blame] | 58 | e->qapi = qapi; |
Paolo Bonzini | fc76ae8 | 2016-07-07 17:53:17 +0200 | [diff] [blame] | 59 | QSLIST_INSERT_HEAD(&qov->stack, e, node); |
Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 60 | } |
| 61 | |
Eric Blake | a861564 | 2016-01-29 06:49:00 -0700 | [diff] [blame] | 62 | /* Pop a value off the stack of QObjects being built, and return it. */ |
Daniel P. Berrange | 7d5e199 | 2016-09-30 15:45:28 +0100 | [diff] [blame] | 63 | static QObject *qobject_output_pop(QObjectOutputVisitor *qov, void *qapi) |
Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 64 | { |
Paolo Bonzini | fc76ae8 | 2016-07-07 17:53:17 +0200 | [diff] [blame] | 65 | QStackEntry *e = QSLIST_FIRST(&qov->stack); |
Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 66 | QObject *value; |
Eric Blake | a861564 | 2016-01-29 06:49:00 -0700 | [diff] [blame] | 67 | |
| 68 | assert(e); |
Eric Blake | 1158bb2 | 2016-06-09 10:48:34 -0600 | [diff] [blame] | 69 | assert(e->qapi == qapi); |
Paolo Bonzini | fc76ae8 | 2016-07-07 17:53:17 +0200 | [diff] [blame] | 70 | QSLIST_REMOVE_HEAD(&qov->stack, node); |
Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 71 | value = e->value; |
Eric Blake | a861564 | 2016-01-29 06:49:00 -0700 | [diff] [blame] | 72 | assert(value); |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 73 | g_free(e); |
Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 74 | return value; |
| 75 | } |
| 76 | |
Eric Blake | a861564 | 2016-01-29 06:49:00 -0700 | [diff] [blame] | 77 | /* Add @value to the current QObject being built. |
| 78 | * If the stack is visiting a dictionary or list, @value is now owned |
| 79 | * by that container. Otherwise, @value is now the root. */ |
Daniel P. Berrange | 7d5e199 | 2016-09-30 15:45:28 +0100 | [diff] [blame] | 80 | static void qobject_output_add_obj(QObjectOutputVisitor *qov, const char *name, |
| 81 | QObject *value) |
Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 82 | { |
Paolo Bonzini | fc76ae8 | 2016-07-07 17:53:17 +0200 | [diff] [blame] | 83 | QStackEntry *e = QSLIST_FIRST(&qov->stack); |
Eric Blake | 455ba08 | 2016-01-29 06:49:01 -0700 | [diff] [blame] | 84 | QObject *cur = e ? e->value : NULL; |
Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 85 | |
Eric Blake | 455ba08 | 2016-01-29 06:49:01 -0700 | [diff] [blame] | 86 | if (!cur) { |
Eric Blake | 56a6f02 | 2016-04-28 15:45:26 -0600 | [diff] [blame] | 87 | /* Don't allow reuse of visitor on more than one root */ |
| 88 | assert(!qov->root); |
Eric Blake | 455ba08 | 2016-01-29 06:49:01 -0700 | [diff] [blame] | 89 | qov->root = value; |
| 90 | } else { |
| 91 | switch (qobject_type(cur)) { |
| 92 | case QTYPE_QDICT: |
| 93 | assert(name); |
Max Reitz | 7dc847e | 2018-02-24 16:40:29 +0100 | [diff] [blame] | 94 | qdict_put_obj(qobject_to(QDict, cur), name, value); |
Eric Blake | 455ba08 | 2016-01-29 06:49:01 -0700 | [diff] [blame] | 95 | break; |
| 96 | case QTYPE_QLIST: |
Eric Blake | 56a6f02 | 2016-04-28 15:45:26 -0600 | [diff] [blame] | 97 | assert(!name); |
Max Reitz | 7dc847e | 2018-02-24 16:40:29 +0100 | [diff] [blame] | 98 | qlist_append_obj(qobject_to(QList, cur), value); |
Eric Blake | 455ba08 | 2016-01-29 06:49:01 -0700 | [diff] [blame] | 99 | break; |
| 100 | default: |
| 101 | g_assert_not_reached(); |
| 102 | } |
Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 103 | } |
| 104 | } |
| 105 | |
Daniel P. Berrange | 7d5e199 | 2016-09-30 15:45:28 +0100 | [diff] [blame] | 106 | static void qobject_output_start_struct(Visitor *v, const char *name, |
| 107 | void **obj, size_t unused, Error **errp) |
Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 108 | { |
Daniel P. Berrange | 7d5e199 | 2016-09-30 15:45:28 +0100 | [diff] [blame] | 109 | QObjectOutputVisitor *qov = to_qov(v); |
Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 110 | QDict *dict = qdict_new(); |
| 111 | |
Daniel P. Berrange | 7d5e199 | 2016-09-30 15:45:28 +0100 | [diff] [blame] | 112 | qobject_output_add(qov, name, dict); |
| 113 | qobject_output_push(qov, dict, obj); |
Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 114 | } |
| 115 | |
Daniel P. Berrange | 7d5e199 | 2016-09-30 15:45:28 +0100 | [diff] [blame] | 116 | static void qobject_output_end_struct(Visitor *v, void **obj) |
Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 117 | { |
Daniel P. Berrange | 7d5e199 | 2016-09-30 15:45:28 +0100 | [diff] [blame] | 118 | QObjectOutputVisitor *qov = to_qov(v); |
| 119 | QObject *value = qobject_output_pop(qov, obj); |
Eric Blake | 56a6f02 | 2016-04-28 15:45:26 -0600 | [diff] [blame] | 120 | assert(qobject_type(value) == QTYPE_QDICT); |
Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 121 | } |
| 122 | |
Daniel P. Berrange | 7d5e199 | 2016-09-30 15:45:28 +0100 | [diff] [blame] | 123 | static void qobject_output_start_list(Visitor *v, const char *name, |
| 124 | GenericList **listp, size_t size, |
| 125 | Error **errp) |
Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 126 | { |
Daniel P. Berrange | 7d5e199 | 2016-09-30 15:45:28 +0100 | [diff] [blame] | 127 | QObjectOutputVisitor *qov = to_qov(v); |
Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 128 | QList *list = qlist_new(); |
| 129 | |
Daniel P. Berrange | 7d5e199 | 2016-09-30 15:45:28 +0100 | [diff] [blame] | 130 | qobject_output_add(qov, name, list); |
| 131 | qobject_output_push(qov, list, listp); |
Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 132 | } |
| 133 | |
Daniel P. Berrange | 7d5e199 | 2016-09-30 15:45:28 +0100 | [diff] [blame] | 134 | static GenericList *qobject_output_next_list(Visitor *v, GenericList *tail, |
| 135 | size_t size) |
Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 136 | { |
Eric Blake | d9f62dd | 2016-04-28 15:45:31 -0600 | [diff] [blame] | 137 | return tail->next; |
Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 138 | } |
| 139 | |
Daniel P. Berrange | 7d5e199 | 2016-09-30 15:45:28 +0100 | [diff] [blame] | 140 | static void qobject_output_end_list(Visitor *v, void **obj) |
Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 141 | { |
Daniel P. Berrange | 7d5e199 | 2016-09-30 15:45:28 +0100 | [diff] [blame] | 142 | QObjectOutputVisitor *qov = to_qov(v); |
| 143 | QObject *value = qobject_output_pop(qov, obj); |
Eric Blake | 56a6f02 | 2016-04-28 15:45:26 -0600 | [diff] [blame] | 144 | assert(qobject_type(value) == QTYPE_QLIST); |
Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 145 | } |
| 146 | |
Daniel P. Berrange | 7d5e199 | 2016-09-30 15:45:28 +0100 | [diff] [blame] | 147 | static void qobject_output_type_int64(Visitor *v, const char *name, |
| 148 | int64_t *obj, Error **errp) |
Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 149 | { |
Daniel P. Berrange | 7d5e199 | 2016-09-30 15:45:28 +0100 | [diff] [blame] | 150 | QObjectOutputVisitor *qov = to_qov(v); |
Marc-André Lureau | 01b2ffc | 2017-06-07 20:35:58 +0400 | [diff] [blame] | 151 | qobject_output_add(qov, name, qnum_from_int(*obj)); |
Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 152 | } |
| 153 | |
Daniel P. Berrange | 7d5e199 | 2016-09-30 15:45:28 +0100 | [diff] [blame] | 154 | static void qobject_output_type_uint64(Visitor *v, const char *name, |
| 155 | uint64_t *obj, Error **errp) |
Eric Blake | f755dea | 2016-01-29 06:48:50 -0700 | [diff] [blame] | 156 | { |
Daniel P. Berrange | 7d5e199 | 2016-09-30 15:45:28 +0100 | [diff] [blame] | 157 | QObjectOutputVisitor *qov = to_qov(v); |
Marc-André Lureau | 5923f85 | 2017-06-07 20:36:03 +0400 | [diff] [blame] | 158 | qobject_output_add(qov, name, qnum_from_uint(*obj)); |
Eric Blake | f755dea | 2016-01-29 06:48:50 -0700 | [diff] [blame] | 159 | } |
| 160 | |
Daniel P. Berrange | 7d5e199 | 2016-09-30 15:45:28 +0100 | [diff] [blame] | 161 | static void qobject_output_type_bool(Visitor *v, const char *name, bool *obj, |
| 162 | Error **errp) |
Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 163 | { |
Daniel P. Berrange | 7d5e199 | 2016-09-30 15:45:28 +0100 | [diff] [blame] | 164 | QObjectOutputVisitor *qov = to_qov(v); |
| 165 | qobject_output_add(qov, name, qbool_from_bool(*obj)); |
Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 166 | } |
| 167 | |
Daniel P. Berrange | 7d5e199 | 2016-09-30 15:45:28 +0100 | [diff] [blame] | 168 | static void qobject_output_type_str(Visitor *v, const char *name, char **obj, |
| 169 | Error **errp) |
Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 170 | { |
Daniel P. Berrange | 7d5e199 | 2016-09-30 15:45:28 +0100 | [diff] [blame] | 171 | QObjectOutputVisitor *qov = to_qov(v); |
Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 172 | if (*obj) { |
Daniel P. Berrange | 7d5e199 | 2016-09-30 15:45:28 +0100 | [diff] [blame] | 173 | qobject_output_add(qov, name, qstring_from_str(*obj)); |
Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 174 | } else { |
Daniel P. Berrange | 7d5e199 | 2016-09-30 15:45:28 +0100 | [diff] [blame] | 175 | qobject_output_add(qov, name, qstring_from_str("")); |
Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 176 | } |
| 177 | } |
| 178 | |
Daniel P. Berrange | 7d5e199 | 2016-09-30 15:45:28 +0100 | [diff] [blame] | 179 | static void qobject_output_type_number(Visitor *v, const char *name, |
| 180 | double *obj, Error **errp) |
Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 181 | { |
Daniel P. Berrange | 7d5e199 | 2016-09-30 15:45:28 +0100 | [diff] [blame] | 182 | QObjectOutputVisitor *qov = to_qov(v); |
Marc-André Lureau | 01b2ffc | 2017-06-07 20:35:58 +0400 | [diff] [blame] | 183 | qobject_output_add(qov, name, qnum_from_double(*obj)); |
Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 184 | } |
| 185 | |
Daniel P. Berrange | 7d5e199 | 2016-09-30 15:45:28 +0100 | [diff] [blame] | 186 | static void qobject_output_type_any(Visitor *v, const char *name, |
| 187 | QObject **obj, Error **errp) |
Markus Armbruster | 28770e0 | 2015-09-16 13:06:24 +0200 | [diff] [blame] | 188 | { |
Daniel P. Berrange | 7d5e199 | 2016-09-30 15:45:28 +0100 | [diff] [blame] | 189 | QObjectOutputVisitor *qov = to_qov(v); |
Marc-André Lureau | f5a74a5 | 2018-04-19 17:01:44 +0200 | [diff] [blame] | 190 | |
| 191 | qobject_output_add_obj(qov, name, qobject_ref(*obj)); |
Markus Armbruster | 28770e0 | 2015-09-16 13:06:24 +0200 | [diff] [blame] | 192 | } |
| 193 | |
Markus Armbruster | d2f95f4 | 2017-06-26 18:22:59 +0200 | [diff] [blame] | 194 | static void qobject_output_type_null(Visitor *v, const char *name, |
| 195 | QNull **obj, Error **errp) |
Eric Blake | 3bc97fd | 2016-04-28 15:45:22 -0600 | [diff] [blame] | 196 | { |
Daniel P. Berrange | 7d5e199 | 2016-09-30 15:45:28 +0100 | [diff] [blame] | 197 | QObjectOutputVisitor *qov = to_qov(v); |
Markus Armbruster | 006ca09 | 2017-06-26 13:52:24 +0200 | [diff] [blame] | 198 | qobject_output_add(qov, name, qnull()); |
Eric Blake | 3bc97fd | 2016-04-28 15:45:22 -0600 | [diff] [blame] | 199 | } |
| 200 | |
Eric Blake | 56a6f02 | 2016-04-28 15:45:26 -0600 | [diff] [blame] | 201 | /* Finish building, and return the root object. |
| 202 | * The root object is never null. The caller becomes the object's |
Marc-André Lureau | cb3e7f0 | 2018-04-19 17:01:43 +0200 | [diff] [blame] | 203 | * owner, and should use qobject_unref() when done with it. */ |
Daniel P. Berrange | 7d5e199 | 2016-09-30 15:45:28 +0100 | [diff] [blame] | 204 | static void qobject_output_complete(Visitor *v, void *opaque) |
Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 205 | { |
Daniel P. Berrange | 7d5e199 | 2016-09-30 15:45:28 +0100 | [diff] [blame] | 206 | QObjectOutputVisitor *qov = to_qov(v); |
Eric Blake | 3b098d5 | 2016-06-09 10:48:43 -0600 | [diff] [blame] | 207 | |
Eric Blake | 56a6f02 | 2016-04-28 15:45:26 -0600 | [diff] [blame] | 208 | /* A visit must have occurred, with each start paired with end. */ |
Paolo Bonzini | fc76ae8 | 2016-07-07 17:53:17 +0200 | [diff] [blame] | 209 | assert(qov->root && QSLIST_EMPTY(&qov->stack)); |
Eric Blake | 3b098d5 | 2016-06-09 10:48:43 -0600 | [diff] [blame] | 210 | assert(opaque == qov->result); |
Eric Blake | 56a6f02 | 2016-04-28 15:45:26 -0600 | [diff] [blame] | 211 | |
Marc-André Lureau | f5a74a5 | 2018-04-19 17:01:44 +0200 | [diff] [blame] | 212 | *qov->result = qobject_ref(qov->root); |
Eric Blake | 3b098d5 | 2016-06-09 10:48:43 -0600 | [diff] [blame] | 213 | qov->result = NULL; |
Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 214 | } |
| 215 | |
Daniel P. Berrange | 7d5e199 | 2016-09-30 15:45:28 +0100 | [diff] [blame] | 216 | static void qobject_output_free(Visitor *v) |
Eric Blake | 2c0ef9f | 2016-06-09 10:48:35 -0600 | [diff] [blame] | 217 | { |
Daniel P. Berrange | 7d5e199 | 2016-09-30 15:45:28 +0100 | [diff] [blame] | 218 | QObjectOutputVisitor *qov = to_qov(v); |
Paolo Bonzini | fc76ae8 | 2016-07-07 17:53:17 +0200 | [diff] [blame] | 219 | QStackEntry *e; |
Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 220 | |
Paolo Bonzini | fc76ae8 | 2016-07-07 17:53:17 +0200 | [diff] [blame] | 221 | while (!QSLIST_EMPTY(&qov->stack)) { |
| 222 | e = QSLIST_FIRST(&qov->stack); |
| 223 | QSLIST_REMOVE_HEAD(&qov->stack, node); |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 224 | g_free(e); |
Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 225 | } |
| 226 | |
Marc-André Lureau | cb3e7f0 | 2018-04-19 17:01:43 +0200 | [diff] [blame] | 227 | qobject_unref(qov->root); |
Eric Blake | 1830f22 | 2016-06-09 10:48:40 -0600 | [diff] [blame] | 228 | g_free(qov); |
Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 229 | } |
| 230 | |
Daniel P. Berrange | 7d5e199 | 2016-09-30 15:45:28 +0100 | [diff] [blame] | 231 | Visitor *qobject_output_visitor_new(QObject **result) |
Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 232 | { |
Daniel P. Berrange | 7d5e199 | 2016-09-30 15:45:28 +0100 | [diff] [blame] | 233 | QObjectOutputVisitor *v; |
Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 234 | |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 235 | v = g_malloc0(sizeof(*v)); |
Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 236 | |
Eric Blake | 983f52d | 2016-04-28 15:45:09 -0600 | [diff] [blame] | 237 | v->visitor.type = VISITOR_OUTPUT; |
Daniel P. Berrange | 7d5e199 | 2016-09-30 15:45:28 +0100 | [diff] [blame] | 238 | v->visitor.start_struct = qobject_output_start_struct; |
| 239 | v->visitor.end_struct = qobject_output_end_struct; |
| 240 | v->visitor.start_list = qobject_output_start_list; |
| 241 | v->visitor.next_list = qobject_output_next_list; |
| 242 | v->visitor.end_list = qobject_output_end_list; |
| 243 | v->visitor.type_int64 = qobject_output_type_int64; |
| 244 | v->visitor.type_uint64 = qobject_output_type_uint64; |
| 245 | v->visitor.type_bool = qobject_output_type_bool; |
| 246 | v->visitor.type_str = qobject_output_type_str; |
| 247 | v->visitor.type_number = qobject_output_type_number; |
| 248 | v->visitor.type_any = qobject_output_type_any; |
| 249 | v->visitor.type_null = qobject_output_type_null; |
| 250 | v->visitor.complete = qobject_output_complete; |
| 251 | v->visitor.free = qobject_output_free; |
Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 252 | |
Eric Blake | 3b098d5 | 2016-06-09 10:48:43 -0600 | [diff] [blame] | 253 | *result = NULL; |
| 254 | v->result = result; |
Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 255 | |
Eric Blake | 3b098d5 | 2016-06-09 10:48:43 -0600 | [diff] [blame] | 256 | return &v->visitor; |
Michael Roth | e4e6aa1 | 2011-07-19 14:50:34 -0500 | [diff] [blame] | 257 | } |