| 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 extends PingPongService { | 12 class PingPongServiceImpl implements PingPongService { |
| 13 PingPongServiceStub _stub; |
| 13 Application _application; | 14 Application _application; |
| 14 PingPongClientProxy _proxy; | 15 PingPongClientProxy _proxy; |
| 15 | 16 |
| 16 PingPongServiceImpl(Application application, MojoMessagePipeEndpoint endpoint) | 17 PingPongServiceImpl(Application application, MojoMessagePipeEndpoint endpoint) |
| 17 : _application = application, super(endpoint) { | 18 : _application = application { |
| 18 super.delegate = this; | 19 _stub = new PingPongServiceStub.fromEndpoint(endpoint) |
| 20 ..delegate = this |
| 21 ..listen(); |
| 19 } | 22 } |
| 20 | 23 |
| 21 void setClient(PingPongClientProxy proxy) { | 24 void setClient(Proxy proxy) { |
| 22 assert(_proxy == null); | 25 assert(_proxy == null); |
| 23 _proxy = proxy; | 26 _proxy = new PingPongClientProxy(proxy); |
| 24 } | 27 } |
| 25 | 28 |
| 26 void ping(int pingValue) => _proxy.pong(pingValue + 1); | 29 void ping(int pingValue) => _proxy.pong(pingValue + 1); |
| 27 | 30 |
| 28 void quit() { | 31 void quit() { |
| 29 if (_proxy != null) { | 32 if (_proxy != null) { |
| 30 _proxy.close(); | 33 PingPongClientProxyClose(_proxy); |
| 31 } | 34 } |
| 32 super.close(); | 35 _stub.close(); |
| 33 if (_application != null) { | 36 if (_application != null) { |
| 34 _application.close(); | 37 _application.close(); |
| 35 } | 38 } |
| 36 } | 39 } |
| 37 } | 40 } |
| 38 | 41 |
| 39 class PingPongApplication extends Application { | 42 class PingPongApplication extends Application { |
| 40 PingPongApplication.fromHandle(MojoHandle handle) : super.fromHandle(handle); | 43 PingPongApplication.fromHandle(MojoHandle handle) : super.fromHandle(handle); |
| 41 | 44 |
| 42 void acceptConnection(String requestorUrl, ApplicationConnection connection) { | 45 void acceptConnection(String requestorUrl, ApplicationConnection connection) { |
| 43 connection.provideService(PingPongService.name, | 46 connection.provideService(PingPongServiceName, |
| 44 (endpoint) => new PingPongServiceImpl(this, endpoint)); | 47 (endpoint) => new PingPongServiceImpl(this, endpoint)); |
| 45 connection.listen(); | 48 connection.listen(); |
| 46 } | 49 } |
| 47 } | 50 } |
| 48 | 51 |
| 49 main(List args) { | 52 main(List args) { |
| 50 MojoHandle appHandle = new MojoHandle(args[0]); | 53 MojoHandle appHandle = new MojoHandle(args[0]); |
| 51 String url = args[1]; | 54 String url = args[1]; |
| 52 var pingPongApplication = new PingPongApplication.fromHandle(appHandle); | 55 new PingPongApplication.fromHandle(appHandle); |
| 53 pingPongApplication.listen(); | |
| 54 } | 56 } |
| OLD | NEW |