qobject-input-visitor.h 2.9 KB

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