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

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

Issue 2006093002: Dart: Futures -> Callbacks. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Merge 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 // WARNING: DO NOT EDIT. This file was generated by a program. 1 // WARNING: DO NOT EDIT. This file was generated by a program.
2 // See $MOJO_SDK/tools/bindings/mojom_bindings_generator.py. 2 // See $MOJO_SDK/tools/bindings/mojom_bindings_generator.py.
3 3
4 library http_server_mojom; 4 library http_server_mojom;
5 import 'dart:async'; 5 import 'dart:async';
6 import 'package:mojo/bindings.dart' as bindings; 6 import 'package:mojo/bindings.dart' as bindings;
7 import 'package:mojo/core.dart' as core; 7 import 'package:mojo/core.dart' as core;
8 import 'package:mojo/mojo/bindings/types/service_describer.mojom.dart' as servic e_describer; 8 import 'package:mojo/mojo/bindings/types/service_describer.mojom.dart' as servic e_describer;
9 import 'package:mojo_services/http_server/http_request.mojom.dart' as http_reque st_mojom; 9 import 'package:mojo_services/http_server/http_request.mojom.dart' as http_reque st_mojom;
10 import 'package:mojo_services/http_server/http_response.mojom.dart' as http_resp onse_mojom; 10 import 'package:mojo_services/http_server/http_response.mojom.dart' as http_resp onse_mojom;
11 11
12 12
13 13
14 class _HttpServerSetHandlerParams extends bindings.Struct { 14 class _HttpServerSetHandlerParams extends bindings.Struct {
15 static const List<bindings.StructDataHeader> kVersions = const [ 15 static const List<bindings.StructDataHeader> kVersions = const [
16 const bindings.StructDataHeader(24, 0) 16 const bindings.StructDataHeader(24, 0)
17 ]; 17 ];
18 String pattern = null; 18 String pattern = null;
19 HttpHandlerInterface handler = null; 19 HttpHandlerInterface handler = null;
20 20
21 _HttpServerSetHandlerParams() : super(kVersions.last.size); 21 _HttpServerSetHandlerParams() : super(kVersions.last.size);
22 22
23 _HttpServerSetHandlerParams.init(
24 String this.pattern,
25 HttpHandlerInterface this.handler
26 ) : super(kVersions.last.size);
27
23 static _HttpServerSetHandlerParams deserialize(bindings.Message message) { 28 static _HttpServerSetHandlerParams deserialize(bindings.Message message) {
24 var decoder = new bindings.Decoder(message); 29 var decoder = new bindings.Decoder(message);
25 var result = decode(decoder); 30 var result = decode(decoder);
26 if (decoder.excessHandles != null) { 31 if (decoder.excessHandles != null) {
27 decoder.excessHandles.forEach((h) => h.close()); 32 decoder.excessHandles.forEach((h) => h.close());
28 } 33 }
29 return result; 34 return result;
30 } 35 }
31 36
32 static _HttpServerSetHandlerParams decode(bindings.Decoder decoder0) { 37 static _HttpServerSetHandlerParams decode(bindings.Decoder decoder0) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 101
97 102
98 class HttpServerSetHandlerResponseParams extends bindings.Struct { 103 class HttpServerSetHandlerResponseParams extends bindings.Struct {
99 static const List<bindings.StructDataHeader> kVersions = const [ 104 static const List<bindings.StructDataHeader> kVersions = const [
100 const bindings.StructDataHeader(16, 0) 105 const bindings.StructDataHeader(16, 0)
101 ]; 106 ];
102 bool success = false; 107 bool success = false;
103 108
104 HttpServerSetHandlerResponseParams() : super(kVersions.last.size); 109 HttpServerSetHandlerResponseParams() : super(kVersions.last.size);
105 110
111 HttpServerSetHandlerResponseParams.init(
112 bool this.success
113 ) : super(kVersions.last.size);
114
106 static HttpServerSetHandlerResponseParams deserialize(bindings.Message message ) { 115 static HttpServerSetHandlerResponseParams deserialize(bindings.Message message ) {
107 var decoder = new bindings.Decoder(message); 116 var decoder = new bindings.Decoder(message);
108 var result = decode(decoder); 117 var result = decode(decoder);
109 if (decoder.excessHandles != null) { 118 if (decoder.excessHandles != null) {
110 decoder.excessHandles.forEach((h) => h.close()); 119 decoder.excessHandles.forEach((h) => h.close());
111 } 120 }
112 return result; 121 return result;
113 } 122 }
114 123
115 static HttpServerSetHandlerResponseParams decode(bindings.Decoder decoder0) { 124 static HttpServerSetHandlerResponseParams decode(bindings.Decoder decoder0) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 } 176 }
168 177
169 178
170 class _HttpServerGetPortParams extends bindings.Struct { 179 class _HttpServerGetPortParams extends bindings.Struct {
171 static const List<bindings.StructDataHeader> kVersions = const [ 180 static const List<bindings.StructDataHeader> kVersions = const [
172 const bindings.StructDataHeader(8, 0) 181 const bindings.StructDataHeader(8, 0)
173 ]; 182 ];
174 183
175 _HttpServerGetPortParams() : super(kVersions.last.size); 184 _HttpServerGetPortParams() : super(kVersions.last.size);
176 185
186 _HttpServerGetPortParams.init(
187 ) : super(kVersions.last.size);
188
177 static _HttpServerGetPortParams deserialize(bindings.Message message) { 189 static _HttpServerGetPortParams deserialize(bindings.Message message) {
178 var decoder = new bindings.Decoder(message); 190 var decoder = new bindings.Decoder(message);
179 var result = decode(decoder); 191 var result = decode(decoder);
180 if (decoder.excessHandles != null) { 192 if (decoder.excessHandles != null) {
181 decoder.excessHandles.forEach((h) => h.close()); 193 decoder.excessHandles.forEach((h) => h.close());
182 } 194 }
183 return result; 195 return result;
184 } 196 }
185 197
186 static _HttpServerGetPortParams decode(bindings.Decoder decoder0) { 198 static _HttpServerGetPortParams decode(bindings.Decoder decoder0) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 238
227 239
228 class HttpServerGetPortResponseParams extends bindings.Struct { 240 class HttpServerGetPortResponseParams extends bindings.Struct {
229 static const List<bindings.StructDataHeader> kVersions = const [ 241 static const List<bindings.StructDataHeader> kVersions = const [
230 const bindings.StructDataHeader(16, 0) 242 const bindings.StructDataHeader(16, 0)
231 ]; 243 ];
232 int port = 0; 244 int port = 0;
233 245
234 HttpServerGetPortResponseParams() : super(kVersions.last.size); 246 HttpServerGetPortResponseParams() : super(kVersions.last.size);
235 247
248 HttpServerGetPortResponseParams.init(
249 int this.port
250 ) : super(kVersions.last.size);
251
236 static HttpServerGetPortResponseParams deserialize(bindings.Message message) { 252 static HttpServerGetPortResponseParams deserialize(bindings.Message message) {
237 var decoder = new bindings.Decoder(message); 253 var decoder = new bindings.Decoder(message);
238 var result = decode(decoder); 254 var result = decode(decoder);
239 if (decoder.excessHandles != null) { 255 if (decoder.excessHandles != null) {
240 decoder.excessHandles.forEach((h) => h.close()); 256 decoder.excessHandles.forEach((h) => h.close());
241 } 257 }
242 return result; 258 return result;
243 } 259 }
244 260
245 static HttpServerGetPortResponseParams decode(bindings.Decoder decoder0) { 261 static HttpServerGetPortResponseParams decode(bindings.Decoder decoder0) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 314
299 315
300 class _HttpHandlerHandleRequestParams extends bindings.Struct { 316 class _HttpHandlerHandleRequestParams extends bindings.Struct {
301 static const List<bindings.StructDataHeader> kVersions = const [ 317 static const List<bindings.StructDataHeader> kVersions = const [
302 const bindings.StructDataHeader(16, 0) 318 const bindings.StructDataHeader(16, 0)
303 ]; 319 ];
304 http_request_mojom.HttpRequest request = null; 320 http_request_mojom.HttpRequest request = null;
305 321
306 _HttpHandlerHandleRequestParams() : super(kVersions.last.size); 322 _HttpHandlerHandleRequestParams() : super(kVersions.last.size);
307 323
324 _HttpHandlerHandleRequestParams.init(
325 http_request_mojom.HttpRequest this.request
326 ) : super(kVersions.last.size);
327
308 static _HttpHandlerHandleRequestParams deserialize(bindings.Message message) { 328 static _HttpHandlerHandleRequestParams deserialize(bindings.Message message) {
309 var decoder = new bindings.Decoder(message); 329 var decoder = new bindings.Decoder(message);
310 var result = decode(decoder); 330 var result = decode(decoder);
311 if (decoder.excessHandles != null) { 331 if (decoder.excessHandles != null) {
312 decoder.excessHandles.forEach((h) => h.close()); 332 decoder.excessHandles.forEach((h) => h.close());
313 } 333 }
314 return result; 334 return result;
315 } 335 }
316 336
317 static _HttpHandlerHandleRequestParams decode(bindings.Decoder decoder0) { 337 static _HttpHandlerHandleRequestParams decode(bindings.Decoder decoder0) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 390
371 391
372 class HttpHandlerHandleRequestResponseParams extends bindings.Struct { 392 class HttpHandlerHandleRequestResponseParams extends bindings.Struct {
373 static const List<bindings.StructDataHeader> kVersions = const [ 393 static const List<bindings.StructDataHeader> kVersions = const [
374 const bindings.StructDataHeader(16, 0) 394 const bindings.StructDataHeader(16, 0)
375 ]; 395 ];
376 http_response_mojom.HttpResponse response = null; 396 http_response_mojom.HttpResponse response = null;
377 397
378 HttpHandlerHandleRequestResponseParams() : super(kVersions.last.size); 398 HttpHandlerHandleRequestResponseParams() : super(kVersions.last.size);
379 399
400 HttpHandlerHandleRequestResponseParams.init(
401 http_response_mojom.HttpResponse this.response
402 ) : super(kVersions.last.size);
403
380 static HttpHandlerHandleRequestResponseParams deserialize(bindings.Message mes sage) { 404 static HttpHandlerHandleRequestResponseParams deserialize(bindings.Message mes sage) {
381 var decoder = new bindings.Decoder(message); 405 var decoder = new bindings.Decoder(message);
382 var result = decode(decoder); 406 var result = decode(decoder);
383 if (decoder.excessHandles != null) { 407 if (decoder.excessHandles != null) {
384 decoder.excessHandles.forEach((h) => h.close()); 408 decoder.excessHandles.forEach((h) => h.close());
385 } 409 }
386 return result; 410 return result;
387 } 411 }
388 412
389 static HttpHandlerHandleRequestResponseParams decode(bindings.Decoder decoder0 ) { 413 static HttpHandlerHandleRequestResponseParams decode(bindings.Decoder decoder0 ) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 Map toJson() { 461 Map toJson() {
438 throw new bindings.MojoCodecError( 462 throw new bindings.MojoCodecError(
439 'Object containing handles cannot be encoded to JSON.'); 463 'Object containing handles cannot be encoded to JSON.');
440 } 464 }
441 } 465 }
442 466
443 const int _httpServerMethodSetHandlerName = 0; 467 const int _httpServerMethodSetHandlerName = 0;
444 const int _httpServerMethodGetPortName = 1; 468 const int _httpServerMethodGetPortName = 1;
445 469
446 class _HttpServerServiceDescription implements service_describer.ServiceDescript ion { 470 class _HttpServerServiceDescription implements service_describer.ServiceDescript ion {
447 dynamic getTopLevelInterface([Function responseFactory]) => 471 void getTopLevelInterface(Function responder) {
448 responseFactory(null); 472 responder(null);
473 }
449 474
450 dynamic getTypeDefinition(String typeKey, [Function responseFactory]) => 475 void getTypeDefinition(String typeKey, Function responder) {
451 responseFactory(null); 476 responder(null);
477 }
452 478
453 dynamic getAllTypeDefinitions([Function responseFactory]) => 479 void getAllTypeDefinitions(Function responder) {
454 responseFactory(null); 480 responder(null);
481 }
455 } 482 }
456 483
457 abstract class HttpServer { 484 abstract class HttpServer {
458 static const String serviceName = null; 485 static const String serviceName = null;
459 486
460 static service_describer.ServiceDescription _cachedServiceDescription; 487 static service_describer.ServiceDescription _cachedServiceDescription;
461 static service_describer.ServiceDescription get serviceDescription { 488 static service_describer.ServiceDescription get serviceDescription {
462 if (_cachedServiceDescription == null) { 489 if (_cachedServiceDescription == null) {
463 _cachedServiceDescription = new _HttpServerServiceDescription(); 490 _cachedServiceDescription = new _HttpServerServiceDescription();
464 } 491 }
465 return _cachedServiceDescription; 492 return _cachedServiceDescription;
466 } 493 }
467 494
468 static HttpServerProxy connectToService( 495 static HttpServerProxy connectToService(
469 bindings.ServiceConnector s, String url, [String serviceName]) { 496 bindings.ServiceConnector s, String url, [String serviceName]) {
470 HttpServerProxy p = new HttpServerProxy.unbound(); 497 HttpServerProxy p = new HttpServerProxy.unbound();
471 String name = serviceName ?? HttpServer.serviceName; 498 String name = serviceName ?? HttpServer.serviceName;
472 if ((name == null) || name.isEmpty) { 499 if ((name == null) || name.isEmpty) {
473 throw new core.MojoApiError( 500 throw new core.MojoApiError(
474 "If an interface has no ServiceName, then one must be provided."); 501 "If an interface has no ServiceName, then one must be provided.");
475 } 502 }
476 s.connectToService(url, p, name); 503 s.connectToService(url, p, name);
477 return p; 504 return p;
478 } 505 }
479 dynamic setHandler(String pattern,HttpHandlerInterface handler,[Function respo nseFactory = null]); 506 void setHandler(String pattern,HttpHandlerInterface handler,void callback(bool success));
480 dynamic getPort([Function responseFactory = null]); 507 void getPort(void callback(int port));
481 } 508 }
482 509
483 abstract class HttpServerInterface 510 abstract class HttpServerInterface
484 implements bindings.MojoInterface<HttpServer>, 511 implements bindings.MojoInterface<HttpServer>,
485 HttpServer { 512 HttpServer {
486 factory HttpServerInterface([HttpServer impl]) => 513 factory HttpServerInterface([HttpServer impl]) =>
487 new HttpServerStub.unbound(impl); 514 new HttpServerStub.unbound(impl);
488 515
489 factory HttpServerInterface.fromEndpoint( 516 factory HttpServerInterface.fromEndpoint(
490 core.MojoMessagePipeEndpoint endpoint, 517 core.MojoMessagePipeEndpoint endpoint,
(...skipping 29 matching lines...) Expand all
520 547
521 void handleResponse(bindings.ServiceMessage message) { 548 void handleResponse(bindings.ServiceMessage message) {
522 switch (message.header.type) { 549 switch (message.header.type) {
523 case _httpServerMethodSetHandlerName: 550 case _httpServerMethodSetHandlerName:
524 var r = HttpServerSetHandlerResponseParams.deserialize( 551 var r = HttpServerSetHandlerResponseParams.deserialize(
525 message.payload); 552 message.payload);
526 if (!message.header.hasRequestId) { 553 if (!message.header.hasRequestId) {
527 proxyError("Expected a message with a valid request Id."); 554 proxyError("Expected a message with a valid request Id.");
528 return; 555 return;
529 } 556 }
530 Completer c = completerMap[message.header.requestId]; 557 Function callback = callbackMap[message.header.requestId];
531 if (c == null) { 558 if (callback == null) {
532 proxyError( 559 proxyError(
533 "Message had unknown request Id: ${message.header.requestId}"); 560 "Message had unknown request Id: ${message.header.requestId}");
534 return; 561 return;
535 } 562 }
536 completerMap.remove(message.header.requestId); 563 callbackMap.remove(message.header.requestId);
537 if (c.isCompleted) { 564 callback(r.success );
538 proxyError("Response completer already completed");
539 return;
540 }
541 c.complete(r);
542 break; 565 break;
543 case _httpServerMethodGetPortName: 566 case _httpServerMethodGetPortName:
544 var r = HttpServerGetPortResponseParams.deserialize( 567 var r = HttpServerGetPortResponseParams.deserialize(
545 message.payload); 568 message.payload);
546 if (!message.header.hasRequestId) { 569 if (!message.header.hasRequestId) {
547 proxyError("Expected a message with a valid request Id."); 570 proxyError("Expected a message with a valid request Id.");
548 return; 571 return;
549 } 572 }
550 Completer c = completerMap[message.header.requestId]; 573 Function callback = callbackMap[message.header.requestId];
551 if (c == null) { 574 if (callback == null) {
552 proxyError( 575 proxyError(
553 "Message had unknown request Id: ${message.header.requestId}"); 576 "Message had unknown request Id: ${message.header.requestId}");
554 return; 577 return;
555 } 578 }
556 completerMap.remove(message.header.requestId); 579 callbackMap.remove(message.header.requestId);
557 if (c.isCompleted) { 580 callback(r.port );
558 proxyError("Response completer already completed");
559 return;
560 }
561 c.complete(r);
562 break; 581 break;
563 default: 582 default:
564 proxyError("Unexpected message type: ${message.header.type}"); 583 proxyError("Unexpected message type: ${message.header.type}");
565 close(immediate: true); 584 close(immediate: true);
566 break; 585 break;
567 } 586 }
568 } 587 }
569 588
570 @override 589 @override
571 String toString() { 590 String toString() {
(...skipping 24 matching lines...) Expand all
596 return newMockedProxy; 615 return newMockedProxy;
597 } 616 }
598 617
599 static HttpServerProxy newFromEndpoint( 618 static HttpServerProxy newFromEndpoint(
600 core.MojoMessagePipeEndpoint endpoint) { 619 core.MojoMessagePipeEndpoint endpoint) {
601 assert(endpoint.setDescription("For HttpServerProxy")); 620 assert(endpoint.setDescription("For HttpServerProxy"));
602 return new HttpServerProxy.fromEndpoint(endpoint); 621 return new HttpServerProxy.fromEndpoint(endpoint);
603 } 622 }
604 623
605 624
606 dynamic setHandler(String pattern,HttpHandlerInterface handler,[Function respo nseFactory = null]) { 625 void setHandler(String pattern,HttpHandlerInterface handler,void callback(bool success)) {
607 if (impl != null) { 626 if (impl != null) {
608 return new Future(() => impl.setHandler(pattern,handler,_HttpServerStubCon trol._httpServerSetHandlerResponseParamsFactory)); 627 impl.setHandler(pattern,handler,callback);
628 return;
609 } 629 }
610 var params = new _HttpServerSetHandlerParams(); 630 var params = new _HttpServerSetHandlerParams();
611 params.pattern = pattern; 631 params.pattern = pattern;
612 params.handler = handler; 632 params.handler = handler;
613 return ctrl.sendMessageWithRequestId( 633 ctrl.sendMessageWithRequestId(
614 params, 634 params,
615 _httpServerMethodSetHandlerName, 635 _httpServerMethodSetHandlerName,
616 -1, 636 -1,
617 bindings.MessageHeader.kMessageExpectsResponse); 637 bindings.MessageHeader.kMessageExpectsResponse,
638 callback);
618 } 639 }
619 dynamic getPort([Function responseFactory = null]) { 640 void getPort(void callback(int port)) {
620 if (impl != null) { 641 if (impl != null) {
621 return new Future(() => impl.getPort(_HttpServerStubControl._httpServerGet PortResponseParamsFactory)); 642 impl.getPort(callback);
643 return;
622 } 644 }
623 var params = new _HttpServerGetPortParams(); 645 var params = new _HttpServerGetPortParams();
624 return ctrl.sendMessageWithRequestId( 646 ctrl.sendMessageWithRequestId(
625 params, 647 params,
626 _httpServerMethodGetPortName, 648 _httpServerMethodGetPortName,
627 -1, 649 -1,
628 bindings.MessageHeader.kMessageExpectsResponse); 650 bindings.MessageHeader.kMessageExpectsResponse,
651 callback);
629 } 652 }
630 } 653 }
631 654
632 class _HttpServerStubControl 655 class _HttpServerStubControl
633 extends bindings.StubMessageHandler 656 extends bindings.StubMessageHandler
634 implements bindings.StubControl<HttpServer> { 657 implements bindings.StubControl<HttpServer> {
635 HttpServer _impl; 658 HttpServer _impl;
636 659
637 _HttpServerStubControl.fromEndpoint( 660 _HttpServerStubControl.fromEndpoint(
638 core.MojoMessagePipeEndpoint endpoint, [HttpServer impl]) 661 core.MojoMessagePipeEndpoint endpoint, [HttpServer impl])
639 : super.fromEndpoint(endpoint, autoBegin: impl != null) { 662 : super.fromEndpoint(endpoint, autoBegin: impl != null) {
640 _impl = impl; 663 _impl = impl;
641 } 664 }
642 665
643 _HttpServerStubControl.fromHandle( 666 _HttpServerStubControl.fromHandle(
644 core.MojoHandle handle, [HttpServer impl]) 667 core.MojoHandle handle, [HttpServer impl])
645 : super.fromHandle(handle, autoBegin: impl != null) { 668 : super.fromHandle(handle, autoBegin: impl != null) {
646 _impl = impl; 669 _impl = impl;
647 } 670 }
648 671
649 _HttpServerStubControl.unbound([this._impl]) : super.unbound(); 672 _HttpServerStubControl.unbound([this._impl]) : super.unbound();
650 673
651 String get serviceName => HttpServer.serviceName; 674 String get serviceName => HttpServer.serviceName;
652 675
653 676
654 static HttpServerSetHandlerResponseParams _httpServerSetHandlerResponseParamsF actory(bool success) { 677 Function _httpServerSetHandlerResponseParamsResponder(
655 var result = new HttpServerSetHandlerResponseParams(); 678 int requestId) {
656 result.success = success; 679 return (bool success) {
657 return result; 680 var result = new HttpServerSetHandlerResponseParams();
681 result.success = success;
682 sendResponse(buildResponseWithId(
683 result,
684 _httpServerMethodSetHandlerName,
685 requestId,
686 bindings.MessageHeader.kMessageIsResponse));
687 };
658 } 688 }
659 static HttpServerGetPortResponseParams _httpServerGetPortResponseParamsFactory (int port) { 689 Function _httpServerGetPortResponseParamsResponder(
660 var result = new HttpServerGetPortResponseParams(); 690 int requestId) {
661 result.port = port; 691 return (int port) {
662 return result; 692 var result = new HttpServerGetPortResponseParams();
693 result.port = port;
694 sendResponse(buildResponseWithId(
695 result,
696 _httpServerMethodGetPortName,
697 requestId,
698 bindings.MessageHeader.kMessageIsResponse));
699 };
663 } 700 }
664 701
665 dynamic handleMessage(bindings.ServiceMessage message) { 702 void handleMessage(bindings.ServiceMessage message) {
666 if (bindings.ControlMessageHandler.isControlMessage(message)) { 703 if (bindings.ControlMessageHandler.isControlMessage(message)) {
667 return bindings.ControlMessageHandler.handleMessage(this, 704 bindings.ControlMessageHandler.handleMessage(
668 0, 705 this, 0, message);
669 message); 706 return;
670 } 707 }
671 if (_impl == null) { 708 if (_impl == null) {
672 throw new core.MojoApiError("$this has no implementation set"); 709 throw new core.MojoApiError("$this has no implementation set");
673 } 710 }
674 switch (message.header.type) { 711 switch (message.header.type) {
675 case _httpServerMethodSetHandlerName: 712 case _httpServerMethodSetHandlerName:
676 var params = _HttpServerSetHandlerParams.deserialize( 713 var params = _HttpServerSetHandlerParams.deserialize(
677 message.payload); 714 message.payload);
678 var response = _impl.setHandler(params.pattern,params.handler,_httpServe rSetHandlerResponseParamsFactory); 715 _impl.setHandler(params.pattern, params.handler, _httpServerSetHandlerRe sponseParamsResponder(message.header.requestId));
679 if (response is Future) {
680 return response.then((response) {
681 if (response != null) {
682 return buildResponseWithId(
683 response,
684 _httpServerMethodSetHandlerName,
685 message.header.requestId,
686 bindings.MessageHeader.kMessageIsResponse);
687 }
688 });
689 } else if (response != null) {
690 return buildResponseWithId(
691 response,
692 _httpServerMethodSetHandlerName,
693 message.header.requestId,
694 bindings.MessageHeader.kMessageIsResponse);
695 }
696 break; 716 break;
697 case _httpServerMethodGetPortName: 717 case _httpServerMethodGetPortName:
698 var response = _impl.getPort(_httpServerGetPortResponseParamsFactory); 718 _impl.getPort(_httpServerGetPortResponseParamsResponder(message.header.r equestId));
699 if (response is Future) {
700 return response.then((response) {
701 if (response != null) {
702 return buildResponseWithId(
703 response,
704 _httpServerMethodGetPortName,
705 message.header.requestId,
706 bindings.MessageHeader.kMessageIsResponse);
707 }
708 });
709 } else if (response != null) {
710 return buildResponseWithId(
711 response,
712 _httpServerMethodGetPortName,
713 message.header.requestId,
714 bindings.MessageHeader.kMessageIsResponse);
715 }
716 break; 719 break;
717 default: 720 default:
718 throw new bindings.MojoCodecError("Unexpected message name"); 721 throw new bindings.MojoCodecError("Unexpected message name");
719 break; 722 break;
720 } 723 }
721 return null;
722 } 724 }
723 725
724 HttpServer get impl => _impl; 726 HttpServer get impl => _impl;
725 set impl(HttpServer d) { 727 set impl(HttpServer d) {
726 if (d == null) { 728 if (d == null) {
727 throw new core.MojoApiError("$this: Cannot set a null implementation"); 729 throw new core.MojoApiError("$this: Cannot set a null implementation");
728 } 730 }
729 if (isBound && (_impl == null)) { 731 if (isBound && (_impl == null)) {
730 beginHandlingEvents(); 732 beginHandlingEvents();
731 } 733 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 core.MojoHandle handle, [HttpServer impl]) 767 core.MojoHandle handle, [HttpServer impl])
766 : super(new _HttpServerStubControl.fromHandle(handle, impl)); 768 : super(new _HttpServerStubControl.fromHandle(handle, impl));
767 769
768 static HttpServerStub newFromEndpoint( 770 static HttpServerStub newFromEndpoint(
769 core.MojoMessagePipeEndpoint endpoint) { 771 core.MojoMessagePipeEndpoint endpoint) {
770 assert(endpoint.setDescription("For HttpServerStub")); 772 assert(endpoint.setDescription("For HttpServerStub"));
771 return new HttpServerStub.fromEndpoint(endpoint); 773 return new HttpServerStub.fromEndpoint(endpoint);
772 } 774 }
773 775
774 776
775 dynamic setHandler(String pattern,HttpHandlerInterface handler,[Function respo nseFactory = null]) { 777 void setHandler(String pattern,HttpHandlerInterface handler,void callback(bool success)) {
776 return impl.setHandler(pattern,handler,responseFactory); 778 return impl.setHandler(pattern,handler,callback);
777 } 779 }
778 dynamic getPort([Function responseFactory = null]) { 780 void getPort(void callback(int port)) {
779 return impl.getPort(responseFactory); 781 return impl.getPort(callback);
780 } 782 }
781 } 783 }
782 784
783 const int _httpHandlerMethodHandleRequestName = 0; 785 const int _httpHandlerMethodHandleRequestName = 0;
784 786
785 class _HttpHandlerServiceDescription implements service_describer.ServiceDescrip tion { 787 class _HttpHandlerServiceDescription implements service_describer.ServiceDescrip tion {
786 dynamic getTopLevelInterface([Function responseFactory]) => 788 void getTopLevelInterface(Function responder) {
787 responseFactory(null); 789 responder(null);
790 }
788 791
789 dynamic getTypeDefinition(String typeKey, [Function responseFactory]) => 792 void getTypeDefinition(String typeKey, Function responder) {
790 responseFactory(null); 793 responder(null);
794 }
791 795
792 dynamic getAllTypeDefinitions([Function responseFactory]) => 796 void getAllTypeDefinitions(Function responder) {
793 responseFactory(null); 797 responder(null);
798 }
794 } 799 }
795 800
796 abstract class HttpHandler { 801 abstract class HttpHandler {
797 static const String serviceName = null; 802 static const String serviceName = null;
798 803
799 static service_describer.ServiceDescription _cachedServiceDescription; 804 static service_describer.ServiceDescription _cachedServiceDescription;
800 static service_describer.ServiceDescription get serviceDescription { 805 static service_describer.ServiceDescription get serviceDescription {
801 if (_cachedServiceDescription == null) { 806 if (_cachedServiceDescription == null) {
802 _cachedServiceDescription = new _HttpHandlerServiceDescription(); 807 _cachedServiceDescription = new _HttpHandlerServiceDescription();
803 } 808 }
804 return _cachedServiceDescription; 809 return _cachedServiceDescription;
805 } 810 }
806 811
807 static HttpHandlerProxy connectToService( 812 static HttpHandlerProxy connectToService(
808 bindings.ServiceConnector s, String url, [String serviceName]) { 813 bindings.ServiceConnector s, String url, [String serviceName]) {
809 HttpHandlerProxy p = new HttpHandlerProxy.unbound(); 814 HttpHandlerProxy p = new HttpHandlerProxy.unbound();
810 String name = serviceName ?? HttpHandler.serviceName; 815 String name = serviceName ?? HttpHandler.serviceName;
811 if ((name == null) || name.isEmpty) { 816 if ((name == null) || name.isEmpty) {
812 throw new core.MojoApiError( 817 throw new core.MojoApiError(
813 "If an interface has no ServiceName, then one must be provided."); 818 "If an interface has no ServiceName, then one must be provided.");
814 } 819 }
815 s.connectToService(url, p, name); 820 s.connectToService(url, p, name);
816 return p; 821 return p;
817 } 822 }
818 dynamic handleRequest(http_request_mojom.HttpRequest request,[Function respons eFactory = null]); 823 void handleRequest(http_request_mojom.HttpRequest request,void callback(http_r esponse_mojom.HttpResponse response));
819 } 824 }
820 825
821 abstract class HttpHandlerInterface 826 abstract class HttpHandlerInterface
822 implements bindings.MojoInterface<HttpHandler>, 827 implements bindings.MojoInterface<HttpHandler>,
823 HttpHandler { 828 HttpHandler {
824 factory HttpHandlerInterface([HttpHandler impl]) => 829 factory HttpHandlerInterface([HttpHandler impl]) =>
825 new HttpHandlerStub.unbound(impl); 830 new HttpHandlerStub.unbound(impl);
826 831
827 factory HttpHandlerInterface.fromEndpoint( 832 factory HttpHandlerInterface.fromEndpoint(
828 core.MojoMessagePipeEndpoint endpoint, 833 core.MojoMessagePipeEndpoint endpoint,
(...skipping 29 matching lines...) Expand all
858 863
859 void handleResponse(bindings.ServiceMessage message) { 864 void handleResponse(bindings.ServiceMessage message) {
860 switch (message.header.type) { 865 switch (message.header.type) {
861 case _httpHandlerMethodHandleRequestName: 866 case _httpHandlerMethodHandleRequestName:
862 var r = HttpHandlerHandleRequestResponseParams.deserialize( 867 var r = HttpHandlerHandleRequestResponseParams.deserialize(
863 message.payload); 868 message.payload);
864 if (!message.header.hasRequestId) { 869 if (!message.header.hasRequestId) {
865 proxyError("Expected a message with a valid request Id."); 870 proxyError("Expected a message with a valid request Id.");
866 return; 871 return;
867 } 872 }
868 Completer c = completerMap[message.header.requestId]; 873 Function callback = callbackMap[message.header.requestId];
869 if (c == null) { 874 if (callback == null) {
870 proxyError( 875 proxyError(
871 "Message had unknown request Id: ${message.header.requestId}"); 876 "Message had unknown request Id: ${message.header.requestId}");
872 return; 877 return;
873 } 878 }
874 completerMap.remove(message.header.requestId); 879 callbackMap.remove(message.header.requestId);
875 if (c.isCompleted) { 880 callback(r.response );
876 proxyError("Response completer already completed");
877 return;
878 }
879 c.complete(r);
880 break; 881 break;
881 default: 882 default:
882 proxyError("Unexpected message type: ${message.header.type}"); 883 proxyError("Unexpected message type: ${message.header.type}");
883 close(immediate: true); 884 close(immediate: true);
884 break; 885 break;
885 } 886 }
886 } 887 }
887 888
888 @override 889 @override
889 String toString() { 890 String toString() {
(...skipping 24 matching lines...) Expand all
914 return newMockedProxy; 915 return newMockedProxy;
915 } 916 }
916 917
917 static HttpHandlerProxy newFromEndpoint( 918 static HttpHandlerProxy newFromEndpoint(
918 core.MojoMessagePipeEndpoint endpoint) { 919 core.MojoMessagePipeEndpoint endpoint) {
919 assert(endpoint.setDescription("For HttpHandlerProxy")); 920 assert(endpoint.setDescription("For HttpHandlerProxy"));
920 return new HttpHandlerProxy.fromEndpoint(endpoint); 921 return new HttpHandlerProxy.fromEndpoint(endpoint);
921 } 922 }
922 923
923 924
924 dynamic handleRequest(http_request_mojom.HttpRequest request,[Function respons eFactory = null]) { 925 void handleRequest(http_request_mojom.HttpRequest request,void callback(http_r esponse_mojom.HttpResponse response)) {
925 if (impl != null) { 926 if (impl != null) {
926 return new Future(() => impl.handleRequest(request,_HttpHandlerStubControl ._httpHandlerHandleRequestResponseParamsFactory)); 927 impl.handleRequest(request,callback);
928 return;
927 } 929 }
928 var params = new _HttpHandlerHandleRequestParams(); 930 var params = new _HttpHandlerHandleRequestParams();
929 params.request = request; 931 params.request = request;
930 return ctrl.sendMessageWithRequestId( 932 ctrl.sendMessageWithRequestId(
931 params, 933 params,
932 _httpHandlerMethodHandleRequestName, 934 _httpHandlerMethodHandleRequestName,
933 -1, 935 -1,
934 bindings.MessageHeader.kMessageExpectsResponse); 936 bindings.MessageHeader.kMessageExpectsResponse,
937 callback);
935 } 938 }
936 } 939 }
937 940
938 class _HttpHandlerStubControl 941 class _HttpHandlerStubControl
939 extends bindings.StubMessageHandler 942 extends bindings.StubMessageHandler
940 implements bindings.StubControl<HttpHandler> { 943 implements bindings.StubControl<HttpHandler> {
941 HttpHandler _impl; 944 HttpHandler _impl;
942 945
943 _HttpHandlerStubControl.fromEndpoint( 946 _HttpHandlerStubControl.fromEndpoint(
944 core.MojoMessagePipeEndpoint endpoint, [HttpHandler impl]) 947 core.MojoMessagePipeEndpoint endpoint, [HttpHandler impl])
945 : super.fromEndpoint(endpoint, autoBegin: impl != null) { 948 : super.fromEndpoint(endpoint, autoBegin: impl != null) {
946 _impl = impl; 949 _impl = impl;
947 } 950 }
948 951
949 _HttpHandlerStubControl.fromHandle( 952 _HttpHandlerStubControl.fromHandle(
950 core.MojoHandle handle, [HttpHandler impl]) 953 core.MojoHandle handle, [HttpHandler impl])
951 : super.fromHandle(handle, autoBegin: impl != null) { 954 : super.fromHandle(handle, autoBegin: impl != null) {
952 _impl = impl; 955 _impl = impl;
953 } 956 }
954 957
955 _HttpHandlerStubControl.unbound([this._impl]) : super.unbound(); 958 _HttpHandlerStubControl.unbound([this._impl]) : super.unbound();
956 959
957 String get serviceName => HttpHandler.serviceName; 960 String get serviceName => HttpHandler.serviceName;
958 961
959 962
960 static HttpHandlerHandleRequestResponseParams _httpHandlerHandleRequestRespons eParamsFactory(http_response_mojom.HttpResponse response) { 963 Function _httpHandlerHandleRequestResponseParamsResponder(
961 var result = new HttpHandlerHandleRequestResponseParams(); 964 int requestId) {
962 result.response = response; 965 return (http_response_mojom.HttpResponse response) {
963 return result; 966 var result = new HttpHandlerHandleRequestResponseParams();
967 result.response = response;
968 sendResponse(buildResponseWithId(
969 result,
970 _httpHandlerMethodHandleRequestName,
971 requestId,
972 bindings.MessageHeader.kMessageIsResponse));
973 };
964 } 974 }
965 975
966 dynamic handleMessage(bindings.ServiceMessage message) { 976 void handleMessage(bindings.ServiceMessage message) {
967 if (bindings.ControlMessageHandler.isControlMessage(message)) { 977 if (bindings.ControlMessageHandler.isControlMessage(message)) {
968 return bindings.ControlMessageHandler.handleMessage(this, 978 bindings.ControlMessageHandler.handleMessage(
969 0, 979 this, 0, message);
970 message); 980 return;
971 } 981 }
972 if (_impl == null) { 982 if (_impl == null) {
973 throw new core.MojoApiError("$this has no implementation set"); 983 throw new core.MojoApiError("$this has no implementation set");
974 } 984 }
975 switch (message.header.type) { 985 switch (message.header.type) {
976 case _httpHandlerMethodHandleRequestName: 986 case _httpHandlerMethodHandleRequestName:
977 var params = _HttpHandlerHandleRequestParams.deserialize( 987 var params = _HttpHandlerHandleRequestParams.deserialize(
978 message.payload); 988 message.payload);
979 var response = _impl.handleRequest(params.request,_httpHandlerHandleRequ estResponseParamsFactory); 989 _impl.handleRequest(params.request, _httpHandlerHandleRequestResponsePar amsResponder(message.header.requestId));
980 if (response is Future) {
981 return response.then((response) {
982 if (response != null) {
983 return buildResponseWithId(
984 response,
985 _httpHandlerMethodHandleRequestName,
986 message.header.requestId,
987 bindings.MessageHeader.kMessageIsResponse);
988 }
989 });
990 } else if (response != null) {
991 return buildResponseWithId(
992 response,
993 _httpHandlerMethodHandleRequestName,
994 message.header.requestId,
995 bindings.MessageHeader.kMessageIsResponse);
996 }
997 break; 990 break;
998 default: 991 default:
999 throw new bindings.MojoCodecError("Unexpected message name"); 992 throw new bindings.MojoCodecError("Unexpected message name");
1000 break; 993 break;
1001 } 994 }
1002 return null;
1003 } 995 }
1004 996
1005 HttpHandler get impl => _impl; 997 HttpHandler get impl => _impl;
1006 set impl(HttpHandler d) { 998 set impl(HttpHandler d) {
1007 if (d == null) { 999 if (d == null) {
1008 throw new core.MojoApiError("$this: Cannot set a null implementation"); 1000 throw new core.MojoApiError("$this: Cannot set a null implementation");
1009 } 1001 }
1010 if (isBound && (_impl == null)) { 1002 if (isBound && (_impl == null)) {
1011 beginHandlingEvents(); 1003 beginHandlingEvents();
1012 } 1004 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1046 core.MojoHandle handle, [HttpHandler impl]) 1038 core.MojoHandle handle, [HttpHandler impl])
1047 : super(new _HttpHandlerStubControl.fromHandle(handle, impl)); 1039 : super(new _HttpHandlerStubControl.fromHandle(handle, impl));
1048 1040
1049 static HttpHandlerStub newFromEndpoint( 1041 static HttpHandlerStub newFromEndpoint(
1050 core.MojoMessagePipeEndpoint endpoint) { 1042 core.MojoMessagePipeEndpoint endpoint) {
1051 assert(endpoint.setDescription("For HttpHandlerStub")); 1043 assert(endpoint.setDescription("For HttpHandlerStub"));
1052 return new HttpHandlerStub.fromEndpoint(endpoint); 1044 return new HttpHandlerStub.fromEndpoint(endpoint);
1053 } 1045 }
1054 1046
1055 1047
1056 dynamic handleRequest(http_request_mojom.HttpRequest request,[Function respons eFactory = null]) { 1048 void handleRequest(http_request_mojom.HttpRequest request,void callback(http_r esponse_mojom.HttpResponse response)) {
1057 return impl.handleRequest(request,responseFactory); 1049 return impl.handleRequest(request,callback);
1058 } 1050 }
1059 } 1051 }
1060 1052
1061 1053
1062 1054
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698