OLD | NEW |
1 #!mojo mojo:dart_content_handler | 1 #!mojo mojo:dart_content_handler |
2 | 2 |
3 // Copyright 2015 The Chromium Authors. All rights reserved. | 3 // Copyright 2015 The Chromium Authors. All rights reserved. |
4 // Use of this source code is governed by a BSD-style license that can be | 4 // Use of this source code is governed by a BSD-style license that can be |
5 // found in the LICENSE file. | 5 // found in the LICENSE file. |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:mojo_application'; | 8 import 'dart:mojo_application'; |
9 import 'dart:mojo_bindings'; | 9 import 'dart:mojo_bindings'; |
10 import 'dart:mojo_core'; | 10 import 'dart:mojo_core'; |
11 | 11 |
12 import 'package:services/dart/test/pingpong_service.mojom.dart'; | 12 import 'package:services/dart/test/pingpong_service.mojom.dart'; |
13 | 13 |
14 class PingPongServiceImpl extends PingPongServiceStub { | 14 class PingPongServiceImpl extends PingPongServiceStub { |
| 15 Application _application; |
15 PingPongClientProxy _proxy; | 16 PingPongClientProxy _proxy; |
16 | 17 |
17 PingPongServiceImpl(MojoMessagePipeEndpoint endpoint) : super(endpoint); | 18 PingPongServiceImpl(MojoMessagePipeEndpoint endpoint, Application application) |
| 19 : _application = application, |
| 20 super(endpoint); |
18 | 21 |
19 void setClient(PingPongClientProxy proxy) { | 22 void setClient(PingPongClientProxy proxy) { |
20 _proxy = proxy; | 23 _proxy = proxy; |
21 } | 24 } |
22 | 25 |
23 void ping(int pingValue) => _proxy.callPong(pingValue + 1); | 26 void ping(int pingValue) => _proxy.callPong(pingValue + 1); |
24 | 27 |
25 void quit() { | 28 void quit() { |
26 if (_proxy != null) { | 29 if (_proxy != null) { |
27 _proxy.close(); | 30 _proxy.close(); |
28 } | 31 } |
29 close(); | 32 close(); |
| 33 if (_application != null) { |
| 34 _application.close(); |
| 35 } |
30 } | 36 } |
31 } | 37 } |
32 | 38 |
33 class PingPongApplication extends Application { | 39 class PingPongApplication extends Application { |
34 PingPongApplication.fromHandle(MojoHandle handle) : super.fromHandle(handle); | 40 PingPongApplication.fromHandle(MojoHandle handle) : super.fromHandle(handle); |
35 | 41 |
36 Function stubFactoryClosure() => | 42 Function stubFactoryClosure() => |
37 (endpoint) => new PingPongServiceImpl(endpoint); | 43 (endpoint) => new PingPongServiceImpl(endpoint, this); |
38 } | 44 } |
39 | 45 |
40 main(List args) { | 46 main(List args) { |
41 MojoHandle shellHandle = new MojoHandle(args[0]); | 47 MojoHandle appHandle = new MojoHandle(args[0]); |
42 String url = args[1]; | 48 String url = args[1]; |
43 var pingPongApplication = new PingPongApplication.fromHandle(shellHandle); | 49 var pingPongApplication = new PingPongApplication.fromHandle(appHandle); |
44 pingPongApplication.listen(); | 50 pingPongApplication.listen(); |
45 } | 51 } |
OLD | NEW |