2
0

qapi-code-gen.rst 66 KB

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