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/core.dart'; | 8 import 'package:mojo/core.dart'; |
9 import 'package:_mojo_for_test_only/mojo/examples/echo.mojom.dart'; | 9 import 'package:_mojo_for_test_only/mojo/examples/echo.mojom.dart'; |
10 | 10 |
11 class EchoClientApplication extends Application { | 11 class EchoClientApplication extends Application { |
12 final _echoProxy = new EchoProxy.unbound(); | 12 final _echoProxy = new EchoProxy.unbound(); |
13 | 13 |
14 EchoClientApplication.fromHandle(MojoHandle handle) | 14 EchoClientApplication.fromHandle(MojoHandle handle) |
15 : super.fromHandle(handle) { | 15 : super.fromHandle(handle) { |
16 onError = ((_) { | 16 onError = ((_) { |
17 _closeHandles(); | 17 _closeHandles(); |
18 }); | 18 }); |
19 } | 19 } |
20 | 20 |
21 @override | 21 @override |
22 void initialize(List<String> arguments, String url) { | 22 void initialize(List<String> arguments, String url) { |
23 // See README.md for how to specify an alternate server on the command line. | 23 // See README.md for how to specify an alternate server on the command line. |
24 final server = (arguments.length > 0) ? arguments[1] : "dart_echo_server"; | 24 final server = (arguments.length > 0) ? arguments[1] : "dart_echo_server"; |
25 connectToService(url.replaceAll("dart_echo_client", server), _echoProxy); | 25 connectToService(url.replaceAll("dart_echo_client", server), _echoProxy); |
26 | 26 |
27 _echoProxy.ptr.echoString("hello world").then((response) { | 27 _echoProxy.echoString("hello world").then((response) { |
28 print("${response.value}"); | 28 print("${response.value}"); |
29 }).whenComplete(_closeHandles); | 29 }).whenComplete(_closeHandles); |
30 } | 30 } |
31 | 31 |
32 Future _closeHandles() async { | 32 Future _closeHandles() async { |
33 await _echoProxy.close(); | 33 await _echoProxy.close(); |
34 await close(); | 34 await close(); |
35 MojoHandle.reportLeakedHandles(); | 35 MojoHandle.reportLeakedHandles(); |
36 } | 36 } |
37 } | 37 } |
38 | 38 |
39 main(List args, Object handleToken) { | 39 main(List args, Object handleToken) { |
40 MojoHandle appHandle = new MojoHandle(handleToken); | 40 MojoHandle appHandle = new MojoHandle(handleToken); |
41 new EchoClientApplication.fromHandle(appHandle); | 41 new EchoClientApplication.fromHandle(appHandle); |
42 } | 42 } |
OLD | NEW |