2
0

qobject-input-visitor.h 2.9 KB

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