Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Mojom IDL | |
| 2 | |
| 3 The Mojom IDL (interface definition language) is primarily used to describe | |
| 4 *interfaces* to be used on [message pipes](message_pipes.md). Below, we describe | |
| 5 practical aspects of the Mojom language. Elsewhere, we describe the [Mojom | |
| 6 protocol](mojom_protocol.md). (**TODO(vtl)**: Also, serialization format? | |
| 7 Versioning?) | |
| 8 | |
| 9 Text files written in Mojom IDL are given the `.mojom` extension by convention | |
| 10 (and are usually referred to as Mojom/mojom/`.mojom` files). The Mojom bindings | |
| 11 generator (**TODO(vtl)**: link?) may be used to generate code in a variety of | |
| 12 languages (including C++, Dart, and Go) from a Mojom file. Such generated code | |
| 13 "implements" the things specified in the Mojom file, in a way that's appropriate | |
| 14 for the particular target language. | |
| 15 | |
| 16 ## Interfaces | |
| 17 | |
| 18 A Mojom *interface* is (typically) used to describe communication on a message | |
| 19 pipe. Typically, message pipes are created with a particular interface in mind, | |
| 20 with one endpoint designated the *client* (which sends *request* messages and | |
| 21 receives *response* messages) and the other designed that *server* or *impl* | |
| 22 (which receives request messages and receives response messages). | |
|
vardhan
2016/03/03 00:55:38
and *sends* response messages
viettrungluu
2016/03/03 01:01:54
Done.
| |
| 23 | |
| 24 For example, take the following Mojom interface definition: | |
| 25 ```mojom | |
| 26 interface MyInterface { | |
| 27 Foo(int32 a, string b); | |
| 28 Bar() => (bool x, uint32 y); | |
| 29 Baz() => (); | |
| 30 }; | |
| 31 ``` | |
| 32 This specifies a Mojom interface in which the client may send three types of | |
| 33 messages, namely `Foo`, `Bar`, and `Baz` (see the note below about names in | |
| 34 Mojom). The first does not have a response message defined, whereas the latter | |
| 35 two do. Whenever the server receives a `Bar` or `Baz` message, it *must* | |
| 36 (eventually) send a (single) corresponding response message. | |
| 37 | |
| 38 The `Foo` request message contains two pieces of data: a signed (two's | |
| 39 complement) 32-bit integer called `a` and a Unicode string called `b`. On the | |
| 40 "wire", the message basically consists of metadata and a (serialized) *struct* | |
| 41 (see below) containing `a` and `b`. | |
| 42 | |
| 43 The `Bar` request message contains no data, so on the wire it's just metadata | |
| 44 and an empty struct. It has a response message, containing a boolean value `x` | |
| 45 and an unsigned 32-bit integer `y`, which on the wire consists of metadata and a | |
| 46 struct with `x` and `y`. Each time the server receives a `Bar` message, it is | |
| 47 supposed to (eventually) respond by sending the response message. (Note: The | |
| 48 client may include as part of the request message's metadata an identifier for | |
| 49 the request; the response's metadata will then include this identifier, allowing | |
| 50 it to match responses to requests.) | |
| 51 | |
| 52 The `Baz` request message also contains no data. It requires a response, also | |
| 53 containing no data. Note that even though the response has no data, a response | |
| 54 message must nonetheless be sent, functioning as an "ack". (Thus this is | |
| 55 different from not having a response, as was the case for `Foo`.) | |
| 56 | |
| 57 ### Names in Mojom | |
| 58 | |
| 59 Names in Mojom are not important. Except in affecting compatibility at level of | |
|
vardhan
2016/03/03 00:55:38
should you mention that naming in the [ServiceName
viettrungluu
2016/03/03 01:01:54
I'll have to mention it somewhere. I'll have to th
rudominer
2016/03/03 01:04:33
at the level of
| |
| 60 source code (when generating bindings), names in a Mojom file may be changed | |
| 61 arbirarily without any effect on the "meaning" of the Mojom file (subject to | |
|
vardhan
2016/03/03 00:55:38
(sp) arbitrarily
viettrungluu
2016/03/03 01:01:54
Done.
| |
| 62 basic language requirements, e.g., avoiding collisions with keywords and other | |
| 63 names). E.g., the following is completely equivalent to the interface discussed | |
| 64 above: | |
| 65 ```mojom | |
| 66 interface Something { | |
| 67 One(int32 an_integer, string a_string); | |
| 68 Two() => (bool a_boolean, uint32 an_unsigned); | |
| 69 Three() => (); | |
| 70 }; | |
| 71 ``` | |
| 72 The `Something` interface is compatible at a binary level with `MyInterface`. A | |
| 73 client using the `Something` interface may communicate with a server | |
| 74 implementing the `MyInterface` with no issues, and vice versa. | |
| 75 | |
| 76 The reason for this is that elements (messages, parameters, struct members, | |
| 77 etc.) are actually identified by *ordinal* value. They may be specified | |
| 78 explicitly (using `@123` notation; see below). If they are not specified | |
| 79 explicitly, they are automatically assigned. (The ordinal values for each | |
| 80 interface/struct/etc. must assign distinct values for each item, in a | |
| 81 consecutive range starting at 0.) | |
| 82 | |
| 83 Explicitly assigning ordinals allows Mojom files to be rearranged "physically" | |
| 84 without changing their meaning. E.g., perhaps one would write: | |
| 85 ```mojom | |
| 86 interface MyInterface { | |
| 87 Bar@1() => (bool x@0, uint32 y@1); | |
| 88 Baz@2() => (); | |
| 89 | |
| 90 // Please don't use this in new code! | |
| 91 FooDeprecated@0(int32 a@0, string b@1); | |
| 92 }; | |
| 93 ``` | |
| 94 | |
| 95 Ordinals also tie into the versioning scheme (**TODO(vtl)**: link?), which | |
| 96 allows Mojom files to be evolved in a backwards-compatible way. We will not | |
| 97 discuss this matter further here. | |
| 98 | |
| 99 | |
| 100 **TODO(vtl)**: Write/(re)organize the sections below. | |
| 101 | |
| 102 ## Structs | |
| 103 | |
| 104 ## Modules | |
| 105 | |
| 106 ## Data types | |
| 107 | |
| 108 ### Primitive types | |
| 109 | |
| 110 ### Enums | |
| 111 | |
| 112 ### Strings | |
| 113 | |
| 114 ### Nullability | |
| 115 | |
| 116 ### Structs | |
| 117 | |
| 118 ### Arrays | |
| 119 | |
| 120 ### Maps | |
| 121 | |
| 122 ### Unions | |
| 123 | |
| 124 ### Handle values | |
| 125 | |
| 126 ### Interface values | |
| 127 | |
| 128 ### Interface requests | |
| 129 | |
| 130 ## Consts | |
| 131 | |
| 132 ## Annotations | |
| 133 | |
| 134 ## Pipelining | |
| OLD | NEW |