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