| 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 | 6 |
| 7 import 'package:mojo/application.dart'; | 7 import 'package:mojo/application.dart'; |
| 8 import 'package:mojo/bindings.dart'; | 8 import 'package:mojo/bindings.dart'; |
| 9 import 'package:mojo/core.dart'; | 9 import 'package:mojo/core.dart'; |
| 10 | 10 |
| 11 import 'package:_mojo_for_test_only/test/pingpong_service.mojom.dart'; | 11 import 'package:_mojo_for_test_only/test/pingpong_service.mojom.dart'; |
| 12 | 12 |
| 13 class PingPongServiceImpl implements PingPongService { | 13 class PingPongServiceImpl implements PingPongService { |
| 14 PingPongServiceStub _stub; | 14 PingPongService _service; |
| 15 Application _application; | 15 Application _application; |
| 16 PingPongClientProxy _pingPongClient; | 16 PingPongClient _pingPongClient; |
| 17 | 17 |
| 18 PingPongServiceImpl(this._application, MojoMessagePipeEndpoint endpoint) { | 18 PingPongServiceImpl(this._application, MojoMessagePipeEndpoint endpoint) { |
| 19 _stub = new PingPongServiceStub.fromEndpoint(endpoint, this); | 19 _service = new PingPongServiceInterface.fromEndpoint(endpoint, this); |
| 20 } | 20 } |
| 21 | 21 |
| 22 PingPongServiceImpl.fromStub(this._stub) { | 22 PingPongServiceImpl.fromInterfaceRequest( |
| 23 _stub.impl = this; | 23 PingPongServiceInterfaceRequest service) { |
| 24 service.impl = this; |
| 25 _service = service; |
| 24 } | 26 } |
| 25 | 27 |
| 26 void setClient(Proxy proxy) { | 28 void setClient(PingPongClientInterface client) { |
| 27 assert(_pingPongClient == null); | 29 assert(_pingPongClient == null); |
| 28 _pingPongClient = proxy; | 30 _pingPongClient = client; |
| 29 } | 31 } |
| 30 | 32 |
| 31 void ping(int pingValue) => _pingPongClient.pong(pingValue + 1); | 33 void ping(int pingValue) => _pingPongClient.pong(pingValue + 1); |
| 32 | 34 |
| 33 // These methods are unimplemented; they merely throw on invocation. | 35 // These methods are unimplemented; they merely throw on invocation. |
| 34 dynamic pingTargetUrl(String url, int count, [Function responseFactory]) => | 36 dynamic pingTargetUrl(String url, int count, [Function responseFactory]) => |
| 35 throw "Unimplemented"; | 37 throw "Unimplemented"; |
| 36 dynamic pingTargetService( | 38 dynamic pingTargetService(PingPongServiceInterface service, int count, |
| 37 Object service, int count, [Function responseFactory]) => | 39 [Function responseFactory]) => |
| 38 throw "Unimplemented"; | 40 throw "Unimplemented"; |
| 39 dynamic getPingPongServiceDelayed( | 41 dynamic getPingPongServiceDelayed(PingPongServiceInterfaceRequest service, |
| 40 Object service, [Function responseFactory]) => | 42 [Function responseFactory]) => |
| 41 throw "Unimplemented"; | 43 throw "Unimplemented"; |
| 42 | 44 |
| 43 void getPingPongService(Object service) { | 45 void getPingPongService(PingPongServiceInterfaceRequest service) { |
| 44 new PingPongServiceImpl.fromStub(service); | 46 new PingPongServiceImpl.fromInterfaceRequest(service); |
| 45 } | 47 } |
| 46 | 48 |
| 47 void quit() {} | 49 void quit() {} |
| 48 } | 50 } |
| 49 | 51 |
| 50 class PingPongApplication extends Application { | 52 class PingPongApplication extends Application { |
| 51 PingPongApplication.fromHandle(MojoHandle handle) : super.fromHandle(handle); | 53 PingPongApplication.fromHandle(MojoHandle handle) : super.fromHandle(handle); |
| 52 | 54 |
| 53 @override | 55 @override |
| 54 void acceptConnection(String requestorUrl, String resolvedUrl, | 56 void acceptConnection(String requestorUrl, String resolvedUrl, |
| 55 ApplicationConnection connection) { | 57 ApplicationConnection connection) { |
| 56 // Provide the service implemented by PingPongServiceImpl. | 58 // Provide the service implemented by PingPongServiceImpl. |
| 57 connection.provideService(PingPongService.serviceName, | 59 connection.provideService(PingPongService.serviceName, |
| 58 (endpoint) => new PingPongServiceImpl(this, endpoint)); | 60 (endpoint) => new PingPongServiceImpl(this, endpoint)); |
| 59 } | 61 } |
| 60 | 62 |
| 61 Future closeApplication() async { | 63 Future closeApplication() async { |
| 62 await close(); | 64 await close(); |
| 63 MojoHandle.reportLeakedHandles(); | 65 MojoHandle.reportLeakedHandles(); |
| 64 } | 66 } |
| 65 } | 67 } |
| 66 | 68 |
| 67 main(List args, Object handleToken) { | 69 main(List args, Object handleToken) { |
| 68 MojoHandle appHandle = new MojoHandle(handleToken); | 70 MojoHandle appHandle = new MojoHandle(handleToken); |
| 69 new PingPongApplication.fromHandle(appHandle); | 71 new PingPongApplication.fromHandle(appHandle); |
| 70 } | 72 } |
| OLD | NEW |