xemu/qapi
Laszlo Ersek eb7ee2cbeb qapi: introduce OptsVisitor
This visitor supports parsing

  -option [type=]discriminator[,optarg1=val1][,optarg2=val2][,...]

style QemuOpts objects into "native" C structures. After defining the type
tree in the qapi schema (see below), a root type traversal with this
visitor linked to the underlying QemuOpts object will build the "native" C
representation of the option.

The type tree in the schema, corresponding to an option with a
discriminator, must have the following structure:

  struct
    scalar member for non-discriminated optarg 1 [*]
    list for repeating non-discriminated optarg 2 [*]
      wrapper struct
        single scalar member
    union
      struct for discriminator case 1
        scalar member for optarg 3 [*]
        list for repeating optarg 4 [*]
          wrapper struct
            single scalar member
        scalar member for optarg 5 [*]
      struct for discriminator case 2
        ...

The "type" optarg name is fixed for the discriminator role. Its schema
representation is "union of structures", and each discriminator value must
correspond to a member name in the union.

If the option takes no "type" descriminator, then the type subtree rooted
at the union must be absent from the schema (including the union itself).

Optarg values can be of scalar types str / bool / integers / size.

Members marked with [*] may be defined as optional in the schema,
describing an optional optarg.

Repeating an optarg is supported; its schema representation must be "list
of structure with single mandatory scalar member". If an optarg is not
described as repeating in the schema (ie. it is defined as a scalar field
instead of a list), its last occurrence will take effect. Ordering between
differently named optargs is not preserved.

A mandatory list (or an optional one which is reported to be available),
corresponding to a repeating optarg, has at least one element after
successful parsing.

v1->v2:
- Update opts_type_size() prototype to uint64_t.
- Add opts_type_uint64() for options needing the full uint64_t range.
  (Internals could be extracted to "cutils.c".)
- Allow negative values in opts_type_int().
- Rebase to nested Makefiles.

v2->v3:
- Factor opts_visitor_insert() out of opts_start_struct() and call it
  separately for opts_root->id if there's any.
- Don't require non-negative values in opts_type_int()'s error message.
- g_malloc0() may return NULL for zero-sized requests. Support empty
  structures by requesting 1 byte for them instead.

Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
2012-07-23 11:55:17 +01:00
..
Makefile.objs qapi: introduce OptsVisitor 2012-07-23 11:55:17 +01:00
opts-visitor.c qapi: introduce OptsVisitor 2012-07-23 11:55:17 +01:00
opts-visitor.h qapi: introduce OptsVisitor 2012-07-23 11:55:17 +01:00
qapi-dealloc-visitor.c qapi: dealloc visitor, support freeing of nested lists 2011-10-04 11:00:46 -03:00
qapi-dealloc-visitor.h qapi: add QAPI dealloc visitor 2011-07-21 16:48:13 -03:00
qapi-types-core.h qmp: do not include monitor.h from qapi-types-core.h 2012-06-15 10:41:05 -03:00
qapi-visit-core.c qapi: introduce "size" type 2012-07-23 11:55:17 +01:00
qapi-visit-core.h qapi: introduce "size" type 2012-07-23 11:55:17 +01:00
qapi-visit-impl.h qapi: allow sharing enum implementation across visitors 2012-02-21 10:21:05 +01:00
qmp-core.h qapi: add support for command options 2012-05-15 09:15:16 -05:00
qmp-dispatch.c qapi: add support for command options 2012-05-15 09:15:16 -05:00
qmp-input-visitor.c qapi: QMP input visitor, handle floats parsed as ints 2012-05-14 10:08:39 -03:00
qmp-input-visitor.h qapi: add strict mode to input visitor 2012-03-27 09:15:13 -03:00
qmp-output-visitor.c qapi: fix double free in qmp_output_visitor_cleanup() 2012-03-27 09:11:00 -03:00
qmp-output-visitor.h qapi: add QMP output visitor 2011-07-21 16:48:13 -03:00
qmp-registry.c qapi: add support for command options 2012-05-15 09:15:16 -05:00
string-input-visitor.c qapi: add string-based visitors 2012-02-21 10:21:05 +01:00
string-input-visitor.h qapi: add string-based visitors 2012-02-21 10:21:05 +01:00
string-output-visitor.c qapi: String visitor, use %f representation for floats 2012-06-08 16:11:14 +02:00
string-output-visitor.h qapi: add string-based visitors 2012-02-21 10:21:05 +01:00