Michael Roth | c40cc0a | 2011-07-19 14:50:33 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Input Visitor |
| 3 | * |
Markus Armbruster | aa3a982 | 2017-03-03 13:32:48 +0100 | [diff] [blame] | 4 | * Copyright (C) 2017 Red Hat, Inc. |
Michael Roth | c40cc0a | 2011-07-19 14:50:33 -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 | |
Daniel P. Berrange | b3db211 | 2016-09-30 15:45:27 +0100 | [diff] [blame] | 15 | #ifndef QOBJECT_INPUT_VISITOR_H |
| 16 | #define QOBJECT_INPUT_VISITOR_H |
Michael Roth | c40cc0a | 2011-07-19 14:50:33 -0500 | [diff] [blame] | 17 | |
Paolo Bonzini | 7b1b5d1 | 2012-12-17 18:19:43 +0100 | [diff] [blame] | 18 | #include "qapi/visitor.h" |
Michael Roth | c40cc0a | 2011-07-19 14:50:33 -0500 | [diff] [blame] | 19 | |
Daniel P. Berrange | 09e6836 | 2016-09-30 15:45:27 +0100 | [diff] [blame] | 20 | typedef struct QObjectInputVisitor QObjectInputVisitor; |
Michael Roth | c40cc0a | 2011-07-19 14:50:33 -0500 | [diff] [blame] | 21 | |
Eric Blake | fc471c1 | 2016-04-28 15:45:13 -0600 | [diff] [blame] | 22 | /* |
Markus Armbruster | aa3a982 | 2017-03-03 13:32:48 +0100 | [diff] [blame] | 23 | * Create a QObject input visitor for @obj |
| 24 | * |
| 25 | * A QObject input visitor visit builds a QAPI object from a QObject. |
| 26 | * This simultaneously walks the QAPI object being built and the |
| 27 | * QObject. The latter walk starts at @obj. |
| 28 | * |
| 29 | * visit_type_FOO() creates an instance of QAPI type FOO. The visited |
| 30 | * QObject must match FOO. QDict matches struct/union types, QList |
| 31 | * matches list types, QString matches type 'str' and enumeration |
Marc-André Lureau | 01b2ffc | 2017-06-07 20:35:58 +0400 | [diff] [blame] | 32 | * types, QNum matches integer and float types, QBool matches type |
| 33 | * 'bool'. Type 'any' is matched by QObject. A QAPI alternate type |
| 34 | * is matched when one of its member types is. |
Markus Armbruster | aa3a982 | 2017-03-03 13:32:48 +0100 | [diff] [blame] | 35 | * |
| 36 | * visit_start_struct() ... visit_end_struct() visits a QDict and |
| 37 | * creates a QAPI struct/union. Visits in between visit the |
| 38 | * dictionary members. visit_optional() is true when the QDict has |
| 39 | * this member. visit_check_struct() fails if unvisited members |
| 40 | * remain. |
| 41 | * |
| 42 | * visit_start_list() ... visit_end_list() visits a QList and creates |
| 43 | * a QAPI list. Visits in between visit list members, one after the |
| 44 | * other. visit_next_list() returns NULL when all QList members have |
| 45 | * been visited. visit_check_list() fails if unvisited members |
| 46 | * remain. |
| 47 | * |
| 48 | * visit_start_alternate() ... visit_end_alternate() visits a QObject |
| 49 | * and creates a QAPI alternate. The visit in between visits the same |
| 50 | * QObject and initializes the alternate member that is in use. |
| 51 | * |
| 52 | * Error messages refer to parts of @obj in JavaScript/Python syntax. |
| 53 | * For example, 'a.b[2]' refers to the second member of the QList |
| 54 | * member 'b' of the QDict member 'a' of QDict @obj. |
| 55 | * |
| 56 | * The caller is responsible for freeing the visitor with |
| 57 | * visit_free(). |
Eric Blake | fc471c1 | 2016-04-28 15:45:13 -0600 | [diff] [blame] | 58 | */ |
Markus Armbruster | 048abb7 | 2017-03-03 13:32:39 +0100 | [diff] [blame] | 59 | Visitor *qobject_input_visitor_new(QObject *obj); |
Michael Roth | c40cc0a | 2011-07-19 14:50:33 -0500 | [diff] [blame] | 60 | |
Daniel P. Berrange | cbd8acf | 2017-02-28 22:26:50 +0100 | [diff] [blame] | 61 | /* |
| 62 | * Create a QObject input visitor for @obj for use with keyval_parse() |
| 63 | * |
| 64 | * This is like qobject_input_visitor_new(), except scalars are all |
| 65 | * QString, and error messages refer to parts of @obj in the syntax |
| 66 | * keyval_parse() uses for KEYs. |
| 67 | */ |
| 68 | Visitor *qobject_input_visitor_new_keyval(QObject *obj); |
| 69 | |
Markus Armbruster | 9d1eab4 | 2017-02-28 22:27:06 +0100 | [diff] [blame] | 70 | /* |
| 71 | * Create a QObject input visitor for parsing @str. |
| 72 | * |
| 73 | * If @str looks like JSON, parse it as JSON, else as KEY=VALUE,... |
| 74 | * @implied_key applies to KEY=VALUE, and works as in keyval_parse(). |
| 75 | * On failure, store an error through @errp and return NULL. |
| 76 | * On success, return a new QObject input visitor for the parse. |
| 77 | */ |
| 78 | Visitor *qobject_input_visitor_new_str(const char *str, |
| 79 | const char *implied_key, |
| 80 | Error **errp); |
| 81 | |
Michael Roth | c40cc0a | 2011-07-19 14:50:33 -0500 | [diff] [blame] | 82 | #endif |