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 library echo_mojom; | 5 library echo_mojom; |
6 import 'dart:async'; | 6 import 'dart:async'; |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 import 'dart:convert'; | 8 import 'dart:convert'; |
9 import 'dart:io'; | 9 import 'dart:io'; |
10 import 'dart:typed_data'; | 10 import 'dart:typed_data'; |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 | 172 |
173 dynamic getAllTypeDefinitions([Function responseFactory]) => | 173 dynamic getAllTypeDefinitions([Function responseFactory]) => |
174 responseFactory(getAllMojomTypeDefinitions()); | 174 responseFactory(getAllMojomTypeDefinitions()); |
175 } | 175 } |
176 | 176 |
177 abstract class Echo { | 177 abstract class Echo { |
178 static const String serviceName = "mojo::examples::Echo"; | 178 static const String serviceName = "mojo::examples::Echo"; |
179 dynamic echoString(String value,[Function responseFactory = null]); | 179 dynamic echoString(String value,[Function responseFactory = null]); |
180 } | 180 } |
181 | 181 |
182 | 182 class _EchoProxyControl |
183 class _EchoProxyControl extends bindings.ProxyMessageHandler | 183 extends bindings.ProxyMessageHandler |
184 implements bindings.ProxyControl { | 184 implements bindings.ProxyControl { |
185 _EchoProxyControl.fromEndpoint( | 185 _EchoProxyControl.fromEndpoint( |
186 core.MojoMessagePipeEndpoint endpoint) : super.fromEndpoint(endpoint); | 186 core.MojoMessagePipeEndpoint endpoint) : super.fromEndpoint(endpoint); |
187 | 187 |
188 _EchoProxyControl.fromHandle( | 188 _EchoProxyControl.fromHandle( |
189 core.MojoHandle handle) : super.fromHandle(handle); | 189 core.MojoHandle handle) : super.fromHandle(handle); |
190 | 190 |
191 _EchoProxyControl.unbound() : super.unbound(); | 191 _EchoProxyControl.unbound() : super.unbound(); |
192 | 192 |
193 service_describer.ServiceDescription get serviceDescription => | 193 service_describer.ServiceDescription get serviceDescription => |
194 new _EchoServiceDescription(); | 194 new _EchoServiceDescription(); |
195 | 195 |
196 String get serviceName => Echo.serviceName; | 196 String get serviceName => Echo.serviceName; |
197 | 197 |
198 @override | |
199 void handleResponse(bindings.ServiceMessage message) { | 198 void handleResponse(bindings.ServiceMessage message) { |
200 switch (message.header.type) { | 199 switch (message.header.type) { |
201 case _echoMethodEchoStringName: | 200 case _echoMethodEchoStringName: |
202 var r = EchoEchoStringResponseParams.deserialize( | 201 var r = EchoEchoStringResponseParams.deserialize( |
203 message.payload); | 202 message.payload); |
204 if (!message.header.hasRequestId) { | 203 if (!message.header.hasRequestId) { |
205 proxyError("Expected a message with a valid request Id."); | 204 proxyError("Expected a message with a valid request Id."); |
206 return; | 205 return; |
207 } | 206 } |
208 Completer c = completerMap[message.header.requestId]; | 207 Completer c = completerMap[message.header.requestId]; |
(...skipping 16 matching lines...) Expand all Loading... |
225 } | 224 } |
226 } | 225 } |
227 | 226 |
228 @override | 227 @override |
229 String toString() { | 228 String toString() { |
230 var superString = super.toString(); | 229 var superString = super.toString(); |
231 return "_EchoProxyControl($superString)"; | 230 return "_EchoProxyControl($superString)"; |
232 } | 231 } |
233 } | 232 } |
234 | 233 |
235 | 234 class EchoProxy |
236 class EchoProxy extends bindings.Proxy | 235 extends bindings.Proxy |
237 implements Echo { | 236 implements Echo { |
238 EchoProxy.fromEndpoint( | 237 EchoProxy.fromEndpoint( |
239 core.MojoMessagePipeEndpoint endpoint) | 238 core.MojoMessagePipeEndpoint endpoint) |
240 : super(new _EchoProxyControl.fromEndpoint(endpoint)); | 239 : super(new _EchoProxyControl.fromEndpoint(endpoint)); |
241 | 240 |
242 EchoProxy.fromHandle(core.MojoHandle handle) | 241 EchoProxy.fromHandle(core.MojoHandle handle) |
243 : super(new _EchoProxyControl.fromHandle(handle)); | 242 : super(new _EchoProxyControl.fromHandle(handle)); |
244 | 243 |
245 EchoProxy.unbound() | 244 EchoProxy.unbound() |
246 : super(new _EchoProxyControl.unbound()); | 245 : super(new _EchoProxyControl.unbound()); |
247 | 246 |
(...skipping 15 matching lines...) Expand all Loading... |
263 var params = new _EchoEchoStringParams(); | 262 var params = new _EchoEchoStringParams(); |
264 params.value = value; | 263 params.value = value; |
265 return ctrl.sendMessageWithRequestId( | 264 return ctrl.sendMessageWithRequestId( |
266 params, | 265 params, |
267 _echoMethodEchoStringName, | 266 _echoMethodEchoStringName, |
268 -1, | 267 -1, |
269 bindings.MessageHeader.kMessageExpectsResponse); | 268 bindings.MessageHeader.kMessageExpectsResponse); |
270 } | 269 } |
271 } | 270 } |
272 | 271 |
273 | 272 class _EchoStubControl |
274 class EchoStub extends bindings.Stub { | 273 extends bindings.StubMessageHandler |
| 274 implements bindings.StubControl<Echo> { |
275 Echo _impl; | 275 Echo _impl; |
276 | 276 |
277 EchoStub.fromEndpoint( | 277 _EchoStubControl.fromEndpoint( |
278 core.MojoMessagePipeEndpoint endpoint, [Echo impl]) | 278 core.MojoMessagePipeEndpoint endpoint, [Echo impl]) |
279 : super.fromEndpoint(endpoint, autoBegin: impl != null) { | 279 : super.fromEndpoint(endpoint, autoBegin: impl != null) { |
280 _impl = impl; | 280 _impl = impl; |
281 } | 281 } |
282 | 282 |
283 EchoStub.fromHandle( | 283 _EchoStubControl.fromHandle( |
284 core.MojoHandle handle, [Echo impl]) | 284 core.MojoHandle handle, [Echo impl]) |
285 : super.fromHandle(handle, autoBegin: impl != null) { | 285 : super.fromHandle(handle, autoBegin: impl != null) { |
286 _impl = impl; | 286 _impl = impl; |
287 } | 287 } |
288 | 288 |
289 EchoStub.unbound([this._impl]) : super.unbound(); | 289 _EchoStubControl.unbound([this._impl]) : super.unbound(); |
290 | |
291 static EchoStub newFromEndpoint( | |
292 core.MojoMessagePipeEndpoint endpoint) { | |
293 assert(endpoint.setDescription("For EchoStub")); | |
294 return new EchoStub.fromEndpoint(endpoint); | |
295 } | |
296 | 290 |
297 | 291 |
298 EchoEchoStringResponseParams _echoEchoStringResponseParamsFactory(String value
) { | 292 EchoEchoStringResponseParams _echoEchoStringResponseParamsFactory(String value
) { |
299 var result = new EchoEchoStringResponseParams(); | 293 var result = new EchoEchoStringResponseParams(); |
300 result.value = value; | 294 result.value = value; |
301 return result; | 295 return result; |
302 } | 296 } |
303 | 297 |
304 dynamic handleMessage(bindings.ServiceMessage message) { | 298 dynamic handleMessage(bindings.ServiceMessage message) { |
305 if (bindings.ControlMessageHandler.isControlMessage(message)) { | 299 if (bindings.ControlMessageHandler.isControlMessage(message)) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 } | 346 } |
353 | 347 |
354 @override | 348 @override |
355 void bind(core.MojoMessagePipeEndpoint endpoint) { | 349 void bind(core.MojoMessagePipeEndpoint endpoint) { |
356 super.bind(endpoint); | 350 super.bind(endpoint); |
357 if (!isOpen && (_impl != null)) { | 351 if (!isOpen && (_impl != null)) { |
358 beginHandlingEvents(); | 352 beginHandlingEvents(); |
359 } | 353 } |
360 } | 354 } |
361 | 355 |
| 356 @override |
362 String toString() { | 357 String toString() { |
363 var superString = super.toString(); | 358 var superString = super.toString(); |
364 return "EchoStub($superString)"; | 359 return "_EchoStubControl($superString)"; |
365 } | 360 } |
366 | 361 |
367 int get version => 0; | 362 int get version => 0; |
368 | 363 |
369 static service_describer.ServiceDescription _cachedServiceDescription; | 364 static service_describer.ServiceDescription _cachedServiceDescription; |
370 static service_describer.ServiceDescription get serviceDescription { | 365 static service_describer.ServiceDescription get serviceDescription { |
371 if (_cachedServiceDescription == null) { | 366 if (_cachedServiceDescription == null) { |
372 _cachedServiceDescription = new _EchoServiceDescription(); | 367 _cachedServiceDescription = new _EchoServiceDescription(); |
373 } | 368 } |
374 return _cachedServiceDescription; | 369 return _cachedServiceDescription; |
375 } | 370 } |
376 } | 371 } |
377 | 372 |
| 373 class EchoStub |
| 374 extends bindings.Stub<Echo> |
| 375 implements Echo { |
| 376 EchoStub.fromEndpoint( |
| 377 core.MojoMessagePipeEndpoint endpoint, [Echo impl]) |
| 378 : super(new _EchoStubControl.fromEndpoint(endpoint, impl)); |
| 379 |
| 380 EchoStub.fromHandle( |
| 381 core.MojoHandle handle, [Echo impl]) |
| 382 : super(new _EchoStubControl.fromHandle(handle, impl)); |
| 383 |
| 384 EchoStub.unbound([Echo impl]) |
| 385 : super(new _EchoStubControl.unbound(impl)); |
| 386 |
| 387 static EchoStub newFromEndpoint( |
| 388 core.MojoMessagePipeEndpoint endpoint) { |
| 389 assert(endpoint.setDescription("For EchoStub")); |
| 390 return new EchoStub.fromEndpoint(endpoint); |
| 391 } |
| 392 |
| 393 static service_describer.ServiceDescription get serviceDescription => |
| 394 _EchoStubControl.serviceDescription; |
| 395 |
| 396 |
| 397 dynamic echoString(String value,[Function responseFactory = null]) { |
| 398 return impl.echoString(value,responseFactory); |
| 399 } |
| 400 } |
| 401 |
378 | 402 |
379 mojom_types.RuntimeTypeInfo getRuntimeTypeInfo() => _runtimeTypeInfo ?? | 403 mojom_types.RuntimeTypeInfo getRuntimeTypeInfo() => _runtimeTypeInfo ?? |
380 _initRuntimeTypeInfo(); | 404 _initRuntimeTypeInfo(); |
381 | 405 |
382 Map<String, mojom_types.UserDefinedType> getAllMojomTypeDefinitions() { | 406 Map<String, mojom_types.UserDefinedType> getAllMojomTypeDefinitions() { |
383 return getRuntimeTypeInfo().typeMap; | 407 return getRuntimeTypeInfo().typeMap; |
384 } | 408 } |
385 | 409 |
386 var _runtimeTypeInfo; | 410 var _runtimeTypeInfo; |
387 mojom_types.RuntimeTypeInfo _initRuntimeTypeInfo() { | 411 mojom_types.RuntimeTypeInfo _initRuntimeTypeInfo() { |
388 // serializedRuntimeTypeInfo contains the bytes of the Mojo serialization of | 412 // serializedRuntimeTypeInfo contains the bytes of the Mojo serialization of |
389 // a mojom_types.RuntimeTypeInfo struct describing the Mojom types in this | 413 // a mojom_types.RuntimeTypeInfo struct describing the Mojom types in this |
390 // file. The string contains the base64 encoding of the gzip-compressed bytes. | 414 // file. The string contains the base64 encoding of the gzip-compressed bytes. |
391 var serializedRuntimeTypeInfo = "H4sIAAAJbogC/5JggAABKN0BpdHFLZD4jEDMAeXLALEIE
OfmZ+VbWaVWJOYW5KQWW1m5JmfkY1OvDMTSQBwSGeAa7+0aaQXSqAfTpwfThmG/Aw77STGPEaqfGUm/B
pRWgNIBjBA6A0ozoNkPC4cZUHoBlP4PBRsYsAN0dytgCWd2JHFhIOYG4uDUorLM5FS/xNxUosKbB4hZg
BjGlwJiIah6LMGCEc6cQMwFxC5AbAPE+qXFRfo5+cmJOfrp+fnpOan6Gfm5qfpVRYn6ICP1i4uS9WHG6
qcCjQUTeiC5XGLci24/jM8DDS9c4Ycebxeg9AMm7PEGAwZofFCcYROHASFoeIDcG1xSlJmXjj3cQGqYq
Bhu6OkD5r8bjMT7CwQscPgLli4Q/tItSi0sTS0uwe4/GKCW/9Dj0wFHOXODgThAbDxr4NDPC8SsQFyWm
FOaiiN+RansfwakNI4eHhJIbmNEUk/rdCENLXtQ0kVxQX5ecepousCRLjQGQboABAAA///YBJ9/yAcAA
A=="; | 415 var serializedRuntimeTypeInfo = "H4sIAAAJbogC/5JggAABKN0BpdHFLZD4jEDMAeXLALEIE
OfmZ+VbWaVWJOYW5KQWW1m5JmfkY1OvDMTSQBwSGeAa7+0aaQXSqAfTpwfThmG/Aw77STGPEaqfGUm/B
pRWgNIBjBA6A0ozoNkPC4cZUHoBlP4PBRsYsAN0dytgCWd2JHFhIOYG4uDUorLM5FS/xNxUosKbB4hZg
BjGlwJiIah6LMGCEc6cQMwFxC5AbAPE+qXFRfo5+cmJOfrp+fnpOan6Gfm5qfpVRYn6ICP1i4uS9WHG6
qcCjQUTeiC5XGLci24/jM8DDS9c4Ycebxeg9AMm7PEGAwZofFCcYROHASFoeIDcG1xSlJmXjj3cQGqYq
Bhu6OkD5r8bjMT7CwQscPgLli4Q/tItSi0sTS0uwe4/GKCW/9Dj0wFHOXODgThAbDxr4NDPC8SsQFyWm
FOaiiN+RansfwakNI4eHhJIbmNEUk/rdCENLXtQ0kVxQX5ecepousCRLjQGQboABAAA///YBJ9/yAcAA
A=="; |
392 | 416 |
393 // Deserialize RuntimeTypeInfo | 417 // Deserialize RuntimeTypeInfo |
394 var bytes = BASE64.decode(serializedRuntimeTypeInfo); | 418 var bytes = BASE64.decode(serializedRuntimeTypeInfo); |
395 var unzippedBytes = new ZLibDecoder().convert(bytes); | 419 var unzippedBytes = new ZLibDecoder().convert(bytes); |
396 var bdata = new ByteData.view(unzippedBytes.buffer); | 420 var bdata = new ByteData.view(unzippedBytes.buffer); |
397 var message = new bindings.Message(bdata, null, unzippedBytes.length, 0); | 421 var message = new bindings.Message(bdata, null, unzippedBytes.length, 0); |
398 _runtimeTypeInfo = mojom_types.RuntimeTypeInfo.deserialize(message); | 422 _runtimeTypeInfo = mojom_types.RuntimeTypeInfo.deserialize(message); |
399 return _runtimeTypeInfo; | 423 return _runtimeTypeInfo; |
400 } | 424 } |
OLD | NEW |