OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 part of bindings; | 5 part of bindings; |
6 | 6 |
7 /// The object that [ProxyMessageHandler.errorFuture] completes with when there | 7 /// The object that [ProxyMessageHandler.errorFuture] completes with when there |
8 /// is an error. | 8 /// is an error. |
9 class ProxyError { | 9 class ProxyError { |
10 final String message; | 10 final String message; |
(...skipping 26 matching lines...) Expand all Loading... |
37 | 37 |
38 /// This is a convenience method that simply forwards to | 38 /// This is a convenience method that simply forwards to |
39 /// ctrl.responseOrError(). If a Mojo interface has a method | 39 /// ctrl.responseOrError(). If a Mojo interface has a method |
40 /// 'responseOrError', its name will be mangled to be 'responseOrError_'. | 40 /// 'responseOrError', its name will be mangled to be 'responseOrError_'. |
41 Future responseOrError(Future f) => ctrl.responseOrError(f); | 41 Future responseOrError(Future f) => ctrl.responseOrError(f); |
42 } | 42 } |
43 | 43 |
44 /// Generated Proxy classes have a factory Proxy.connectToService which takes | 44 /// Generated Proxy classes have a factory Proxy.connectToService which takes |
45 /// a ServiceConnector, a url, and optionally a service name and returns a | 45 /// a ServiceConnector, a url, and optionally a service name and returns a |
46 /// bound Proxy. For example, every class extending the Application base class | 46 /// bound Proxy. For example, every class extending the Application base class |
47 /// in package:mojo/application.dart inherits and implementation of the | 47 /// in package:mojo/application.dart inherits an implementation of the |
48 /// ServiceConnector interface. | 48 /// ServiceConnector interface. |
49 abstract class ServiceConnector { | 49 abstract class ServiceConnector { |
50 /// Connects [proxy] to the service called [serviceName] that lives at [url]. | 50 /// Connects [proxy] to the service called [serviceName] that lives at [url]. |
51 void connectToService(String url, Proxy proxy, [String serviceName]); | 51 void connectToService(String url, Proxy proxy, [String serviceName]); |
52 } | 52 } |
53 | 53 |
54 class ProxyMessageHandler extends core.MojoEventHandler { | 54 abstract class ProxyMessageHandler extends core.MojoEventHandler { |
55 HashMap<int, Completer> _completerMap = new HashMap<int, Completer>(); | 55 HashMap<int, Completer> _completerMap = new HashMap<int, Completer>(); |
56 Completer _errorCompleter = new Completer(); | 56 Completer _errorCompleter = new Completer(); |
57 Set<Completer> _errorCompleters; | 57 Set<Completer> _errorCompleters; |
58 int _nextId = 0; | 58 int _nextId = 0; |
59 int _version = 0; | 59 int _version = 0; |
60 int _pendingCount = 0; | 60 int _pendingCount = 0; |
61 | 61 |
62 ProxyMessageHandler.fromEndpoint(core.MojoMessagePipeEndpoint endpoint) | 62 ProxyMessageHandler.fromEndpoint(core.MojoMessagePipeEndpoint endpoint) |
63 : super.fromEndpoint(endpoint); | 63 : super.fromEndpoint(endpoint); |
64 | 64 |
65 ProxyMessageHandler.fromHandle(core.MojoHandle handle) | 65 ProxyMessageHandler.fromHandle(core.MojoHandle handle) |
66 : super.fromHandle(handle); | 66 : super.fromHandle(handle); |
67 | 67 |
68 ProxyMessageHandler.unbound() : super.unbound(); | 68 ProxyMessageHandler.unbound() : super.unbound(); |
69 | 69 |
70 /// The function that handles responses to sent proxy message. It should be | 70 /// The function that handles responses to sent proxy message. It should be |
71 /// implemented by the generated ProxyControl classes that extend | 71 /// implemented by the generated ProxyControl classes that extend |
72 /// [ProxyMessageHandler]. | 72 /// [ProxyMessageHandler]. |
73 void handleResponse(ServiceMessage msg) {} | 73 void handleResponse(ServiceMessage msg); |
74 | 74 |
75 /// If there is an error in using this proxy, this future completes with | 75 /// If there is an error in using this proxy, this future completes with |
76 /// a ProxyError. | 76 /// a ProxyError. |
77 Future get errorFuture => _errorCompleter.future; | 77 Future get errorFuture => _errorCompleter.future; |
78 | 78 |
79 /// Version of this interface that the remote side supports. Updated when a | 79 /// Version of this interface that the remote side supports. Updated when a |
80 /// call to [queryVersion] or [requireVersion] is made. | 80 /// call to [queryVersion] or [requireVersion] is made. |
81 int get version => _version; | 81 int get version => _version; |
82 | 82 |
83 /// Returns a service description, which exposes the mojom type information | 83 /// Returns a service description, which exposes the mojom type information |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 _pendingCount++; | 166 _pendingCount++; |
167 } else { | 167 } else { |
168 proxyError("Write to message pipe endpoint failed: ${endpoint}"); | 168 proxyError("Write to message pipe endpoint failed: ${endpoint}"); |
169 } | 169 } |
170 return completer.future; | 170 return completer.future; |
171 } | 171 } |
172 | 172 |
173 // Need a getter for this for access in subclasses. | 173 // Need a getter for this for access in subclasses. |
174 HashMap<int, Completer> get completerMap => _completerMap; | 174 HashMap<int, Completer> get completerMap => _completerMap; |
175 | 175 |
| 176 @override |
176 String toString() { | 177 String toString() { |
177 var superString = super.toString(); | 178 var superString = super.toString(); |
178 return "ProxyMessageHandler(${superString})"; | 179 return "ProxyMessageHandler(${superString})"; |
179 } | 180 } |
180 | 181 |
181 /// Queries the max version that the remote side supports. | 182 /// Queries the max version that the remote side supports. |
182 /// Updates [version]. | 183 /// Updates [version]. |
183 Future<int> queryVersion() async { | 184 Future<int> queryVersion() async { |
184 var params = new icm.RunMessageParams(); | 185 var params = new icm.RunMessageParams(); |
185 params.reserved0 = 16; | 186 params.reserved0 = 16; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 return; | 282 return; |
282 } | 283 } |
283 completerMap.remove(message.header.requestId); | 284 completerMap.remove(message.header.requestId); |
284 if (c.isCompleted) { | 285 if (c.isCompleted) { |
285 proxyError("Control message response completer already completed"); | 286 proxyError("Control message response completer already completed"); |
286 return; | 287 return; |
287 } | 288 } |
288 c.complete(response); | 289 c.complete(response); |
289 } | 290 } |
290 } | 291 } |
OLD | NEW |