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