OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 import 'dart:async'; |
| 6 import 'dart:isolate'; |
| 7 import 'dart:mojo_bindings' as bindings; |
| 8 import 'dart:mojo_core' as core; |
| 9 |
| 10 import 'package:mojo/public/interfaces/bindings/tests/sample_service.mojom.dart'
as sample; |
| 11 |
| 12 class ExpectPortInterfaceImpl implements sample.PortInterface { |
| 13 String _expected; |
| 14 ExpectPortInterfaceImpl([this._expected = ""]); |
| 15 |
| 16 void postMessage(String messageText, sample.PortClient port) { |
| 17 assert(messageText == _expected); |
| 18 port.close(); |
| 19 } |
| 20 } |
| 21 |
| 22 class ServiceImpl extends sample.ServiceInterface { |
| 23 ServiceImpl(core.MojoMessagePipeEndpoint endpoint) : super(endpoint); |
| 24 |
| 25 void frobinate(sample.Foo foo, int baz, sample.PortClient portClient) { |
| 26 var portInterface = new sample.PortInterface.unbound(); |
| 27 portInterface.delegate = new ExpectPortInterfaceImpl(); |
| 28 portClient.callPostMessage("frobinated", portInterface); |
| 29 portInterface.listen(); |
| 30 callDidFrobinate(42); |
| 31 portClient.close(); |
| 32 } |
| 33 |
| 34 void getPort(sample.PortInterface portInterface) { |
| 35 portInterface.delegate = new ExpectPortInterfaceImpl("port"); |
| 36 portInterface.listen(); |
| 37 } |
| 38 } |
| 39 |
| 40 class ServiceClientImpl extends sample.ServiceClientInterface |
| 41 with sample.ServiceCalls { |
| 42 Completer completer; |
| 43 |
| 44 ServiceClientImpl(core.MojoMessagePipeEndpoint endpoint) : super(endpoint); |
| 45 |
| 46 void didFrobinate(int result) { |
| 47 assert(result == 42); |
| 48 completer.complete(null); |
| 49 } |
| 50 |
| 51 Future run() { |
| 52 completer = new Completer(); |
| 53 |
| 54 listen(); |
| 55 var portClient = new sample.PortClient.unbound(); |
| 56 callGetPort(portClient); |
| 57 portClient.close(); |
| 58 |
| 59 var portInterface = new sample.PortInterface.unbound(); |
| 60 portInterface.delegate = new ExpectPortInterfaceImpl("frobinated"); |
| 61 callFrobinate(new sample.Foo(), sample.BazOptions_EXTRA, portInterface); |
| 62 portInterface.listen(); |
| 63 return completer.future; |
| 64 } |
| 65 } |
| 66 |
| 67 void serviceIsolate(core.MojoMessagePipeEndpoint endpoint) { |
| 68 var service = new ServiceImpl(endpoint); |
| 69 service.listen(); |
| 70 } |
| 71 |
| 72 main() async { |
| 73 var pipe = new core.MojoMessagePipe(); |
| 74 var isolate = await Isolate.spawn(serviceIsolate, pipe.endpoints[0]); |
| 75 |
| 76 var serviceClient = new ServiceClientImpl(pipe.endpoints[1]); |
| 77 await serviceClient.run(); |
| 78 |
| 79 serviceClient.close(); |
| 80 } |
OLD | NEW |