blob: e7e7281f5b7764a329db41bdff62f5e084ad3d16 [file] [log] [blame]
Michael Rothb84da832011-07-19 14:50:46 -05001= How to use the QAPI code generator =
2
Eric Blake6fb55452015-05-04 09:04:58 -06003Copyright IBM Corp. 2011
4Copyright (C) 2012-2015 Red Hat, Inc.
5
6This work is licensed under the terms of the GNU GPL, version 2 or
7later. See the COPYING file in the top-level directory.
8
9== Introduction ==
10
Michael Rothb84da832011-07-19 14:50:46 -050011QAPI is a native C API within QEMU which provides management-level
Eric Blakee790e662015-05-04 09:04:59 -060012functionality to internal and external users. For external
13users/processes, this interface is made available by a JSON-based wire
14format for the QEMU Monitor Protocol (QMP) for controlling qemu, as
15well as the QEMU Guest Agent (QGA) for communicating with the guest.
Eric Blake363b4262015-05-04 09:05:35 -060016The remainder of this document uses "Client JSON Protocol" when
17referring to the wire contents of a QMP or QGA connection.
Michael Rothb84da832011-07-19 14:50:46 -050018
Eric Blake363b4262015-05-04 09:05:35 -060019To map Client JSON Protocol interfaces to the native C QAPI
20implementations, a JSON-based schema is used to define types and
21function signatures, and a set of scripts is used to generate types,
22signatures, and marshaling/dispatch code. This document will describe
23how the schemas, scripts, and resulting code are used.
Michael Rothb84da832011-07-19 14:50:46 -050024
25
26== QMP/Guest agent schema ==
27
Eric Blakee790e662015-05-04 09:04:59 -060028A QAPI schema file is designed to be loosely based on JSON
29(http://www.ietf.org/rfc/rfc7159.txt) with changes for quoting style
30and the use of comments; a QAPI schema file is then parsed by a python
31code generation program. A valid QAPI schema consists of a series of
32top-level expressions, with no commas between them. Where
33dictionaries (JSON objects) are used, they are parsed as python
34OrderedDicts so that ordering is preserved (for predictable layout of
35generated C structs and parameter lists). Ordering doesn't matter
36between top-level expressions or the keys within an expression, but
37does matter within dictionary values for 'data' and 'returns' members
38of a single expression. QAPI schema input is written using 'single
Eric Blake363b4262015-05-04 09:05:35 -060039quotes' instead of JSON's "double quotes" (in contrast, Client JSON
40Protocol uses no comments, and while input accepts 'single quotes' as
41an extension, output is strict JSON using only "double quotes"). As
42in JSON, trailing commas are not permitted in arrays or dictionaries.
43Input must be ASCII (although QMP supports full Unicode strings, the
44QAPI parser does not). At present, there is no place where a QAPI
45schema requires the use of JSON numbers or null.
Michael Rothb84da832011-07-19 14:50:46 -050046
Eric Blakee790e662015-05-04 09:04:59 -060047Comments are allowed; anything between an unquoted # and the following
48newline is ignored. Although there is not yet a documentation
49generator, a form of stylized comments has developed for consistently
50documenting details about an expression and when it was added to the
51schema. The documentation is delimited between two lines of ##, then
52the first line names the expression, an optional overview is provided,
53then individual documentation about each member of 'data' is provided,
54and finally, a 'Since: x.y.z' tag lists the release that introduced
55the expression. Optional fields are tagged with the phrase
56'#optional', often with their default value; and extensions added
57after the expression was first released are also given a '(since
58x.y.z)' comment. For example:
Michael Rothb84da832011-07-19 14:50:46 -050059
Eric Blakee790e662015-05-04 09:04:59 -060060 ##
61 # @BlockStats:
62 #
63 # Statistics of a virtual block device or a block backing device.
64 #
65 # @device: #optional If the stats are for a virtual block device, the name
66 # corresponding to the virtual block device.
67 #
68 # @stats: A @BlockDeviceStats for the device.
69 #
70 # @parent: #optional This describes the file block device if it has one.
71 #
72 # @backing: #optional This describes the backing block device if it has one.
73 # (Since 2.0)
74 #
75 # Since: 0.14.0
76 ##
Eric Blake3b2a8b82015-05-04 09:05:26 -060077 { 'struct': 'BlockStats',
Eric Blakee790e662015-05-04 09:04:59 -060078 'data': {'*device': 'str', 'stats': 'BlockDeviceStats',
79 '*parent': 'BlockStats',
80 '*backing': 'BlockStats'} }
Michael Rothb84da832011-07-19 14:50:46 -050081
Eric Blakee790e662015-05-04 09:04:59 -060082The schema sets up a series of types, as well as commands and events
83that will use those types. Forward references are allowed: the parser
84scans in two passes, where the first pass learns all type names, and
85the second validates the schema and generates the code. This allows
86the definition of complex structs that can have mutually recursive
Eric Blake363b4262015-05-04 09:05:35 -060087types, and allows for indefinite nesting of Client JSON Protocol that
88satisfies the schema. A type name should not be defined more than
89once. It is permissible for the schema to contain additional types
90not used by any commands or events in the Client JSON Protocol, for
91the side effect of generated C code used internally.
Michael Rothb84da832011-07-19 14:50:46 -050092
Eric Blake7b1b98c2015-05-04 09:05:12 -060093There are seven top-level expressions recognized by the parser:
Eric Blake3b2a8b82015-05-04 09:05:26 -060094'include', 'command', 'struct', 'enum', 'union', 'alternate', and
Eric Blake7b1b98c2015-05-04 09:05:12 -060095'event'. There are several groups of types: simple types (a number of
96built-in types, such as 'int' and 'str'; as well as enumerations),
97complex types (structs and two flavors of unions), and alternate types
98(a choice between other types). The 'command' and 'event' expressions
Eric Blakee790e662015-05-04 09:04:59 -060099can refer to existing types by name, or list an anonymous type as a
100dictionary. Listing a type name inside an array refers to a
101single-dimension array of that type; multi-dimension arrays are not
102directly supported (although an array of a complex struct that
103contains an array member is possible).
104
105Types, commands, and events share a common namespace. Therefore,
106generally speaking, type definitions should always use CamelCase for
107user-defined type names, while built-in types are lowercase. Type
108definitions should not end in 'Kind', as this namespace is used for
109creating implicit C enums for visiting union types. Command names,
110and field names within a type, should be all lower case with words
111separated by a hyphen. However, some existing older commands and
112complex types use underscore; when extending such expressions,
113consistency is preferred over blindly avoiding underscore. Event
114names should be ALL_CAPS with words separated by underscore. The
115special string '**' appears for some commands that manually perform
116their own type checking rather than relying on the type-safe code
117produced by the qapi code generators.
118
119Any name (command, event, type, field, or enum value) beginning with
120"x-" is marked experimental, and may be withdrawn or changed
121incompatibly in a future release. Downstream vendors may add
122extensions; such extensions should begin with a prefix matching
123"__RFQDN_" (for the reverse-fully-qualified-domain-name of the
124vendor), even if the rest of the name uses dash (example:
125__com.redhat_drive-mirror). Other than downstream extensions (with
126leading underscore and the use of dots), all names should begin with a
127letter, and contain only ASCII letters, digits, dash, and underscore.
128It is okay to reuse names that match C keywords; the generator will
129rename a field named "default" in the QAPI to "q_default" in the
130generated C code.
131
132In the rest of this document, usage lines are given for each
133expression type, with literal strings written in lower case and
134placeholders written in capitals. If a literal string includes a
135prefix of '*', that key/value pair can be omitted from the expression.
Eric Blake3b2a8b82015-05-04 09:05:26 -0600136For example, a usage statement that includes '*base':STRUCT-NAME
Eric Blakee790e662015-05-04 09:04:59 -0600137means that an expression has an optional key 'base', which if present
Eric Blake3b2a8b82015-05-04 09:05:26 -0600138must have a value that forms a struct name.
Eric Blakee790e662015-05-04 09:04:59 -0600139
140
141=== Built-in Types ===
142
143The following types are built-in to the parser:
144 'str' - arbitrary UTF-8 string
145 'int' - 64-bit signed integer (although the C code may place further
146 restrictions on acceptable range)
147 'number' - floating point number
148 'bool' - JSON value of true or false
149 'int8', 'int16', 'int32', 'int64' - like 'int', but enforce maximum
150 bit size
151 'uint8', 'uint16', 'uint32', 'uint64' - unsigned counterparts
152 'size' - like 'uint64', but allows scaled suffix from command line
153 visitor
Kevin Wolf51631492013-07-16 13:17:27 +0200154
Lluís Vilanovaa719a272014-05-07 20:46:15 +0200155
156=== Includes ===
157
Eric Blakee790e662015-05-04 09:04:59 -0600158Usage: { 'include': STRING }
159
Lluís Vilanovaa719a272014-05-07 20:46:15 +0200160The QAPI schema definitions can be modularized using the 'include' directive:
161
Eric Blakee790e662015-05-04 09:04:59 -0600162 { 'include': 'path/to/file.json' }
Lluís Vilanovaa719a272014-05-07 20:46:15 +0200163
164The directive is evaluated recursively, and include paths are relative to the
Eric Blakee790e662015-05-04 09:04:59 -0600165file using the directive. Multiple includes of the same file are
Markus Armbruster4247f832015-06-09 15:24:36 +0200166idempotent. No other keys should appear in the expression, and the include
Eric Blakee790e662015-05-04 09:04:59 -0600167value should be a string.
168
169As a matter of style, it is a good idea to have all files be
170self-contained, but at the moment, nothing prevents an included file
171from making a forward reference to a type that is only introduced by
172an outer file. The parser may be made stricter in the future to
173prevent incomplete include files.
Lluís Vilanovaa719a272014-05-07 20:46:15 +0200174
175
Eric Blake3b2a8b82015-05-04 09:05:26 -0600176=== Struct types ===
Kevin Wolf51631492013-07-16 13:17:27 +0200177
Eric Blake3b2a8b82015-05-04 09:05:26 -0600178Usage: { 'struct': STRING, 'data': DICT, '*base': STRUCT-NAME }
Eric Blakee790e662015-05-04 09:04:59 -0600179
Eric Blake3b2a8b82015-05-04 09:05:26 -0600180A struct is a dictionary containing a single 'data' key whose
Eric Blakee790e662015-05-04 09:04:59 -0600181value is a dictionary. This corresponds to a struct in C or an Object
182in JSON. Each value of the 'data' dictionary must be the name of a
183type, or a one-element array containing a type name. An example of a
Eric Blake3b2a8b82015-05-04 09:05:26 -0600184struct is:
Michael Rothb84da832011-07-19 14:50:46 -0500185
Eric Blake3b2a8b82015-05-04 09:05:26 -0600186 { 'struct': 'MyType',
Stefan Hajnocziacf83942011-10-28 15:58:26 +0100187 'data': { 'member1': 'str', 'member2': 'int', '*member3': 'str' } }
Michael Rothb84da832011-07-19 14:50:46 -0500188
Eric Blakee790e662015-05-04 09:04:59 -0600189The use of '*' as a prefix to the name means the member is optional in
Eric Blake363b4262015-05-04 09:05:35 -0600190the corresponding JSON protocol usage.
Michael Rothb84da832011-07-19 14:50:46 -0500191
Eric Blakecc162652014-05-07 09:57:41 +0800192The default initialization value of an optional argument should not be changed
193between versions of QEMU unless the new default maintains backward
194compatibility to the user-visible behavior of the old default.
195
196With proper documentation, this policy still allows some flexibility; for
197example, documenting that a default of 0 picks an optimal buffer size allows
198one release to declare the optimal size at 512 while another release declares
199the optimal size at 4096 - the user-visible behavior is not the bytes used by
200the buffer, but the fact that the buffer was optimal size.
201
202On input structures (only mentioned in the 'data' side of a command), changing
203from mandatory to optional is safe (older clients will supply the option, and
204newer clients can benefit from the default); changing from optional to
205mandatory is backwards incompatible (older clients may be omitting the option,
206and must continue to work).
207
208On output structures (only mentioned in the 'returns' side of a command),
209changing from mandatory to optional is in general unsafe (older clients may be
210expecting the field, and could crash if it is missing), although it can be done
211if the only way that the optional argument will be omitted is when it is
212triggered by the presence of a new input flag to the command that older clients
213don't know to send. Changing from optional to mandatory is safe.
214
215A structure that is used in both input and output of various commands
216must consider the backwards compatibility constraints of both directions
217of use.
Kevin Wolf622f5572013-09-19 11:56:36 +0200218
Eric Blake3b2a8b82015-05-04 09:05:26 -0600219A struct definition can specify another struct as its base.
Kevin Wolf622f5572013-09-19 11:56:36 +0200220In this case, the fields of the base type are included as top-level fields
Eric Blake363b4262015-05-04 09:05:35 -0600221of the new struct's dictionary in the Client JSON Protocol wire
222format. An example definition is:
Kevin Wolf622f5572013-09-19 11:56:36 +0200223
Eric Blake3b2a8b82015-05-04 09:05:26 -0600224 { 'struct': 'BlockdevOptionsGenericFormat', 'data': { 'file': 'str' } }
225 { 'struct': 'BlockdevOptionsGenericCOWFormat',
Kevin Wolf622f5572013-09-19 11:56:36 +0200226 'base': 'BlockdevOptionsGenericFormat',
227 'data': { '*backing': 'str' } }
228
229An example BlockdevOptionsGenericCOWFormat object on the wire could use
230both fields like this:
231
232 { "file": "/some/place/my-image",
233 "backing": "/some/place/my-backing-file" }
234
Eric Blakee790e662015-05-04 09:04:59 -0600235
Kevin Wolf51631492013-07-16 13:17:27 +0200236=== Enumeration types ===
237
Eric Blakee790e662015-05-04 09:04:59 -0600238Usage: { 'enum': STRING, 'data': ARRAY-OF-STRING }
239
240An enumeration type is a dictionary containing a single 'data' key
241whose value is a list of strings. An example enumeration is:
Michael Rothb84da832011-07-19 14:50:46 -0500242
243 { 'enum': 'MyEnum', 'data': [ 'value1', 'value2', 'value3' ] }
244
Eric Blakee790e662015-05-04 09:04:59 -0600245Nothing prevents an empty enumeration, although it is probably not
246useful. The list of strings should be lower case; if an enum name
247represents multiple words, use '-' between words. The string 'max' is
248not allowed as an enum value, and values should not be repeated.
249
Eric Blake363b4262015-05-04 09:05:35 -0600250The enumeration values are passed as strings over the Client JSON
251Protocol, but are encoded as C enum integral values in generated code.
252While the C code starts numbering at 0, it is better to use explicit
Eric Blakee790e662015-05-04 09:04:59 -0600253comparisons to enum values than implicit comparisons to 0; the C code
254will also include a generated enum member ending in _MAX for tracking
255the size of the enum, useful when using common functions for
256converting between strings and enum values. Since the wire format
257always passes by name, it is acceptable to reorder or add new
Eric Blake363b4262015-05-04 09:05:35 -0600258enumeration members in any location without breaking clients of Client
259JSON Protocol; however, removing enum values would break
260compatibility. For any struct that has a field that will only contain
261a finite set of string values, using an enum type for that field is
262better than open-coding the field to be type 'str'.
Eric Blakee790e662015-05-04 09:04:59 -0600263
264
Kevin Wolf51631492013-07-16 13:17:27 +0200265=== Union types ===
266
Eric Blakee790e662015-05-04 09:04:59 -0600267Usage: { 'union': STRING, 'data': DICT }
Eric Blake3b2a8b82015-05-04 09:05:26 -0600268or: { 'union': STRING, 'data': DICT, 'base': STRUCT-NAME,
Eric Blakee790e662015-05-04 09:04:59 -0600269 'discriminator': ENUM-MEMBER-OF-BASE }
Eric Blakee790e662015-05-04 09:04:59 -0600270
271Union types are used to let the user choose between several different
Eric Blake7b1b98c2015-05-04 09:05:12 -0600272variants for an object. There are two flavors: simple (no
273discriminator or base), flat (both discriminator and base). A union
274type is defined using a data dictionary as explained in the following
275paragraphs.
Kevin Wolf51631492013-07-16 13:17:27 +0200276
Eric Blakee790e662015-05-04 09:04:59 -0600277A simple union type defines a mapping from automatic discriminator
278values to data types like in this example:
Kevin Wolf51631492013-07-16 13:17:27 +0200279
Eric Blake3b2a8b82015-05-04 09:05:26 -0600280 { 'struct': 'FileOptions', 'data': { 'filename': 'str' } }
281 { 'struct': 'Qcow2Options',
Kevin Wolf51631492013-07-16 13:17:27 +0200282 'data': { 'backing-file': 'str', 'lazy-refcounts': 'bool' } }
283
284 { 'union': 'BlockdevOptions',
285 'data': { 'file': 'FileOptions',
286 'qcow2': 'Qcow2Options' } }
287
Eric Blake363b4262015-05-04 09:05:35 -0600288In the Client JSON Protocol, a simple union is represented by a
289dictionary that contains the 'type' field as a discriminator, and a
290'data' field that is of the specified data type corresponding to the
291discriminator value, as in these examples:
Kevin Wolf51631492013-07-16 13:17:27 +0200292
Eric Blakee790e662015-05-04 09:04:59 -0600293 { "type": "file", "data" : { "filename": "/some/place/my-image" } }
Kevin Wolf51631492013-07-16 13:17:27 +0200294 { "type": "qcow2", "data" : { "backing-file": "/some/place/my-image",
295 "lazy-refcounts": true } }
296
Eric Blakee790e662015-05-04 09:04:59 -0600297The generated C code uses a struct containing a union. Additionally,
298an implicit C enum 'NameKind' is created, corresponding to the union
299'Name', for accessing the various branches of the union. No branch of
300the union can be named 'max', as this would collide with the implicit
301enum. The value for each branch can be of any type.
Kevin Wolf51631492013-07-16 13:17:27 +0200302
Kevin Wolf50f2bdc2013-07-03 15:58:57 +0200303
Eric Blake3b2a8b82015-05-04 09:05:26 -0600304A flat union definition specifies a struct as its base, and
Eric Blakee790e662015-05-04 09:04:59 -0600305avoids nesting on the wire. All branches of the union must be
306complex types, and the top-level fields of the union dictionary on
307the wire will be combination of fields from both the base type and the
308appropriate branch type (when merging two dictionaries, there must be
309no keys in common). The 'discriminator' field must be the name of an
Eric Blake3b2a8b82015-05-04 09:05:26 -0600310enum-typed member of the base struct.
Eric Blakee790e662015-05-04 09:04:59 -0600311
312The following example enhances the above simple union example by
313adding a common field 'readonly', renaming the discriminator to
314something more applicable, and reducing the number of {} required on
315the wire:
Kevin Wolf50f2bdc2013-07-03 15:58:57 +0200316
Wenchao Xiabceae762014-03-06 17:08:56 -0800317 { 'enum': 'BlockdevDriver', 'data': [ 'raw', 'qcow2' ] }
Eric Blake3b2a8b82015-05-04 09:05:26 -0600318 { 'struct': 'BlockdevCommonOptions',
Wenchao Xiabceae762014-03-06 17:08:56 -0800319 'data': { 'driver': 'BlockdevDriver', 'readonly': 'bool' } }
Kevin Wolf50f2bdc2013-07-03 15:58:57 +0200320 { 'union': 'BlockdevOptions',
321 'base': 'BlockdevCommonOptions',
322 'discriminator': 'driver',
Eric Blakee790e662015-05-04 09:04:59 -0600323 'data': { 'file': 'FileOptions',
Kevin Wolf50f2bdc2013-07-03 15:58:57 +0200324 'qcow2': 'Qcow2Options' } }
325
Eric Blakee790e662015-05-04 09:04:59 -0600326Resulting in these JSON objects:
Kevin Wolf50f2bdc2013-07-03 15:58:57 +0200327
Eric Blakee790e662015-05-04 09:04:59 -0600328 { "driver": "file", "readonly": true,
329 "filename": "/some/place/my-image" }
330 { "driver": "qcow2", "readonly": false,
331 "backing-file": "/some/place/my-image", "lazy-refcounts": true }
332
333Notice that in a flat union, the discriminator name is controlled by
334the user, but because it must map to a base member with enum type, the
335code generator can ensure that branches exist for all values of the
336enum (although the order of the keys need not match the declaration of
337the enum). In the resulting generated C data types, a flat union is
338represented as a struct with the base member fields included directly,
339and then a union of structures for each branch of the struct.
340
341A simple union can always be re-written as a flat union where the base
342class has a single member named 'type', and where each branch of the
Eric Blake3b2a8b82015-05-04 09:05:26 -0600343union has a struct with a single member named 'data'. That is,
Eric Blakee790e662015-05-04 09:04:59 -0600344
345 { 'union': 'Simple', 'data': { 'one': 'str', 'two': 'int' } }
346
347is identical on the wire to:
348
349 { 'enum': 'Enum', 'data': ['one', 'two'] }
Eric Blake3b2a8b82015-05-04 09:05:26 -0600350 { 'struct': 'Base', 'data': { 'type': 'Enum' } }
351 { 'struct': 'Branch1', 'data': { 'data': 'str' } }
352 { 'struct': 'Branch2', 'data': { 'data': 'int' } }
Eric Blakee790e662015-05-04 09:04:59 -0600353 { 'union': 'Flat': 'base': 'Base', 'discriminator': 'type',
354 'data': { 'one': 'Branch1', 'two': 'Branch2' } }
Kevin Wolf50f2bdc2013-07-03 15:58:57 +0200355
356
Eric Blake7b1b98c2015-05-04 09:05:12 -0600357=== Alternate types ===
Kevin Wolf69dd62d2013-07-08 16:14:21 +0200358
Eric Blake7b1b98c2015-05-04 09:05:12 -0600359Usage: { 'alternate': STRING, 'data': DICT }
360
361An alternate type is one that allows a choice between two or more JSON
362data types (string, integer, number, or object, but currently not
363array) on the wire. The definition is similar to a simple union type,
364where each branch of the union names a QAPI type. For example:
365
366 { 'alternate': 'BlockRef',
Kevin Wolf69dd62d2013-07-08 16:14:21 +0200367 'data': { 'definition': 'BlockdevOptions',
368 'reference': 'str' } }
369
Eric Blake7b1b98c2015-05-04 09:05:12 -0600370Just like for a simple union, an implicit C enum 'NameKind' is created
371to enumerate the branches for the alternate 'Name'.
372
373Unlike a union, the discriminator string is never passed on the wire
Eric Blake363b4262015-05-04 09:05:35 -0600374for the Client JSON Protocol. Instead, the value's JSON type serves
375as an implicit discriminator, which in turn means that an alternate
376can only express a choice between types represented differently in
377JSON. If a branch is typed as the 'bool' built-in, the alternate
378accepts true and false; if it is typed as any of the various numeric
379built-ins, it accepts a JSON number; if it is typed as a 'str'
380built-in or named enum type, it accepts a JSON string; and if it is
381typed as a complex type (struct or union), it accepts a JSON object.
382Two different complex types, for instance, aren't permitted, because
383both are represented as a JSON object.
Eric Blake7b1b98c2015-05-04 09:05:12 -0600384
385The example alternate declaration above allows using both of the
386following example objects:
Kevin Wolf69dd62d2013-07-08 16:14:21 +0200387
388 { "file": "my_existing_block_device_id" }
389 { "file": { "driver": "file",
390 "readonly": false,
Eric Blake63922c62013-10-19 17:52:33 +0100391 "filename": "/tmp/mydisk.qcow2" } }
Kevin Wolf69dd62d2013-07-08 16:14:21 +0200392
393
Kevin Wolf51631492013-07-16 13:17:27 +0200394=== Commands ===
Michael Rothb84da832011-07-19 14:50:46 -0500395
Eric Blakee790e662015-05-04 09:04:59 -0600396Usage: { 'command': STRING, '*data': COMPLEX-TYPE-NAME-OR-DICT,
397 '*returns': TYPE-NAME-OR-DICT,
398 '*gen': false, '*success-response': false }
Michael Rothb84da832011-07-19 14:50:46 -0500399
Eric Blakee790e662015-05-04 09:04:59 -0600400Commands are defined by using a dictionary containing several members,
401where three members are most common. The 'command' member is a
Eric Blake363b4262015-05-04 09:05:35 -0600402mandatory string, and determines the "execute" value passed in a
403Client JSON Protocol command exchange.
Michael Rothb84da832011-07-19 14:50:46 -0500404
Eric Blakee790e662015-05-04 09:04:59 -0600405The 'data' argument maps to the "arguments" dictionary passed in as
Eric Blake363b4262015-05-04 09:05:35 -0600406part of a Client JSON Protocol command. The 'data' member is optional
407and defaults to {} (an empty dictionary). If present, it must be the
408string name of a complex type, a one-element array containing the name
409of a complex type, or a dictionary that declares an anonymous type
410with the same semantics as a 'struct' expression, with one exception
411noted below when 'gen' is used.
Eric Blakee790e662015-05-04 09:04:59 -0600412
413The 'returns' member describes what will appear in the "return" field
Eric Blake363b4262015-05-04 09:05:35 -0600414of a Client JSON Protocol reply on successful completion of a command.
415The member is optional from the command declaration; if absent, the
416"return" field will be an empty dictionary. If 'returns' is present,
417it must be the string name of a complex or built-in type, a
418one-element array containing the name of a complex or built-in type,
419or a dictionary that declares an anonymous type with the same
420semantics as a 'struct' expression, with one exception noted below
421when 'gen' is used. Although it is permitted to have the 'returns'
422member name a built-in type or an array of built-in types, any command
423that does this cannot be extended to return additional information in
424the future; thus, new commands should strongly consider returning a
425dictionary-based type or an array of dictionaries, even if the
426dictionary only contains one field at the present.
Eric Blakee790e662015-05-04 09:04:59 -0600427
Eric Blake363b4262015-05-04 09:05:35 -0600428All commands in Client JSON Protocol use a dictionary to report
429failure, with no way to specify that in QAPI. Where the error return
430is different than the usual GenericError class in order to help the
431client react differently to certain error conditions, it is worth
432documenting this in the comments before the command declaration.
Eric Blakee790e662015-05-04 09:04:59 -0600433
434Some example commands:
435
436 { 'command': 'my-first-command',
437 'data': { 'arg1': 'str', '*arg2': 'str' } }
Eric Blake3b2a8b82015-05-04 09:05:26 -0600438 { 'struct': 'MyType', 'data': { '*value': 'str' } }
Eric Blakee790e662015-05-04 09:04:59 -0600439 { 'command': 'my-second-command',
440 'returns': [ 'MyType' ] }
441
Eric Blake363b4262015-05-04 09:05:35 -0600442which would validate this Client JSON Protocol transaction:
Eric Blakee790e662015-05-04 09:04:59 -0600443
444 => { "execute": "my-first-command",
445 "arguments": { "arg1": "hello" } }
446 <= { "return": { } }
447 => { "execute": "my-second-command" }
448 <= { "return": [ { "value": "one" }, { } ] }
449
450In rare cases, QAPI cannot express a type-safe representation of a
Eric Blake363b4262015-05-04 09:05:35 -0600451corresponding Client JSON Protocol command. In these cases, if the
452command expression includes the key 'gen' with boolean value false,
453then the 'data' or 'returns' member that intends to bypass generated
454type-safety and do its own manual validation should use an inline
455dictionary definition, with a value of '**' rather than a valid type
456name for the keys that the generated code will not validate. Please
457try to avoid adding new commands that rely on this, and instead use
458type-safe unions. For an example of bypass usage:
Eric Blakee790e662015-05-04 09:04:59 -0600459
460 { 'command': 'netdev_add',
461 'data': {'type': 'str', 'id': 'str', '*props': '**'},
462 'gen': false }
463
464Normally, the QAPI schema is used to describe synchronous exchanges,
465where a response is expected. But in some cases, the action of a
466command is expected to change state in a way that a successful
467response is not possible (although the command will still return a
468normal dictionary error on failure). When a successful reply is not
469possible, the command expression should include the optional key
470'success-response' with boolean value false. So far, only QGA makes
471use of this field.
472
Michael Rothb84da832011-07-19 14:50:46 -0500473
Wenchao Xia21cd70d2014-06-18 08:43:28 +0200474=== Events ===
475
Eric Blakee790e662015-05-04 09:04:59 -0600476Usage: { 'event': STRING, '*data': COMPLEX-TYPE-NAME-OR-DICT }
477
478Events are defined with the keyword 'event'. It is not allowed to
479name an event 'MAX', since the generator also produces a C enumeration
480of all event names with a generated _MAX value at the end. When
481'data' is also specified, additional info will be included in the
Eric Blake3b2a8b82015-05-04 09:05:26 -0600482event, with similar semantics to a 'struct' expression. Finally there
Eric Blakee790e662015-05-04 09:04:59 -0600483will be C API generated in qapi-event.h; when called by QEMU code, a
484message with timestamp will be emitted on the wire.
Wenchao Xia21cd70d2014-06-18 08:43:28 +0200485
486An example event is:
487
488{ 'event': 'EVENT_C',
489 'data': { '*a': 'int', 'b': 'str' } }
490
491Resulting in this JSON object:
492
493{ "event": "EVENT_C",
494 "data": { "b": "test string" },
495 "timestamp": { "seconds": 1267020223, "microseconds": 435656 } }
Michael Rothb84da832011-07-19 14:50:46 -0500496
Eric Blake59a2c4c2014-09-26 09:20:33 -0600497
Michael Rothb84da832011-07-19 14:50:46 -0500498== Code generation ==
499
500Schemas are fed into 3 scripts to generate all the code/files that, paired
501with the core QAPI libraries, comprise everything required to take JSON
Eric Blake363b4262015-05-04 09:05:35 -0600502commands read in by a Client JSON Protocol server, unmarshal the arguments into
Michael Rothb84da832011-07-19 14:50:46 -0500503the underlying C types, call into the corresponding C function, and map the
Eric Blake363b4262015-05-04 09:05:35 -0600504response back to a Client JSON Protocol response to be returned to the user.
Michael Rothb84da832011-07-19 14:50:46 -0500505
506As an example, we'll use the following schema, which describes a single
507complex user-defined type (which will produce a C struct, along with a list
508node structure that can be used to chain together a list of such types in
509case we want to accept/return a list of this type with a command), and a
510command which takes that type as a parameter and returns the same type:
511
Markus Armbruster87a560c2014-05-14 17:27:23 +0200512 $ cat example-schema.json
Eric Blake3b2a8b82015-05-04 09:05:26 -0600513 { 'struct': 'UserDefOne',
Michael Rothb84da832011-07-19 14:50:46 -0500514 'data': { 'integer': 'int', 'string': 'str' } }
515
516 { 'command': 'my-command',
517 'data': {'arg1': 'UserDefOne'},
518 'returns': 'UserDefOne' }
Michael Rothb84da832011-07-19 14:50:46 -0500519
Eric Blake59a2c4c2014-09-26 09:20:33 -0600520 { 'event': 'MY_EVENT' }
521
Michael Rothb84da832011-07-19 14:50:46 -0500522=== scripts/qapi-types.py ===
523
524Used to generate the C types defined by a schema. The following files are
525created:
526
527$(prefix)qapi-types.h - C types corresponding to types defined in
528 the schema you pass in
529$(prefix)qapi-types.c - Cleanup functions for the above C types
530
531The $(prefix) is an optional parameter used as a namespace to keep the
532generated code from one schema/code-generation separated from others so code
533can be generated/used from multiple schemas without clobbering previously
534created code.
535
536Example:
537
Markus Armbruster87a560c2014-05-14 17:27:23 +0200538 $ python scripts/qapi-types.py --output-dir="qapi-generated" \
Markus Armbruster16d80f62015-04-02 13:32:16 +0200539 --prefix="example-" example-schema.json
Markus Armbruster87a560c2014-05-14 17:27:23 +0200540 $ cat qapi-generated/example-qapi-types.c
Markus Armbruster6e2bb3e2014-05-07 09:53:43 +0200541[Uninteresting stuff omitted...]
Michael Rothb84da832011-07-19 14:50:46 -0500542
Eric Blake59a2c4c2014-09-26 09:20:33 -0600543 void qapi_free_UserDefOneList(UserDefOneList *obj)
Markus Armbruster6e2bb3e2014-05-07 09:53:43 +0200544 {
545 QapiDeallocVisitor *md;
546 Visitor *v;
547
548 if (!obj) {
549 return;
550 }
551
552 md = qapi_dealloc_visitor_new();
553 v = qapi_dealloc_get_visitor(md);
554 visit_type_UserDefOneList(v, &obj, NULL, NULL);
555 qapi_dealloc_visitor_cleanup(md);
556 }
557
Markus Armbruster4247f832015-06-09 15:24:36 +0200558
Eric Blake59a2c4c2014-09-26 09:20:33 -0600559 void qapi_free_UserDefOne(UserDefOne *obj)
Michael Rothb84da832011-07-19 14:50:46 -0500560 {
561 QapiDeallocVisitor *md;
562 Visitor *v;
563
564 if (!obj) {
565 return;
566 }
567
568 md = qapi_dealloc_visitor_new();
569 v = qapi_dealloc_get_visitor(md);
570 visit_type_UserDefOne(v, &obj, NULL, NULL);
571 qapi_dealloc_visitor_cleanup(md);
572 }
573
Markus Armbruster87a560c2014-05-14 17:27:23 +0200574 $ cat qapi-generated/example-qapi-types.h
Markus Armbruster6e2bb3e2014-05-07 09:53:43 +0200575[Uninteresting stuff omitted...]
Michael Rothb84da832011-07-19 14:50:46 -0500576
Markus Armbruster6e2bb3e2014-05-07 09:53:43 +0200577 #ifndef EXAMPLE_QAPI_TYPES_H
578 #define EXAMPLE_QAPI_TYPES_H
579
Eric Blakee790e662015-05-04 09:04:59 -0600580[Built-in types omitted...]
Michael Rothb84da832011-07-19 14:50:46 -0500581
582 typedef struct UserDefOne UserDefOne;
583
584 typedef struct UserDefOneList
585 {
Markus Armbruster6e2bb3e2014-05-07 09:53:43 +0200586 union {
587 UserDefOne *value;
588 uint64_t padding;
589 };
Michael Rothb84da832011-07-19 14:50:46 -0500590 struct UserDefOneList *next;
591 } UserDefOneList;
592
Eric Blakee790e662015-05-04 09:04:59 -0600593[Functions on built-in types omitted...]
Markus Armbruster6e2bb3e2014-05-07 09:53:43 +0200594
Michael Rothb84da832011-07-19 14:50:46 -0500595 struct UserDefOne
596 {
597 int64_t integer;
Eric Blake59a2c4c2014-09-26 09:20:33 -0600598 char *string;
Michael Rothb84da832011-07-19 14:50:46 -0500599 };
600
Eric Blake59a2c4c2014-09-26 09:20:33 -0600601 void qapi_free_UserDefOneList(UserDefOneList *obj);
602 void qapi_free_UserDefOne(UserDefOne *obj);
Michael Rothb84da832011-07-19 14:50:46 -0500603
604 #endif
605
Michael Rothb84da832011-07-19 14:50:46 -0500606=== scripts/qapi-visit.py ===
607
608Used to generate the visitor functions used to walk through and convert
609a QObject (as provided by QMP) to a native C data structure and
610vice-versa, as well as the visitor function used to dealloc a complex
611schema-defined C type.
612
613The following files are generated:
614
615$(prefix)qapi-visit.c: visitor function for a particular C type, used
616 to automagically convert QObjects into the
617 corresponding C type and vice-versa, as well
618 as for deallocating memory for an existing C
619 type
620
621$(prefix)qapi-visit.h: declarations for previously mentioned visitor
622 functions
623
624Example:
625
Markus Armbruster87a560c2014-05-14 17:27:23 +0200626 $ python scripts/qapi-visit.py --output-dir="qapi-generated"
Markus Armbruster16d80f62015-04-02 13:32:16 +0200627 --prefix="example-" example-schema.json
Markus Armbruster87a560c2014-05-14 17:27:23 +0200628 $ cat qapi-generated/example-qapi-visit.c
Markus Armbruster6e2bb3e2014-05-07 09:53:43 +0200629[Uninteresting stuff omitted...]
Michael Rothb84da832011-07-19 14:50:46 -0500630
Eric Blake59a2c4c2014-09-26 09:20:33 -0600631 static void visit_type_UserDefOne_fields(Visitor *m, UserDefOne **obj, Error **errp)
Markus Armbruster6e2bb3e2014-05-07 09:53:43 +0200632 {
633 Error *err = NULL;
634 visit_type_int(m, &(*obj)->integer, "integer", &err);
Markus Armbruster297a3642014-05-07 09:53:54 +0200635 if (err) {
636 goto out;
637 }
Markus Armbruster6e2bb3e2014-05-07 09:53:43 +0200638 visit_type_str(m, &(*obj)->string, "string", &err);
Markus Armbruster297a3642014-05-07 09:53:54 +0200639 if (err) {
640 goto out;
641 }
Markus Armbruster6e2bb3e2014-05-07 09:53:43 +0200642
Markus Armbruster297a3642014-05-07 09:53:54 +0200643 out:
Markus Armbruster6e2bb3e2014-05-07 09:53:43 +0200644 error_propagate(errp, err);
645 }
Michael Rothb84da832011-07-19 14:50:46 -0500646
Eric Blake59a2c4c2014-09-26 09:20:33 -0600647 void visit_type_UserDefOne(Visitor *m, UserDefOne **obj, const char *name, Error **errp)
Michael Rothb84da832011-07-19 14:50:46 -0500648 {
Markus Armbruster297a3642014-05-07 09:53:54 +0200649 Error *err = NULL;
650
651 visit_start_struct(m, (void **)obj, "UserDefOne", name, sizeof(UserDefOne), &err);
652 if (!err) {
653 if (*obj) {
654 visit_type_UserDefOne_fields(m, obj, errp);
Markus Armbruster6e2bb3e2014-05-07 09:53:43 +0200655 }
Markus Armbruster297a3642014-05-07 09:53:54 +0200656 visit_end_struct(m, &err);
Markus Armbruster6e2bb3e2014-05-07 09:53:43 +0200657 }
Markus Armbruster297a3642014-05-07 09:53:54 +0200658 error_propagate(errp, err);
Michael Rothb84da832011-07-19 14:50:46 -0500659 }
660
Eric Blake59a2c4c2014-09-26 09:20:33 -0600661 void visit_type_UserDefOneList(Visitor *m, UserDefOneList **obj, const char *name, Error **errp)
Michael Rothb84da832011-07-19 14:50:46 -0500662 {
Markus Armbruster6e2bb3e2014-05-07 09:53:43 +0200663 Error *err = NULL;
Markus Armbruster297a3642014-05-07 09:53:54 +0200664 GenericList *i, **prev;
Michael Rothb84da832011-07-19 14:50:46 -0500665
Markus Armbruster297a3642014-05-07 09:53:54 +0200666 visit_start_list(m, name, &err);
667 if (err) {
668 goto out;
Michael Rothb84da832011-07-19 14:50:46 -0500669 }
Markus Armbruster297a3642014-05-07 09:53:54 +0200670
671 for (prev = (GenericList **)obj;
672 !err && (i = visit_next_list(m, prev, &err)) != NULL;
673 prev = &i) {
674 UserDefOneList *native_i = (UserDefOneList *)i;
675 visit_type_UserDefOne(m, &native_i->value, NULL, &err);
676 }
677
678 error_propagate(errp, err);
679 err = NULL;
680 visit_end_list(m, &err);
681 out:
682 error_propagate(errp, err);
Michael Rothb84da832011-07-19 14:50:46 -0500683 }
Markus Armbruster87a560c2014-05-14 17:27:23 +0200684 $ cat qapi-generated/example-qapi-visit.h
Markus Armbruster6e2bb3e2014-05-07 09:53:43 +0200685[Uninteresting stuff omitted...]
Michael Rothb84da832011-07-19 14:50:46 -0500686
Markus Armbruster6e2bb3e2014-05-07 09:53:43 +0200687 #ifndef EXAMPLE_QAPI_VISIT_H
688 #define EXAMPLE_QAPI_VISIT_H
Michael Rothb84da832011-07-19 14:50:46 -0500689
Eric Blakee790e662015-05-04 09:04:59 -0600690[Visitors for built-in types omitted...]
Michael Rothb84da832011-07-19 14:50:46 -0500691
Eric Blake59a2c4c2014-09-26 09:20:33 -0600692 void visit_type_UserDefOne(Visitor *m, UserDefOne **obj, const char *name, Error **errp);
693 void visit_type_UserDefOneList(Visitor *m, UserDefOneList **obj, const char *name, Error **errp);
Michael Rothb84da832011-07-19 14:50:46 -0500694
695 #endif
Michael Rothb84da832011-07-19 14:50:46 -0500696
Michael Rothb84da832011-07-19 14:50:46 -0500697=== scripts/qapi-commands.py ===
698
699Used to generate the marshaling/dispatch functions for the commands defined
700in the schema. The following files are generated:
701
702$(prefix)qmp-marshal.c: command marshal/dispatch functions for each
703 QMP command defined in the schema. Functions
704 generated by qapi-visit.py are used to
Stefan Weil2542bfd2011-08-28 21:45:40 +0200705 convert QObjects received from the wire into
Michael Rothb84da832011-07-19 14:50:46 -0500706 function parameters, and uses the same
707 visitor functions to convert native C return
708 values to QObjects from transmission back
709 over the wire.
710
711$(prefix)qmp-commands.h: Function prototypes for the QMP commands
712 specified in the schema.
713
714Example:
715
Eric Blake59a2c4c2014-09-26 09:20:33 -0600716 $ python scripts/qapi-commands.py --output-dir="qapi-generated"
Markus Armbruster16d80f62015-04-02 13:32:16 +0200717 --prefix="example-" example-schema.json
Markus Armbruster87a560c2014-05-14 17:27:23 +0200718 $ cat qapi-generated/example-qmp-marshal.c
Markus Armbruster6e2bb3e2014-05-07 09:53:43 +0200719[Uninteresting stuff omitted...]
Michael Rothb84da832011-07-19 14:50:46 -0500720
Eric Blake59a2c4c2014-09-26 09:20:33 -0600721 static void qmp_marshal_output_my_command(UserDefOne *ret_in, QObject **ret_out, Error **errp)
Michael Rothb84da832011-07-19 14:50:46 -0500722 {
Markus Armbruster297a3642014-05-07 09:53:54 +0200723 Error *local_err = NULL;
Michael Rothb84da832011-07-19 14:50:46 -0500724 QmpOutputVisitor *mo = qmp_output_visitor_new();
Markus Armbrusterf9bee752014-05-07 09:53:44 +0200725 QapiDeallocVisitor *md;
Michael Rothb84da832011-07-19 14:50:46 -0500726 Visitor *v;
727
728 v = qmp_output_get_visitor(mo);
Markus Armbruster297a3642014-05-07 09:53:54 +0200729 visit_type_UserDefOne(v, &ret_in, "unused", &local_err);
730 if (local_err) {
731 goto out;
Markus Armbruster6e2bb3e2014-05-07 09:53:43 +0200732 }
Markus Armbruster297a3642014-05-07 09:53:54 +0200733 *ret_out = qmp_output_get_qobject(mo);
734
735 out:
736 error_propagate(errp, local_err);
Markus Armbruster6e2bb3e2014-05-07 09:53:43 +0200737 qmp_output_visitor_cleanup(mo);
Markus Armbrusterf9bee752014-05-07 09:53:44 +0200738 md = qapi_dealloc_visitor_new();
Michael Rothb84da832011-07-19 14:50:46 -0500739 v = qapi_dealloc_get_visitor(md);
Markus Armbruster6e2bb3e2014-05-07 09:53:43 +0200740 visit_type_UserDefOne(v, &ret_in, "unused", NULL);
Michael Rothb84da832011-07-19 14:50:46 -0500741 qapi_dealloc_visitor_cleanup(md);
Michael Rothb84da832011-07-19 14:50:46 -0500742 }
743
Markus Armbruster6e2bb3e2014-05-07 09:53:43 +0200744 static void qmp_marshal_input_my_command(QDict *args, QObject **ret, Error **errp)
Michael Rothb84da832011-07-19 14:50:46 -0500745 {
Markus Armbruster297a3642014-05-07 09:53:54 +0200746 Error *local_err = NULL;
Eric Blake59a2c4c2014-09-26 09:20:33 -0600747 UserDefOne *retval = NULL;
Markus Armbrusterf9bee752014-05-07 09:53:44 +0200748 QmpInputVisitor *mi = qmp_input_visitor_new_strict(QOBJECT(args));
Michael Rothb84da832011-07-19 14:50:46 -0500749 QapiDeallocVisitor *md;
750 Visitor *v;
Eric Blake59a2c4c2014-09-26 09:20:33 -0600751 UserDefOne *arg1 = NULL;
Michael Rothb84da832011-07-19 14:50:46 -0500752
Michael Rothb84da832011-07-19 14:50:46 -0500753 v = qmp_input_get_visitor(mi);
Markus Armbruster297a3642014-05-07 09:53:54 +0200754 visit_type_UserDefOne(v, &arg1, "arg1", &local_err);
755 if (local_err) {
Michael Rothb84da832011-07-19 14:50:46 -0500756 goto out;
757 }
Markus Armbruster297a3642014-05-07 09:53:54 +0200758
759 retval = qmp_my_command(arg1, &local_err);
760 if (local_err) {
761 goto out;
Markus Armbruster6e2bb3e2014-05-07 09:53:43 +0200762 }
Michael Rothb84da832011-07-19 14:50:46 -0500763
Markus Armbruster297a3642014-05-07 09:53:54 +0200764 qmp_marshal_output_my_command(retval, ret, &local_err);
765
Michael Rothb84da832011-07-19 14:50:46 -0500766 out:
Markus Armbruster297a3642014-05-07 09:53:54 +0200767 error_propagate(errp, local_err);
Markus Armbrusterf9bee752014-05-07 09:53:44 +0200768 qmp_input_visitor_cleanup(mi);
Michael Rothb84da832011-07-19 14:50:46 -0500769 md = qapi_dealloc_visitor_new();
770 v = qapi_dealloc_get_visitor(md);
Markus Armbruster6e2bb3e2014-05-07 09:53:43 +0200771 visit_type_UserDefOne(v, &arg1, "arg1", NULL);
Michael Rothb84da832011-07-19 14:50:46 -0500772 qapi_dealloc_visitor_cleanup(md);
Michael Rothb84da832011-07-19 14:50:46 -0500773 }
774
775 static void qmp_init_marshal(void)
776 {
Markus Armbruster6e2bb3e2014-05-07 09:53:43 +0200777 qmp_register_command("my-command", qmp_marshal_input_my_command, QCO_NO_OPTIONS);
Michael Rothb84da832011-07-19 14:50:46 -0500778 }
779
780 qapi_init(qmp_init_marshal);
Markus Armbruster87a560c2014-05-14 17:27:23 +0200781 $ cat qapi-generated/example-qmp-commands.h
Markus Armbruster6e2bb3e2014-05-07 09:53:43 +0200782[Uninteresting stuff omitted...]
Michael Rothb84da832011-07-19 14:50:46 -0500783
Markus Armbruster6e2bb3e2014-05-07 09:53:43 +0200784 #ifndef EXAMPLE_QMP_COMMANDS_H
785 #define EXAMPLE_QMP_COMMANDS_H
Michael Rothb84da832011-07-19 14:50:46 -0500786
787 #include "example-qapi-types.h"
Markus Armbruster6e2bb3e2014-05-07 09:53:43 +0200788 #include "qapi/qmp/qdict.h"
789 #include "qapi/error.h"
Michael Rothb84da832011-07-19 14:50:46 -0500790
Eric Blake59a2c4c2014-09-26 09:20:33 -0600791 UserDefOne *qmp_my_command(UserDefOne *arg1, Error **errp);
792
793 #endif
794
795=== scripts/qapi-event.py ===
796
797Used to generate the event-related C code defined by a schema. The
798following files are created:
799
800$(prefix)qapi-event.h - Function prototypes for each event type, plus an
801 enumeration of all event names
802$(prefix)qapi-event.c - Implementation of functions to send an event
803
804Example:
805
806 $ python scripts/qapi-event.py --output-dir="qapi-generated"
Markus Armbruster16d80f62015-04-02 13:32:16 +0200807 --prefix="example-" example-schema.json
Eric Blake59a2c4c2014-09-26 09:20:33 -0600808 $ cat qapi-generated/example-qapi-event.c
809[Uninteresting stuff omitted...]
810
811 void qapi_event_send_my_event(Error **errp)
812 {
813 QDict *qmp;
814 Error *local_err = NULL;
815 QMPEventFuncEmit emit;
816 emit = qmp_event_get_func_emit();
817 if (!emit) {
818 return;
819 }
820
821 qmp = qmp_event_build_dict("MY_EVENT");
822
823 emit(EXAMPLE_QAPI_EVENT_MY_EVENT, qmp, &local_err);
824
825 error_propagate(errp, local_err);
826 QDECREF(qmp);
827 }
828
829 const char *EXAMPLE_QAPIEvent_lookup[] = {
830 "MY_EVENT",
831 NULL,
832 };
833 $ cat qapi-generated/example-qapi-event.h
834[Uninteresting stuff omitted...]
835
836 #ifndef EXAMPLE_QAPI_EVENT_H
837 #define EXAMPLE_QAPI_EVENT_H
838
839 #include "qapi/error.h"
840 #include "qapi/qmp/qdict.h"
841 #include "example-qapi-types.h"
842
843
844 void qapi_event_send_my_event(Error **errp);
845
846 extern const char *EXAMPLE_QAPIEvent_lookup[];
847 typedef enum EXAMPLE_QAPIEvent
848 {
849 EXAMPLE_QAPI_EVENT_MY_EVENT = 0,
850 EXAMPLE_QAPI_EVENT_MAX = 1,
851 } EXAMPLE_QAPIEvent;
Michael Rothb84da832011-07-19 14:50:46 -0500852
853 #endif