Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: mojo/public/interfaces/bindings/mojom_types.mojom

Issue 2250183003: Make the fuchsia mojo/public repo the source of truth. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 [DartPackage="mojo",
6 JavaPackage="org.chromium.mojo.bindings.types"]
7 module mojo.bindings.types;
8
9 /*
10 * This file contains definitions of data structures used to represent
11 * Mojom types and values.
12 *
13 * As described in the Mojom Language Specification, Mojom types are defined
14 * recursively and consequently a |Type| object may recursively contain
15 * other |Type| objects. For example a |Type| object representing an
16 * array<int32> will contain a |Type| object representing an int32.
17 *
18 * A Mojom type declaration may contain an identifier that resolves to a
19 * user-defined type: a struct, union, enum or interface. We use |TypeReference|
20 * to represent an occurrence of such an identifier. A |TypeReference| may be
21 * resolved or not. Resolved means that the user-defined type to which the
22 * identifier refers has been found and associated with the |TypeReference|.
23 * A |Type| object is fully-resolved if it, and recursively all of its
24 * sub-components, do not contain any unresolved TypeReferences.
25 *
26 * A resolved |TypeReference| does not literally contain a structure
27 * representing the user-defined type that it represents but rather refers to
28 * its target type indirectly via a string called a |type_key|. The type_key may
29 * be used to lookup the user-defined type to which it refers.
30 *
31 * The mapping from |type_keys| to user-defined types is not
32 * represented by any structures in this file and instead must be maintained
33 * by a higher layer context in which this file is used. For example the
34 * |ServiceDescription| interface defined in service_describer.mojom includes
35 * the method:
36 * GetTypeDefinition(string type_key) => UserDefinedType? type);
37 * for this purpose.
38 * We refer to this higher-layer context as the *owning context.*
39 *
40 * In addition to types, Mojom values are also representd by structures in this
41 * file. A |Value| may be a LiteralValue, a ConstantReference,
42 * an EnumValueReference or a BuiltinConstantValue. Similarly to the situation
43 * with TypeReferences, ConstantReferences and EnumValueReferences contain a
44 * key which may be used to lookup user-defined value (an EnumValue or a
45 * DeclaredConstant) in the owning context.
46 */
47
48 // The different kinds of types. We divide the types into five categories:
49 // simple, string, compound, handle, and user-defined.
50 union Type {
51 SimpleType simple_type;
52
53 StringType string_type;
54
55 // The compound types. These are built from simpler types.
56 ArrayType array_type;
57 MapType map_type;
58
59 HandleType handle_type;
60
61 // This represents an occurrence of a user-defined type identifier that
62 // refers to an enum, struct, union, interface or interface request.
63 TypeReference type_reference;
64 };
65
66 // The set of simple types.
67 enum SimpleType {
68 BOOL,
69 DOUBLE,
70 FLOAT,
71 INT8,
72 INT16,
73 INT32,
74 INT64,
75 UINT8,
76 UINT16,
77 UINT32,
78 UINT64,
79 };
80
81 struct StringType {
82 bool nullable;
83 };
84
85 struct HandleType {
86 enum Kind {
87 UNSPECIFIED,
88 MESSAGE_PIPE,
89 DATA_PIPE_CONSUMER,
90 DATA_PIPE_PRODUCER,
91 SHARED_BUFFER,
92 };
93
94 bool nullable;
95 Kind kind = UNSPECIFIED;
96 };
97
98 struct ArrayType {
99 bool nullable;
100 // If fixed_length < 0 then the array does not have a fixed length;
101 int32 fixed_length = -1;
102
103 Type element_type;
104 };
105
106 struct MapType {
107 bool nullable;
108 // The key_type must be a non-reference type or a string.
109 Type key_type;
110 Type value_type;
111 };
112
113 // Represents an occurence of a user-defined type identifier that should
114 // resolve to an enum, struct, union, interface or interface request. This type
115 // reference may be either resolved or unresolved. If the reference has been
116 // resolved then the |type_key| field is populated.
117 struct TypeReference {
118 // Was this occurrence marked as nullable?
119 bool nullable;
120
121 // Was this occurrence marked as being an interface request? If so then
122 // this reference must (eventually) resolve to an interface type.
123 bool is_interface_request;
124
125 // The identifier, as it appears in the occurrence. Note that this may be
126 // a short name, a fully-qualified identifier, or a partially qualified
127 // identifier. Either this field or type_key must be non-null. Some
128 // implementations will keep this field even after the reference has been
129 // resolved.
130 // Note(rudominer) Consider requiring this to be the fully-qualified
131 // identifier which would imply that some name resolution must always occur
132 // before a TypeReference structure is created. Otherwise consider adding
133 // a Scope field to TypeReference so that resolution may occur later.
134 string? identifier;
135
136 // This field is non-null if this reference has been resolved.
137 string? type_key;
138 };
139
140 ////////////////////////////////////////////////////////////////////////////
141 // The data structures below represent user-defined types or type
142 // declarations. Instances of these are not literally contained in a
143 // |Type| object. Instead the owning context is used to lookup a UserDefinedType
144 // given a type_key.
145 ////////////////////////////////////////////////////////////////////////////
146
147 // Represents a user-defined type referenced
148 // via its identifier from another Mojom object.
149 union UserDefinedType {
150 MojomEnum enum_type;
151 MojomStruct struct_type;
152 MojomUnion union_type;
153 MojomInterface interface_type;
154 };
155
156 // A field of a struct. These structures are contained in the |fields| field
157 // of the |MojomStruct| struct.
158 struct StructField {
159 DeclarationData? decl_data; // Some implementations may not provide this.
160
161 Type type;
162
163 DefaultFieldValue? default_value;
164
165 // The offset in bytes from the start of the serialized struct, not including
166 // the eight-byte header, of the first byte of this field. In the case of
167 // boolean fields, this refers to the byte in which the field's bit is
168 // located but not which bit corresponds to the field.
169 uint32 offset;
170
171 // In the case of a boolean field, this value gives the zero-based
172 // index of the bit within the field's byte within the serialized struct.
173 // Otherwise this value is -1.
174 int8 bit;
175
176 // The minimum version of the containing struct that includes this field.
177 // The earliest version is version 0.
178 uint32 min_version;
179 };
180
181 union DefaultFieldValue {
182 Value value;
183 DefaultKeyword default_keyword;
184 };
185
186 // A built-in pseudo-value, indicated by the keyword "default", that
187 // specifies that the default value of a user-defined type should be used.
188 struct DefaultKeyword {};
189
190 struct StructVersion {
191 uint32 version_number;
192
193 // The number of fields included in this version of the struct. The fields
194 // will be an initial segment of those in the |fields| field of MojomStruct.
195 uint32 num_fields;
196
197 // The total payload size for this version of the struct, including
198 // the eight-byte header.
199 uint32 num_bytes;
200 };
201
202 struct MojomStruct {
203 DeclarationData? decl_data; // Some implementations may not provide this.
204
205 // The fields are in ordinal order. Note that this may be different than
206 // the order in which the fields are declared in the .mojom file.
207 array<StructField> fields;
208
209 // Information about the different declared versions of this MojomStruct.
210 // Versions are implicitly declared in a .mojom file by use of the
211 // "MinVersion" attribute on the fields. If |version_info| is not null then
212 // it contains at least one element for version 0 and its elements are
213 // in increasing |version_number| order. Note that version numbers may
214 // not be consecutive.
215 array<StructVersion>? version_info;
216 };
217
218 // A field of a union. These structures are contained in the |fields| field
219 // of the |MojomUnion| struct.
220 struct UnionField {
221 DeclarationData? decl_data; // Some implementations may not provide this.
222
223 Type type;
224 uint32 tag;
225 };
226
227 struct MojomUnion {
228 DeclarationData? decl_data; // Some implementations may not provide this.
229
230 // The fields are in tag order. Note that this may be different than
231 // the order in which the fields are declared in the .mojom file.
232 array<UnionField> fields;
233 };
234
235 struct EnumValue {
236 DeclarationData? decl_data;
237
238 // This is the value specified in the right-hand-side of the optional
239 // initializer of an enum value declaration. The value must be a literal value
240 // of integer type or an EnumValueReference that resolves to a different
241 // EnumValue from the same MojomEnum that was defined earlier lexically,
242 // or a ConstantReference that resolves to
243 // a DeclaredConstant whose |resolved_concrete_value| is one of those.
244 Value? initializer_value;
245
246 // The resolved concrete integer value corresponding to this enum value.
247 // This number is computed based on the |specified_value|s of all of the
248 // EnumValues in a MojomEnum.
249 int32 int_value;
250 };
251
252 struct MojomEnum {
253 DeclarationData? decl_data; // Some implementations may not provide this.
254
255 // The enum values in declaration order.
256 array<EnumValue> values;
257 };
258
259 struct MojomMethod {
260 DeclarationData? decl_data; // Some implementations may not provide this.
261
262 MojomStruct parameters;
263
264 // Note that there is a difference between response_params being null and
265 // it containing zero fields. The former means that the method does
266 // not have a return message. The latter means that it does have a
267 // zero-argument return message.
268 MojomStruct? response_params;
269
270 uint32 ordinal;
271
272 // The minimum version of the containing interface that includes this method.
273 // The earliest version is version 0.
274 uint32 min_version;
275 };
276
277 struct MojomInterface {
278 DeclarationData? decl_data;
279
280 // If the declaration of this interface has been annotated with the
281 // "ServiceName=" attribute then this field contains the value of that
282 // attribute, otherwise this is null. The presence of this field indicates
283 // that this is the top-level interface for the named service: When
284 // the method ConnectToService(service_name) from the ServiceProvider
285 // interface is invoked, an implementation of ServiceProvider will, by
286 // default, return the interface that has been annotated with the
287 // given service_name if there is a unique such interface.
288 string? service_name;
289
290 // All the methods in the interface. The keys are the method ordinals.
291 map<uint32, MojomMethod> methods;
292
293 // This value is the least integer that is at least as great as all of the
294 // |min_version| fields in all of the methods and parameters in this
295 // interface. In more detail it is the maximum of the |min_version| fields of
296 // each MojomMethod in this interface, and the |min_version| fields of each
297 // StructField of each MojomStruct in the |params| and |response_params|
298 // fields of each MojomMethod in this interface.
299 uint32 current_version;
300 };
301
302 ////////////////////////////////////////////////////////////////////////////
303 // Mojom values
304 ////////////////////////////////////////////////////////////////////////////
305
306 // A value may occur as the default value of a struct field, as the
307 // right-hand-side of a constant declaration, or as the right-hand-side
308 // of an enum value specifier.
309 union Value {
310 // A literal number, boolean or string
311 LiteralValue literal_value;
312
313 // A reference to a DeclaredConstant.
314 ConstantReference constant_reference;
315
316 // A reference to an EnumValue
317 EnumValueReference enum_value_reference;
318
319 // A built-in numeric constant.
320 BuiltinConstantValue builtin_value;
321 };
322
323 union LiteralValue {
324 bool bool_value;
325 double double_value;
326 float float_value;
327 int8 int8_value;
328 int16 int16_value;
329 int32 int32_value;
330 int64 int64_value;
331 string string_value;
332 uint8 uint8_value;
333 uint16 uint16_value;
334 uint32 uint32_value;
335 uint64 uint64_value;
336 };
337
338 // Represents the built-in floating-point constants.
339 enum BuiltinConstantValue {
340 DOUBLE_INFINITY,
341 DOUBLE_NEGATIVE_INFINITY,
342 DOUBLE_NAN,
343 FLOAT_INFINITY,
344 FLOAT_NEGATIVE_INFINITY,
345 FLOAT_NAN,
346 };
347
348 // A reference to a DeclaredConstant.
349 struct ConstantReference {
350 // The identifier, as it appears at the reference site.
351 string identifier;
352
353 // The DeclaredConstant to which this reference has resolved can be looked up
354 // using this key in the appropriate map in the owning context.
355 string constant_key;
356 };
357
358 // A reference to an EnumValue
359 struct EnumValueReference {
360 // The identifier, as it appears at the reference site.
361 string identifier;
362
363 // The type key of the MojomEnum containing the EnumValue to which this
364 // reference has resolved. The MojomEnum can be looked up using this key in
365 // the appropriate map in the owning context.
366 string enum_type_key;
367
368 // The 0-based index into the |values| array within the MojomEnum specified
369 // by |enum_type_key| of the EnumValue to which this reference has resolved.
370 uint32 enum_value_index;
371 };
372
373 // This represents a Mojom constant declaration.
374 struct DeclaredConstant {
375 DeclarationData decl_data;
376
377 // The type must be a StringType, BOOL, a numeric type or a TypeReference
378 // whose resolved type is a MojomEnum.
379 Type type;
380
381 // This is the value specified in the right-hand-side of the constant
382 // declaration. The value must be one of the following:
383 // (a) a LiteralValue or a BuiltinConstantValue of the same type as |type|
384 // (b) an EnumValueReference that resolves to an EnumValue of the same
385 // enum type as |type|, or
386 // (c) a ConstantReference that resolves to a different
387 // DeclaredConstant whose |resolved_concrete_value| is one of (a) or (b)
388 Value value;
389
390
391 // The resolved concrete value. This must be a LiteralValue, a
392 // BuiltinConstantValue, or an EnumValueReference. It may not be a
393 // ConstantReference.
394 //
395 // The resolved concrete value is defined as follows:
396 // If |value| is a LiteralValue, a BuiltinConstantValue or an
397 // EnunValueReference then the resolved
398 // concrete value is conceptually equal to |value| and this will
399 // be indicated by setting the |resolved_concrete_value| field to null.
400 //
401 // Otherwise |value| is a ConstantReference that refers to a different
402 // DeclaredConstant and in this case |resolved_concrete_value| will be
403 // non-null. It will be set to the conceptual resolved concrete value of that
404 // other DeclaredConstant (even if that other declared constant has its own
405 // |resolved_concrete_value| field set to null.) This chain of references
406 // must terminate in well-formed Mojom.
407 //
408 // In the case that |resolved_concrete_value| is set to an EnumValueReference
409 // only the |enum_type_key| and |enum_value_index| fields of the
410 // EnumValueReference are meaningful. The other fields should be ignored.
411 Value? resolved_concrete_value;
412 };
413
414 ////////////////////////////////////////////////////////////////////////////
415 // Declaration Data
416 ////////////////////////////////////////////////////////////////////////////
417
418 struct Attribute {
419 string key;
420
421 // TODO(rudominer) The grammar allows an attribute value to be a name but the
422 // parser currently converts the name into a string literal. Do we want to
423 // maintain the distinction between a name and a string literal for attribute
424 // values?
425 LiteralValue value;
426 };
427
428 // This structure contains additional data that may be present in
429 // a Mojom declaration. Some owning contexts may
430 // provide some of this data.
431 struct DeclarationData {
432 array<Attribute>? attributes;
433
434 string? short_name; // Some implementations may not provide names.
435
436 // The fully-qualified identifier is the concatenation of the names of the
437 // containing scopes, starting from the module name, with a period ('.')
438 // between components and with the |short_name| at the end.
439 string? full_identifier;
440
441 // The serialization ordinal of this element as declared in the
442 // .mojom file using the "@" notation.
443 int32 declared_ordinal = -1; // Negative value means unset.
444
445 // The zero-based ordinal position of this element within its containing
446 // scope as it appears in the Mojom declaration. This is not the serialization
447 // ordinal.
448 int32 declaration_order = -1;
449
450 SourceFileInfo? source_file_info;
451
452 // Some types (namely structs and interfaces) act as namespaces in which
453 // enums and constants may be declared. Some implementations may populate
454 // this field in order to describe that containment.
455 ContainedDeclarations? contained_declarations;
456
457 // If this DeclarationData is for an enum or a constant that is contained
458 // in a struct or interface, then this field, if populated, is the type_key
459 // that refers to the containing struct or interface. This field plays a
460 // role inverse to that of |contained_declarations|.
461 string? container_type_key;
462 };
463
464 struct SourceFileInfo {
465 string file_name;
466
467 // The 1-based line and column number. A value of zero means unset.
468 uint32 line_number;
469 uint32 column_number;
470 };
471
472 // Some types (namely structs and interfaces) act as namespaces in which
473 // enums and constants may be declared.
474 struct ContainedDeclarations {
475 // The type keys of enums declared in this namespace.
476 array<string>? enums;
477
478 // The the constant keys of constants declared in this namespace.
479 array<string>? constants;
480 };
481
482 ///////////////// Runtime Type Information //////////////////////
483
484 // This structure contains the information necessary for an implementation of
485 // |ServiceDescription| (see service_describer.mojom), but restricted to a
486 // single .mojom file and not restricted to a single service.
487 //
488 // Note that this structure is not literally a component of a MojomFileGraph.
489 // Instead, at compile time an instance of this structure is created and
490 // serialized to an array of bytes that is stored in the
491 // |serialized_runtime_type_info| field of each |MojomFile|. Then at code
492 // generation time this array of bytes is written into the generated source
493 // code as a literal array of bytes. Then at runtime this array of bytes
494 // is deserialized into an instance of RuntimeTypeInfo that may be used by
495 // an implementation of |ServiceDescription|.
496 struct RuntimeTypeInfo {
497 // Maps a service name to the type key of the associated interface for all of
498 // the services contained in a single .mojom file. A "service" is an
499 // interface that has been annoted with the "ServiceName" annotation.
500 // This indicates that it can be returned from
501 // ServiceProvider.ProvideService() and its description can be returned
502 // from ServiceDescriber.DescribeService().
503 map<string, string> services;
504
505 // All of the resolved user-defined-types contained in a single .mojom File.
506 // The keys are the |type_key|s. Note that the complete set of types
507 // referenced (recursively) from a single Mojom service is not necessarily
508 // restricted to a single .mojom file. Thus this map does not necessarily
509 // contain all of the types necessary to completely describe a service listed
510 // in the |services| map above. At runtime an implementation of
511 // |ServiceDescription| needs to merge the |RuntimeTypeInfo|
512 // from all of the generated modules in the file graph and then filter on only
513 // those types in the complete type set of a single service.
514 map<string, UserDefinedType> type_map;
515 };
OLDNEW
« no previous file with comments | « mojo/public/interfaces/bindings/mojom_files.mojom ('k') | mojo/public/interfaces/bindings/service_describer.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698