OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 library sample_import_mojom; | 5 library sample_import_mojom; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; |
8 | 9 |
9 import 'package:mojo/bindings.dart' as bindings; | 10 import 'package:mojo/bindings.dart' as bindings; |
10 import 'package:mojo/core.dart' as core; | 11 import 'package:mojo/core.dart' as core; |
| 12 import 'package:mojo/mojo/bindings/types/mojom_types.mojom.dart' as mojom_types; |
| 13 import 'package:mojo/mojo/bindings/types/service_describer.mojom.dart' as servic
e_describer; |
11 | 14 |
12 class Shape extends bindings.MojoEnum { | 15 class Shape extends bindings.MojoEnum { |
13 static const Shape rectangle = const Shape._(1); | 16 static const Shape rectangle = const Shape._(1); |
14 static const Shape circle = const Shape._(2); | 17 static const Shape circle = const Shape._(2); |
15 static const Shape triangle = const Shape._(3); | 18 static const Shape triangle = const Shape._(3); |
16 static const Shape last = const Shape._(3); | 19 static const Shape last = const Shape._(3); |
17 | 20 |
18 const Shape._(int v) : super(v); | 21 const Shape._(int v) : super(v); |
19 | 22 |
20 static const Map<String, Shape> valuesMap = const { | 23 static const Map<String, Shape> valuesMap = const { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 String toString() { | 63 String toString() { |
61 switch(this) { | 64 switch(this) { |
62 case rectangle: | 65 case rectangle: |
63 return 'Shape.rectangle'; | 66 return 'Shape.rectangle'; |
64 case circle: | 67 case circle: |
65 return 'Shape.circle'; | 68 return 'Shape.circle'; |
66 case triangle: | 69 case triangle: |
67 return 'Shape.triangle'; | 70 return 'Shape.triangle'; |
68 case last: | 71 case last: |
69 return 'Shape.last'; | 72 return 'Shape.last'; |
| 73 default: |
| 74 return null; |
70 } | 75 } |
71 } | 76 } |
72 | 77 |
73 int toJson() => mojoEnumValue; | 78 int toJson() => mojoEnumValue; |
74 } | 79 } |
75 | 80 |
| 81 mojom_types.MojomEnum _sampleImportShape() { |
| 82 return new mojom_types.MojomEnum() |
| 83 ..declData = (new mojom_types.DeclarationData() |
| 84 ..shortName = 'Shape' |
| 85 ..fullIdentifier = 'imported.Shape') |
| 86 ..values = <mojom_types.EnumValue>[ |
| 87 new mojom_types.EnumValue() |
| 88 ..declData = (new mojom_types.DeclarationData() |
| 89 ..shortName = 'Rectangle') |
| 90 ..enumTypeKey = 'sample_import_Shape__' |
| 91 ..intValue = 1, |
| 92 new mojom_types.EnumValue() |
| 93 ..declData = (new mojom_types.DeclarationData() |
| 94 ..shortName = 'Circle') |
| 95 ..enumTypeKey = 'sample_import_Shape__' |
| 96 ..intValue = 2, |
| 97 new mojom_types.EnumValue() |
| 98 ..declData = (new mojom_types.DeclarationData() |
| 99 ..shortName = 'Triangle') |
| 100 ..enumTypeKey = 'sample_import_Shape__' |
| 101 ..intValue = 3, |
| 102 new mojom_types.EnumValue() |
| 103 ..declData = (new mojom_types.DeclarationData() |
| 104 ..shortName = 'Last') |
| 105 ..enumTypeKey = 'sample_import_Shape__' |
| 106 ..intValue = 3,]; |
| 107 } |
| 108 |
76 class AnotherShape extends bindings.MojoEnum { | 109 class AnotherShape extends bindings.MojoEnum { |
77 static const AnotherShape rectangle = const AnotherShape._(10); | 110 static const AnotherShape rectangle = const AnotherShape._(10); |
78 static const AnotherShape circle = const AnotherShape._(11); | 111 static const AnotherShape circle = const AnotherShape._(11); |
79 static const AnotherShape triangle = const AnotherShape._(12); | 112 static const AnotherShape triangle = const AnotherShape._(12); |
80 | 113 |
81 const AnotherShape._(int v) : super(v); | 114 const AnotherShape._(int v) : super(v); |
82 | 115 |
83 static const Map<String, AnotherShape> valuesMap = const { | 116 static const Map<String, AnotherShape> valuesMap = const { |
84 "rectangle": rectangle, | 117 "rectangle": rectangle, |
85 "circle": circle, | 118 "circle": circle, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 } | 150 } |
118 | 151 |
119 String toString() { | 152 String toString() { |
120 switch(this) { | 153 switch(this) { |
121 case rectangle: | 154 case rectangle: |
122 return 'AnotherShape.rectangle'; | 155 return 'AnotherShape.rectangle'; |
123 case circle: | 156 case circle: |
124 return 'AnotherShape.circle'; | 157 return 'AnotherShape.circle'; |
125 case triangle: | 158 case triangle: |
126 return 'AnotherShape.triangle'; | 159 return 'AnotherShape.triangle'; |
| 160 default: |
| 161 return null; |
127 } | 162 } |
128 } | 163 } |
129 | 164 |
130 int toJson() => mojoEnumValue; | 165 int toJson() => mojoEnumValue; |
131 } | 166 } |
132 | 167 |
| 168 mojom_types.MojomEnum _sampleImportAnotherShape() { |
| 169 return new mojom_types.MojomEnum() |
| 170 ..declData = (new mojom_types.DeclarationData() |
| 171 ..shortName = 'AnotherShape' |
| 172 ..fullIdentifier = 'imported.AnotherShape') |
| 173 ..values = <mojom_types.EnumValue>[ |
| 174 new mojom_types.EnumValue() |
| 175 ..declData = (new mojom_types.DeclarationData() |
| 176 ..shortName = 'Rectangle') |
| 177 ..enumTypeKey = 'sample_import_AnotherShape__' |
| 178 ..intValue = 10, |
| 179 new mojom_types.EnumValue() |
| 180 ..declData = (new mojom_types.DeclarationData() |
| 181 ..shortName = 'Circle') |
| 182 ..enumTypeKey = 'sample_import_AnotherShape__' |
| 183 ..intValue = 11, |
| 184 new mojom_types.EnumValue() |
| 185 ..declData = (new mojom_types.DeclarationData() |
| 186 ..shortName = 'Triangle') |
| 187 ..enumTypeKey = 'sample_import_AnotherShape__' |
| 188 ..intValue = 12,]; |
| 189 } |
| 190 |
133 class YetAnotherShape extends bindings.MojoEnum { | 191 class YetAnotherShape extends bindings.MojoEnum { |
134 static const YetAnotherShape rectangle = const YetAnotherShape._(20); | 192 static const YetAnotherShape rectangle = const YetAnotherShape._(20); |
135 static const YetAnotherShape circle = const YetAnotherShape._(21); | 193 static const YetAnotherShape circle = const YetAnotherShape._(21); |
136 static const YetAnotherShape triangle = const YetAnotherShape._(22); | 194 static const YetAnotherShape triangle = const YetAnotherShape._(22); |
137 | 195 |
138 const YetAnotherShape._(int v) : super(v); | 196 const YetAnotherShape._(int v) : super(v); |
139 | 197 |
140 static const Map<String, YetAnotherShape> valuesMap = const { | 198 static const Map<String, YetAnotherShape> valuesMap = const { |
141 "rectangle": rectangle, | 199 "rectangle": rectangle, |
142 "circle": circle, | 200 "circle": circle, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 } | 232 } |
175 | 233 |
176 String toString() { | 234 String toString() { |
177 switch(this) { | 235 switch(this) { |
178 case rectangle: | 236 case rectangle: |
179 return 'YetAnotherShape.rectangle'; | 237 return 'YetAnotherShape.rectangle'; |
180 case circle: | 238 case circle: |
181 return 'YetAnotherShape.circle'; | 239 return 'YetAnotherShape.circle'; |
182 case triangle: | 240 case triangle: |
183 return 'YetAnotherShape.triangle'; | 241 return 'YetAnotherShape.triangle'; |
| 242 default: |
| 243 return null; |
184 } | 244 } |
185 } | 245 } |
186 | 246 |
187 int toJson() => mojoEnumValue; | 247 int toJson() => mojoEnumValue; |
188 } | 248 } |
189 | 249 |
| 250 mojom_types.MojomEnum _sampleImportYetAnotherShape() { |
| 251 return new mojom_types.MojomEnum() |
| 252 ..declData = (new mojom_types.DeclarationData() |
| 253 ..shortName = 'YetAnotherShape' |
| 254 ..fullIdentifier = 'imported.YetAnotherShape') |
| 255 ..values = <mojom_types.EnumValue>[ |
| 256 new mojom_types.EnumValue() |
| 257 ..declData = (new mojom_types.DeclarationData() |
| 258 ..shortName = 'Rectangle') |
| 259 ..enumTypeKey = 'sample_import_YetAnotherShape__' |
| 260 ..intValue = 20, |
| 261 new mojom_types.EnumValue() |
| 262 ..declData = (new mojom_types.DeclarationData() |
| 263 ..shortName = 'Circle') |
| 264 ..enumTypeKey = 'sample_import_YetAnotherShape__' |
| 265 ..intValue = 21, |
| 266 new mojom_types.EnumValue() |
| 267 ..declData = (new mojom_types.DeclarationData() |
| 268 ..shortName = 'Triangle') |
| 269 ..enumTypeKey = 'sample_import_YetAnotherShape__' |
| 270 ..intValue = 22,]; |
| 271 } |
| 272 |
190 | 273 |
191 | 274 |
192 class Point extends bindings.Struct { | 275 class Point extends bindings.Struct { |
193 static const List<bindings.StructDataHeader> kVersions = const [ | 276 static const List<bindings.StructDataHeader> kVersions = const [ |
194 const bindings.StructDataHeader(16, 0) | 277 const bindings.StructDataHeader(16, 0) |
195 ]; | 278 ]; |
196 int x = 0; | 279 int x = 0; |
197 int y = 0; | 280 int y = 0; |
198 | 281 |
199 Point() : super(kVersions.last.size); | 282 Point() : super(kVersions.last.size); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 } | 340 } |
258 | 341 |
259 Map toJson() { | 342 Map toJson() { |
260 Map map = new Map(); | 343 Map map = new Map(); |
261 map["x"] = x; | 344 map["x"] = x; |
262 map["y"] = y; | 345 map["y"] = y; |
263 return map; | 346 return map; |
264 } | 347 } |
265 } | 348 } |
266 | 349 |
| 350 mojom_types.MojomStruct _sampleImportPoint() { |
| 351 return new mojom_types.MojomStruct() |
| 352 ..declData = (new mojom_types.DeclarationData() |
| 353 ..shortName = 'Point' |
| 354 ..fullIdentifier = 'imported.Point') |
| 355 ..fields = <mojom_types.StructField>[ |
| 356 new mojom_types.StructField() |
| 357 ..declData = (new mojom_types.DeclarationData() |
| 358 ..shortName = 'X') |
| 359 ..type = (new mojom_types.Type() |
| 360 ..simpleType = mojom_types.SimpleType.int32), |
| 361 new mojom_types.StructField() |
| 362 ..declData = (new mojom_types.DeclarationData() |
| 363 ..shortName = 'Y') |
| 364 ..type = (new mojom_types.Type() |
| 365 ..simpleType = mojom_types.SimpleType.int32),]; |
| 366 } |
| 367 |
267 | 368 |
268 class _ImportedInterfaceDoSomethingParams extends bindings.Struct { | 369 class _ImportedInterfaceDoSomethingParams extends bindings.Struct { |
269 static const List<bindings.StructDataHeader> kVersions = const [ | 370 static const List<bindings.StructDataHeader> kVersions = const [ |
270 const bindings.StructDataHeader(8, 0) | 371 const bindings.StructDataHeader(8, 0) |
271 ]; | 372 ]; |
272 | 373 |
273 _ImportedInterfaceDoSomethingParams() : super(kVersions.last.size); | 374 _ImportedInterfaceDoSomethingParams() : super(kVersions.last.size); |
274 | 375 |
275 static _ImportedInterfaceDoSomethingParams deserialize(bindings.Message messag
e) { | 376 static _ImportedInterfaceDoSomethingParams deserialize(bindings.Message messag
e) { |
276 var decoder = new bindings.Decoder(message); | 377 var decoder = new bindings.Decoder(message); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 String toString() { | 416 String toString() { |
316 return "_ImportedInterfaceDoSomethingParams("")"; | 417 return "_ImportedInterfaceDoSomethingParams("")"; |
317 } | 418 } |
318 | 419 |
319 Map toJson() { | 420 Map toJson() { |
320 Map map = new Map(); | 421 Map map = new Map(); |
321 return map; | 422 return map; |
322 } | 423 } |
323 } | 424 } |
324 | 425 |
| 426 mojom_types.MojomStruct _sampleImportImportedInterfaceDoSomethingParams() { |
| 427 return new mojom_types.MojomStruct() |
| 428 ..declData = (new mojom_types.DeclarationData() |
| 429 ..shortName = 'ImportedInterfaceDoSomethingParams' |
| 430 ..fullIdentifier = 'imported.ImportedInterface_DoSomething_Params') |
| 431 ..fields = <mojom_types.StructField>[]; |
| 432 } |
| 433 |
| 434 |
325 const int _ImportedInterface_doSomethingName = 0; | 435 const int _ImportedInterface_doSomethingName = 0; |
326 | 436 |
| 437 mojom_types.MojomInterface _sampleImportImportedInterface() { |
| 438 return new mojom_types.MojomInterface() |
| 439 ..declData = (new mojom_types.DeclarationData() |
| 440 ..shortName = 'ImportedInterface' |
| 441 ..fullIdentifier = 'imported.ImportedInterface') |
| 442 ..interfaceName = 'ImportedInterface' |
| 443 ..methods = <int, mojom_types.MojomMethod>{ |
| 444 _ImportedInterface_doSomethingName: new mojom_types.MojomMethod() |
| 445 ..declData = (new mojom_types.DeclarationData() |
| 446 ..shortName = 'DoSomething') |
| 447 ..ordinal = _ImportedInterface_doSomethingName |
| 448 ..parameters = _sampleImportImportedInterfaceDoSomethingParams(), |
| 449 }; |
| 450 } |
| 451 |
| 452 class _ImportedInterfaceServiceDescription implements service_describer.ServiceD
escription { |
| 453 dynamic getTopLevelInterface([Function responseFactory]) => |
| 454 _sampleImportImportedInterface(); |
| 455 |
| 456 dynamic getTypeDefinition(String typeKey, [Function responseFactory]) => |
| 457 getAllMojomTypeDefinitions()[typeKey]; |
| 458 |
| 459 dynamic getAllTypeDefinitions([Function responseFactory]) => |
| 460 getAllMojomTypeDefinitions(); |
| 461 } |
| 462 |
327 abstract class ImportedInterface { | 463 abstract class ImportedInterface { |
328 static const String serviceName = null; | 464 static const String serviceName = null; |
329 void doSomething(); | 465 void doSomething(); |
330 } | 466 } |
331 | 467 |
332 | 468 |
333 class _ImportedInterfaceProxyImpl extends bindings.Proxy { | 469 class _ImportedInterfaceProxyImpl extends bindings.Proxy { |
334 _ImportedInterfaceProxyImpl.fromEndpoint( | 470 _ImportedInterfaceProxyImpl.fromEndpoint( |
335 core.MojoMessagePipeEndpoint endpoint) : super.fromEndpoint(endpoint); | 471 core.MojoMessagePipeEndpoint endpoint) : super.fromEndpoint(endpoint); |
336 | 472 |
337 _ImportedInterfaceProxyImpl.fromHandle(core.MojoHandle handle) : | 473 _ImportedInterfaceProxyImpl.fromHandle(core.MojoHandle handle) : |
338 super.fromHandle(handle); | 474 super.fromHandle(handle); |
339 | 475 |
340 _ImportedInterfaceProxyImpl.unbound() : super.unbound(); | 476 _ImportedInterfaceProxyImpl.unbound() : super.unbound(); |
341 | 477 |
342 static _ImportedInterfaceProxyImpl newFromEndpoint( | 478 static _ImportedInterfaceProxyImpl newFromEndpoint( |
343 core.MojoMessagePipeEndpoint endpoint) { | 479 core.MojoMessagePipeEndpoint endpoint) { |
344 assert(endpoint.setDescription("For _ImportedInterfaceProxyImpl")); | 480 assert(endpoint.setDescription("For _ImportedInterfaceProxyImpl")); |
345 return new _ImportedInterfaceProxyImpl.fromEndpoint(endpoint); | 481 return new _ImportedInterfaceProxyImpl.fromEndpoint(endpoint); |
346 } | 482 } |
347 | 483 |
| 484 service_describer.ServiceDescription get serviceDescription => |
| 485 new _ImportedInterfaceServiceDescription(); |
| 486 |
348 void handleResponse(bindings.ServiceMessage message) { | 487 void handleResponse(bindings.ServiceMessage message) { |
349 switch (message.header.type) { | 488 switch (message.header.type) { |
350 default: | 489 default: |
351 proxyError("Unexpected message type: ${message.header.type}"); | 490 proxyError("Unexpected message type: ${message.header.type}"); |
352 close(immediate: true); | 491 close(immediate: true); |
353 break; | 492 break; |
354 } | 493 } |
355 } | 494 } |
356 | 495 |
357 String toString() { | 496 String toString() { |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 assert(_impl == null); | 619 assert(_impl == null); |
481 _impl = d; | 620 _impl = d; |
482 } | 621 } |
483 | 622 |
484 String toString() { | 623 String toString() { |
485 var superString = super.toString(); | 624 var superString = super.toString(); |
486 return "ImportedInterfaceStub($superString)"; | 625 return "ImportedInterfaceStub($superString)"; |
487 } | 626 } |
488 | 627 |
489 int get version => 0; | 628 int get version => 0; |
| 629 |
| 630 service_describer.ServiceDescription get serviceDescription => |
| 631 new _ImportedInterfaceServiceDescription(); |
490 } | 632 } |
491 | 633 |
492 | 634 |
| 635 Map<String, mojom_types.UserDefinedType> _initDescriptions() { |
| 636 var map = new HashMap<String, mojom_types.UserDefinedType>(); |
| 637 map["sample_import_Shape__"] = |
| 638 new mojom_types.UserDefinedType() |
| 639 ..enumType = _sampleImportShape(); |
| 640 map["sample_import_AnotherShape__"] = |
| 641 new mojom_types.UserDefinedType() |
| 642 ..enumType = _sampleImportAnotherShape(); |
| 643 map["sample_import_YetAnotherShape__"] = |
| 644 new mojom_types.UserDefinedType() |
| 645 ..enumType = _sampleImportYetAnotherShape(); |
| 646 map["sample_import_Point__"] = |
| 647 new mojom_types.UserDefinedType() |
| 648 ..structType = _sampleImportPoint(); |
| 649 map["sample_import_ImportedInterface_DoSomething_Params__"] = |
| 650 new mojom_types.UserDefinedType() |
| 651 ..structType = _sampleImportImportedInterfaceDoSomethingParams(); |
| 652 map["sample_import_ImportedInterface__"] = |
| 653 new mojom_types.UserDefinedType() |
| 654 ..interfaceType = _sampleImportImportedInterface(); |
| 655 return map; |
| 656 } |
| 657 |
| 658 var _mojomDesc; |
| 659 Map<String, mojom_types.UserDefinedType> getAllMojomTypeDefinitions() { |
| 660 if (_mojomDesc == null) { |
| 661 _mojomDesc = _initDescriptions(); |
| 662 } |
| 663 return _mojomDesc; |
| 664 } |
| 665 |
OLD | NEW |