| 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 import 'mojo:application'; | 6 import 'mojo:application'; |
| 7 import 'mojo:bindings'; | 7 import 'mojo:bindings'; |
| 8 import 'mojo:core'; | 8 import 'mojo:core'; |
| 9 | 9 |
| 10 import 'package:services/dart/test/pingpong_service.mojom.dart'; | 10 import 'package:services/dart/test/pingpong_service.mojom.dart'; |
| 11 | 11 |
| 12 class PingPongServiceImpl implements PingPongService { | 12 class PingPongServiceImpl implements PingPongService { |
| 13 PingPongServiceStub _stub; | 13 PingPongServiceStub _stub; |
| 14 Application _application; | 14 Application _application; |
| 15 PingPongClientProxy _pingPongClient; | 15 PingPongClientProxy _pingPongClient; |
| 16 | 16 |
| 17 PingPongServiceImpl(Application application, MojoMessagePipeEndpoint endpoint) | 17 PingPongServiceImpl(Application application, MojoMessagePipeEndpoint endpoint) |
| 18 : _application = application { | 18 : _application = application { |
| 19 _stub = new PingPongServiceStub.fromEndpoint(endpoint) | 19 _stub = new PingPongServiceStub.fromEndpoint(endpoint, impl: this); |
| 20 ..delegate = this | |
| 21 ..listen(); | |
| 22 } | 20 } |
| 23 | 21 |
| 24 void setClient(ProxyBase proxyBase) { | 22 void setClient(ProxyBase proxyBase) { |
| 25 assert(_pingPongClient == null); | 23 assert(_pingPongClient == null); |
| 26 _pingPongClient = proxyBase; | 24 _pingPongClient = proxyBase; |
| 27 } | 25 } |
| 28 | 26 |
| 29 void ping(int pingValue) => _pingPongClient.ptr.pong(pingValue + 1); | 27 void ping(int pingValue) => _pingPongClient.ptr.pong(pingValue + 1); |
| 30 | 28 |
| 31 void quit() { | 29 void quit() { |
| 32 if (_pingPongClient != null) { | 30 if (_pingPongClient != null) { |
| 33 _pingPongClient.close(); | 31 _pingPongClient.close(); |
| 34 _pingPongClient = null; | 32 _pingPongClient = null; |
| 35 } | 33 } |
| 36 _stub.close(); | 34 _stub.close(); |
| 37 if (_application != null) { | |
| 38 _application.close(); | |
| 39 } | |
| 40 } | 35 } |
| 41 } | 36 } |
| 42 | 37 |
| 43 class PingPongApplication extends Application { | 38 class PingPongApplication extends Application { |
| 44 PingPongApplication.fromHandle(MojoHandle handle) : super.fromHandle(handle); | 39 PingPongApplication.fromHandle(MojoHandle handle) : super.fromHandle(handle); |
| 45 | 40 |
| 46 @override | 41 @override |
| 47 void acceptConnection(String requestorUrl, String resolvedUrl, | 42 void acceptConnection(String requestorUrl, String resolvedUrl, |
| 48 ApplicationConnection connection) { | 43 ApplicationConnection connection) { |
| 49 connection.provideService(PingPongServiceName, | 44 connection.provideService( |
| 45 PingPongServiceName, |
| 50 (endpoint) => new PingPongServiceImpl(this, endpoint)); | 46 (endpoint) => new PingPongServiceImpl(this, endpoint)); |
| 51 connection.listen(); | 47 // Close the application when the first connection goes down. |
| 48 connection.listen(onClosed: close); |
| 52 } | 49 } |
| 53 } | 50 } |
| 54 | 51 |
| 55 main(List args) { | 52 main(List args) { |
| 56 MojoHandle appHandle = new MojoHandle(args[0]); | 53 MojoHandle appHandle = new MojoHandle(args[0]); |
| 57 String url = args[1]; | 54 String url = args[1]; |
| 58 new PingPongApplication.fromHandle(appHandle); | 55 new PingPongApplication.fromHandle(appHandle); |
| 59 } | 56 } |
| OLD | NEW |