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 |
(...skipping 29 matching lines...) Expand all Loading... |
40 assert(_pingPongClient == null); | 40 assert(_pingPongClient == null); |
41 _pingPongClient = client; | 41 _pingPongClient = client; |
42 } | 42 } |
43 | 43 |
44 void ping(int pingValue) { | 44 void ping(int pingValue) { |
45 if (_pingPongClient != null) { | 45 if (_pingPongClient != null) { |
46 _pingPongClient.pong(pingValue + 1); | 46 _pingPongClient.pong(pingValue + 1); |
47 } | 47 } |
48 } | 48 } |
49 | 49 |
50 Future pingTargetUrl(String url, int count, | 50 void pingTargetUrl(String url, int count, void callback(bool ok)) { |
51 [Function responseFactory]) async { | |
52 if (_application == null) { | 51 if (_application == null) { |
53 return responseFactory(false); | 52 callback(false); |
| 53 return; |
54 } | 54 } |
55 var completer = new Completer(); | 55 var completer = new Completer(); |
56 var pingPongService = new PingPongServiceInterfaceRequest(); | 56 var pingPongService = new PingPongServiceInterfaceRequest(); |
57 _application.connectToService(url, pingPongService); | 57 _application.connectToService(url, pingPongService); |
58 | 58 |
59 var pingPongClient = new PingPongClientImpl(count, completer); | 59 var pingPongClient = new PingPongClientImpl(count, completer); |
60 pingPongService.setClient(pingPongClient.client); | 60 pingPongService.setClient(pingPongClient.client); |
61 | 61 |
62 for (var i = 0; i < count; i++) { | 62 for (var i = 0; i < count; i++) { |
63 pingPongService.ping(i); | 63 pingPongService.ping(i); |
64 } | 64 } |
65 await completer.future; | 65 completer.future.then((_) { |
66 await pingPongService.close(); | 66 callback(true); |
67 | 67 pingPongService.close(); |
68 return responseFactory(true); | 68 //await pingPongService.close(); |
| 69 //return responseFactory(true); |
| 70 }); |
69 } | 71 } |
70 | 72 |
71 Future pingTargetService(PingPongServiceInterface service, int count, | 73 void pingTargetService( |
72 [Function responseFactory]) async { | 74 PingPongServiceInterface service, int count, void callback(bool ok)) { |
73 var pingPongService = service; | 75 var pingPongService = service; |
74 var completer = new Completer(); | 76 var completer = new Completer(); |
75 var client = new PingPongClientImpl(count, completer); | 77 var client = new PingPongClientImpl(count, completer); |
76 pingPongService.setClient(client.client); | 78 pingPongService.setClient(client.client); |
77 | 79 |
78 for (var i = 0; i < count; i++) { | 80 for (var i = 0; i < count; i++) { |
79 pingPongService.ping(i); | 81 pingPongService.ping(i); |
80 } | 82 } |
81 await completer.future; | 83 completer.future.then((_) { |
82 await pingPongService.close(); | 84 callback(true); |
83 | 85 pingPongService.close(); |
84 return responseFactory(true); | 86 //await pingPongService.close(); |
| 87 //return responseFactory(true); |
| 88 }); |
85 } | 89 } |
86 | 90 |
87 getPingPongService(PingPongServiceInterfaceRequest service) { | 91 getPingPongService(PingPongServiceInterfaceRequest service) { |
88 var targetService = new PingPongServiceInterfaceRequest(); | 92 var targetService = new PingPongServiceInterfaceRequest(); |
89 _application.connectToService("mojo:dart_pingpong_target", targetService); | 93 _application.connectToService("mojo:dart_pingpong_target", targetService); |
90 | 94 |
91 // Pass along the interface request to another implementation of the | 95 // Pass along the interface request to another implementation of the |
92 // service. | 96 // service. |
93 targetService.getPingPongService(service); | 97 targetService.getPingPongService(service); |
94 targetService.close(); | 98 targetService.close(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 } | 130 } |
127 } | 131 } |
128 | 132 |
129 main(List args, Object handleToken) { | 133 main(List args, Object handleToken) { |
130 MojoHandle appHandle = new MojoHandle(handleToken); | 134 MojoHandle appHandle = new MojoHandle(handleToken); |
131 new PingPongApplication.fromHandle(appHandle) | 135 new PingPongApplication.fromHandle(appHandle) |
132 ..onError = ((_) { | 136 ..onError = ((_) { |
133 MojoHandle.reportLeakedHandles(); | 137 MojoHandle.reportLeakedHandles(); |
134 }); | 138 }); |
135 } | 139 } |
OLD | NEW |