Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: mojo/dart/packages/mojo_services/lib/prediction/prediction.mojom.dart

Issue 2006093002: Dart: Futures -> Callbacks. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Move code from mojo_patch to proxy.dart Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 prediction_mojom; 5 library prediction_mojom;
6 import 'dart:async'; 6 import 'dart:async';
7 import 'package:mojo/bindings.dart' as bindings; 7 import 'package:mojo/bindings.dart' as bindings;
8 import 'package:mojo/core.dart' as core; 8 import 'package:mojo/core.dart' as core;
9 import 'package:mojo/mojo/bindings/types/service_describer.mojom.dart' as servic e_describer; 9 import 'package:mojo/mojo/bindings/types/service_describer.mojom.dart' as servic e_describer;
10 10
11 11
12 12
13 class PrevWordInfo extends bindings.Struct { 13 class PrevWordInfo extends bindings.Struct {
14 static const List<bindings.StructDataHeader> kVersions = const [ 14 static const List<bindings.StructDataHeader> kVersions = const [
15 const bindings.StructDataHeader(24, 0) 15 const bindings.StructDataHeader(24, 0)
16 ]; 16 ];
17 String word = null; 17 String word = null;
18 bool isBeginningOfSentence = false; 18 bool isBeginningOfSentence = false;
19 19
20 PrevWordInfo() : super(kVersions.last.size); 20 PrevWordInfo() : super(kVersions.last.size);
21 21
22 PrevWordInfo.init(
23 String this.word,
24 bool this.isBeginningOfSentence
25 ) : super(kVersions.last.size);
26
22 static PrevWordInfo deserialize(bindings.Message message) { 27 static PrevWordInfo deserialize(bindings.Message message) {
23 var decoder = new bindings.Decoder(message); 28 var decoder = new bindings.Decoder(message);
24 var result = decode(decoder); 29 var result = decode(decoder);
25 if (decoder.excessHandles != null) { 30 if (decoder.excessHandles != null) {
26 decoder.excessHandles.forEach((h) => h.close()); 31 decoder.excessHandles.forEach((h) => h.close());
27 } 32 }
28 return result; 33 return result;
29 } 34 }
30 35
31 static PrevWordInfo decode(bindings.Decoder decoder0) { 36 static PrevWordInfo decode(bindings.Decoder decoder0) {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 103
99 class PredictionInfo extends bindings.Struct { 104 class PredictionInfo extends bindings.Struct {
100 static const List<bindings.StructDataHeader> kVersions = const [ 105 static const List<bindings.StructDataHeader> kVersions = const [
101 const bindings.StructDataHeader(24, 0) 106 const bindings.StructDataHeader(24, 0)
102 ]; 107 ];
103 List<PrevWordInfo> previousWords = null; 108 List<PrevWordInfo> previousWords = null;
104 String currentWord = null; 109 String currentWord = null;
105 110
106 PredictionInfo() : super(kVersions.last.size); 111 PredictionInfo() : super(kVersions.last.size);
107 112
113 PredictionInfo.init(
114 List<PrevWordInfo> this.previousWords,
115 String this.currentWord
116 ) : super(kVersions.last.size);
117
108 static PredictionInfo deserialize(bindings.Message message) { 118 static PredictionInfo deserialize(bindings.Message message) {
109 var decoder = new bindings.Decoder(message); 119 var decoder = new bindings.Decoder(message);
110 var result = decode(decoder); 120 var result = decode(decoder);
111 if (decoder.excessHandles != null) { 121 if (decoder.excessHandles != null) {
112 decoder.excessHandles.forEach((h) => h.close()); 122 decoder.excessHandles.forEach((h) => h.close());
113 } 123 }
114 return result; 124 return result;
115 } 125 }
116 126
117 static PredictionInfo decode(bindings.Decoder decoder0) { 127 static PredictionInfo decode(bindings.Decoder decoder0) {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 209
200 210
201 class _PredictionServiceGetPredictionListParams extends bindings.Struct { 211 class _PredictionServiceGetPredictionListParams extends bindings.Struct {
202 static const List<bindings.StructDataHeader> kVersions = const [ 212 static const List<bindings.StructDataHeader> kVersions = const [
203 const bindings.StructDataHeader(16, 0) 213 const bindings.StructDataHeader(16, 0)
204 ]; 214 ];
205 PredictionInfo predictionInfo = null; 215 PredictionInfo predictionInfo = null;
206 216
207 _PredictionServiceGetPredictionListParams() : super(kVersions.last.size); 217 _PredictionServiceGetPredictionListParams() : super(kVersions.last.size);
208 218
219 _PredictionServiceGetPredictionListParams.init(
220 PredictionInfo this.predictionInfo
221 ) : super(kVersions.last.size);
222
209 static _PredictionServiceGetPredictionListParams deserialize(bindings.Message message) { 223 static _PredictionServiceGetPredictionListParams deserialize(bindings.Message message) {
210 var decoder = new bindings.Decoder(message); 224 var decoder = new bindings.Decoder(message);
211 var result = decode(decoder); 225 var result = decode(decoder);
212 if (decoder.excessHandles != null) { 226 if (decoder.excessHandles != null) {
213 decoder.excessHandles.forEach((h) => h.close()); 227 decoder.excessHandles.forEach((h) => h.close());
214 } 228 }
215 return result; 229 return result;
216 } 230 }
217 231
218 static _PredictionServiceGetPredictionListParams decode(bindings.Decoder decod er0) { 232 static _PredictionServiceGetPredictionListParams decode(bindings.Decoder decod er0) {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 286
273 287
274 class PredictionServiceGetPredictionListResponseParams extends bindings.Struct { 288 class PredictionServiceGetPredictionListResponseParams extends bindings.Struct {
275 static const List<bindings.StructDataHeader> kVersions = const [ 289 static const List<bindings.StructDataHeader> kVersions = const [
276 const bindings.StructDataHeader(16, 0) 290 const bindings.StructDataHeader(16, 0)
277 ]; 291 ];
278 List<String> predictionList = null; 292 List<String> predictionList = null;
279 293
280 PredictionServiceGetPredictionListResponseParams() : super(kVersions.last.size ); 294 PredictionServiceGetPredictionListResponseParams() : super(kVersions.last.size );
281 295
296 PredictionServiceGetPredictionListResponseParams.init(
297 List<String> this.predictionList
298 ) : super(kVersions.last.size);
299
282 static PredictionServiceGetPredictionListResponseParams deserialize(bindings.M essage message) { 300 static PredictionServiceGetPredictionListResponseParams deserialize(bindings.M essage message) {
283 var decoder = new bindings.Decoder(message); 301 var decoder = new bindings.Decoder(message);
284 var result = decode(decoder); 302 var result = decode(decoder);
285 if (decoder.excessHandles != null) { 303 if (decoder.excessHandles != null) {
286 decoder.excessHandles.forEach((h) => h.close()); 304 decoder.excessHandles.forEach((h) => h.close());
287 } 305 }
288 return result; 306 return result;
289 } 307 }
290 308
291 static PredictionServiceGetPredictionListResponseParams decode(bindings.Decode r decoder0) { 309 static PredictionServiceGetPredictionListResponseParams decode(bindings.Decode r decoder0) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 Map toJson() { 373 Map toJson() {
356 Map map = new Map(); 374 Map map = new Map();
357 map["predictionList"] = predictionList; 375 map["predictionList"] = predictionList;
358 return map; 376 return map;
359 } 377 }
360 } 378 }
361 379
362 const int _predictionServiceMethodGetPredictionListName = 0; 380 const int _predictionServiceMethodGetPredictionListName = 0;
363 381
364 class _PredictionServiceServiceDescription implements service_describer.ServiceD escription { 382 class _PredictionServiceServiceDescription implements service_describer.ServiceD escription {
365 dynamic getTopLevelInterface([Function responseFactory]) => 383 void getTopLevelInterface(Function responder) {
366 responseFactory(null); 384 responder(null);
385 }
367 386
368 dynamic getTypeDefinition(String typeKey, [Function responseFactory]) => 387 void getTypeDefinition(String typeKey, Function responder) {
369 responseFactory(null); 388 responder(null);
389 }
370 390
371 dynamic getAllTypeDefinitions([Function responseFactory]) => 391 void getAllTypeDefinitions(Function responder) {
372 responseFactory(null); 392 responder(null);
393 }
373 } 394 }
374 395
375 abstract class PredictionService { 396 abstract class PredictionService {
376 static const String serviceName = "prediction::PredictionService"; 397 static const String serviceName = "prediction::PredictionService";
377 398
378 static service_describer.ServiceDescription _cachedServiceDescription; 399 static service_describer.ServiceDescription _cachedServiceDescription;
379 static service_describer.ServiceDescription get serviceDescription { 400 static service_describer.ServiceDescription get serviceDescription {
380 if (_cachedServiceDescription == null) { 401 if (_cachedServiceDescription == null) {
381 _cachedServiceDescription = new _PredictionServiceServiceDescription(); 402 _cachedServiceDescription = new _PredictionServiceServiceDescription();
382 } 403 }
383 return _cachedServiceDescription; 404 return _cachedServiceDescription;
384 } 405 }
385 406
386 static PredictionServiceProxy connectToService( 407 static PredictionServiceProxy connectToService(
387 bindings.ServiceConnector s, String url, [String serviceName]) { 408 bindings.ServiceConnector s, String url, [String serviceName]) {
388 PredictionServiceProxy p = new PredictionServiceProxy.unbound(); 409 PredictionServiceProxy p = new PredictionServiceProxy.unbound();
389 String name = serviceName ?? PredictionService.serviceName; 410 String name = serviceName ?? PredictionService.serviceName;
390 if ((name == null) || name.isEmpty) { 411 if ((name == null) || name.isEmpty) {
391 throw new core.MojoApiError( 412 throw new core.MojoApiError(
392 "If an interface has no ServiceName, then one must be provided."); 413 "If an interface has no ServiceName, then one must be provided.");
393 } 414 }
394 s.connectToService(url, p, name); 415 s.connectToService(url, p, name);
395 return p; 416 return p;
396 } 417 }
397 dynamic getPredictionList(PredictionInfo predictionInfo,[Function responseFact ory = null]); 418 void getPredictionList(PredictionInfo predictionInfo,void callback(List<String > predictionList));
398 } 419 }
399 420
400 abstract class PredictionServiceInterface 421 abstract class PredictionServiceInterface
401 implements bindings.MojoInterface<PredictionService>, 422 implements bindings.MojoInterface<PredictionService>,
402 PredictionService { 423 PredictionService {
403 factory PredictionServiceInterface([PredictionService impl]) => 424 factory PredictionServiceInterface([PredictionService impl]) =>
404 new PredictionServiceStub.unbound(impl); 425 new PredictionServiceStub.unbound(impl);
405 factory PredictionServiceInterface.fromEndpoint( 426 factory PredictionServiceInterface.fromEndpoint(
406 core.MojoMessagePipeEndpoint endpoint, 427 core.MojoMessagePipeEndpoint endpoint,
407 [PredictionService impl]) => 428 [PredictionService impl]) =>
(...skipping 22 matching lines...) Expand all
430 451
431 void handleResponse(bindings.ServiceMessage message) { 452 void handleResponse(bindings.ServiceMessage message) {
432 switch (message.header.type) { 453 switch (message.header.type) {
433 case _predictionServiceMethodGetPredictionListName: 454 case _predictionServiceMethodGetPredictionListName:
434 var r = PredictionServiceGetPredictionListResponseParams.deserialize( 455 var r = PredictionServiceGetPredictionListResponseParams.deserialize(
435 message.payload); 456 message.payload);
436 if (!message.header.hasRequestId) { 457 if (!message.header.hasRequestId) {
437 proxyError("Expected a message with a valid request Id."); 458 proxyError("Expected a message with a valid request Id.");
438 return; 459 return;
439 } 460 }
440 Completer c = completerMap[message.header.requestId]; 461 Function callback = callbackMap[message.header.requestId];
441 if (c == null) { 462 if (callback == null) {
442 proxyError( 463 proxyError(
443 "Message had unknown request Id: ${message.header.requestId}"); 464 "Message had unknown request Id: ${message.header.requestId}");
444 return; 465 return;
445 } 466 }
446 completerMap.remove(message.header.requestId); 467 callbackMap.remove(message.header.requestId);
447 if (c.isCompleted) { 468 callback(r.predictionList );
448 proxyError("Response completer already completed");
449 return;
450 }
451 c.complete(r);
452 break; 469 break;
453 default: 470 default:
454 proxyError("Unexpected message type: ${message.header.type}"); 471 proxyError("Unexpected message type: ${message.header.type}");
455 close(immediate: true); 472 close(immediate: true);
456 break; 473 break;
457 } 474 }
458 } 475 }
459 476
460 PredictionService get impl => null; 477 PredictionService get impl => null;
461 set impl(PredictionService _) { 478 set impl(PredictionService _) {
(...skipping 22 matching lines...) Expand all
484 PredictionServiceProxy.unbound() 501 PredictionServiceProxy.unbound()
485 : super(new _PredictionServiceProxyControl.unbound()); 502 : super(new _PredictionServiceProxyControl.unbound());
486 503
487 static PredictionServiceProxy newFromEndpoint( 504 static PredictionServiceProxy newFromEndpoint(
488 core.MojoMessagePipeEndpoint endpoint) { 505 core.MojoMessagePipeEndpoint endpoint) {
489 assert(endpoint.setDescription("For PredictionServiceProxy")); 506 assert(endpoint.setDescription("For PredictionServiceProxy"));
490 return new PredictionServiceProxy.fromEndpoint(endpoint); 507 return new PredictionServiceProxy.fromEndpoint(endpoint);
491 } 508 }
492 509
493 510
494 dynamic getPredictionList(PredictionInfo predictionInfo,[Function responseFact ory = null]) { 511 void getPredictionList(PredictionInfo predictionInfo,void callback(List<String > predictionList)) {
495 var params = new _PredictionServiceGetPredictionListParams(); 512 var params = new _PredictionServiceGetPredictionListParams();
496 params.predictionInfo = predictionInfo; 513 params.predictionInfo = predictionInfo;
497 return ctrl.sendMessageWithRequestId( 514 ctrl.sendMessageWithRequestId(
498 params, 515 params,
499 _predictionServiceMethodGetPredictionListName, 516 _predictionServiceMethodGetPredictionListName,
500 -1, 517 -1,
501 bindings.MessageHeader.kMessageExpectsResponse); 518 bindings.MessageHeader.kMessageExpectsResponse,
519 callback);
502 } 520 }
503 } 521 }
504 522
505 class _PredictionServiceStubControl 523 class _PredictionServiceStubControl
506 extends bindings.StubMessageHandler 524 extends bindings.StubMessageHandler
507 implements bindings.StubControl<PredictionService> { 525 implements bindings.StubControl<PredictionService> {
508 PredictionService _impl; 526 PredictionService _impl;
509 527
510 _PredictionServiceStubControl.fromEndpoint( 528 _PredictionServiceStubControl.fromEndpoint(
511 core.MojoMessagePipeEndpoint endpoint, [PredictionService impl]) 529 core.MojoMessagePipeEndpoint endpoint, [PredictionService impl])
512 : super.fromEndpoint(endpoint, autoBegin: impl != null) { 530 : super.fromEndpoint(endpoint, autoBegin: impl != null) {
513 _impl = impl; 531 _impl = impl;
514 } 532 }
515 533
516 _PredictionServiceStubControl.fromHandle( 534 _PredictionServiceStubControl.fromHandle(
517 core.MojoHandle handle, [PredictionService impl]) 535 core.MojoHandle handle, [PredictionService impl])
518 : super.fromHandle(handle, autoBegin: impl != null) { 536 : super.fromHandle(handle, autoBegin: impl != null) {
519 _impl = impl; 537 _impl = impl;
520 } 538 }
521 539
522 _PredictionServiceStubControl.unbound([this._impl]) : super.unbound(); 540 _PredictionServiceStubControl.unbound([this._impl]) : super.unbound();
523 541
524 String get serviceName => PredictionService.serviceName; 542 String get serviceName => PredictionService.serviceName;
525 543
526 544
527 PredictionServiceGetPredictionListResponseParams _predictionServiceGetPredicti onListResponseParamsFactory(List<String> predictionList) { 545 Function _predictionServiceGetPredictionListResponseParamsResponder(
528 var result = new PredictionServiceGetPredictionListResponseParams(); 546 int requestId) {
529 result.predictionList = predictionList; 547 return (List<String> predictionList) {
530 return result; 548 var result = new PredictionServiceGetPredictionListResponseParams();
549 result.predictionList = predictionList;
550 sendResponse(buildResponseWithId(
551 result,
552 _predictionServiceMethodGetPredictionListName,
553 requestId,
554 bindings.MessageHeader.kMessageIsResponse));
555 };
531 } 556 }
532 557
533 dynamic handleMessage(bindings.ServiceMessage message) { 558 void handleMessage(bindings.ServiceMessage message) {
534 if (bindings.ControlMessageHandler.isControlMessage(message)) { 559 if (bindings.ControlMessageHandler.isControlMessage(message)) {
535 return bindings.ControlMessageHandler.handleMessage(this, 560 bindings.ControlMessageHandler.handleMessage(
536 0, 561 this, 0, message);
537 message); 562 return;
538 } 563 }
539 if (_impl == null) { 564 if (_impl == null) {
540 throw new core.MojoApiError("$this has no implementation set"); 565 throw new core.MojoApiError("$this has no implementation set");
541 } 566 }
542 switch (message.header.type) { 567 switch (message.header.type) {
543 case _predictionServiceMethodGetPredictionListName: 568 case _predictionServiceMethodGetPredictionListName:
544 var params = _PredictionServiceGetPredictionListParams.deserialize( 569 var params = _PredictionServiceGetPredictionListParams.deserialize(
545 message.payload); 570 message.payload);
546 var response = _impl.getPredictionList(params.predictionInfo,_prediction ServiceGetPredictionListResponseParamsFactory); 571 _impl.getPredictionList(params.predictionInfo, _predictionServiceGetPred ictionListResponseParamsResponder(message.header.requestId));
547 if (response is Future) {
548 return response.then((response) {
549 if (response != null) {
550 return buildResponseWithId(
551 response,
552 _predictionServiceMethodGetPredictionListName,
553 message.header.requestId,
554 bindings.MessageHeader.kMessageIsResponse);
555 }
556 });
557 } else if (response != null) {
558 return buildResponseWithId(
559 response,
560 _predictionServiceMethodGetPredictionListName,
561 message.header.requestId,
562 bindings.MessageHeader.kMessageIsResponse);
563 }
564 break; 572 break;
565 default: 573 default:
566 throw new bindings.MojoCodecError("Unexpected message name"); 574 throw new bindings.MojoCodecError("Unexpected message name");
567 break; 575 break;
568 } 576 }
569 return null;
570 } 577 }
571 578
572 PredictionService get impl => _impl; 579 PredictionService get impl => _impl;
573 set impl(PredictionService d) { 580 set impl(PredictionService d) {
574 if (d == null) { 581 if (d == null) {
575 throw new core.MojoApiError("$this: Cannot set a null implementation"); 582 throw new core.MojoApiError("$this: Cannot set a null implementation");
576 } 583 }
577 if (isBound && (_impl == null)) { 584 if (isBound && (_impl == null)) {
578 beginHandlingEvents(); 585 beginHandlingEvents();
579 } 586 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 core.MojoHandle handle, [PredictionService impl]) 620 core.MojoHandle handle, [PredictionService impl])
614 : super(new _PredictionServiceStubControl.fromHandle(handle, impl)); 621 : super(new _PredictionServiceStubControl.fromHandle(handle, impl));
615 622
616 static PredictionServiceStub newFromEndpoint( 623 static PredictionServiceStub newFromEndpoint(
617 core.MojoMessagePipeEndpoint endpoint) { 624 core.MojoMessagePipeEndpoint endpoint) {
618 assert(endpoint.setDescription("For PredictionServiceStub")); 625 assert(endpoint.setDescription("For PredictionServiceStub"));
619 return new PredictionServiceStub.fromEndpoint(endpoint); 626 return new PredictionServiceStub.fromEndpoint(endpoint);
620 } 627 }
621 628
622 629
623 dynamic getPredictionList(PredictionInfo predictionInfo,[Function responseFact ory = null]) { 630 void getPredictionList(PredictionInfo predictionInfo,void callback(List<String > predictionList)) {
624 return impl.getPredictionList(predictionInfo,responseFactory); 631 return impl.getPredictionList(predictionInfo,callback);
625 } 632 }
626 } 633 }
627 634
628 635
629 636
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698