OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 import 'dart:async'; | 5 import 'dart:async'; |
6 | 6 |
7 import 'package:mojo/application.dart'; | 7 import 'package:mojo/application.dart'; |
8 import 'package:mojo/bindings.dart'; | 8 import 'package:mojo/bindings.dart'; |
9 import 'package:mojo/core.dart'; | 9 import 'package:mojo/core.dart'; |
10 import 'package:_mojo_for_test_only/mojo/examples/echo.mojom.dart'; | 10 import 'package:_mojo_for_test_only/mojo/examples/echo.mojom.dart'; |
11 | 11 |
12 class EchoImpl implements Echo { | 12 class EchoImpl implements Echo { |
13 EchoInterface _echo; | 13 EchoInterface _echo; |
14 EchoApplication _application; | 14 EchoApplication _application; |
15 | 15 |
16 EchoImpl(this._application, MojoMessagePipeEndpoint endpoint) { | 16 EchoImpl(this._application, MojoMessagePipeEndpoint endpoint) { |
17 _echo = new EchoInterface.fromEndpoint(endpoint, this); | 17 _echo = new EchoInterface.fromEndpoint(endpoint, this); |
18 _echo.ctrl.onError = _errorHandler; | 18 _echo.ctrl.onError = _errorHandler; |
19 } | 19 } |
20 | 20 |
21 echoString(String value, [Function responseFactory]) => | 21 void echoString(String value, void respond(String response)) { |
22 responseFactory(value); | 22 respond(value); |
| 23 } |
23 | 24 |
24 Future close() => _echo.close(); | 25 Future close() => _echo.close(); |
25 | 26 |
26 _errorHandler(Object e) => _application.removeService(this); | 27 _errorHandler(Object e) => _application.removeService(this); |
27 } | 28 } |
28 | 29 |
29 class EchoApplication extends Application { | 30 class EchoApplication extends Application { |
30 List<EchoImpl> _echoServices; | 31 List<EchoImpl> _echoServices; |
31 bool _closing; | 32 bool _closing; |
32 | 33 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 await service.close(); | 66 await service.close(); |
66 } | 67 } |
67 MojoHandle.reportLeakedHandles(); | 68 MojoHandle.reportLeakedHandles(); |
68 } | 69 } |
69 } | 70 } |
70 | 71 |
71 main(List args, Object handleToken) { | 72 main(List args, Object handleToken) { |
72 MojoHandle appHandle = new MojoHandle(handleToken); | 73 MojoHandle appHandle = new MojoHandle(handleToken); |
73 new EchoApplication.fromHandle(appHandle); | 74 new EchoApplication.fromHandle(appHandle); |
74 } | 75 } |
OLD | NEW |