Chromium Code Reviews| 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(this._application, MojoMessagePipeEndpoint endpoint) { | 17 PingPongServiceImpl(this._application, MojoMessagePipeEndpoint endpoint) { |
| 18 _stub = new PingPongServiceStub.fromEndpoint(endpoint, this); | 18 _stub = new PingPongServiceStub.fromEndpoint(endpoint, this); |
| 19 } | 19 } |
| 20 | 20 |
| 21 void setClient(ProxyBase proxyBase) { | 21 void setClient(ProxyBase proxyBase) { |
| 22 assert(_pingPongClient == null); | 22 assert(_pingPongClient == null); |
| 23 _pingPongClient = proxyBase; | 23 _pingPongClient = proxyBase; |
| 24 } | 24 } |
| 25 | 25 |
| 26 void ping(int pingValue) => _pingPongClient.ptr.pong(pingValue + 1); | 26 void ping(int pingValue) => _pingPongClient.ptr.pong(pingValue + 1); |
| 27 | 27 |
| 28 // These methods are unimplemented; they merely throw on invocation. | |
| 29 Future<PingPongServicePingTargetUrlResponseParams> pingTargetUrl( | |
| 30 String url, int count, [Function responseFactory = null]) => | |
|
zra
2015/03/11 18:38:06
ditto
| |
| 31 throw "Unimplemented"; | |
| 32 Future<PingPongServicePingTargetServiceResponseParams> pingTargetService( | |
| 33 Object service, int count, [Function responseFactory = null]) => | |
|
zra
2015/03/11 18:38:06
ditto
| |
| 34 throw "Unimplemented"; | |
| 35 void getPingPongService(Object service) => throw "Unimplemented"; | |
| 36 | |
| 28 void quit() { | 37 void quit() { |
| 29 if (_pingPongClient != null) { | 38 if (_pingPongClient != null) { |
| 30 _pingPongClient.close(); | 39 _pingPongClient.close(); |
| 31 _pingPongClient = null; | 40 _pingPongClient = null; |
| 32 } | 41 } |
| 33 _stub.close(); | 42 _stub.close(); |
| 34 } | 43 } |
| 35 } | 44 } |
| 36 | 45 |
| 37 class PingPongApplication extends Application { | 46 class PingPongApplication extends Application { |
| 38 PingPongApplication.fromHandle(MojoHandle handle) : super.fromHandle(handle); | 47 PingPongApplication.fromHandle(MojoHandle handle) : super.fromHandle(handle); |
| 39 | 48 |
| 40 @override | 49 @override |
| 41 void acceptConnection(String requestorUrl, String resolvedUrl, | 50 void acceptConnection(String requestorUrl, String resolvedUrl, |
| 42 ApplicationConnection connection) { | 51 ApplicationConnection connection) { |
| 43 connection.provideService(PingPongServiceName, | 52 connection.provideService(PingPongServiceName, |
| 44 (endpoint) => new PingPongServiceImpl(this, endpoint)); | 53 (endpoint) => new PingPongServiceImpl(this, endpoint)); |
| 45 // Close the application when the first connection goes down. | 54 // Close the application when the first connection goes down. |
| 46 connection.onError = close; | 55 connection.onError = close; |
| 47 } | 56 } |
| 48 } | 57 } |
| 49 | 58 |
| 50 main(List args) { | 59 main(List args) { |
| 51 MojoHandle appHandle = new MojoHandle(args[0]); | 60 MojoHandle appHandle = new MojoHandle(args[0]); |
| 52 String url = args[1]; | 61 String url = args[1]; |
| 53 new PingPongApplication.fromHandle(appHandle); | 62 new PingPongApplication.fromHandle(appHandle); |
| 54 } | 63 } |
| OLD | NEW |