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

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: 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 http_server_mojom; 5 library http_server_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 import 'package:mojo_services/http_server/http_request.mojom.dart' as http_reque st_mojom; 10 import 'package:mojo_services/http_server/http_request.mojom.dart' as http_reque st_mojom;
11 import 'package:mojo_services/http_server/http_response.mojom.dart' as http_resp onse_mojom; 11 import 'package:mojo_services/http_server/http_response.mojom.dart' as http_resp onse_mojom;
12 12
13 13
14 14
15 class _HttpServerSetHandlerParams extends bindings.Struct { 15 class _HttpServerSetHandlerParams extends bindings.Struct {
16 static const List<bindings.StructDataHeader> kVersions = const [ 16 static const List<bindings.StructDataHeader> kVersions = const [
17 const bindings.StructDataHeader(24, 0) 17 const bindings.StructDataHeader(24, 0)
18 ]; 18 ];
19 String pattern = null; 19 String pattern = null;
20 HttpHandlerInterface handler = null; 20 HttpHandlerInterface handler = null;
21 21
22 _HttpServerSetHandlerParams() : super(kVersions.last.size); 22 _HttpServerSetHandlerParams() : super(kVersions.last.size);
23 23
24 _HttpServerSetHandlerParams.init(
25 String this.pattern,
26 HttpHandlerInterface this.handler
27 ) : super(kVersions.last.size);
28
24 static _HttpServerSetHandlerParams deserialize(bindings.Message message) { 29 static _HttpServerSetHandlerParams deserialize(bindings.Message message) {
25 var decoder = new bindings.Decoder(message); 30 var decoder = new bindings.Decoder(message);
26 var result = decode(decoder); 31 var result = decode(decoder);
27 if (decoder.excessHandles != null) { 32 if (decoder.excessHandles != null) {
28 decoder.excessHandles.forEach((h) => h.close()); 33 decoder.excessHandles.forEach((h) => h.close());
29 } 34 }
30 return result; 35 return result;
31 } 36 }
32 37
33 static _HttpServerSetHandlerParams decode(bindings.Decoder decoder0) { 38 static _HttpServerSetHandlerParams decode(bindings.Decoder decoder0) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 102
98 103
99 class HttpServerSetHandlerResponseParams extends bindings.Struct { 104 class HttpServerSetHandlerResponseParams extends bindings.Struct {
100 static const List<bindings.StructDataHeader> kVersions = const [ 105 static const List<bindings.StructDataHeader> kVersions = const [
101 const bindings.StructDataHeader(16, 0) 106 const bindings.StructDataHeader(16, 0)
102 ]; 107 ];
103 bool success = false; 108 bool success = false;
104 109
105 HttpServerSetHandlerResponseParams() : super(kVersions.last.size); 110 HttpServerSetHandlerResponseParams() : super(kVersions.last.size);
106 111
112 HttpServerSetHandlerResponseParams.init(
113 bool this.success
114 ) : super(kVersions.last.size);
115
107 static HttpServerSetHandlerResponseParams deserialize(bindings.Message message ) { 116 static HttpServerSetHandlerResponseParams deserialize(bindings.Message message ) {
108 var decoder = new bindings.Decoder(message); 117 var decoder = new bindings.Decoder(message);
109 var result = decode(decoder); 118 var result = decode(decoder);
110 if (decoder.excessHandles != null) { 119 if (decoder.excessHandles != null) {
111 decoder.excessHandles.forEach((h) => h.close()); 120 decoder.excessHandles.forEach((h) => h.close());
112 } 121 }
113 return result; 122 return result;
114 } 123 }
115 124
116 static HttpServerSetHandlerResponseParams decode(bindings.Decoder decoder0) { 125 static HttpServerSetHandlerResponseParams decode(bindings.Decoder decoder0) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 } 177 }
169 178
170 179
171 class _HttpServerGetPortParams extends bindings.Struct { 180 class _HttpServerGetPortParams extends bindings.Struct {
172 static const List<bindings.StructDataHeader> kVersions = const [ 181 static const List<bindings.StructDataHeader> kVersions = const [
173 const bindings.StructDataHeader(8, 0) 182 const bindings.StructDataHeader(8, 0)
174 ]; 183 ];
175 184
176 _HttpServerGetPortParams() : super(kVersions.last.size); 185 _HttpServerGetPortParams() : super(kVersions.last.size);
177 186
187 _HttpServerGetPortParams.init(
188 ) : super(kVersions.last.size);
189
178 static _HttpServerGetPortParams deserialize(bindings.Message message) { 190 static _HttpServerGetPortParams deserialize(bindings.Message message) {
179 var decoder = new bindings.Decoder(message); 191 var decoder = new bindings.Decoder(message);
180 var result = decode(decoder); 192 var result = decode(decoder);
181 if (decoder.excessHandles != null) { 193 if (decoder.excessHandles != null) {
182 decoder.excessHandles.forEach((h) => h.close()); 194 decoder.excessHandles.forEach((h) => h.close());
183 } 195 }
184 return result; 196 return result;
185 } 197 }
186 198
187 static _HttpServerGetPortParams decode(bindings.Decoder decoder0) { 199 static _HttpServerGetPortParams decode(bindings.Decoder decoder0) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 239
228 240
229 class HttpServerGetPortResponseParams extends bindings.Struct { 241 class HttpServerGetPortResponseParams extends bindings.Struct {
230 static const List<bindings.StructDataHeader> kVersions = const [ 242 static const List<bindings.StructDataHeader> kVersions = const [
231 const bindings.StructDataHeader(16, 0) 243 const bindings.StructDataHeader(16, 0)
232 ]; 244 ];
233 int port = 0; 245 int port = 0;
234 246
235 HttpServerGetPortResponseParams() : super(kVersions.last.size); 247 HttpServerGetPortResponseParams() : super(kVersions.last.size);
236 248
249 HttpServerGetPortResponseParams.init(
250 int this.port
251 ) : super(kVersions.last.size);
252
237 static HttpServerGetPortResponseParams deserialize(bindings.Message message) { 253 static HttpServerGetPortResponseParams deserialize(bindings.Message message) {
238 var decoder = new bindings.Decoder(message); 254 var decoder = new bindings.Decoder(message);
239 var result = decode(decoder); 255 var result = decode(decoder);
240 if (decoder.excessHandles != null) { 256 if (decoder.excessHandles != null) {
241 decoder.excessHandles.forEach((h) => h.close()); 257 decoder.excessHandles.forEach((h) => h.close());
242 } 258 }
243 return result; 259 return result;
244 } 260 }
245 261
246 static HttpServerGetPortResponseParams decode(bindings.Decoder decoder0) { 262 static HttpServerGetPortResponseParams decode(bindings.Decoder decoder0) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 315
300 316
301 class _HttpHandlerHandleRequestParams extends bindings.Struct { 317 class _HttpHandlerHandleRequestParams extends bindings.Struct {
302 static const List<bindings.StructDataHeader> kVersions = const [ 318 static const List<bindings.StructDataHeader> kVersions = const [
303 const bindings.StructDataHeader(16, 0) 319 const bindings.StructDataHeader(16, 0)
304 ]; 320 ];
305 http_request_mojom.HttpRequest request = null; 321 http_request_mojom.HttpRequest request = null;
306 322
307 _HttpHandlerHandleRequestParams() : super(kVersions.last.size); 323 _HttpHandlerHandleRequestParams() : super(kVersions.last.size);
308 324
325 _HttpHandlerHandleRequestParams.init(
326 http_request_mojom.HttpRequest this.request
327 ) : super(kVersions.last.size);
328
309 static _HttpHandlerHandleRequestParams deserialize(bindings.Message message) { 329 static _HttpHandlerHandleRequestParams deserialize(bindings.Message message) {
310 var decoder = new bindings.Decoder(message); 330 var decoder = new bindings.Decoder(message);
311 var result = decode(decoder); 331 var result = decode(decoder);
312 if (decoder.excessHandles != null) { 332 if (decoder.excessHandles != null) {
313 decoder.excessHandles.forEach((h) => h.close()); 333 decoder.excessHandles.forEach((h) => h.close());
314 } 334 }
315 return result; 335 return result;
316 } 336 }
317 337
318 static _HttpHandlerHandleRequestParams decode(bindings.Decoder decoder0) { 338 static _HttpHandlerHandleRequestParams decode(bindings.Decoder decoder0) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 391
372 392
373 class HttpHandlerHandleRequestResponseParams extends bindings.Struct { 393 class HttpHandlerHandleRequestResponseParams extends bindings.Struct {
374 static const List<bindings.StructDataHeader> kVersions = const [ 394 static const List<bindings.StructDataHeader> kVersions = const [
375 const bindings.StructDataHeader(16, 0) 395 const bindings.StructDataHeader(16, 0)
376 ]; 396 ];
377 http_response_mojom.HttpResponse response = null; 397 http_response_mojom.HttpResponse response = null;
378 398
379 HttpHandlerHandleRequestResponseParams() : super(kVersions.last.size); 399 HttpHandlerHandleRequestResponseParams() : super(kVersions.last.size);
380 400
401 HttpHandlerHandleRequestResponseParams.init(
402 http_response_mojom.HttpResponse this.response
403 ) : super(kVersions.last.size);
404
381 static HttpHandlerHandleRequestResponseParams deserialize(bindings.Message mes sage) { 405 static HttpHandlerHandleRequestResponseParams deserialize(bindings.Message mes sage) {
382 var decoder = new bindings.Decoder(message); 406 var decoder = new bindings.Decoder(message);
383 var result = decode(decoder); 407 var result = decode(decoder);
384 if (decoder.excessHandles != null) { 408 if (decoder.excessHandles != null) {
385 decoder.excessHandles.forEach((h) => h.close()); 409 decoder.excessHandles.forEach((h) => h.close());
386 } 410 }
387 return result; 411 return result;
388 } 412 }
389 413
390 static HttpHandlerHandleRequestResponseParams decode(bindings.Decoder decoder0 ) { 414 static HttpHandlerHandleRequestResponseParams decode(bindings.Decoder decoder0 ) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 Map toJson() { 462 Map toJson() {
439 throw new bindings.MojoCodecError( 463 throw new bindings.MojoCodecError(
440 'Object containing handles cannot be encoded to JSON.'); 464 'Object containing handles cannot be encoded to JSON.');
441 } 465 }
442 } 466 }
443 467
444 const int _httpServerMethodSetHandlerName = 0; 468 const int _httpServerMethodSetHandlerName = 0;
445 const int _httpServerMethodGetPortName = 1; 469 const int _httpServerMethodGetPortName = 1;
446 470
447 class _HttpServerServiceDescription implements service_describer.ServiceDescript ion { 471 class _HttpServerServiceDescription implements service_describer.ServiceDescript ion {
448 dynamic getTopLevelInterface([Function responseFactory]) => 472 void getTopLevelInterface(Function responder) {
449 responseFactory(null); 473 responder(null);
474 }
450 475
451 dynamic getTypeDefinition(String typeKey, [Function responseFactory]) => 476 void getTypeDefinition(String typeKey, Function responder) {
452 responseFactory(null); 477 responder(null);
478 }
453 479
454 dynamic getAllTypeDefinitions([Function responseFactory]) => 480 void getAllTypeDefinitions(Function responder) {
455 responseFactory(null); 481 responder(null);
482 }
456 } 483 }
457 484
458 abstract class HttpServer { 485 abstract class HttpServer {
459 static const String serviceName = null; 486 static const String serviceName = null;
460 487
461 static service_describer.ServiceDescription _cachedServiceDescription; 488 static service_describer.ServiceDescription _cachedServiceDescription;
462 static service_describer.ServiceDescription get serviceDescription { 489 static service_describer.ServiceDescription get serviceDescription {
463 if (_cachedServiceDescription == null) { 490 if (_cachedServiceDescription == null) {
464 _cachedServiceDescription = new _HttpServerServiceDescription(); 491 _cachedServiceDescription = new _HttpServerServiceDescription();
465 } 492 }
466 return _cachedServiceDescription; 493 return _cachedServiceDescription;
467 } 494 }
468 495
469 static HttpServerProxy connectToService( 496 static HttpServerProxy connectToService(
470 bindings.ServiceConnector s, String url, [String serviceName]) { 497 bindings.ServiceConnector s, String url, [String serviceName]) {
471 HttpServerProxy p = new HttpServerProxy.unbound(); 498 HttpServerProxy p = new HttpServerProxy.unbound();
472 String name = serviceName ?? HttpServer.serviceName; 499 String name = serviceName ?? HttpServer.serviceName;
473 if ((name == null) || name.isEmpty) { 500 if ((name == null) || name.isEmpty) {
474 throw new core.MojoApiError( 501 throw new core.MojoApiError(
475 "If an interface has no ServiceName, then one must be provided."); 502 "If an interface has no ServiceName, then one must be provided.");
476 } 503 }
477 s.connectToService(url, p, name); 504 s.connectToService(url, p, name);
478 return p; 505 return p;
479 } 506 }
480 dynamic setHandler(String pattern,HttpHandlerInterface handler,[Function respo nseFactory = null]); 507 void setHandler(String pattern,HttpHandlerInterface handler,void callback(bool success));
481 dynamic getPort([Function responseFactory = null]); 508 void getPort(void callback(int port));
482 } 509 }
483 510
484 abstract class HttpServerInterface 511 abstract class HttpServerInterface
485 implements bindings.MojoInterface<HttpServer>, 512 implements bindings.MojoInterface<HttpServer>,
486 HttpServer { 513 HttpServer {
487 factory HttpServerInterface([HttpServer impl]) => 514 factory HttpServerInterface([HttpServer impl]) =>
488 new HttpServerStub.unbound(impl); 515 new HttpServerStub.unbound(impl);
489 factory HttpServerInterface.fromEndpoint( 516 factory HttpServerInterface.fromEndpoint(
490 core.MojoMessagePipeEndpoint endpoint, 517 core.MojoMessagePipeEndpoint endpoint,
491 [HttpServer impl]) => 518 [HttpServer impl]) =>
(...skipping 22 matching lines...) Expand all
514 541
515 void handleResponse(bindings.ServiceMessage message) { 542 void handleResponse(bindings.ServiceMessage message) {
516 switch (message.header.type) { 543 switch (message.header.type) {
517 case _httpServerMethodSetHandlerName: 544 case _httpServerMethodSetHandlerName:
518 var r = HttpServerSetHandlerResponseParams.deserialize( 545 var r = HttpServerSetHandlerResponseParams.deserialize(
519 message.payload); 546 message.payload);
520 if (!message.header.hasRequestId) { 547 if (!message.header.hasRequestId) {
521 proxyError("Expected a message with a valid request Id."); 548 proxyError("Expected a message with a valid request Id.");
522 return; 549 return;
523 } 550 }
524 Completer c = completerMap[message.header.requestId]; 551 Function callback = callbackMap[message.header.requestId];
525 if (c == null) { 552 if (callback == null) {
526 proxyError( 553 proxyError(
527 "Message had unknown request Id: ${message.header.requestId}"); 554 "Message had unknown request Id: ${message.header.requestId}");
528 return; 555 return;
529 } 556 }
530 completerMap.remove(message.header.requestId); 557 callbackMap.remove(message.header.requestId);
531 if (c.isCompleted) { 558 callback(r.success );
532 proxyError("Response completer already completed");
533 return;
534 }
535 c.complete(r);
536 break; 559 break;
537 case _httpServerMethodGetPortName: 560 case _httpServerMethodGetPortName:
538 var r = HttpServerGetPortResponseParams.deserialize( 561 var r = HttpServerGetPortResponseParams.deserialize(
539 message.payload); 562 message.payload);
540 if (!message.header.hasRequestId) { 563 if (!message.header.hasRequestId) {
541 proxyError("Expected a message with a valid request Id."); 564 proxyError("Expected a message with a valid request Id.");
542 return; 565 return;
543 } 566 }
544 Completer c = completerMap[message.header.requestId]; 567 Function callback = callbackMap[message.header.requestId];
545 if (c == null) { 568 if (callback == null) {
546 proxyError( 569 proxyError(
547 "Message had unknown request Id: ${message.header.requestId}"); 570 "Message had unknown request Id: ${message.header.requestId}");
548 return; 571 return;
549 } 572 }
550 completerMap.remove(message.header.requestId); 573 callbackMap.remove(message.header.requestId);
551 if (c.isCompleted) { 574 callback(r.port );
552 proxyError("Response completer already completed");
553 return;
554 }
555 c.complete(r);
556 break; 575 break;
557 default: 576 default:
558 proxyError("Unexpected message type: ${message.header.type}"); 577 proxyError("Unexpected message type: ${message.header.type}");
559 close(immediate: true); 578 close(immediate: true);
560 break; 579 break;
561 } 580 }
562 } 581 }
563 582
564 HttpServer get impl => null; 583 HttpServer get impl => null;
565 set impl(HttpServer _) { 584 set impl(HttpServer _) {
(...skipping 22 matching lines...) Expand all
588 HttpServerProxy.unbound() 607 HttpServerProxy.unbound()
589 : super(new _HttpServerProxyControl.unbound()); 608 : super(new _HttpServerProxyControl.unbound());
590 609
591 static HttpServerProxy newFromEndpoint( 610 static HttpServerProxy newFromEndpoint(
592 core.MojoMessagePipeEndpoint endpoint) { 611 core.MojoMessagePipeEndpoint endpoint) {
593 assert(endpoint.setDescription("For HttpServerProxy")); 612 assert(endpoint.setDescription("For HttpServerProxy"));
594 return new HttpServerProxy.fromEndpoint(endpoint); 613 return new HttpServerProxy.fromEndpoint(endpoint);
595 } 614 }
596 615
597 616
598 dynamic setHandler(String pattern,HttpHandlerInterface handler,[Function respo nseFactory = null]) { 617 void setHandler(String pattern,HttpHandlerInterface handler,void callback(bool success)) {
599 var params = new _HttpServerSetHandlerParams(); 618 var params = new _HttpServerSetHandlerParams();
600 params.pattern = pattern; 619 params.pattern = pattern;
601 params.handler = handler; 620 params.handler = handler;
602 return ctrl.sendMessageWithRequestId( 621 ctrl.sendMessageWithRequestId(
603 params, 622 params,
604 _httpServerMethodSetHandlerName, 623 _httpServerMethodSetHandlerName,
605 -1, 624 -1,
606 bindings.MessageHeader.kMessageExpectsResponse); 625 bindings.MessageHeader.kMessageExpectsResponse,
626 callback);
607 } 627 }
608 dynamic getPort([Function responseFactory = null]) { 628 void getPort(void callback(int port)) {
609 var params = new _HttpServerGetPortParams(); 629 var params = new _HttpServerGetPortParams();
610 return ctrl.sendMessageWithRequestId( 630 ctrl.sendMessageWithRequestId(
611 params, 631 params,
612 _httpServerMethodGetPortName, 632 _httpServerMethodGetPortName,
613 -1, 633 -1,
614 bindings.MessageHeader.kMessageExpectsResponse); 634 bindings.MessageHeader.kMessageExpectsResponse,
635 callback);
615 } 636 }
616 } 637 }
617 638
618 class _HttpServerStubControl 639 class _HttpServerStubControl
619 extends bindings.StubMessageHandler 640 extends bindings.StubMessageHandler
620 implements bindings.StubControl<HttpServer> { 641 implements bindings.StubControl<HttpServer> {
621 HttpServer _impl; 642 HttpServer _impl;
622 643
623 _HttpServerStubControl.fromEndpoint( 644 _HttpServerStubControl.fromEndpoint(
624 core.MojoMessagePipeEndpoint endpoint, [HttpServer impl]) 645 core.MojoMessagePipeEndpoint endpoint, [HttpServer impl])
625 : super.fromEndpoint(endpoint, autoBegin: impl != null) { 646 : super.fromEndpoint(endpoint, autoBegin: impl != null) {
626 _impl = impl; 647 _impl = impl;
627 } 648 }
628 649
629 _HttpServerStubControl.fromHandle( 650 _HttpServerStubControl.fromHandle(
630 core.MojoHandle handle, [HttpServer impl]) 651 core.MojoHandle handle, [HttpServer impl])
631 : super.fromHandle(handle, autoBegin: impl != null) { 652 : super.fromHandle(handle, autoBegin: impl != null) {
632 _impl = impl; 653 _impl = impl;
633 } 654 }
634 655
635 _HttpServerStubControl.unbound([this._impl]) : super.unbound(); 656 _HttpServerStubControl.unbound([this._impl]) : super.unbound();
636 657
637 String get serviceName => HttpServer.serviceName; 658 String get serviceName => HttpServer.serviceName;
638 659
639 660
640 HttpServerSetHandlerResponseParams _httpServerSetHandlerResponseParamsFactory( bool success) { 661 Function _httpServerSetHandlerResponseParamsResponder(
641 var result = new HttpServerSetHandlerResponseParams(); 662 int requestId) {
642 result.success = success; 663 return (bool success) {
643 return result; 664 var result = new HttpServerSetHandlerResponseParams();
665 result.success = success;
666 sendResponse(buildResponseWithId(
667 result,
668 _httpServerMethodSetHandlerName,
669 requestId,
670 bindings.MessageHeader.kMessageIsResponse));
671 };
644 } 672 }
645 HttpServerGetPortResponseParams _httpServerGetPortResponseParamsFactory(int po rt) { 673 Function _httpServerGetPortResponseParamsResponder(
646 var result = new HttpServerGetPortResponseParams(); 674 int requestId) {
647 result.port = port; 675 return (int port) {
648 return result; 676 var result = new HttpServerGetPortResponseParams();
677 result.port = port;
678 sendResponse(buildResponseWithId(
679 result,
680 _httpServerMethodGetPortName,
681 requestId,
682 bindings.MessageHeader.kMessageIsResponse));
683 };
649 } 684 }
650 685
651 dynamic handleMessage(bindings.ServiceMessage message) { 686 void handleMessage(bindings.ServiceMessage message) {
652 if (bindings.ControlMessageHandler.isControlMessage(message)) { 687 if (bindings.ControlMessageHandler.isControlMessage(message)) {
653 return bindings.ControlMessageHandler.handleMessage(this, 688 bindings.ControlMessageHandler.handleMessage(
654 0, 689 this, 0, message);
655 message); 690 return;
656 } 691 }
657 if (_impl == null) { 692 if (_impl == null) {
658 throw new core.MojoApiError("$this has no implementation set"); 693 throw new core.MojoApiError("$this has no implementation set");
659 } 694 }
660 switch (message.header.type) { 695 switch (message.header.type) {
661 case _httpServerMethodSetHandlerName: 696 case _httpServerMethodSetHandlerName:
662 var params = _HttpServerSetHandlerParams.deserialize( 697 var params = _HttpServerSetHandlerParams.deserialize(
663 message.payload); 698 message.payload);
664 var response = _impl.setHandler(params.pattern,params.handler,_httpServe rSetHandlerResponseParamsFactory); 699 _impl.setHandler(params.pattern, params.handler, _httpServerSetHandlerRe sponseParamsResponder(message.header.requestId));
665 if (response is Future) {
666 return response.then((response) {
667 if (response != null) {
668 return buildResponseWithId(
669 response,
670 _httpServerMethodSetHandlerName,
671 message.header.requestId,
672 bindings.MessageHeader.kMessageIsResponse);
673 }
674 });
675 } else if (response != null) {
676 return buildResponseWithId(
677 response,
678 _httpServerMethodSetHandlerName,
679 message.header.requestId,
680 bindings.MessageHeader.kMessageIsResponse);
681 }
682 break; 700 break;
683 case _httpServerMethodGetPortName: 701 case _httpServerMethodGetPortName:
684 var response = _impl.getPort(_httpServerGetPortResponseParamsFactory); 702 _impl.getPort(_httpServerGetPortResponseParamsResponder(message.header.r equestId));
685 if (response is Future) {
686 return response.then((response) {
687 if (response != null) {
688 return buildResponseWithId(
689 response,
690 _httpServerMethodGetPortName,
691 message.header.requestId,
692 bindings.MessageHeader.kMessageIsResponse);
693 }
694 });
695 } else if (response != null) {
696 return buildResponseWithId(
697 response,
698 _httpServerMethodGetPortName,
699 message.header.requestId,
700 bindings.MessageHeader.kMessageIsResponse);
701 }
702 break; 703 break;
703 default: 704 default:
704 throw new bindings.MojoCodecError("Unexpected message name"); 705 throw new bindings.MojoCodecError("Unexpected message name");
705 break; 706 break;
706 } 707 }
707 return null;
708 } 708 }
709 709
710 HttpServer get impl => _impl; 710 HttpServer get impl => _impl;
711 set impl(HttpServer d) { 711 set impl(HttpServer d) {
712 if (d == null) { 712 if (d == null) {
713 throw new core.MojoApiError("$this: Cannot set a null implementation"); 713 throw new core.MojoApiError("$this: Cannot set a null implementation");
714 } 714 }
715 if (isBound && (_impl == null)) { 715 if (isBound && (_impl == null)) {
716 beginHandlingEvents(); 716 beginHandlingEvents();
717 } 717 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 core.MojoHandle handle, [HttpServer impl]) 751 core.MojoHandle handle, [HttpServer impl])
752 : super(new _HttpServerStubControl.fromHandle(handle, impl)); 752 : super(new _HttpServerStubControl.fromHandle(handle, impl));
753 753
754 static HttpServerStub newFromEndpoint( 754 static HttpServerStub newFromEndpoint(
755 core.MojoMessagePipeEndpoint endpoint) { 755 core.MojoMessagePipeEndpoint endpoint) {
756 assert(endpoint.setDescription("For HttpServerStub")); 756 assert(endpoint.setDescription("For HttpServerStub"));
757 return new HttpServerStub.fromEndpoint(endpoint); 757 return new HttpServerStub.fromEndpoint(endpoint);
758 } 758 }
759 759
760 760
761 dynamic setHandler(String pattern,HttpHandlerInterface handler,[Function respo nseFactory = null]) { 761 void setHandler(String pattern,HttpHandlerInterface handler,void callback(bool success)) {
762 return impl.setHandler(pattern,handler,responseFactory); 762 return impl.setHandler(pattern,handler,callback);
763 } 763 }
764 dynamic getPort([Function responseFactory = null]) { 764 void getPort(void callback(int port)) {
765 return impl.getPort(responseFactory); 765 return impl.getPort(callback);
766 } 766 }
767 } 767 }
768 768
769 const int _httpHandlerMethodHandleRequestName = 0; 769 const int _httpHandlerMethodHandleRequestName = 0;
770 770
771 class _HttpHandlerServiceDescription implements service_describer.ServiceDescrip tion { 771 class _HttpHandlerServiceDescription implements service_describer.ServiceDescrip tion {
772 dynamic getTopLevelInterface([Function responseFactory]) => 772 void getTopLevelInterface(Function responder) {
773 responseFactory(null); 773 responder(null);
774 }
774 775
775 dynamic getTypeDefinition(String typeKey, [Function responseFactory]) => 776 void getTypeDefinition(String typeKey, Function responder) {
776 responseFactory(null); 777 responder(null);
778 }
777 779
778 dynamic getAllTypeDefinitions([Function responseFactory]) => 780 void getAllTypeDefinitions(Function responder) {
779 responseFactory(null); 781 responder(null);
782 }
780 } 783 }
781 784
782 abstract class HttpHandler { 785 abstract class HttpHandler {
783 static const String serviceName = null; 786 static const String serviceName = null;
784 787
785 static service_describer.ServiceDescription _cachedServiceDescription; 788 static service_describer.ServiceDescription _cachedServiceDescription;
786 static service_describer.ServiceDescription get serviceDescription { 789 static service_describer.ServiceDescription get serviceDescription {
787 if (_cachedServiceDescription == null) { 790 if (_cachedServiceDescription == null) {
788 _cachedServiceDescription = new _HttpHandlerServiceDescription(); 791 _cachedServiceDescription = new _HttpHandlerServiceDescription();
789 } 792 }
790 return _cachedServiceDescription; 793 return _cachedServiceDescription;
791 } 794 }
792 795
793 static HttpHandlerProxy connectToService( 796 static HttpHandlerProxy connectToService(
794 bindings.ServiceConnector s, String url, [String serviceName]) { 797 bindings.ServiceConnector s, String url, [String serviceName]) {
795 HttpHandlerProxy p = new HttpHandlerProxy.unbound(); 798 HttpHandlerProxy p = new HttpHandlerProxy.unbound();
796 String name = serviceName ?? HttpHandler.serviceName; 799 String name = serviceName ?? HttpHandler.serviceName;
797 if ((name == null) || name.isEmpty) { 800 if ((name == null) || name.isEmpty) {
798 throw new core.MojoApiError( 801 throw new core.MojoApiError(
799 "If an interface has no ServiceName, then one must be provided."); 802 "If an interface has no ServiceName, then one must be provided.");
800 } 803 }
801 s.connectToService(url, p, name); 804 s.connectToService(url, p, name);
802 return p; 805 return p;
803 } 806 }
804 dynamic handleRequest(http_request_mojom.HttpRequest request,[Function respons eFactory = null]); 807 void handleRequest(http_request_mojom.HttpRequest request,void callback(http_r esponse_mojom.HttpResponse response));
805 } 808 }
806 809
807 abstract class HttpHandlerInterface 810 abstract class HttpHandlerInterface
808 implements bindings.MojoInterface<HttpHandler>, 811 implements bindings.MojoInterface<HttpHandler>,
809 HttpHandler { 812 HttpHandler {
810 factory HttpHandlerInterface([HttpHandler impl]) => 813 factory HttpHandlerInterface([HttpHandler impl]) =>
811 new HttpHandlerStub.unbound(impl); 814 new HttpHandlerStub.unbound(impl);
812 factory HttpHandlerInterface.fromEndpoint( 815 factory HttpHandlerInterface.fromEndpoint(
813 core.MojoMessagePipeEndpoint endpoint, 816 core.MojoMessagePipeEndpoint endpoint,
814 [HttpHandler impl]) => 817 [HttpHandler impl]) =>
(...skipping 22 matching lines...) Expand all
837 840
838 void handleResponse(bindings.ServiceMessage message) { 841 void handleResponse(bindings.ServiceMessage message) {
839 switch (message.header.type) { 842 switch (message.header.type) {
840 case _httpHandlerMethodHandleRequestName: 843 case _httpHandlerMethodHandleRequestName:
841 var r = HttpHandlerHandleRequestResponseParams.deserialize( 844 var r = HttpHandlerHandleRequestResponseParams.deserialize(
842 message.payload); 845 message.payload);
843 if (!message.header.hasRequestId) { 846 if (!message.header.hasRequestId) {
844 proxyError("Expected a message with a valid request Id."); 847 proxyError("Expected a message with a valid request Id.");
845 return; 848 return;
846 } 849 }
847 Completer c = completerMap[message.header.requestId]; 850 Function callback = callbackMap[message.header.requestId];
848 if (c == null) { 851 if (callback == null) {
849 proxyError( 852 proxyError(
850 "Message had unknown request Id: ${message.header.requestId}"); 853 "Message had unknown request Id: ${message.header.requestId}");
851 return; 854 return;
852 } 855 }
853 completerMap.remove(message.header.requestId); 856 callbackMap.remove(message.header.requestId);
854 if (c.isCompleted) { 857 callback(r.response );
855 proxyError("Response completer already completed");
856 return;
857 }
858 c.complete(r);
859 break; 858 break;
860 default: 859 default:
861 proxyError("Unexpected message type: ${message.header.type}"); 860 proxyError("Unexpected message type: ${message.header.type}");
862 close(immediate: true); 861 close(immediate: true);
863 break; 862 break;
864 } 863 }
865 } 864 }
866 865
867 HttpHandler get impl => null; 866 HttpHandler get impl => null;
868 set impl(HttpHandler _) { 867 set impl(HttpHandler _) {
(...skipping 22 matching lines...) Expand all
891 HttpHandlerProxy.unbound() 890 HttpHandlerProxy.unbound()
892 : super(new _HttpHandlerProxyControl.unbound()); 891 : super(new _HttpHandlerProxyControl.unbound());
893 892
894 static HttpHandlerProxy newFromEndpoint( 893 static HttpHandlerProxy newFromEndpoint(
895 core.MojoMessagePipeEndpoint endpoint) { 894 core.MojoMessagePipeEndpoint endpoint) {
896 assert(endpoint.setDescription("For HttpHandlerProxy")); 895 assert(endpoint.setDescription("For HttpHandlerProxy"));
897 return new HttpHandlerProxy.fromEndpoint(endpoint); 896 return new HttpHandlerProxy.fromEndpoint(endpoint);
898 } 897 }
899 898
900 899
901 dynamic handleRequest(http_request_mojom.HttpRequest request,[Function respons eFactory = null]) { 900 void handleRequest(http_request_mojom.HttpRequest request,void callback(http_r esponse_mojom.HttpResponse response)) {
902 var params = new _HttpHandlerHandleRequestParams(); 901 var params = new _HttpHandlerHandleRequestParams();
903 params.request = request; 902 params.request = request;
904 return ctrl.sendMessageWithRequestId( 903 ctrl.sendMessageWithRequestId(
905 params, 904 params,
906 _httpHandlerMethodHandleRequestName, 905 _httpHandlerMethodHandleRequestName,
907 -1, 906 -1,
908 bindings.MessageHeader.kMessageExpectsResponse); 907 bindings.MessageHeader.kMessageExpectsResponse,
908 callback);
909 } 909 }
910 } 910 }
911 911
912 class _HttpHandlerStubControl 912 class _HttpHandlerStubControl
913 extends bindings.StubMessageHandler 913 extends bindings.StubMessageHandler
914 implements bindings.StubControl<HttpHandler> { 914 implements bindings.StubControl<HttpHandler> {
915 HttpHandler _impl; 915 HttpHandler _impl;
916 916
917 _HttpHandlerStubControl.fromEndpoint( 917 _HttpHandlerStubControl.fromEndpoint(
918 core.MojoMessagePipeEndpoint endpoint, [HttpHandler impl]) 918 core.MojoMessagePipeEndpoint endpoint, [HttpHandler impl])
919 : super.fromEndpoint(endpoint, autoBegin: impl != null) { 919 : super.fromEndpoint(endpoint, autoBegin: impl != null) {
920 _impl = impl; 920 _impl = impl;
921 } 921 }
922 922
923 _HttpHandlerStubControl.fromHandle( 923 _HttpHandlerStubControl.fromHandle(
924 core.MojoHandle handle, [HttpHandler impl]) 924 core.MojoHandle handle, [HttpHandler impl])
925 : super.fromHandle(handle, autoBegin: impl != null) { 925 : super.fromHandle(handle, autoBegin: impl != null) {
926 _impl = impl; 926 _impl = impl;
927 } 927 }
928 928
929 _HttpHandlerStubControl.unbound([this._impl]) : super.unbound(); 929 _HttpHandlerStubControl.unbound([this._impl]) : super.unbound();
930 930
931 String get serviceName => HttpHandler.serviceName; 931 String get serviceName => HttpHandler.serviceName;
932 932
933 933
934 HttpHandlerHandleRequestResponseParams _httpHandlerHandleRequestResponseParams Factory(http_response_mojom.HttpResponse response) { 934 Function _httpHandlerHandleRequestResponseParamsResponder(
935 var result = new HttpHandlerHandleRequestResponseParams(); 935 int requestId) {
936 result.response = response; 936 return (http_response_mojom.HttpResponse response) {
937 return result; 937 var result = new HttpHandlerHandleRequestResponseParams();
938 result.response = response;
939 sendResponse(buildResponseWithId(
940 result,
941 _httpHandlerMethodHandleRequestName,
942 requestId,
943 bindings.MessageHeader.kMessageIsResponse));
944 };
938 } 945 }
939 946
940 dynamic handleMessage(bindings.ServiceMessage message) { 947 void handleMessage(bindings.ServiceMessage message) {
941 if (bindings.ControlMessageHandler.isControlMessage(message)) { 948 if (bindings.ControlMessageHandler.isControlMessage(message)) {
942 return bindings.ControlMessageHandler.handleMessage(this, 949 bindings.ControlMessageHandler.handleMessage(
943 0, 950 this, 0, message);
944 message); 951 return;
945 } 952 }
946 if (_impl == null) { 953 if (_impl == null) {
947 throw new core.MojoApiError("$this has no implementation set"); 954 throw new core.MojoApiError("$this has no implementation set");
948 } 955 }
949 switch (message.header.type) { 956 switch (message.header.type) {
950 case _httpHandlerMethodHandleRequestName: 957 case _httpHandlerMethodHandleRequestName:
951 var params = _HttpHandlerHandleRequestParams.deserialize( 958 var params = _HttpHandlerHandleRequestParams.deserialize(
952 message.payload); 959 message.payload);
953 var response = _impl.handleRequest(params.request,_httpHandlerHandleRequ estResponseParamsFactory); 960 _impl.handleRequest(params.request, _httpHandlerHandleRequestResponsePar amsResponder(message.header.requestId));
954 if (response is Future) {
955 return response.then((response) {
956 if (response != null) {
957 return buildResponseWithId(
958 response,
959 _httpHandlerMethodHandleRequestName,
960 message.header.requestId,
961 bindings.MessageHeader.kMessageIsResponse);
962 }
963 });
964 } else if (response != null) {
965 return buildResponseWithId(
966 response,
967 _httpHandlerMethodHandleRequestName,
968 message.header.requestId,
969 bindings.MessageHeader.kMessageIsResponse);
970 }
971 break; 961 break;
972 default: 962 default:
973 throw new bindings.MojoCodecError("Unexpected message name"); 963 throw new bindings.MojoCodecError("Unexpected message name");
974 break; 964 break;
975 } 965 }
976 return null;
977 } 966 }
978 967
979 HttpHandler get impl => _impl; 968 HttpHandler get impl => _impl;
980 set impl(HttpHandler d) { 969 set impl(HttpHandler d) {
981 if (d == null) { 970 if (d == null) {
982 throw new core.MojoApiError("$this: Cannot set a null implementation"); 971 throw new core.MojoApiError("$this: Cannot set a null implementation");
983 } 972 }
984 if (isBound && (_impl == null)) { 973 if (isBound && (_impl == null)) {
985 beginHandlingEvents(); 974 beginHandlingEvents();
986 } 975 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1020 core.MojoHandle handle, [HttpHandler impl]) 1009 core.MojoHandle handle, [HttpHandler impl])
1021 : super(new _HttpHandlerStubControl.fromHandle(handle, impl)); 1010 : super(new _HttpHandlerStubControl.fromHandle(handle, impl));
1022 1011
1023 static HttpHandlerStub newFromEndpoint( 1012 static HttpHandlerStub newFromEndpoint(
1024 core.MojoMessagePipeEndpoint endpoint) { 1013 core.MojoMessagePipeEndpoint endpoint) {
1025 assert(endpoint.setDescription("For HttpHandlerStub")); 1014 assert(endpoint.setDescription("For HttpHandlerStub"));
1026 return new HttpHandlerStub.fromEndpoint(endpoint); 1015 return new HttpHandlerStub.fromEndpoint(endpoint);
1027 } 1016 }
1028 1017
1029 1018
1030 dynamic handleRequest(http_request_mojom.HttpRequest request,[Function respons eFactory = null]) { 1019 void handleRequest(http_request_mojom.HttpRequest request,void callback(http_r esponse_mojom.HttpResponse response)) {
1031 return impl.handleRequest(request,responseFactory); 1020 return impl.handleRequest(request,callback);
1032 } 1021 }
1033 } 1022 }
1034 1023
1035 1024
1036 1025
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698