| 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'; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 stub.close(); | 25 stub.close(); |
| 26 } | 26 } |
| 27 } | 27 } |
| 28 } | 28 } |
| 29 | 29 |
| 30 class PingPongServiceImpl implements PingPongService { | 30 class PingPongServiceImpl implements PingPongService { |
| 31 PingPongServiceStub _stub; | 31 PingPongServiceStub _stub; |
| 32 Application _application; | 32 Application _application; |
| 33 PingPongClientProxy _pingPongClient; | 33 PingPongClientProxy _pingPongClient; |
| 34 | 34 |
| 35 PingPongServiceImpl(Application application, MojoMessagePipeEndpoint endpoint) | 35 PingPongServiceImpl(this._application, MojoMessagePipeEndpoint endpoint) { |
| 36 : _application = application { | 36 _stub = new PingPongServiceStub.fromEndpoint(endpoint, this); |
| 37 _stub = new PingPongServiceStub.fromEndpoint(endpoint, impl: this); | |
| 38 } | 37 } |
| 39 | 38 |
| 40 PingPongServiceImpl.fromStub(this._stub) { | 39 PingPongServiceImpl.fromStub(this._stub) { |
| 41 _stub.impl = this; | 40 _stub.impl = this; |
| 42 } | 41 } |
| 43 | 42 |
| 44 listen() => _stub.listen(); | |
| 45 | |
| 46 void setClient(ProxyBase proxyBase) { | 43 void setClient(ProxyBase proxyBase) { |
| 47 assert(_pingPongClient == null); | 44 assert(_pingPongClient == null); |
| 48 _pingPongClient = proxyBase; | 45 _pingPongClient = proxyBase; |
| 49 } | 46 } |
| 50 | 47 |
| 51 void ping(int pingValue) { | 48 void ping(int pingValue) { |
| 52 if (_pingPongClient != null) { | 49 if (_pingPongClient != null) { |
| 53 _pingPongClient.ptr.pong(pingValue + 1); | 50 _pingPongClient.ptr.pong(pingValue + 1); |
| 54 } | 51 } |
| 55 } | 52 } |
| 56 | 53 |
| 57 Future pingTargetUrl(String url, int count, Function responseFactory) async { | 54 Future pingTargetUrl(String url, int count, Function responseFactory) async { |
| 58 if (_application == null) { | 55 if (_application == null) { |
| 59 return responseFactory(false); | 56 return responseFactory(false); |
| 60 } | 57 } |
| 61 var completer = new Completer(); | 58 var completer = new Completer(); |
| 62 var pingPongService = new PingPongServiceProxy.unbound(); | 59 var pingPongService = new PingPongServiceProxy.unbound(); |
| 63 _application.connectToService(url, pingPongService); | 60 _application.connectToService(url, pingPongService); |
| 64 | 61 |
| 65 var pingPongClient = new PingPongClientImpl.unbound(count, completer); | 62 var pingPongClient = new PingPongClientImpl.unbound(count, completer); |
| 66 pingPongService.ptr.setClient(pingPongClient.stub); | 63 pingPongService.ptr.setClient(pingPongClient.stub); |
| 67 pingPongClient.stub.listen(); | |
| 68 | 64 |
| 69 for (var i = 0; i < count; i++) { | 65 for (var i = 0; i < count; i++) { |
| 70 pingPongService.ptr.ping(i); | 66 pingPongService.ptr.ping(i); |
| 71 } | 67 } |
| 72 await completer.future; | 68 await completer.future; |
| 73 pingPongService.ptr.quit(); | 69 pingPongService.ptr.quit(); |
| 74 pingPongService.close(); | 70 pingPongService.close(); |
| 75 | 71 |
| 76 return responseFactory(true); | 72 return responseFactory(true); |
| 77 } | 73 } |
| 78 | 74 |
| 79 Future pingTargetService(ProxyBase proxyBase, int count, | 75 Future pingTargetService( |
| 80 Function responseFactory) async { | 76 ProxyBase proxyBase, int count, Function responseFactory) async { |
| 81 var pingPongService = proxyBase; | 77 var pingPongService = proxyBase; |
| 82 var completer = new Completer(); | 78 var completer = new Completer(); |
| 83 var client = new PingPongClientImpl.unbound(count, completer); | 79 var client = new PingPongClientImpl.unbound(count, completer); |
| 84 pingPongService.ptr.setClient(client.stub); | 80 pingPongService.ptr.setClient(client.stub); |
| 85 client.stub.listen(); | |
| 86 | 81 |
| 87 for (var i = 0; i < count; i++) { | 82 for (var i = 0; i < count; i++) { |
| 88 pingPongService.ptr.ping(i); | 83 pingPongService.ptr.ping(i); |
| 89 } | 84 } |
| 90 await completer.future; | 85 await completer.future; |
| 91 pingPongService.ptr.quit(); | 86 pingPongService.ptr.quit(); |
| 92 pingPongService.close(); | 87 pingPongService.close(); |
| 93 | 88 |
| 94 return responseFactory(true); | 89 return responseFactory(true); |
| 95 } | 90 } |
| 96 | 91 |
| 97 getPingPongService(PingPongServiceStub serviceStub) { | 92 getPingPongService(PingPongServiceStub serviceStub) { |
| 98 new PingPongServiceImpl.fromStub(serviceStub)..listen(); | 93 new PingPongServiceImpl.fromStub(serviceStub); |
| 99 } | 94 } |
| 100 | 95 |
| 101 void quit() { | 96 void quit() { |
| 102 if (_pingPongClient != null) { | 97 if (_pingPongClient != null) { |
| 103 _pingPongClient.close(); | 98 _pingPongClient.close(); |
| 104 _pingPongClient = null; | 99 _pingPongClient = null; |
| 105 } | 100 } |
| 106 _stub.close(); | 101 _stub.close(); |
| 107 _stub = null; | 102 _stub = null; |
| 108 } | 103 } |
| 109 } | 104 } |
| 110 | 105 |
| 111 class PingPongApplication extends Application { | 106 class PingPongApplication extends Application { |
| 112 PingPongApplication.fromHandle(MojoHandle handle) : super.fromHandle(handle); | 107 PingPongApplication.fromHandle(MojoHandle handle) : super.fromHandle(handle); |
| 113 | 108 |
| 114 @override | 109 @override |
| 115 void acceptConnection(String requestorUrl, String resolvedUrl, | 110 void acceptConnection(String requestorUrl, String resolvedUrl, |
| 116 ApplicationConnection connection) { | 111 ApplicationConnection connection) { |
| 117 connection.provideService( | 112 connection.provideService(PingPongServiceName, |
| 118 PingPongServiceName, | |
| 119 (endpoint) => new PingPongServiceImpl(this, endpoint)); | 113 (endpoint) => new PingPongServiceImpl(this, endpoint)); |
| 120 connection.listen(); | |
| 121 } | 114 } |
| 122 } | 115 } |
| 123 | 116 |
| 124 main(List args) { | 117 main(List args) { |
| 125 MojoHandle appHandle = new MojoHandle(args[0]); | 118 MojoHandle appHandle = new MojoHandle(args[0]); |
| 126 String url = args[1]; | 119 String url = args[1]; |
| 127 new PingPongApplication.fromHandle(appHandle); | 120 new PingPongApplication.fromHandle(appHandle); |
| 128 } | 121 } |
| OLD | NEW |