qapi-code-gen.rst 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992
  1. ==================================
  2. How to use the QAPI code generator
  3. ==================================
  4. ..
  5. Copyright IBM Corp. 2011
  6. Copyright (C) 2012-2016 Red Hat, Inc.
  7. This work is licensed under the terms of the GNU GPL, version 2 or
  8. later. See the COPYING file in the top-level directory.
  9. Introduction
  10. ============
  11. QAPI is a native C API within QEMU which provides management-level
  12. functionality to internal and external users. For external
  13. users/processes, this interface is made available by a JSON-based wire
  14. format for the QEMU Monitor Protocol (QMP) for controlling qemu, as
  15. well as the QEMU Guest Agent (QGA) for communicating with the guest.
  16. The remainder of this document uses "Client JSON Protocol" when
  17. referring to the wire contents of a QMP or QGA connection.
  18. To map between Client JSON Protocol interfaces and the native C API,
  19. we generate C code from a QAPI schema. This document describes the
  20. QAPI schema language, and how it gets mapped to the Client JSON
  21. Protocol and to C. It additionally provides guidance on maintaining
  22. Client JSON Protocol compatibility.
  23. The QAPI schema language
  24. ========================
  25. The QAPI schema defines the Client JSON Protocol's commands and
  26. events, as well as types used by them. Forward references are
  27. allowed.
  28. It is permissible for the schema to contain additional types not used
  29. by any commands or events, for the side effect of generated C code
  30. used internally.
  31. There are several kinds of types: simple types (a number of built-in
  32. types, such as ``int`` and ``str``; as well as enumerations), arrays,
  33. complex types (structs and two flavors of unions), and alternate types
  34. (a choice between other types).
  35. Schema syntax
  36. -------------
  37. Syntax is loosely based on `JSON <http://www.ietf.org/rfc/rfc8259.txt>`_.
  38. Differences:
  39. * Comments: start with a hash character (``#``) that is not part of a
  40. string, and extend to the end of the line.
  41. * Strings are enclosed in ``'single quotes'``, not ``"double quotes"``.
  42. * Strings are restricted to printable ASCII, and escape sequences to
  43. just ``\\``.
  44. * Numbers and ``null`` are not supported.
  45. A second layer of syntax defines the sequences of JSON texts that are
  46. a correctly structured QAPI schema. We provide a grammar for this
  47. syntax in an EBNF-like notation:
  48. * Production rules look like ``non-terminal = expression``
  49. * Concatenation: expression ``A B`` matches expression ``A``, then ``B``
  50. * Alternation: expression ``A | B`` matches expression ``A`` or ``B``
  51. * Repetition: expression ``A...`` matches zero or more occurrences of
  52. expression ``A``
  53. * Repetition: expression ``A, ...`` matches zero or more occurrences of
  54. expression ``A`` separated by ``,``
  55. * Grouping: expression ``( A )`` matches expression ``A``
  56. * JSON's structural characters are terminals: ``{ } [ ] : ,``
  57. * JSON's literal names are terminals: ``false true``
  58. * String literals enclosed in ``'single quotes'`` are terminal, and match
  59. this JSON string, with a leading ``*`` stripped off
  60. * When JSON object member's name starts with ``*``, the member is
  61. optional.
  62. * The symbol ``STRING`` is a terminal, and matches any JSON string
  63. * The symbol ``BOOL`` is a terminal, and matches JSON ``false`` or ``true``
  64. * ALL-CAPS words other than ``STRING`` are non-terminals
  65. The order of members within JSON objects does not matter unless
  66. explicitly noted.
  67. A QAPI schema consists of a series of top-level expressions::
  68. SCHEMA = TOP-LEVEL-EXPR...
  69. The top-level expressions are all JSON objects. Code and
  70. documentation is generated in schema definition order. Code order
  71. should not matter.
  72. A top-level expressions is either a directive or a definition::
  73. TOP-LEVEL-EXPR = DIRECTIVE | DEFINITION
  74. There are two kinds of directives and six kinds of definitions::
  75. DIRECTIVE = INCLUDE | PRAGMA
  76. DEFINITION = ENUM | STRUCT | UNION | ALTERNATE | COMMAND | EVENT
  77. These are discussed in detail below.
  78. Built-in Types
  79. --------------
  80. The following types are predefined, and map to C as follows:
  81. ============= ============== ============================================
  82. Schema C JSON
  83. ============= ============== ============================================
  84. ``str`` ``char *`` any JSON string, UTF-8
  85. ``number`` ``double`` any JSON number
  86. ``int`` ``int64_t`` a JSON number without fractional part
  87. that fits into the C integer type
  88. ``int8`` ``int8_t`` likewise
  89. ``int16`` ``int16_t`` likewise
  90. ``int32`` ``int32_t`` likewise
  91. ``int64`` ``int64_t`` likewise
  92. ``uint8`` ``uint8_t`` likewise
  93. ``uint16`` ``uint16_t`` likewise
  94. ``uint32`` ``uint32_t`` likewise
  95. ``uint64`` ``uint64_t`` likewise
  96. ``size`` ``uint64_t`` like ``uint64_t``, except
  97. ``StringInputVisitor`` accepts size suffixes
  98. ``bool`` ``bool`` JSON ``true`` or ``false``
  99. ``null`` ``QNull *`` JSON ``null``
  100. ``any`` ``QObject *`` any JSON value
  101. ``QType`` ``QType`` JSON string matching enum ``QType`` values
  102. ============= ============== ============================================
  103. Include directives
  104. ------------------
  105. Syntax::
  106. INCLUDE = { 'include': STRING }
  107. The QAPI schema definitions can be modularized using the 'include' directive::
  108. { 'include': 'path/to/file.json' }
  109. The directive is evaluated recursively, and include paths are relative
  110. to the file using the directive. Multiple includes of the same file
  111. are idempotent.
  112. As a matter of style, it is a good idea to have all files be
  113. self-contained, but at the moment, nothing prevents an included file
  114. from making a forward reference to a type that is only introduced by
  115. an outer file. The parser may be made stricter in the future to
  116. prevent incomplete include files.
  117. .. _pragma:
  118. Pragma directives
  119. -----------------
  120. Syntax::
  121. PRAGMA = { 'pragma': {
  122. '*doc-required': BOOL,
  123. '*command-name-exceptions': [ STRING, ... ],
  124. '*command-returns-exceptions': [ STRING, ... ],
  125. '*member-name-exceptions': [ STRING, ... ] } }
  126. The pragma directive lets you control optional generator behavior.
  127. Pragma's scope is currently the complete schema. Setting the same
  128. pragma to different values in parts of the schema doesn't work.
  129. Pragma 'doc-required' takes a boolean value. If true, documentation
  130. is required. Default is false.
  131. Pragma 'command-name-exceptions' takes a list of commands whose names
  132. may contain ``"_"`` instead of ``"-"``. Default is none.
  133. Pragma 'command-returns-exceptions' takes a list of commands that may
  134. violate the rules on permitted return types. Default is none.
  135. Pragma 'member-name-exceptions' takes a list of types whose member
  136. names may contain uppercase letters, and ``"_"`` instead of ``"-"``.
  137. Default is none.
  138. .. _ENUM-VALUE:
  139. Enumeration types
  140. -----------------
  141. Syntax::
  142. ENUM = { 'enum': STRING,
  143. 'data': [ ENUM-VALUE, ... ],
  144. '*prefix': STRING,
  145. '*if': COND,
  146. '*features': FEATURES }
  147. ENUM-VALUE = STRING
  148. | { 'name': STRING, '*if': COND }
  149. Member 'enum' names the enum type.
  150. Each member of the 'data' array defines a value of the enumeration
  151. type. The form STRING is shorthand for :code:`{ 'name': STRING }`. The
  152. 'name' values must be be distinct.
  153. Example::
  154. { 'enum': 'MyEnum', 'data': [ 'value1', 'value2', 'value3' ] }
  155. Nothing prevents an empty enumeration, although it is probably not
  156. useful.
  157. On the wire, an enumeration type's value is represented by its
  158. (string) name. In C, it's represented by an enumeration constant.
  159. These are of the form PREFIX_NAME, where PREFIX is derived from the
  160. enumeration type's name, and NAME from the value's name. For the
  161. example above, the generator maps 'MyEnum' to MY_ENUM and 'value1' to
  162. VALUE1, resulting in the enumeration constant MY_ENUM_VALUE1. The
  163. optional 'prefix' member overrides PREFIX.
  164. The generated C enumeration constants have values 0, 1, ..., N-1 (in
  165. QAPI schema order), where N is the number of values. There is an
  166. additional enumeration constant PREFIX__MAX with value N.
  167. Do not use string or an integer type when an enumeration type can do
  168. the job satisfactorily.
  169. The optional 'if' member specifies a conditional. See `Configuring the
  170. schema`_ below for more on this.
  171. The optional 'features' member specifies features. See Features_
  172. below for more on this.
  173. .. _TYPE-REF:
  174. Type references and array types
  175. -------------------------------
  176. Syntax::
  177. TYPE-REF = STRING | ARRAY-TYPE
  178. ARRAY-TYPE = [ STRING ]
  179. A string denotes the type named by the string.
  180. A one-element array containing a string denotes an array of the type
  181. named by the string. Example: ``['int']`` denotes an array of ``int``.
  182. Struct types
  183. ------------
  184. Syntax::
  185. STRUCT = { 'struct': STRING,
  186. 'data': MEMBERS,
  187. '*base': STRING,
  188. '*if': COND,
  189. '*features': FEATURES }
  190. MEMBERS = { MEMBER, ... }
  191. MEMBER = STRING : TYPE-REF
  192. | STRING : { 'type': TYPE-REF,
  193. '*if': COND,
  194. '*features': FEATURES }
  195. Member 'struct' names the struct type.
  196. Each MEMBER of the 'data' object defines a member of the struct type.
  197. .. _MEMBERS:
  198. The MEMBER's STRING name consists of an optional ``*`` prefix and the
  199. struct member name. If ``*`` is present, the member is optional.
  200. The MEMBER's value defines its properties, in particular its type.
  201. The form TYPE-REF_ is shorthand for :code:`{ 'type': TYPE-REF }`.
  202. Example::
  203. { 'struct': 'MyType',
  204. 'data': { 'member1': 'str', 'member2': ['int'], '*member3': 'str' } }
  205. A struct type corresponds to a struct in C, and an object in JSON.
  206. The C struct's members are generated in QAPI schema order.
  207. The optional 'base' member names a struct type whose members are to be
  208. included in this type. They go first in the C struct.
  209. Example::
  210. { 'struct': 'BlockdevOptionsGenericFormat',
  211. 'data': { 'file': 'str' } }
  212. { 'struct': 'BlockdevOptionsGenericCOWFormat',
  213. 'base': 'BlockdevOptionsGenericFormat',
  214. 'data': { '*backing': 'str' } }
  215. An example BlockdevOptionsGenericCOWFormat object on the wire could use
  216. both members like this::
  217. { "file": "/some/place/my-image",
  218. "backing": "/some/place/my-backing-file" }
  219. The optional 'if' member specifies a conditional. See `Configuring
  220. the schema`_ below for more on this.
  221. The optional 'features' member specifies features. See Features_
  222. below for more on this.
  223. Union types
  224. -----------
  225. Syntax::
  226. UNION = { 'union': STRING,
  227. 'data': BRANCHES,
  228. '*if': COND,
  229. '*features': FEATURES }
  230. | { 'union': STRING,
  231. 'data': BRANCHES,
  232. 'base': ( MEMBERS | STRING ),
  233. 'discriminator': STRING,
  234. '*if': COND,
  235. '*features': FEATURES }
  236. BRANCHES = { BRANCH, ... }
  237. BRANCH = STRING : TYPE-REF
  238. | STRING : { 'type': TYPE-REF, '*if': COND }
  239. Member 'union' names the union type.
  240. There are two flavors of union types: simple (no discriminator or
  241. base), and flat (both discriminator and base).
  242. Each BRANCH of the 'data' object defines a branch of the union. A
  243. union must have at least one branch.
  244. The BRANCH's STRING name is the branch name.
  245. The BRANCH's value defines the branch's properties, in particular its
  246. type. The form TYPE-REF_ is shorthand for :code:`{ 'type': TYPE-REF }`.
  247. A simple union type defines a mapping from automatic discriminator
  248. values to data types like in this example::
  249. { 'struct': 'BlockdevOptionsFile', 'data': { 'filename': 'str' } }
  250. { 'struct': 'BlockdevOptionsQcow2',
  251. 'data': { 'backing': 'str', '*lazy-refcounts': 'bool' } }
  252. { 'union': 'BlockdevOptionsSimple',
  253. 'data': { 'file': 'BlockdevOptionsFile',
  254. 'qcow2': 'BlockdevOptionsQcow2' } }
  255. In the Client JSON Protocol, a simple union is represented by an
  256. object that contains the 'type' member as a discriminator, and a
  257. 'data' member that is of the specified data type corresponding to the
  258. discriminator value, as in these examples::
  259. { "type": "file", "data": { "filename": "/some/place/my-image" } }
  260. { "type": "qcow2", "data": { "backing": "/some/place/my-image",
  261. "lazy-refcounts": true } }
  262. The generated C code uses a struct containing a union. Additionally,
  263. an implicit C enum 'NameKind' is created, corresponding to the union
  264. 'Name', for accessing the various branches of the union. The value
  265. for each branch can be of any type.
  266. Flat unions permit arbitrary common members that occur in all variants
  267. of the union, not just a discriminator. Their discriminators need not
  268. be named 'type'. They also avoid nesting on the wire.
  269. The 'base' member defines the common members. If it is a MEMBERS_
  270. object, it defines common members just like a struct type's 'data'
  271. member defines struct type members. If it is a STRING, it names a
  272. struct type whose members are the common members.
  273. All flat union branches must be `Struct types`_.
  274. In the Client JSON Protocol, a flat union is represented by an object
  275. with the common members (from the base type) and the selected branch's
  276. members. The two sets of member names must be disjoint. Member
  277. 'discriminator' must name a non-optional enum-typed member of the base
  278. struct.
  279. The following example enhances the above simple union example by
  280. adding an optional common member 'read-only', renaming the
  281. discriminator to something more applicable than the simple union's
  282. default of 'type', and reducing the number of ``{}`` required on the wire::
  283. { 'enum': 'BlockdevDriver', 'data': [ 'file', 'qcow2' ] }
  284. { 'union': 'BlockdevOptions',
  285. 'base': { 'driver': 'BlockdevDriver', '*read-only': 'bool' },
  286. 'discriminator': 'driver',
  287. 'data': { 'file': 'BlockdevOptionsFile',
  288. 'qcow2': 'BlockdevOptionsQcow2' } }
  289. Resulting in these JSON objects::
  290. { "driver": "file", "read-only": true,
  291. "filename": "/some/place/my-image" }
  292. { "driver": "qcow2", "read-only": false,
  293. "backing": "/some/place/my-image", "lazy-refcounts": true }
  294. Notice that in a flat union, the discriminator name is controlled by
  295. the user, but because it must map to a base member with enum type, the
  296. code generator ensures that branches match the existing values of the
  297. enum. The order of branches need not match the order of the enum
  298. values. The branches need not cover all possible enum values.
  299. Omitted enum values are still valid branches that add no additional
  300. members to the data type. In the resulting generated C data types, a
  301. flat union is represented as a struct with the base members in QAPI
  302. schema order, and then a union of structures for each branch of the
  303. struct.
  304. A simple union can always be re-written as a flat union where the base
  305. class has a single member named 'type', and where each branch of the
  306. union has a struct with a single member named 'data'. That is, ::
  307. { 'union': 'Simple', 'data': { 'one': 'str', 'two': 'int' } }
  308. is identical on the wire to::
  309. { 'enum': 'Enum', 'data': ['one', 'two'] }
  310. { 'struct': 'Branch1', 'data': { 'data': 'str' } }
  311. { 'struct': 'Branch2', 'data': { 'data': 'int' } }
  312. { 'union': 'Flat', 'base': { 'type': 'Enum' }, 'discriminator': 'type',
  313. 'data': { 'one': 'Branch1', 'two': 'Branch2' } }
  314. The optional 'if' member specifies a conditional. See `Configuring
  315. the schema`_ below for more on this.
  316. The optional 'features' member specifies features. See Features_
  317. below for more on this.
  318. Alternate types
  319. ---------------
  320. Syntax::
  321. ALTERNATE = { 'alternate': STRING,
  322. 'data': ALTERNATIVES,
  323. '*if': COND,
  324. '*features': FEATURES }
  325. ALTERNATIVES = { ALTERNATIVE, ... }
  326. ALTERNATIVE = STRING : STRING
  327. | STRING : { 'type': STRING, '*if': COND }
  328. Member 'alternate' names the alternate type.
  329. Each ALTERNATIVE of the 'data' object defines a branch of the
  330. alternate. An alternate must have at least one branch.
  331. The ALTERNATIVE's STRING name is the branch name.
  332. The ALTERNATIVE's value defines the branch's properties, in particular
  333. its type. The form STRING is shorthand for :code:`{ 'type': STRING }`.
  334. Example::
  335. { 'alternate': 'BlockdevRef',
  336. 'data': { 'definition': 'BlockdevOptions',
  337. 'reference': 'str' } }
  338. An alternate type is like a union type, except there is no
  339. discriminator on the wire. Instead, the branch to use is inferred
  340. from the value. An alternate can only express a choice between types
  341. represented differently on the wire.
  342. If a branch is typed as the 'bool' built-in, the alternate accepts
  343. true and false; if it is typed as any of the various numeric
  344. built-ins, it accepts a JSON number; if it is typed as a 'str'
  345. built-in or named enum type, it accepts a JSON string; if it is typed
  346. as the 'null' built-in, it accepts JSON null; and if it is typed as a
  347. complex type (struct or union), it accepts a JSON object.
  348. The example alternate declaration above allows using both of the
  349. following example objects::
  350. { "file": "my_existing_block_device_id" }
  351. { "file": { "driver": "file",
  352. "read-only": false,
  353. "filename": "/tmp/mydisk.qcow2" } }
  354. The optional 'if' member specifies a conditional. See `Configuring
  355. the schema`_ below for more on this.
  356. The optional 'features' member specifies features. See Features_
  357. below for more on this.
  358. Commands
  359. --------
  360. Syntax::
  361. COMMAND = { 'command': STRING,
  362. (
  363. '*data': ( MEMBERS | STRING ),
  364. |
  365. 'data': STRING,
  366. 'boxed': true,
  367. )
  368. '*returns': TYPE-REF,
  369. '*success-response': false,
  370. '*gen': false,
  371. '*allow-oob': true,
  372. '*allow-preconfig': true,
  373. '*coroutine': true,
  374. '*if': COND,
  375. '*features': FEATURES }
  376. Member 'command' names the command.
  377. Member 'data' defines the arguments. It defaults to an empty MEMBERS_
  378. object.
  379. If 'data' is a MEMBERS_ object, then MEMBERS defines arguments just
  380. like a struct type's 'data' defines struct type members.
  381. If 'data' is a STRING, then STRING names a complex type whose members
  382. are the arguments. A union type requires ``'boxed': true``.
  383. Member 'returns' defines the command's return type. It defaults to an
  384. empty struct type. It must normally be a complex type or an array of
  385. a complex type. To return anything else, the command must be listed
  386. in pragma 'commands-returns-exceptions'. If you do this, extending
  387. the command to return additional information will be harder. Use of
  388. the pragma for new commands is strongly discouraged.
  389. A command's error responses are not specified in the QAPI schema.
  390. Error conditions should be documented in comments.
  391. In the Client JSON Protocol, the value of the "execute" or "exec-oob"
  392. member is the command name. The value of the "arguments" member then
  393. has to conform to the arguments, and the value of the success
  394. response's "return" member will conform to the return type.
  395. Some example commands::
  396. { 'command': 'my-first-command',
  397. 'data': { 'arg1': 'str', '*arg2': 'str' } }
  398. { 'struct': 'MyType', 'data': { '*value': 'str' } }
  399. { 'command': 'my-second-command',
  400. 'returns': [ 'MyType' ] }
  401. which would validate this Client JSON Protocol transaction::
  402. => { "execute": "my-first-command",
  403. "arguments": { "arg1": "hello" } }
  404. <= { "return": { } }
  405. => { "execute": "my-second-command" }
  406. <= { "return": [ { "value": "one" }, { } ] }
  407. The generator emits a prototype for the C function implementing the
  408. command. The function itself needs to be written by hand. See
  409. section `Code generated for commands`_ for examples.
  410. The function returns the return type. When member 'boxed' is absent,
  411. it takes the command arguments as arguments one by one, in QAPI schema
  412. order. Else it takes them wrapped in the C struct generated for the
  413. complex argument type. It takes an additional ``Error **`` argument in
  414. either case.
  415. The generator also emits a marshalling function that extracts
  416. arguments for the user's function out of an input QDict, calls the
  417. user's function, and if it succeeded, builds an output QObject from
  418. its return value. This is for use by the QMP monitor core.
  419. In rare cases, QAPI cannot express a type-safe representation of a
  420. corresponding Client JSON Protocol command. You then have to suppress
  421. generation of a marshalling function by including a member 'gen' with
  422. boolean value false, and instead write your own function. For
  423. example::
  424. { 'command': 'netdev_add',
  425. 'data': {'type': 'str', 'id': 'str'},
  426. 'gen': false }
  427. Please try to avoid adding new commands that rely on this, and instead
  428. use type-safe unions.
  429. Normally, the QAPI schema is used to describe synchronous exchanges,
  430. where a response is expected. But in some cases, the action of a
  431. command is expected to change state in a way that a successful
  432. response is not possible (although the command will still return an
  433. error object on failure). When a successful reply is not possible,
  434. the command definition includes the optional member 'success-response'
  435. with boolean value false. So far, only QGA makes use of this member.
  436. Member 'allow-oob' declares whether the command supports out-of-band
  437. (OOB) execution. It defaults to false. For example::
  438. { 'command': 'migrate_recover',
  439. 'data': { 'uri': 'str' }, 'allow-oob': true }
  440. See qmp-spec.txt for out-of-band execution syntax and semantics.
  441. Commands supporting out-of-band execution can still be executed
  442. in-band.
  443. When a command is executed in-band, its handler runs in the main
  444. thread with the BQL held.
  445. When a command is executed out-of-band, its handler runs in a
  446. dedicated monitor I/O thread with the BQL *not* held.
  447. An OOB-capable command handler must satisfy the following conditions:
  448. - It terminates quickly.
  449. - It does not invoke system calls that may block.
  450. - It does not access guest RAM that may block when userfaultfd is
  451. enabled for postcopy live migration.
  452. - It takes only "fast" locks, i.e. all critical sections protected by
  453. any lock it takes also satisfy the conditions for OOB command
  454. handler code.
  455. The restrictions on locking limit access to shared state. Such access
  456. requires synchronization, but OOB commands can't take the BQL or any
  457. other "slow" lock.
  458. When in doubt, do not implement OOB execution support.
  459. Member 'allow-preconfig' declares whether the command is available
  460. before the machine is built. It defaults to false. For example::
  461. { 'enum': 'QMPCapability',
  462. 'data': [ 'oob' ] }
  463. { 'command': 'qmp_capabilities',
  464. 'data': { '*enable': [ 'QMPCapability' ] },
  465. 'allow-preconfig': true }
  466. QMP is available before the machine is built only when QEMU was
  467. started with --preconfig.
  468. Member 'coroutine' tells the QMP dispatcher whether the command handler
  469. is safe to be run in a coroutine. It defaults to false. If it is true,
  470. the command handler is called from coroutine context and may yield while
  471. waiting for an external event (such as I/O completion) in order to avoid
  472. blocking the guest and other background operations.
  473. Coroutine safety can be hard to prove, similar to thread safety. Common
  474. pitfalls are:
  475. - The global mutex isn't held across ``qemu_coroutine_yield()``, so
  476. operations that used to assume that they execute atomically may have
  477. to be more careful to protect against changes in the global state.
  478. - Nested event loops (``AIO_WAIT_WHILE()`` etc.) are problematic in
  479. coroutine context and can easily lead to deadlocks. They should be
  480. replaced by yielding and reentering the coroutine when the condition
  481. becomes false.
  482. Since the command handler may assume coroutine context, any callers
  483. other than the QMP dispatcher must also call it in coroutine context.
  484. In particular, HMP commands calling such a QMP command handler must be
  485. marked ``.coroutine = true`` in hmp-commands.hx.
  486. It is an error to specify both ``'coroutine': true`` and ``'allow-oob': true``
  487. for a command. We don't currently have a use case for both together and
  488. without a use case, it's not entirely clear what the semantics should
  489. be.
  490. The optional 'if' member specifies a conditional. See `Configuring
  491. the schema`_ below for more on this.
  492. The optional 'features' member specifies features. See Features_
  493. below for more on this.
  494. Events
  495. ------
  496. Syntax::
  497. EVENT = { 'event': STRING,
  498. (
  499. '*data': ( MEMBERS | STRING ),
  500. |
  501. 'data': STRING,
  502. 'boxed': true,
  503. )
  504. '*if': COND,
  505. '*features': FEATURES }
  506. Member 'event' names the event. This is the event name used in the
  507. Client JSON Protocol.
  508. Member 'data' defines the event-specific data. It defaults to an
  509. empty MEMBERS object.
  510. If 'data' is a MEMBERS object, then MEMBERS defines event-specific
  511. data just like a struct type's 'data' defines struct type members.
  512. If 'data' is a STRING, then STRING names a complex type whose members
  513. are the event-specific data. A union type requires ``'boxed': true``.
  514. An example event is::
  515. { 'event': 'EVENT_C',
  516. 'data': { '*a': 'int', 'b': 'str' } }
  517. Resulting in this JSON object::
  518. { "event": "EVENT_C",
  519. "data": { "b": "test string" },
  520. "timestamp": { "seconds": 1267020223, "microseconds": 435656 } }
  521. The generator emits a function to send the event. When member 'boxed'
  522. is absent, it takes event-specific data one by one, in QAPI schema
  523. order. Else it takes them wrapped in the C struct generated for the
  524. complex type. See section `Code generated for events`_ for examples.
  525. The optional 'if' member specifies a conditional. See `Configuring
  526. the schema`_ below for more on this.
  527. The optional 'features' member specifies features. See Features_
  528. below for more on this.
  529. .. _FEATURE:
  530. Features
  531. --------
  532. Syntax::
  533. FEATURES = [ FEATURE, ... ]
  534. FEATURE = STRING
  535. | { 'name': STRING, '*if': COND }
  536. Sometimes, the behaviour of QEMU changes compatibly, but without a
  537. change in the QMP syntax (usually by allowing values or operations
  538. that previously resulted in an error). QMP clients may still need to
  539. know whether the extension is available.
  540. For this purpose, a list of features can be specified for a command or
  541. struct type. Each list member can either be ``{ 'name': STRING, '*if':
  542. COND }``, or STRING, which is shorthand for ``{ 'name': STRING }``.
  543. The optional 'if' member specifies a conditional. See `Configuring
  544. the schema`_ below for more on this.
  545. Example::
  546. { 'struct': 'TestType',
  547. 'data': { 'number': 'int' },
  548. 'features': [ 'allow-negative-numbers' ] }
  549. The feature strings are exposed to clients in introspection, as
  550. explained in section `Client JSON Protocol introspection`_.
  551. Intended use is to have each feature string signal that this build of
  552. QEMU shows a certain behaviour.
  553. Special features
  554. ~~~~~~~~~~~~~~~~
  555. Feature "deprecated" marks a command, event, or struct member as
  556. deprecated. It is not supported elsewhere so far.
  557. Naming rules and reserved names
  558. -------------------------------
  559. All names must begin with a letter, and contain only ASCII letters,
  560. digits, hyphen, and underscore. There are two exceptions: enum values
  561. may start with a digit, and names that are downstream extensions (see
  562. section `Downstream extensions`_) start with underscore.
  563. Names beginning with ``q_`` are reserved for the generator, which uses
  564. them for munging QMP names that resemble C keywords or other
  565. problematic strings. For example, a member named ``default`` in qapi
  566. becomes ``q_default`` in the generated C code.
  567. Types, commands, and events share a common namespace. Therefore,
  568. generally speaking, type definitions should always use CamelCase for
  569. user-defined type names, while built-in types are lowercase.
  570. Type names ending with ``Kind`` or ``List`` are reserved for the
  571. generator, which uses them for implicit union enums and array types,
  572. respectively.
  573. Command names, and member names within a type, should be all lower
  574. case with words separated by a hyphen. However, some existing older
  575. commands and complex types use underscore; when extending them,
  576. consistency is preferred over blindly avoiding underscore.
  577. Event names should be ALL_CAPS with words separated by underscore.
  578. Member name ``u`` and names starting with ``has-`` or ``has_`` are reserved
  579. for the generator, which uses them for unions and for tracking
  580. optional members.
  581. Any name (command, event, type, member, or enum value) beginning with
  582. ``x-`` is marked experimental, and may be withdrawn or changed
  583. incompatibly in a future release.
  584. Pragmas ``command-name-exceptions`` and ``member-name-exceptions`` let
  585. you violate naming rules. Use for new code is strongly discouraged. See
  586. `Pragma directives`_ for details.
  587. Downstream extensions
  588. ---------------------
  589. QAPI schema names that are externally visible, say in the Client JSON
  590. Protocol, need to be managed with care. Names starting with a
  591. downstream prefix of the form __RFQDN_ are reserved for the downstream
  592. who controls the valid, reverse fully qualified domain name RFQDN.
  593. RFQDN may only contain ASCII letters, digits, hyphen and period.
  594. Example: Red Hat, Inc. controls redhat.com, and may therefore add a
  595. downstream command ``__com.redhat_drive-mirror``.
  596. Configuring the schema
  597. ----------------------
  598. Syntax::
  599. COND = STRING
  600. | { 'all: [ COND, ... ] }
  601. | { 'any: [ COND, ... ] }
  602. | { 'not': COND }
  603. All definitions take an optional 'if' member. Its value must be a
  604. string, or an object with a single member 'all', 'any' or 'not'.
  605. The C code generated for the definition will then be guarded by an #if
  606. preprocessing directive with an operand generated from that condition:
  607. * STRING will generate defined(STRING)
  608. * { 'all': [COND, ...] } will generate (COND && ...)
  609. * { 'any': [COND, ...] } will generate (COND || ...)
  610. * { 'not': COND } will generate !COND
  611. Example: a conditional struct ::
  612. { 'struct': 'IfStruct', 'data': { 'foo': 'int' },
  613. 'if': { 'all': [ 'CONFIG_FOO', 'HAVE_BAR' ] } }
  614. gets its generated code guarded like this::
  615. #if defined(CONFIG_FOO) && defined(HAVE_BAR)
  616. ... generated code ...
  617. #endif /* defined(HAVE_BAR) && defined(CONFIG_FOO) */
  618. Individual members of complex types, commands arguments, and
  619. event-specific data can also be made conditional. This requires the
  620. longhand form of MEMBER.
  621. Example: a struct type with unconditional member 'foo' and conditional
  622. member 'bar' ::
  623. { 'struct': 'IfStruct', 'data':
  624. { 'foo': 'int',
  625. 'bar': { 'type': 'int', 'if': 'IFCOND'} } }
  626. A union's discriminator may not be conditional.
  627. Likewise, individual enumeration values be conditional. This requires
  628. the longhand form of ENUM-VALUE_.
  629. Example: an enum type with unconditional value 'foo' and conditional
  630. value 'bar' ::
  631. { 'enum': 'IfEnum', 'data':
  632. [ 'foo',
  633. { 'name' : 'bar', 'if': 'IFCOND' } ] }
  634. Likewise, features can be conditional. This requires the longhand
  635. form of FEATURE_.
  636. Example: a struct with conditional feature 'allow-negative-numbers' ::
  637. { 'struct': 'TestType',
  638. 'data': { 'number': 'int' },
  639. 'features': [ { 'name': 'allow-negative-numbers',
  640. 'if': 'IFCOND' } ] }
  641. Please note that you are responsible to ensure that the C code will
  642. compile with an arbitrary combination of conditions, since the
  643. generator is unable to check it at this point.
  644. The conditions apply to introspection as well, i.e. introspection
  645. shows a conditional entity only when the condition is satisfied in
  646. this particular build.
  647. Documentation comments
  648. ----------------------
  649. A multi-line comment that starts and ends with a ``##`` line is a
  650. documentation comment.
  651. If the documentation comment starts like ::
  652. ##
  653. # @SYMBOL:
  654. it documents the definition of SYMBOL, else it's free-form
  655. documentation.
  656. See below for more on `Definition documentation`_.
  657. Free-form documentation may be used to provide additional text and
  658. structuring content.
  659. Headings and subheadings
  660. ~~~~~~~~~~~~~~~~~~~~~~~~
  661. A free-form documentation comment containing a line which starts with
  662. some ``=`` symbols and then a space defines a section heading::
  663. ##
  664. # = This is a top level heading
  665. #
  666. # This is a free-form comment which will go under the
  667. # top level heading.
  668. ##
  669. ##
  670. # == This is a second level heading
  671. ##
  672. A heading line must be the first line of the documentation
  673. comment block.
  674. Section headings must always be correctly nested, so you can only
  675. define a third-level heading inside a second-level heading, and so on.
  676. Documentation markup
  677. ~~~~~~~~~~~~~~~~~~~~
  678. Documentation comments can use most rST markup. In particular,
  679. a ``::`` literal block can be used for examples::
  680. # ::
  681. #
  682. # Text of the example, may span
  683. # multiple lines
  684. ``*`` starts an itemized list::
  685. # * First item, may span
  686. # multiple lines
  687. # * Second item
  688. You can also use ``-`` instead of ``*``.
  689. A decimal number followed by ``.`` starts a numbered list::
  690. # 1. First item, may span
  691. # multiple lines
  692. # 2. Second item
  693. The actual number doesn't matter.
  694. Lists of either kind must be preceded and followed by a blank line.
  695. If a list item's text spans multiple lines, then the second and
  696. subsequent lines must be correctly indented to line up with the
  697. first character of the first line.
  698. The usual ****strong****, *\*emphasized\** and ````literal```` markup
  699. should be used. If you need a single literal ``*``, you will need to
  700. backslash-escape it. As an extension beyond the usual rST syntax, you
  701. can also use ``@foo`` to reference a name in the schema; this is rendered
  702. the same way as ````foo````.
  703. Example::
  704. ##
  705. # Some text foo with **bold** and *emphasis*
  706. # 1. with a list
  707. # 2. like that
  708. #
  709. # And some code:
  710. #
  711. # ::
  712. #
  713. # $ echo foo
  714. # -> do this
  715. # <- get that
  716. ##
  717. Definition documentation
  718. ~~~~~~~~~~~~~~~~~~~~~~~~
  719. Definition documentation, if present, must immediately precede the
  720. definition it documents.
  721. When documentation is required (see pragma_ 'doc-required'), every
  722. definition must have documentation.
  723. Definition documentation starts with a line naming the definition,
  724. followed by an optional overview, a description of each argument (for
  725. commands and events), member (for structs and unions), branch (for
  726. alternates), or value (for enums), and finally optional tagged
  727. sections.
  728. Descriptions of arguments can span multiple lines. The description
  729. text can start on the line following the '\@argname:', in which case it
  730. must not be indented at all. It can also start on the same line as
  731. the '\@argname:'. In this case if it spans multiple lines then second
  732. and subsequent lines must be indented to line up with the first
  733. character of the first line of the description::
  734. # @argone:
  735. # This is a two line description
  736. # in the first style.
  737. #
  738. # @argtwo: This is a two line description
  739. # in the second style.
  740. The number of spaces between the ':' and the text is not significant.
  741. .. admonition:: FIXME
  742. The parser accepts these things in almost any order.
  743. .. admonition:: FIXME
  744. union branches should be described, too.
  745. Extensions added after the definition was first released carry a
  746. '(since x.y.z)' comment.
  747. A tagged section starts with one of the following words:
  748. "Note:"/"Notes:", "Since:", "Example"/"Examples", "Returns:", "TODO:".
  749. The section ends with the start of a new section.
  750. The text of a section can start on a new line, in
  751. which case it must not be indented at all. It can also start
  752. on the same line as the 'Note:', 'Returns:', etc tag. In this
  753. case if it spans multiple lines then second and subsequent
  754. lines must be indented to match the first, in the same way as
  755. multiline argument descriptions.
  756. A 'Since: x.y.z' tagged section lists the release that introduced the
  757. definition.
  758. The text of a section can start on a new line, in
  759. which case it must not be indented at all. It can also start
  760. on the same line as the 'Note:', 'Returns:', etc tag. In this
  761. case if it spans multiple lines then second and subsequent
  762. lines must be indented to match the first.
  763. An 'Example' or 'Examples' section is automatically rendered
  764. entirely as literal fixed-width text. In other sections,
  765. the text is formatted, and rST markup can be used.
  766. For example::
  767. ##
  768. # @BlockStats:
  769. #
  770. # Statistics of a virtual block device or a block backing device.
  771. #
  772. # @device: If the stats are for a virtual block device, the name
  773. # corresponding to the virtual block device.
  774. #
  775. # @node-name: The node name of the device. (since 2.3)
  776. #
  777. # ... more members ...
  778. #
  779. # Since: 0.14.0
  780. ##
  781. { 'struct': 'BlockStats',
  782. 'data': {'*device': 'str', '*node-name': 'str',
  783. ... more members ... } }
  784. ##
  785. # @query-blockstats:
  786. #
  787. # Query the @BlockStats for all virtual block devices.
  788. #
  789. # @query-nodes: If true, the command will query all the
  790. # block nodes ... explain, explain ... (since 2.3)
  791. #
  792. # Returns: A list of @BlockStats for each virtual block devices.
  793. #
  794. # Since: 0.14.0
  795. #
  796. # Example:
  797. #
  798. # -> { "execute": "query-blockstats" }
  799. # <- {
  800. # ... lots of output ...
  801. # }
  802. #
  803. ##
  804. { 'command': 'query-blockstats',
  805. 'data': { '*query-nodes': 'bool' },
  806. 'returns': ['BlockStats'] }
  807. Client JSON Protocol introspection
  808. ==================================
  809. Clients of a Client JSON Protocol commonly need to figure out what
  810. exactly the server (QEMU) supports.
  811. For this purpose, QMP provides introspection via command
  812. query-qmp-schema. QGA currently doesn't support introspection.
  813. While Client JSON Protocol wire compatibility should be maintained
  814. between qemu versions, we cannot make the same guarantees for
  815. introspection stability. For example, one version of qemu may provide
  816. a non-variant optional member of a struct, and a later version rework
  817. the member to instead be non-optional and associated with a variant.
  818. Likewise, one version of qemu may list a member with open-ended type
  819. 'str', and a later version could convert it to a finite set of strings
  820. via an enum type; or a member may be converted from a specific type to
  821. an alternate that represents a choice between the original type and
  822. something else.
  823. query-qmp-schema returns a JSON array of SchemaInfo objects. These
  824. objects together describe the wire ABI, as defined in the QAPI schema.
  825. There is no specified order to the SchemaInfo objects returned; a
  826. client must search for a particular name throughout the entire array
  827. to learn more about that name, but is at least guaranteed that there
  828. will be no collisions between type, command, and event names.
  829. However, the SchemaInfo can't reflect all the rules and restrictions
  830. that apply to QMP. It's interface introspection (figuring out what's
  831. there), not interface specification. The specification is in the QAPI
  832. schema. To understand how QMP is to be used, you need to study the
  833. QAPI schema.
  834. Like any other command, query-qmp-schema is itself defined in the QAPI
  835. schema, along with the SchemaInfo type. This text attempts to give an
  836. overview how things work. For details you need to consult the QAPI
  837. schema.
  838. SchemaInfo objects have common members "name", "meta-type",
  839. "features", and additional variant members depending on the value of
  840. meta-type.
  841. Each SchemaInfo object describes a wire ABI entity of a certain
  842. meta-type: a command, event or one of several kinds of type.
  843. SchemaInfo for commands and events have the same name as in the QAPI
  844. schema.
  845. Command and event names are part of the wire ABI, but type names are
  846. not. Therefore, the SchemaInfo for types have auto-generated
  847. meaningless names. For readability, the examples in this section use
  848. meaningful type names instead.
  849. Optional member "features" exposes the entity's feature strings as a
  850. JSON array of strings.
  851. To examine a type, start with a command or event using it, then follow
  852. references by name.
  853. QAPI schema definitions not reachable that way are omitted.
  854. The SchemaInfo for a command has meta-type "command", and variant
  855. members "arg-type", "ret-type" and "allow-oob". On the wire, the
  856. "arguments" member of a client's "execute" command must conform to the
  857. object type named by "arg-type". The "return" member that the server
  858. passes in a success response conforms to the type named by "ret-type".
  859. When "allow-oob" is true, it means the command supports out-of-band
  860. execution. It defaults to false.
  861. If the command takes no arguments, "arg-type" names an object type
  862. without members. Likewise, if the command returns nothing, "ret-type"
  863. names an object type without members.
  864. Example: the SchemaInfo for command query-qmp-schema ::
  865. { "name": "query-qmp-schema", "meta-type": "command",
  866. "arg-type": "q_empty", "ret-type": "SchemaInfoList" }
  867. Type "q_empty" is an automatic object type without members, and type
  868. "SchemaInfoList" is the array of SchemaInfo type.
  869. The SchemaInfo for an event has meta-type "event", and variant member
  870. "arg-type". On the wire, a "data" member that the server passes in an
  871. event conforms to the object type named by "arg-type".
  872. If the event carries no additional information, "arg-type" names an
  873. object type without members. The event may not have a data member on
  874. the wire then.
  875. Each command or event defined with 'data' as MEMBERS object in the
  876. QAPI schema implicitly defines an object type.
  877. Example: the SchemaInfo for EVENT_C from section Events_ ::
  878. { "name": "EVENT_C", "meta-type": "event",
  879. "arg-type": "q_obj-EVENT_C-arg" }
  880. Type "q_obj-EVENT_C-arg" is an implicitly defined object type with
  881. the two members from the event's definition.
  882. The SchemaInfo for struct and union types has meta-type "object".
  883. The SchemaInfo for a struct type has variant member "members".
  884. The SchemaInfo for a union type additionally has variant members "tag"
  885. and "variants".
  886. "members" is a JSON array describing the object's common members, if
  887. any. Each element is a JSON object with members "name" (the member's
  888. name), "type" (the name of its type), and optionally "default". The
  889. member is optional if "default" is present. Currently, "default" can
  890. only have value null. Other values are reserved for future
  891. extensions. The "members" array is in no particular order; clients
  892. must search the entire object when learning whether a particular
  893. member is supported.
  894. Example: the SchemaInfo for MyType from section `Struct types`_ ::
  895. { "name": "MyType", "meta-type": "object",
  896. "members": [
  897. { "name": "member1", "type": "str" },
  898. { "name": "member2", "type": "int" },
  899. { "name": "member3", "type": "str", "default": null } ] }
  900. "features" exposes the command's feature strings as a JSON array of
  901. strings.
  902. Example: the SchemaInfo for TestType from section Features_::
  903. { "name": "TestType", "meta-type": "object",
  904. "members": [
  905. { "name": "number", "type": "int" } ],
  906. "features": ["allow-negative-numbers"] }
  907. "tag" is the name of the common member serving as type tag.
  908. "variants" is a JSON array describing the object's variant members.
  909. Each element is a JSON object with members "case" (the value of type
  910. tag this element applies to) and "type" (the name of an object type
  911. that provides the variant members for this type tag value). The
  912. "variants" array is in no particular order, and is not guaranteed to
  913. list cases in the same order as the corresponding "tag" enum type.
  914. Example: the SchemaInfo for flat union BlockdevOptions from section
  915. `Union types`_ ::
  916. { "name": "BlockdevOptions", "meta-type": "object",
  917. "members": [
  918. { "name": "driver", "type": "BlockdevDriver" },
  919. { "name": "read-only", "type": "bool", "default": null } ],
  920. "tag": "driver",
  921. "variants": [
  922. { "case": "file", "type": "BlockdevOptionsFile" },
  923. { "case": "qcow2", "type": "BlockdevOptionsQcow2" } ] }
  924. Note that base types are "flattened": its members are included in the
  925. "members" array.
  926. A simple union implicitly defines an enumeration type for its implicit
  927. discriminator (called "type" on the wire, see section `Union types`_).
  928. A simple union implicitly defines an object type for each of its
  929. variants.
  930. Example: the SchemaInfo for simple union BlockdevOptionsSimple from section
  931. `Union types`_ ::
  932. { "name": "BlockdevOptionsSimple", "meta-type": "object",
  933. "members": [
  934. { "name": "type", "type": "BlockdevOptionsSimpleKind" } ],
  935. "tag": "type",
  936. "variants": [
  937. { "case": "file", "type": "q_obj-BlockdevOptionsFile-wrapper" },
  938. { "case": "qcow2", "type": "q_obj-BlockdevOptionsQcow2-wrapper" } ] }
  939. Enumeration type "BlockdevOptionsSimpleKind" and the object types
  940. "q_obj-BlockdevOptionsFile-wrapper", "q_obj-BlockdevOptionsQcow2-wrapper"
  941. are implicitly defined.
  942. The SchemaInfo for an alternate type has meta-type "alternate", and
  943. variant member "members". "members" is a JSON array. Each element is
  944. a JSON object with member "type", which names a type. Values of the
  945. alternate type conform to exactly one of its member types. There is
  946. no guarantee on the order in which "members" will be listed.
  947. Example: the SchemaInfo for BlockdevRef from section `Alternate types`_ ::
  948. { "name": "BlockdevRef", "meta-type": "alternate",
  949. "members": [
  950. { "type": "BlockdevOptions" },
  951. { "type": "str" } ] }
  952. The SchemaInfo for an array type has meta-type "array", and variant
  953. member "element-type", which names the array's element type. Array
  954. types are implicitly defined. For convenience, the array's name may
  955. resemble the element type; however, clients should examine member
  956. "element-type" instead of making assumptions based on parsing member
  957. "name".
  958. Example: the SchemaInfo for ['str'] ::
  959. { "name": "[str]", "meta-type": "array",
  960. "element-type": "str" }
  961. The SchemaInfo for an enumeration type has meta-type "enum" and
  962. variant member "values". The values are listed in no particular
  963. order; clients must search the entire enum when learning whether a
  964. particular value is supported.
  965. Example: the SchemaInfo for MyEnum from section `Enumeration types`_ ::
  966. { "name": "MyEnum", "meta-type": "enum",
  967. "values": [ "value1", "value2", "value3" ] }
  968. The SchemaInfo for a built-in type has the same name as the type in
  969. the QAPI schema (see section `Built-in Types`_), with one exception
  970. detailed below. It has variant member "json-type" that shows how
  971. values of this type are encoded on the wire.
  972. Example: the SchemaInfo for str ::
  973. { "name": "str", "meta-type": "builtin", "json-type": "string" }
  974. The QAPI schema supports a number of integer types that only differ in
  975. how they map to C. They are identical as far as SchemaInfo is
  976. concerned. Therefore, they get all mapped to a single type "int" in
  977. SchemaInfo.
  978. As explained above, type names are not part of the wire ABI. Not even
  979. the names of built-in types. Clients should examine member
  980. "json-type" instead of hard-coding names of built-in types.
  981. Compatibility considerations
  982. ============================
  983. Maintaining backward compatibility at the Client JSON Protocol level
  984. while evolving the schema requires some care. This section is about
  985. syntactic compatibility, which is necessary, but not sufficient, for
  986. actual compatibility.
  987. Clients send commands with argument data, and receive command
  988. responses with return data and events with event data.
  989. Adding opt-in functionality to the send direction is backwards
  990. compatible: adding commands, optional arguments, enumeration values,
  991. union and alternate branches; turning an argument type into an
  992. alternate of that type; making mandatory arguments optional. Clients
  993. oblivious of the new functionality continue to work.
  994. Incompatible changes include removing commands, command arguments,
  995. enumeration values, union and alternate branches, adding mandatory
  996. command arguments, and making optional arguments mandatory.
  997. The specified behavior of an absent optional argument should remain
  998. the same. With proper documentation, this policy still allows some
  999. flexibility; for example, when an optional 'buffer-size' argument is
  1000. specified to default to a sensible buffer size, the actual default
  1001. value can still be changed. The specified default behavior is not the
  1002. exact size of the buffer, only that the default size is sensible.
  1003. Adding functionality to the receive direction is generally backwards
  1004. compatible: adding events, adding return and event data members.
  1005. Clients are expected to ignore the ones they don't know.
  1006. Removing "unreachable" stuff like events that can't be triggered
  1007. anymore, optional return or event data members that can't be sent
  1008. anymore, and return or event data member (enumeration) values that
  1009. can't be sent anymore makes no difference to clients, except for
  1010. introspection. The latter can conceivably confuse clients, so tread
  1011. carefully.
  1012. Incompatible changes include removing return and event data members.
  1013. Any change to a command definition's 'data' or one of the types used
  1014. there (recursively) needs to consider send direction compatibility.
  1015. Any change to a command definition's 'return', an event definition's
  1016. 'data', or one of the types used there (recursively) needs to consider
  1017. receive direction compatibility.
  1018. Any change to types used in both contexts need to consider both.
  1019. Enumeration type values and complex and alternate type members may be
  1020. reordered freely. For enumerations and alternate types, this doesn't
  1021. affect the wire encoding. For complex types, this might make the
  1022. implementation emit JSON object members in a different order, which
  1023. the Client JSON Protocol permits.
  1024. Since type names are not visible in the Client JSON Protocol, types
  1025. may be freely renamed. Even certain refactorings are invisible, such
  1026. as splitting members from one type into a common base type.
  1027. Code generation
  1028. ===============
  1029. The QAPI code generator qapi-gen.py generates code and documentation
  1030. from the schema. Together with the core QAPI libraries, this code
  1031. provides everything required to take JSON commands read in by a Client
  1032. JSON Protocol server, unmarshal the arguments into the underlying C
  1033. types, call into the corresponding C function, map the response back
  1034. to a Client JSON Protocol response to be returned to the user, and
  1035. introspect the commands.
  1036. As an example, we'll use the following schema, which describes a
  1037. single complex user-defined type, along with command which takes a
  1038. list of that type as a parameter, and returns a single element of that
  1039. type. The user is responsible for writing the implementation of
  1040. qmp_my_command(); everything else is produced by the generator. ::
  1041. $ cat example-schema.json
  1042. { 'struct': 'UserDefOne',
  1043. 'data': { 'integer': 'int', '*string': 'str' } }
  1044. { 'command': 'my-command',
  1045. 'data': { 'arg1': ['UserDefOne'] },
  1046. 'returns': 'UserDefOne' }
  1047. { 'event': 'MY_EVENT' }
  1048. We run qapi-gen.py like this::
  1049. $ python scripts/qapi-gen.py --output-dir="qapi-generated" \
  1050. --prefix="example-" example-schema.json
  1051. For a more thorough look at generated code, the testsuite includes
  1052. tests/qapi-schema/qapi-schema-tests.json that covers more examples of
  1053. what the generator will accept, and compiles the resulting C code as
  1054. part of 'make check-unit'.
  1055. Code generated for QAPI types
  1056. -----------------------------
  1057. The following files are created:
  1058. ``$(prefix)qapi-types.h``
  1059. C types corresponding to types defined in the schema
  1060. ``$(prefix)qapi-types.c``
  1061. Cleanup functions for the above C types
  1062. The $(prefix) is an optional parameter used as a namespace to keep the
  1063. generated code from one schema/code-generation separated from others so code
  1064. can be generated/used from multiple schemas without clobbering previously
  1065. created code.
  1066. Example::
  1067. $ cat qapi-generated/example-qapi-types.h
  1068. [Uninteresting stuff omitted...]
  1069. #ifndef EXAMPLE_QAPI_TYPES_H
  1070. #define EXAMPLE_QAPI_TYPES_H
  1071. #include "qapi/qapi-builtin-types.h"
  1072. typedef struct UserDefOne UserDefOne;
  1073. typedef struct UserDefOneList UserDefOneList;
  1074. typedef struct q_obj_my_command_arg q_obj_my_command_arg;
  1075. struct UserDefOne {
  1076. int64_t integer;
  1077. bool has_string;
  1078. char *string;
  1079. };
  1080. void qapi_free_UserDefOne(UserDefOne *obj);
  1081. G_DEFINE_AUTOPTR_CLEANUP_FUNC(UserDefOne, qapi_free_UserDefOne)
  1082. struct UserDefOneList {
  1083. UserDefOneList *next;
  1084. UserDefOne *value;
  1085. };
  1086. void qapi_free_UserDefOneList(UserDefOneList *obj);
  1087. G_DEFINE_AUTOPTR_CLEANUP_FUNC(UserDefOneList, qapi_free_UserDefOneList)
  1088. struct q_obj_my_command_arg {
  1089. UserDefOneList *arg1;
  1090. };
  1091. #endif /* EXAMPLE_QAPI_TYPES_H */
  1092. $ cat qapi-generated/example-qapi-types.c
  1093. [Uninteresting stuff omitted...]
  1094. void qapi_free_UserDefOne(UserDefOne *obj)
  1095. {
  1096. Visitor *v;
  1097. if (!obj) {
  1098. return;
  1099. }
  1100. v = qapi_dealloc_visitor_new();
  1101. visit_type_UserDefOne(v, NULL, &obj, NULL);
  1102. visit_free(v);
  1103. }
  1104. void qapi_free_UserDefOneList(UserDefOneList *obj)
  1105. {
  1106. Visitor *v;
  1107. if (!obj) {
  1108. return;
  1109. }
  1110. v = qapi_dealloc_visitor_new();
  1111. visit_type_UserDefOneList(v, NULL, &obj, NULL);
  1112. visit_free(v);
  1113. }
  1114. [Uninteresting stuff omitted...]
  1115. For a modular QAPI schema (see section `Include directives`_), code for
  1116. each sub-module SUBDIR/SUBMODULE.json is actually generated into ::
  1117. SUBDIR/$(prefix)qapi-types-SUBMODULE.h
  1118. SUBDIR/$(prefix)qapi-types-SUBMODULE.c
  1119. If qapi-gen.py is run with option --builtins, additional files are
  1120. created:
  1121. ``qapi-builtin-types.h``
  1122. C types corresponding to built-in types
  1123. ``qapi-builtin-types.c``
  1124. Cleanup functions for the above C types
  1125. Code generated for visiting QAPI types
  1126. --------------------------------------
  1127. These are the visitor functions used to walk through and convert
  1128. between a native QAPI C data structure and some other format (such as
  1129. QObject); the generated functions are named visit_type_FOO() and
  1130. visit_type_FOO_members().
  1131. The following files are generated:
  1132. ``$(prefix)qapi-visit.c``
  1133. Visitor function for a particular C type, used to automagically
  1134. convert QObjects into the corresponding C type and vice-versa, as
  1135. well as for deallocating memory for an existing C type
  1136. ``$(prefix)qapi-visit.h``
  1137. Declarations for previously mentioned visitor functions
  1138. Example::
  1139. $ cat qapi-generated/example-qapi-visit.h
  1140. [Uninteresting stuff omitted...]
  1141. #ifndef EXAMPLE_QAPI_VISIT_H
  1142. #define EXAMPLE_QAPI_VISIT_H
  1143. #include "qapi/qapi-builtin-visit.h"
  1144. #include "example-qapi-types.h"
  1145. bool visit_type_UserDefOne_members(Visitor *v, UserDefOne *obj, Error **errp);
  1146. bool visit_type_UserDefOne(Visitor *v, const char *name,
  1147. UserDefOne **obj, Error **errp);
  1148. bool visit_type_UserDefOneList(Visitor *v, const char *name,
  1149. UserDefOneList **obj, Error **errp);
  1150. bool visit_type_q_obj_my_command_arg_members(Visitor *v, q_obj_my_command_arg *obj, Error **errp);
  1151. #endif /* EXAMPLE_QAPI_VISIT_H */
  1152. $ cat qapi-generated/example-qapi-visit.c
  1153. [Uninteresting stuff omitted...]
  1154. bool visit_type_UserDefOne_members(Visitor *v, UserDefOne *obj, Error **errp)
  1155. {
  1156. if (!visit_type_int(v, "integer", &obj->integer, errp)) {
  1157. return false;
  1158. }
  1159. if (visit_optional(v, "string", &obj->has_string)) {
  1160. if (!visit_type_str(v, "string", &obj->string, errp)) {
  1161. return false;
  1162. }
  1163. }
  1164. return true;
  1165. }
  1166. bool visit_type_UserDefOne(Visitor *v, const char *name,
  1167. UserDefOne **obj, Error **errp)
  1168. {
  1169. bool ok = false;
  1170. if (!visit_start_struct(v, name, (void **)obj, sizeof(UserDefOne), errp)) {
  1171. return false;
  1172. }
  1173. if (!*obj) {
  1174. /* incomplete */
  1175. assert(visit_is_dealloc(v));
  1176. ok = true;
  1177. goto out_obj;
  1178. }
  1179. if (!visit_type_UserDefOne_members(v, *obj, errp)) {
  1180. goto out_obj;
  1181. }
  1182. ok = visit_check_struct(v, errp);
  1183. out_obj:
  1184. visit_end_struct(v, (void **)obj);
  1185. if (!ok && visit_is_input(v)) {
  1186. qapi_free_UserDefOne(*obj);
  1187. *obj = NULL;
  1188. }
  1189. return ok;
  1190. }
  1191. bool visit_type_UserDefOneList(Visitor *v, const char *name,
  1192. UserDefOneList **obj, Error **errp)
  1193. {
  1194. bool ok = false;
  1195. UserDefOneList *tail;
  1196. size_t size = sizeof(**obj);
  1197. if (!visit_start_list(v, name, (GenericList **)obj, size, errp)) {
  1198. return false;
  1199. }
  1200. for (tail = *obj; tail;
  1201. tail = (UserDefOneList *)visit_next_list(v, (GenericList *)tail, size)) {
  1202. if (!visit_type_UserDefOne(v, NULL, &tail->value, errp)) {
  1203. goto out_obj;
  1204. }
  1205. }
  1206. ok = visit_check_list(v, errp);
  1207. out_obj:
  1208. visit_end_list(v, (void **)obj);
  1209. if (!ok && visit_is_input(v)) {
  1210. qapi_free_UserDefOneList(*obj);
  1211. *obj = NULL;
  1212. }
  1213. return ok;
  1214. }
  1215. bool visit_type_q_obj_my_command_arg_members(Visitor *v, q_obj_my_command_arg *obj, Error **errp)
  1216. {
  1217. if (!visit_type_UserDefOneList(v, "arg1", &obj->arg1, errp)) {
  1218. return false;
  1219. }
  1220. return true;
  1221. }
  1222. [Uninteresting stuff omitted...]
  1223. For a modular QAPI schema (see section `Include directives`_), code for
  1224. each sub-module SUBDIR/SUBMODULE.json is actually generated into ::
  1225. SUBDIR/$(prefix)qapi-visit-SUBMODULE.h
  1226. SUBDIR/$(prefix)qapi-visit-SUBMODULE.c
  1227. If qapi-gen.py is run with option --builtins, additional files are
  1228. created:
  1229. ``qapi-builtin-visit.h``
  1230. Visitor functions for built-in types
  1231. ``qapi-builtin-visit.c``
  1232. Declarations for these visitor functions
  1233. Code generated for commands
  1234. ---------------------------
  1235. These are the marshaling/dispatch functions for the commands defined
  1236. in the schema. The generated code provides qmp_marshal_COMMAND(), and
  1237. declares qmp_COMMAND() that the user must implement.
  1238. The following files are generated:
  1239. ``$(prefix)qapi-commands.c``
  1240. Command marshal/dispatch functions for each QMP command defined in
  1241. the schema
  1242. ``$(prefix)qapi-commands.h``
  1243. Function prototypes for the QMP commands specified in the schema
  1244. ``$(prefix)qapi-init-commands.h``
  1245. Command initialization prototype
  1246. ``$(prefix)qapi-init-commands.c``
  1247. Command initialization code
  1248. Example::
  1249. $ cat qapi-generated/example-qapi-commands.h
  1250. [Uninteresting stuff omitted...]
  1251. #ifndef EXAMPLE_QAPI_COMMANDS_H
  1252. #define EXAMPLE_QAPI_COMMANDS_H
  1253. #include "example-qapi-types.h"
  1254. UserDefOne *qmp_my_command(UserDefOneList *arg1, Error **errp);
  1255. void qmp_marshal_my_command(QDict *args, QObject **ret, Error **errp);
  1256. #endif /* EXAMPLE_QAPI_COMMANDS_H */
  1257. $ cat qapi-generated/example-qapi-commands.c
  1258. [Uninteresting stuff omitted...]
  1259. static void qmp_marshal_output_UserDefOne(UserDefOne *ret_in,
  1260. QObject **ret_out, Error **errp)
  1261. {
  1262. Visitor *v;
  1263. v = qobject_output_visitor_new_qmp(ret_out);
  1264. if (visit_type_UserDefOne(v, "unused", &ret_in, errp)) {
  1265. visit_complete(v, ret_out);
  1266. }
  1267. visit_free(v);
  1268. v = qapi_dealloc_visitor_new();
  1269. visit_type_UserDefOne(v, "unused", &ret_in, NULL);
  1270. visit_free(v);
  1271. }
  1272. void qmp_marshal_my_command(QDict *args, QObject **ret, Error **errp)
  1273. {
  1274. Error *err = NULL;
  1275. bool ok = false;
  1276. Visitor *v;
  1277. UserDefOne *retval;
  1278. q_obj_my_command_arg arg = {0};
  1279. v = qobject_input_visitor_new_qmp(QOBJECT(args));
  1280. if (!visit_start_struct(v, NULL, NULL, 0, errp)) {
  1281. goto out;
  1282. }
  1283. if (visit_type_q_obj_my_command_arg_members(v, &arg, errp)) {
  1284. ok = visit_check_struct(v, errp);
  1285. }
  1286. visit_end_struct(v, NULL);
  1287. if (!ok) {
  1288. goto out;
  1289. }
  1290. retval = qmp_my_command(arg.arg1, &err);
  1291. error_propagate(errp, err);
  1292. if (err) {
  1293. goto out;
  1294. }
  1295. qmp_marshal_output_UserDefOne(retval, ret, errp);
  1296. out:
  1297. visit_free(v);
  1298. v = qapi_dealloc_visitor_new();
  1299. visit_start_struct(v, NULL, NULL, 0, NULL);
  1300. visit_type_q_obj_my_command_arg_members(v, &arg, NULL);
  1301. visit_end_struct(v, NULL);
  1302. visit_free(v);
  1303. }
  1304. [Uninteresting stuff omitted...]
  1305. $ cat qapi-generated/example-qapi-init-commands.h
  1306. [Uninteresting stuff omitted...]
  1307. #ifndef EXAMPLE_QAPI_INIT_COMMANDS_H
  1308. #define EXAMPLE_QAPI_INIT_COMMANDS_H
  1309. #include "qapi/qmp/dispatch.h"
  1310. void example_qmp_init_marshal(QmpCommandList *cmds);
  1311. #endif /* EXAMPLE_QAPI_INIT_COMMANDS_H */
  1312. $ cat qapi-generated/example-qapi-init-commands.c
  1313. [Uninteresting stuff omitted...]
  1314. void example_qmp_init_marshal(QmpCommandList *cmds)
  1315. {
  1316. QTAILQ_INIT(cmds);
  1317. qmp_register_command(cmds, "my-command",
  1318. qmp_marshal_my_command, QCO_NO_OPTIONS);
  1319. }
  1320. [Uninteresting stuff omitted...]
  1321. For a modular QAPI schema (see section `Include directives`_), code for
  1322. each sub-module SUBDIR/SUBMODULE.json is actually generated into::
  1323. SUBDIR/$(prefix)qapi-commands-SUBMODULE.h
  1324. SUBDIR/$(prefix)qapi-commands-SUBMODULE.c
  1325. Code generated for events
  1326. -------------------------
  1327. This is the code related to events defined in the schema, providing
  1328. qapi_event_send_EVENT().
  1329. The following files are created:
  1330. ``$(prefix)qapi-events.h``
  1331. Function prototypes for each event type
  1332. ``$(prefix)qapi-events.c``
  1333. Implementation of functions to send an event
  1334. ``$(prefix)qapi-emit-events.h``
  1335. Enumeration of all event names, and common event code declarations
  1336. ``$(prefix)qapi-emit-events.c``
  1337. Common event code definitions
  1338. Example::
  1339. $ cat qapi-generated/example-qapi-events.h
  1340. [Uninteresting stuff omitted...]
  1341. #ifndef EXAMPLE_QAPI_EVENTS_H
  1342. #define EXAMPLE_QAPI_EVENTS_H
  1343. #include "qapi/util.h"
  1344. #include "example-qapi-types.h"
  1345. void qapi_event_send_my_event(void);
  1346. #endif /* EXAMPLE_QAPI_EVENTS_H */
  1347. $ cat qapi-generated/example-qapi-events.c
  1348. [Uninteresting stuff omitted...]
  1349. void qapi_event_send_my_event(void)
  1350. {
  1351. QDict *qmp;
  1352. qmp = qmp_event_build_dict("MY_EVENT");
  1353. example_qapi_event_emit(EXAMPLE_QAPI_EVENT_MY_EVENT, qmp);
  1354. qobject_unref(qmp);
  1355. }
  1356. [Uninteresting stuff omitted...]
  1357. $ cat qapi-generated/example-qapi-emit-events.h
  1358. [Uninteresting stuff omitted...]
  1359. #ifndef EXAMPLE_QAPI_EMIT_EVENTS_H
  1360. #define EXAMPLE_QAPI_EMIT_EVENTS_H
  1361. #include "qapi/util.h"
  1362. typedef enum example_QAPIEvent {
  1363. EXAMPLE_QAPI_EVENT_MY_EVENT,
  1364. EXAMPLE_QAPI_EVENT__MAX,
  1365. } example_QAPIEvent;
  1366. #define example_QAPIEvent_str(val) \
  1367. qapi_enum_lookup(&example_QAPIEvent_lookup, (val))
  1368. extern const QEnumLookup example_QAPIEvent_lookup;
  1369. void example_qapi_event_emit(example_QAPIEvent event, QDict *qdict);
  1370. #endif /* EXAMPLE_QAPI_EMIT_EVENTS_H */
  1371. $ cat qapi-generated/example-qapi-emit-events.c
  1372. [Uninteresting stuff omitted...]
  1373. const QEnumLookup example_QAPIEvent_lookup = {
  1374. .array = (const char *const[]) {
  1375. [EXAMPLE_QAPI_EVENT_MY_EVENT] = "MY_EVENT",
  1376. },
  1377. .size = EXAMPLE_QAPI_EVENT__MAX
  1378. };
  1379. [Uninteresting stuff omitted...]
  1380. For a modular QAPI schema (see section `Include directives`_), code for
  1381. each sub-module SUBDIR/SUBMODULE.json is actually generated into ::
  1382. SUBDIR/$(prefix)qapi-events-SUBMODULE.h
  1383. SUBDIR/$(prefix)qapi-events-SUBMODULE.c
  1384. Code generated for introspection
  1385. --------------------------------
  1386. The following files are created:
  1387. ``$(prefix)qapi-introspect.c``
  1388. Defines a string holding a JSON description of the schema
  1389. ``$(prefix)qapi-introspect.h``
  1390. Declares the above string
  1391. Example::
  1392. $ cat qapi-generated/example-qapi-introspect.h
  1393. [Uninteresting stuff omitted...]
  1394. #ifndef EXAMPLE_QAPI_INTROSPECT_H
  1395. #define EXAMPLE_QAPI_INTROSPECT_H
  1396. #include "qapi/qmp/qlit.h"
  1397. extern const QLitObject example_qmp_schema_qlit;
  1398. #endif /* EXAMPLE_QAPI_INTROSPECT_H */
  1399. $ cat qapi-generated/example-qapi-introspect.c
  1400. [Uninteresting stuff omitted...]
  1401. const QLitObject example_qmp_schema_qlit = QLIT_QLIST(((QLitObject[]) {
  1402. QLIT_QDICT(((QLitDictEntry[]) {
  1403. { "arg-type", QLIT_QSTR("0"), },
  1404. { "meta-type", QLIT_QSTR("command"), },
  1405. { "name", QLIT_QSTR("my-command"), },
  1406. { "ret-type", QLIT_QSTR("1"), },
  1407. {}
  1408. })),
  1409. QLIT_QDICT(((QLitDictEntry[]) {
  1410. { "arg-type", QLIT_QSTR("2"), },
  1411. { "meta-type", QLIT_QSTR("event"), },
  1412. { "name", QLIT_QSTR("MY_EVENT"), },
  1413. {}
  1414. })),
  1415. /* "0" = q_obj_my-command-arg */
  1416. QLIT_QDICT(((QLitDictEntry[]) {
  1417. { "members", QLIT_QLIST(((QLitObject[]) {
  1418. QLIT_QDICT(((QLitDictEntry[]) {
  1419. { "name", QLIT_QSTR("arg1"), },
  1420. { "type", QLIT_QSTR("[1]"), },
  1421. {}
  1422. })),
  1423. {}
  1424. })), },
  1425. { "meta-type", QLIT_QSTR("object"), },
  1426. { "name", QLIT_QSTR("0"), },
  1427. {}
  1428. })),
  1429. /* "1" = UserDefOne */
  1430. QLIT_QDICT(((QLitDictEntry[]) {
  1431. { "members", QLIT_QLIST(((QLitObject[]) {
  1432. QLIT_QDICT(((QLitDictEntry[]) {
  1433. { "name", QLIT_QSTR("integer"), },
  1434. { "type", QLIT_QSTR("int"), },
  1435. {}
  1436. })),
  1437. QLIT_QDICT(((QLitDictEntry[]) {
  1438. { "default", QLIT_QNULL, },
  1439. { "name", QLIT_QSTR("string"), },
  1440. { "type", QLIT_QSTR("str"), },
  1441. {}
  1442. })),
  1443. {}
  1444. })), },
  1445. { "meta-type", QLIT_QSTR("object"), },
  1446. { "name", QLIT_QSTR("1"), },
  1447. {}
  1448. })),
  1449. /* "2" = q_empty */
  1450. QLIT_QDICT(((QLitDictEntry[]) {
  1451. { "members", QLIT_QLIST(((QLitObject[]) {
  1452. {}
  1453. })), },
  1454. { "meta-type", QLIT_QSTR("object"), },
  1455. { "name", QLIT_QSTR("2"), },
  1456. {}
  1457. })),
  1458. QLIT_QDICT(((QLitDictEntry[]) {
  1459. { "element-type", QLIT_QSTR("1"), },
  1460. { "meta-type", QLIT_QSTR("array"), },
  1461. { "name", QLIT_QSTR("[1]"), },
  1462. {}
  1463. })),
  1464. QLIT_QDICT(((QLitDictEntry[]) {
  1465. { "json-type", QLIT_QSTR("int"), },
  1466. { "meta-type", QLIT_QSTR("builtin"), },
  1467. { "name", QLIT_QSTR("int"), },
  1468. {}
  1469. })),
  1470. QLIT_QDICT(((QLitDictEntry[]) {
  1471. { "json-type", QLIT_QSTR("string"), },
  1472. { "meta-type", QLIT_QSTR("builtin"), },
  1473. { "name", QLIT_QSTR("str"), },
  1474. {}
  1475. })),
  1476. {}
  1477. }));
  1478. [Uninteresting stuff omitted...]