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

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: Cleanup Created 4 years, 6 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 426
406 factory PredictionServiceInterface.fromEndpoint( 427 factory PredictionServiceInterface.fromEndpoint(
407 core.MojoMessagePipeEndpoint endpoint, 428 core.MojoMessagePipeEndpoint endpoint,
(...skipping 29 matching lines...) Expand all
437 458
438 void handleResponse(bindings.ServiceMessage message) { 459 void handleResponse(bindings.ServiceMessage message) {
439 switch (message.header.type) { 460 switch (message.header.type) {
440 case _predictionServiceMethodGetPredictionListName: 461 case _predictionServiceMethodGetPredictionListName:
441 var r = PredictionServiceGetPredictionListResponseParams.deserialize( 462 var r = PredictionServiceGetPredictionListResponseParams.deserialize(
442 message.payload); 463 message.payload);
443 if (!message.header.hasRequestId) { 464 if (!message.header.hasRequestId) {
444 proxyError("Expected a message with a valid request Id."); 465 proxyError("Expected a message with a valid request Id.");
445 return; 466 return;
446 } 467 }
447 Completer c = completerMap[message.header.requestId]; 468 Function callback = callbackMap[message.header.requestId];
448 if (c == null) { 469 if (callback == null) {
449 proxyError( 470 proxyError(
450 "Message had unknown request Id: ${message.header.requestId}"); 471 "Message had unknown request Id: ${message.header.requestId}");
451 return; 472 return;
452 } 473 }
453 completerMap.remove(message.header.requestId); 474 callbackMap.remove(message.header.requestId);
454 if (c.isCompleted) { 475 callback(r.predictionList );
455 proxyError("Response completer already completed");
456 return;
457 }
458 c.complete(r);
459 break; 476 break;
460 default: 477 default:
461 proxyError("Unexpected message type: ${message.header.type}"); 478 proxyError("Unexpected message type: ${message.header.type}");
462 close(immediate: true); 479 close(immediate: true);
463 break; 480 break;
464 } 481 }
465 } 482 }
466 483
467 @override 484 @override
468 String toString() { 485 String toString() {
(...skipping 24 matching lines...) Expand all
493 return newMockedProxy; 510 return newMockedProxy;
494 } 511 }
495 512
496 static PredictionServiceProxy newFromEndpoint( 513 static PredictionServiceProxy newFromEndpoint(
497 core.MojoMessagePipeEndpoint endpoint) { 514 core.MojoMessagePipeEndpoint endpoint) {
498 assert(endpoint.setDescription("For PredictionServiceProxy")); 515 assert(endpoint.setDescription("For PredictionServiceProxy"));
499 return new PredictionServiceProxy.fromEndpoint(endpoint); 516 return new PredictionServiceProxy.fromEndpoint(endpoint);
500 } 517 }
501 518
502 519
503 dynamic getPredictionList(PredictionInfo predictionInfo,[Function responseFact ory = null]) { 520 void getPredictionList(PredictionInfo predictionInfo,void callback(List<String > predictionList)) {
504 if (impl != null) { 521 if (impl != null) {
505 return new Future(() => impl.getPredictionList(predictionInfo,_PredictionS erviceStubControl._predictionServiceGetPredictionListResponseParamsFactory)); 522 impl.getPredictionList(predictionInfo,callback);
523 return;
506 } 524 }
507 var params = new _PredictionServiceGetPredictionListParams(); 525 var params = new _PredictionServiceGetPredictionListParams();
508 params.predictionInfo = predictionInfo; 526 params.predictionInfo = predictionInfo;
509 return ctrl.sendMessageWithRequestId( 527 ctrl.sendMessageWithRequestId(
510 params, 528 params,
511 _predictionServiceMethodGetPredictionListName, 529 _predictionServiceMethodGetPredictionListName,
512 -1, 530 -1,
513 bindings.MessageHeader.kMessageExpectsResponse); 531 bindings.MessageHeader.kMessageExpectsResponse,
532 callback);
514 } 533 }
515 } 534 }
516 535
517 class _PredictionServiceStubControl 536 class _PredictionServiceStubControl
518 extends bindings.StubMessageHandler 537 extends bindings.StubMessageHandler
519 implements bindings.StubControl<PredictionService> { 538 implements bindings.StubControl<PredictionService> {
520 PredictionService _impl; 539 PredictionService _impl;
521 540
522 _PredictionServiceStubControl.fromEndpoint( 541 _PredictionServiceStubControl.fromEndpoint(
523 core.MojoMessagePipeEndpoint endpoint, [PredictionService impl]) 542 core.MojoMessagePipeEndpoint endpoint, [PredictionService impl])
524 : super.fromEndpoint(endpoint, autoBegin: impl != null) { 543 : super.fromEndpoint(endpoint, autoBegin: impl != null) {
525 _impl = impl; 544 _impl = impl;
526 } 545 }
527 546
528 _PredictionServiceStubControl.fromHandle( 547 _PredictionServiceStubControl.fromHandle(
529 core.MojoHandle handle, [PredictionService impl]) 548 core.MojoHandle handle, [PredictionService impl])
530 : super.fromHandle(handle, autoBegin: impl != null) { 549 : super.fromHandle(handle, autoBegin: impl != null) {
531 _impl = impl; 550 _impl = impl;
532 } 551 }
533 552
534 _PredictionServiceStubControl.unbound([this._impl]) : super.unbound(); 553 _PredictionServiceStubControl.unbound([this._impl]) : super.unbound();
535 554
536 String get serviceName => PredictionService.serviceName; 555 String get serviceName => PredictionService.serviceName;
537 556
538 557
539 static PredictionServiceGetPredictionListResponseParams _predictionServiceGetP redictionListResponseParamsFactory(List<String> predictionList) { 558 Function _predictionServiceGetPredictionListResponseParamsResponder(
540 var result = new PredictionServiceGetPredictionListResponseParams(); 559 int requestId) {
541 result.predictionList = predictionList; 560 return (List<String> predictionList) {
542 return result; 561 var result = new PredictionServiceGetPredictionListResponseParams();
562 result.predictionList = predictionList;
563 sendResponse(buildResponseWithId(
564 result,
565 _predictionServiceMethodGetPredictionListName,
566 requestId,
567 bindings.MessageHeader.kMessageIsResponse));
568 };
543 } 569 }
544 570
545 dynamic handleMessage(bindings.ServiceMessage message) { 571 void handleMessage(bindings.ServiceMessage message) {
546 if (bindings.ControlMessageHandler.isControlMessage(message)) { 572 if (bindings.ControlMessageHandler.isControlMessage(message)) {
547 return bindings.ControlMessageHandler.handleMessage(this, 573 bindings.ControlMessageHandler.handleMessage(
548 0, 574 this, 0, message);
549 message); 575 return;
550 } 576 }
551 if (_impl == null) { 577 if (_impl == null) {
552 throw new core.MojoApiError("$this has no implementation set"); 578 throw new core.MojoApiError("$this has no implementation set");
553 } 579 }
554 switch (message.header.type) { 580 switch (message.header.type) {
555 case _predictionServiceMethodGetPredictionListName: 581 case _predictionServiceMethodGetPredictionListName:
556 var params = _PredictionServiceGetPredictionListParams.deserialize( 582 var params = _PredictionServiceGetPredictionListParams.deserialize(
557 message.payload); 583 message.payload);
558 var response = _impl.getPredictionList(params.predictionInfo,_prediction ServiceGetPredictionListResponseParamsFactory); 584 _impl.getPredictionList(params.predictionInfo, _predictionServiceGetPred ictionListResponseParamsResponder(message.header.requestId));
559 if (response is Future) {
560 return response.then((response) {
561 if (response != null) {
562 return buildResponseWithId(
563 response,
564 _predictionServiceMethodGetPredictionListName,
565 message.header.requestId,
566 bindings.MessageHeader.kMessageIsResponse);
567 }
568 });
569 } else if (response != null) {
570 return buildResponseWithId(
571 response,
572 _predictionServiceMethodGetPredictionListName,
573 message.header.requestId,
574 bindings.MessageHeader.kMessageIsResponse);
575 }
576 break; 585 break;
577 default: 586 default:
578 throw new bindings.MojoCodecError("Unexpected message name"); 587 throw new bindings.MojoCodecError("Unexpected message name");
579 break; 588 break;
580 } 589 }
581 return null;
582 } 590 }
583 591
584 PredictionService get impl => _impl; 592 PredictionService get impl => _impl;
585 set impl(PredictionService d) { 593 set impl(PredictionService d) {
586 if (d == null) { 594 if (d == null) {
587 throw new core.MojoApiError("$this: Cannot set a null implementation"); 595 throw new core.MojoApiError("$this: Cannot set a null implementation");
588 } 596 }
589 if (isBound && (_impl == null)) { 597 if (isBound && (_impl == null)) {
590 beginHandlingEvents(); 598 beginHandlingEvents();
591 } 599 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 core.MojoHandle handle, [PredictionService impl]) 633 core.MojoHandle handle, [PredictionService impl])
626 : super(new _PredictionServiceStubControl.fromHandle(handle, impl)); 634 : super(new _PredictionServiceStubControl.fromHandle(handle, impl));
627 635
628 static PredictionServiceStub newFromEndpoint( 636 static PredictionServiceStub newFromEndpoint(
629 core.MojoMessagePipeEndpoint endpoint) { 637 core.MojoMessagePipeEndpoint endpoint) {
630 assert(endpoint.setDescription("For PredictionServiceStub")); 638 assert(endpoint.setDescription("For PredictionServiceStub"));
631 return new PredictionServiceStub.fromEndpoint(endpoint); 639 return new PredictionServiceStub.fromEndpoint(endpoint);
632 } 640 }
633 641
634 642
635 dynamic getPredictionList(PredictionInfo predictionInfo,[Function responseFact ory = null]) { 643 void getPredictionList(PredictionInfo predictionInfo,void callback(List<String > predictionList)) {
636 return impl.getPredictionList(predictionInfo,responseFactory); 644 return impl.getPredictionList(predictionInfo,callback);
637 } 645 }
638 } 646 }
639 647
640 648
641 649
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698