OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 library 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; |
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 dynamic getAllTypeDefinitions([Function responseFactory]) => | 454 dynamic getAllTypeDefinitions([Function responseFactory]) => |
455 responseFactory(null); | 455 responseFactory(null); |
456 } | 456 } |
457 | 457 |
458 abstract class HttpServer { | 458 abstract class HttpServer { |
459 static const String serviceName = null; | 459 static const String serviceName = null; |
460 dynamic setHandler(String pattern,Object handler,[Function responseFactory = n
ull]); | 460 dynamic setHandler(String pattern,Object handler,[Function responseFactory = n
ull]); |
461 dynamic getPort([Function responseFactory = null]); | 461 dynamic getPort([Function responseFactory = null]); |
462 } | 462 } |
463 | 463 |
464 | 464 class _HttpServerProxyControl |
465 class _HttpServerProxyControl extends bindings.ProxyMessageHandler | 465 extends bindings.ProxyMessageHandler |
466 implements bindings.ProxyControl { | 466 implements bindings.ProxyControl { |
467 _HttpServerProxyControl.fromEndpoint( | 467 _HttpServerProxyControl.fromEndpoint( |
468 core.MojoMessagePipeEndpoint endpoint) : super.fromEndpoint(endpoint); | 468 core.MojoMessagePipeEndpoint endpoint) : super.fromEndpoint(endpoint); |
469 | 469 |
470 _HttpServerProxyControl.fromHandle( | 470 _HttpServerProxyControl.fromHandle( |
471 core.MojoHandle handle) : super.fromHandle(handle); | 471 core.MojoHandle handle) : super.fromHandle(handle); |
472 | 472 |
473 _HttpServerProxyControl.unbound() : super.unbound(); | 473 _HttpServerProxyControl.unbound() : super.unbound(); |
474 | 474 |
475 service_describer.ServiceDescription get serviceDescription => | 475 service_describer.ServiceDescription get serviceDescription => |
476 new _HttpServerServiceDescription(); | 476 new _HttpServerServiceDescription(); |
477 | 477 |
478 String get serviceName => HttpServer.serviceName; | 478 String get serviceName => HttpServer.serviceName; |
479 | 479 |
480 @override | |
481 void handleResponse(bindings.ServiceMessage message) { | 480 void handleResponse(bindings.ServiceMessage message) { |
482 switch (message.header.type) { | 481 switch (message.header.type) { |
483 case _httpServerMethodSetHandlerName: | 482 case _httpServerMethodSetHandlerName: |
484 var r = HttpServerSetHandlerResponseParams.deserialize( | 483 var r = HttpServerSetHandlerResponseParams.deserialize( |
485 message.payload); | 484 message.payload); |
486 if (!message.header.hasRequestId) { | 485 if (!message.header.hasRequestId) { |
487 proxyError("Expected a message with a valid request Id."); | 486 proxyError("Expected a message with a valid request Id."); |
488 return; | 487 return; |
489 } | 488 } |
490 Completer c = completerMap[message.header.requestId]; | 489 Completer c = completerMap[message.header.requestId]; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 } | 526 } |
528 } | 527 } |
529 | 528 |
530 @override | 529 @override |
531 String toString() { | 530 String toString() { |
532 var superString = super.toString(); | 531 var superString = super.toString(); |
533 return "_HttpServerProxyControl($superString)"; | 532 return "_HttpServerProxyControl($superString)"; |
534 } | 533 } |
535 } | 534 } |
536 | 535 |
537 | 536 class HttpServerProxy |
538 class HttpServerProxy extends bindings.Proxy | 537 extends bindings.Proxy |
539 implements HttpServer { | 538 implements HttpServer { |
540 HttpServerProxy.fromEndpoint( | 539 HttpServerProxy.fromEndpoint( |
541 core.MojoMessagePipeEndpoint endpoint) | 540 core.MojoMessagePipeEndpoint endpoint) |
542 : super(new _HttpServerProxyControl.fromEndpoint(endpoint)); | 541 : super(new _HttpServerProxyControl.fromEndpoint(endpoint)); |
543 | 542 |
544 HttpServerProxy.fromHandle(core.MojoHandle handle) | 543 HttpServerProxy.fromHandle(core.MojoHandle handle) |
545 : super(new _HttpServerProxyControl.fromHandle(handle)); | 544 : super(new _HttpServerProxyControl.fromHandle(handle)); |
546 | 545 |
547 HttpServerProxy.unbound() | 546 HttpServerProxy.unbound() |
548 : super(new _HttpServerProxyControl.unbound()); | 547 : super(new _HttpServerProxyControl.unbound()); |
549 | 548 |
(...skipping 24 matching lines...) Expand all Loading... |
574 dynamic getPort([Function responseFactory = null]) { | 573 dynamic getPort([Function responseFactory = null]) { |
575 var params = new _HttpServerGetPortParams(); | 574 var params = new _HttpServerGetPortParams(); |
576 return ctrl.sendMessageWithRequestId( | 575 return ctrl.sendMessageWithRequestId( |
577 params, | 576 params, |
578 _httpServerMethodGetPortName, | 577 _httpServerMethodGetPortName, |
579 -1, | 578 -1, |
580 bindings.MessageHeader.kMessageExpectsResponse); | 579 bindings.MessageHeader.kMessageExpectsResponse); |
581 } | 580 } |
582 } | 581 } |
583 | 582 |
584 | 583 class _HttpServerStubControl |
585 class HttpServerStub extends bindings.Stub { | 584 extends bindings.StubMessageHandler |
| 585 implements bindings.StubControl<HttpServer> { |
586 HttpServer _impl; | 586 HttpServer _impl; |
587 | 587 |
588 HttpServerStub.fromEndpoint( | 588 _HttpServerStubControl.fromEndpoint( |
589 core.MojoMessagePipeEndpoint endpoint, [HttpServer impl]) | 589 core.MojoMessagePipeEndpoint endpoint, [HttpServer impl]) |
590 : super.fromEndpoint(endpoint, autoBegin: impl != null) { | 590 : super.fromEndpoint(endpoint, autoBegin: impl != null) { |
591 _impl = impl; | 591 _impl = impl; |
592 } | 592 } |
593 | 593 |
594 HttpServerStub.fromHandle( | 594 _HttpServerStubControl.fromHandle( |
595 core.MojoHandle handle, [HttpServer impl]) | 595 core.MojoHandle handle, [HttpServer impl]) |
596 : super.fromHandle(handle, autoBegin: impl != null) { | 596 : super.fromHandle(handle, autoBegin: impl != null) { |
597 _impl = impl; | 597 _impl = impl; |
598 } | 598 } |
599 | 599 |
600 HttpServerStub.unbound([this._impl]) : super.unbound(); | 600 _HttpServerStubControl.unbound([this._impl]) : super.unbound(); |
601 | |
602 static HttpServerStub newFromEndpoint( | |
603 core.MojoMessagePipeEndpoint endpoint) { | |
604 assert(endpoint.setDescription("For HttpServerStub")); | |
605 return new HttpServerStub.fromEndpoint(endpoint); | |
606 } | |
607 | 601 |
608 | 602 |
609 HttpServerSetHandlerResponseParams _httpServerSetHandlerResponseParamsFactory(
bool success) { | 603 HttpServerSetHandlerResponseParams _httpServerSetHandlerResponseParamsFactory(
bool success) { |
610 var result = new HttpServerSetHandlerResponseParams(); | 604 var result = new HttpServerSetHandlerResponseParams(); |
611 result.success = success; | 605 result.success = success; |
612 return result; | 606 return result; |
613 } | 607 } |
614 HttpServerGetPortResponseParams _httpServerGetPortResponseParamsFactory(int po
rt) { | 608 HttpServerGetPortResponseParams _httpServerGetPortResponseParamsFactory(int po
rt) { |
615 var result = new HttpServerGetPortResponseParams(); | 609 var result = new HttpServerGetPortResponseParams(); |
616 result.port = port; | 610 result.port = port; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
688 } | 682 } |
689 | 683 |
690 @override | 684 @override |
691 void bind(core.MojoMessagePipeEndpoint endpoint) { | 685 void bind(core.MojoMessagePipeEndpoint endpoint) { |
692 super.bind(endpoint); | 686 super.bind(endpoint); |
693 if (!isOpen && (_impl != null)) { | 687 if (!isOpen && (_impl != null)) { |
694 beginHandlingEvents(); | 688 beginHandlingEvents(); |
695 } | 689 } |
696 } | 690 } |
697 | 691 |
| 692 @override |
698 String toString() { | 693 String toString() { |
699 var superString = super.toString(); | 694 var superString = super.toString(); |
700 return "HttpServerStub($superString)"; | 695 return "_HttpServerStubControl($superString)"; |
701 } | 696 } |
702 | 697 |
703 int get version => 0; | 698 int get version => 0; |
704 | 699 |
705 static service_describer.ServiceDescription _cachedServiceDescription; | 700 static service_describer.ServiceDescription _cachedServiceDescription; |
706 static service_describer.ServiceDescription get serviceDescription { | 701 static service_describer.ServiceDescription get serviceDescription { |
707 if (_cachedServiceDescription == null) { | 702 if (_cachedServiceDescription == null) { |
708 _cachedServiceDescription = new _HttpServerServiceDescription(); | 703 _cachedServiceDescription = new _HttpServerServiceDescription(); |
709 } | 704 } |
710 return _cachedServiceDescription; | 705 return _cachedServiceDescription; |
711 } | 706 } |
712 } | 707 } |
713 | 708 |
| 709 class HttpServerStub |
| 710 extends bindings.Stub<HttpServer> |
| 711 implements HttpServer { |
| 712 HttpServerStub.fromEndpoint( |
| 713 core.MojoMessagePipeEndpoint endpoint, [HttpServer impl]) |
| 714 : super(new _HttpServerStubControl.fromEndpoint(endpoint, impl)); |
| 715 |
| 716 HttpServerStub.fromHandle( |
| 717 core.MojoHandle handle, [HttpServer impl]) |
| 718 : super(new _HttpServerStubControl.fromHandle(handle, impl)); |
| 719 |
| 720 HttpServerStub.unbound([HttpServer impl]) |
| 721 : super(new _HttpServerStubControl.unbound(impl)); |
| 722 |
| 723 static HttpServerStub newFromEndpoint( |
| 724 core.MojoMessagePipeEndpoint endpoint) { |
| 725 assert(endpoint.setDescription("For HttpServerStub")); |
| 726 return new HttpServerStub.fromEndpoint(endpoint); |
| 727 } |
| 728 |
| 729 static service_describer.ServiceDescription get serviceDescription => |
| 730 _HttpServerStubControl.serviceDescription; |
| 731 |
| 732 |
| 733 dynamic setHandler(String pattern,Object handler,[Function responseFactory = n
ull]) { |
| 734 return impl.setHandler(pattern,handler,responseFactory); |
| 735 } |
| 736 dynamic getPort([Function responseFactory = null]) { |
| 737 return impl.getPort(responseFactory); |
| 738 } |
| 739 } |
| 740 |
714 const int _httpHandlerMethodHandleRequestName = 0; | 741 const int _httpHandlerMethodHandleRequestName = 0; |
715 | 742 |
716 class _HttpHandlerServiceDescription implements service_describer.ServiceDescrip
tion { | 743 class _HttpHandlerServiceDescription implements service_describer.ServiceDescrip
tion { |
717 dynamic getTopLevelInterface([Function responseFactory]) => | 744 dynamic getTopLevelInterface([Function responseFactory]) => |
718 responseFactory(null); | 745 responseFactory(null); |
719 | 746 |
720 dynamic getTypeDefinition(String typeKey, [Function responseFactory]) => | 747 dynamic getTypeDefinition(String typeKey, [Function responseFactory]) => |
721 responseFactory(null); | 748 responseFactory(null); |
722 | 749 |
723 dynamic getAllTypeDefinitions([Function responseFactory]) => | 750 dynamic getAllTypeDefinitions([Function responseFactory]) => |
724 responseFactory(null); | 751 responseFactory(null); |
725 } | 752 } |
726 | 753 |
727 abstract class HttpHandler { | 754 abstract class HttpHandler { |
728 static const String serviceName = null; | 755 static const String serviceName = null; |
729 dynamic handleRequest(http_request_mojom.HttpRequest request,[Function respons
eFactory = null]); | 756 dynamic handleRequest(http_request_mojom.HttpRequest request,[Function respons
eFactory = null]); |
730 } | 757 } |
731 | 758 |
732 | 759 class _HttpHandlerProxyControl |
733 class _HttpHandlerProxyControl extends bindings.ProxyMessageHandler | 760 extends bindings.ProxyMessageHandler |
734 implements bindings.ProxyControl { | 761 implements bindings.ProxyControl { |
735 _HttpHandlerProxyControl.fromEndpoint( | 762 _HttpHandlerProxyControl.fromEndpoint( |
736 core.MojoMessagePipeEndpoint endpoint) : super.fromEndpoint(endpoint); | 763 core.MojoMessagePipeEndpoint endpoint) : super.fromEndpoint(endpoint); |
737 | 764 |
738 _HttpHandlerProxyControl.fromHandle( | 765 _HttpHandlerProxyControl.fromHandle( |
739 core.MojoHandle handle) : super.fromHandle(handle); | 766 core.MojoHandle handle) : super.fromHandle(handle); |
740 | 767 |
741 _HttpHandlerProxyControl.unbound() : super.unbound(); | 768 _HttpHandlerProxyControl.unbound() : super.unbound(); |
742 | 769 |
743 service_describer.ServiceDescription get serviceDescription => | 770 service_describer.ServiceDescription get serviceDescription => |
744 new _HttpHandlerServiceDescription(); | 771 new _HttpHandlerServiceDescription(); |
745 | 772 |
746 String get serviceName => HttpHandler.serviceName; | 773 String get serviceName => HttpHandler.serviceName; |
747 | 774 |
748 @override | |
749 void handleResponse(bindings.ServiceMessage message) { | 775 void handleResponse(bindings.ServiceMessage message) { |
750 switch (message.header.type) { | 776 switch (message.header.type) { |
751 case _httpHandlerMethodHandleRequestName: | 777 case _httpHandlerMethodHandleRequestName: |
752 var r = HttpHandlerHandleRequestResponseParams.deserialize( | 778 var r = HttpHandlerHandleRequestResponseParams.deserialize( |
753 message.payload); | 779 message.payload); |
754 if (!message.header.hasRequestId) { | 780 if (!message.header.hasRequestId) { |
755 proxyError("Expected a message with a valid request Id."); | 781 proxyError("Expected a message with a valid request Id."); |
756 return; | 782 return; |
757 } | 783 } |
758 Completer c = completerMap[message.header.requestId]; | 784 Completer c = completerMap[message.header.requestId]; |
(...skipping 16 matching lines...) Expand all Loading... |
775 } | 801 } |
776 } | 802 } |
777 | 803 |
778 @override | 804 @override |
779 String toString() { | 805 String toString() { |
780 var superString = super.toString(); | 806 var superString = super.toString(); |
781 return "_HttpHandlerProxyControl($superString)"; | 807 return "_HttpHandlerProxyControl($superString)"; |
782 } | 808 } |
783 } | 809 } |
784 | 810 |
785 | 811 class HttpHandlerProxy |
786 class HttpHandlerProxy extends bindings.Proxy | 812 extends bindings.Proxy |
787 implements HttpHandler { | 813 implements HttpHandler { |
788 HttpHandlerProxy.fromEndpoint( | 814 HttpHandlerProxy.fromEndpoint( |
789 core.MojoMessagePipeEndpoint endpoint) | 815 core.MojoMessagePipeEndpoint endpoint) |
790 : super(new _HttpHandlerProxyControl.fromEndpoint(endpoint)); | 816 : super(new _HttpHandlerProxyControl.fromEndpoint(endpoint)); |
791 | 817 |
792 HttpHandlerProxy.fromHandle(core.MojoHandle handle) | 818 HttpHandlerProxy.fromHandle(core.MojoHandle handle) |
793 : super(new _HttpHandlerProxyControl.fromHandle(handle)); | 819 : super(new _HttpHandlerProxyControl.fromHandle(handle)); |
794 | 820 |
795 HttpHandlerProxy.unbound() | 821 HttpHandlerProxy.unbound() |
796 : super(new _HttpHandlerProxyControl.unbound()); | 822 : super(new _HttpHandlerProxyControl.unbound()); |
797 | 823 |
(...skipping 15 matching lines...) Expand all Loading... |
813 var params = new _HttpHandlerHandleRequestParams(); | 839 var params = new _HttpHandlerHandleRequestParams(); |
814 params.request = request; | 840 params.request = request; |
815 return ctrl.sendMessageWithRequestId( | 841 return ctrl.sendMessageWithRequestId( |
816 params, | 842 params, |
817 _httpHandlerMethodHandleRequestName, | 843 _httpHandlerMethodHandleRequestName, |
818 -1, | 844 -1, |
819 bindings.MessageHeader.kMessageExpectsResponse); | 845 bindings.MessageHeader.kMessageExpectsResponse); |
820 } | 846 } |
821 } | 847 } |
822 | 848 |
823 | 849 class _HttpHandlerStubControl |
824 class HttpHandlerStub extends bindings.Stub { | 850 extends bindings.StubMessageHandler |
| 851 implements bindings.StubControl<HttpHandler> { |
825 HttpHandler _impl; | 852 HttpHandler _impl; |
826 | 853 |
827 HttpHandlerStub.fromEndpoint( | 854 _HttpHandlerStubControl.fromEndpoint( |
828 core.MojoMessagePipeEndpoint endpoint, [HttpHandler impl]) | 855 core.MojoMessagePipeEndpoint endpoint, [HttpHandler impl]) |
829 : super.fromEndpoint(endpoint, autoBegin: impl != null) { | 856 : super.fromEndpoint(endpoint, autoBegin: impl != null) { |
830 _impl = impl; | 857 _impl = impl; |
831 } | 858 } |
832 | 859 |
833 HttpHandlerStub.fromHandle( | 860 _HttpHandlerStubControl.fromHandle( |
834 core.MojoHandle handle, [HttpHandler impl]) | 861 core.MojoHandle handle, [HttpHandler impl]) |
835 : super.fromHandle(handle, autoBegin: impl != null) { | 862 : super.fromHandle(handle, autoBegin: impl != null) { |
836 _impl = impl; | 863 _impl = impl; |
837 } | 864 } |
838 | 865 |
839 HttpHandlerStub.unbound([this._impl]) : super.unbound(); | 866 _HttpHandlerStubControl.unbound([this._impl]) : super.unbound(); |
840 | |
841 static HttpHandlerStub newFromEndpoint( | |
842 core.MojoMessagePipeEndpoint endpoint) { | |
843 assert(endpoint.setDescription("For HttpHandlerStub")); | |
844 return new HttpHandlerStub.fromEndpoint(endpoint); | |
845 } | |
846 | 867 |
847 | 868 |
848 HttpHandlerHandleRequestResponseParams _httpHandlerHandleRequestResponseParams
Factory(http_response_mojom.HttpResponse response) { | 869 HttpHandlerHandleRequestResponseParams _httpHandlerHandleRequestResponseParams
Factory(http_response_mojom.HttpResponse response) { |
849 var result = new HttpHandlerHandleRequestResponseParams(); | 870 var result = new HttpHandlerHandleRequestResponseParams(); |
850 result.response = response; | 871 result.response = response; |
851 return result; | 872 return result; |
852 } | 873 } |
853 | 874 |
854 dynamic handleMessage(bindings.ServiceMessage message) { | 875 dynamic handleMessage(bindings.ServiceMessage message) { |
855 if (bindings.ControlMessageHandler.isControlMessage(message)) { | 876 if (bindings.ControlMessageHandler.isControlMessage(message)) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
902 } | 923 } |
903 | 924 |
904 @override | 925 @override |
905 void bind(core.MojoMessagePipeEndpoint endpoint) { | 926 void bind(core.MojoMessagePipeEndpoint endpoint) { |
906 super.bind(endpoint); | 927 super.bind(endpoint); |
907 if (!isOpen && (_impl != null)) { | 928 if (!isOpen && (_impl != null)) { |
908 beginHandlingEvents(); | 929 beginHandlingEvents(); |
909 } | 930 } |
910 } | 931 } |
911 | 932 |
| 933 @override |
912 String toString() { | 934 String toString() { |
913 var superString = super.toString(); | 935 var superString = super.toString(); |
914 return "HttpHandlerStub($superString)"; | 936 return "_HttpHandlerStubControl($superString)"; |
915 } | 937 } |
916 | 938 |
917 int get version => 0; | 939 int get version => 0; |
918 | 940 |
919 static service_describer.ServiceDescription _cachedServiceDescription; | 941 static service_describer.ServiceDescription _cachedServiceDescription; |
920 static service_describer.ServiceDescription get serviceDescription { | 942 static service_describer.ServiceDescription get serviceDescription { |
921 if (_cachedServiceDescription == null) { | 943 if (_cachedServiceDescription == null) { |
922 _cachedServiceDescription = new _HttpHandlerServiceDescription(); | 944 _cachedServiceDescription = new _HttpHandlerServiceDescription(); |
923 } | 945 } |
924 return _cachedServiceDescription; | 946 return _cachedServiceDescription; |
925 } | 947 } |
926 } | 948 } |
927 | 949 |
| 950 class HttpHandlerStub |
| 951 extends bindings.Stub<HttpHandler> |
| 952 implements HttpHandler { |
| 953 HttpHandlerStub.fromEndpoint( |
| 954 core.MojoMessagePipeEndpoint endpoint, [HttpHandler impl]) |
| 955 : super(new _HttpHandlerStubControl.fromEndpoint(endpoint, impl)); |
| 956 |
| 957 HttpHandlerStub.fromHandle( |
| 958 core.MojoHandle handle, [HttpHandler impl]) |
| 959 : super(new _HttpHandlerStubControl.fromHandle(handle, impl)); |
| 960 |
| 961 HttpHandlerStub.unbound([HttpHandler impl]) |
| 962 : super(new _HttpHandlerStubControl.unbound(impl)); |
| 963 |
| 964 static HttpHandlerStub newFromEndpoint( |
| 965 core.MojoMessagePipeEndpoint endpoint) { |
| 966 assert(endpoint.setDescription("For HttpHandlerStub")); |
| 967 return new HttpHandlerStub.fromEndpoint(endpoint); |
| 968 } |
| 969 |
| 970 static service_describer.ServiceDescription get serviceDescription => |
| 971 _HttpHandlerStubControl.serviceDescription; |
| 972 |
| 973 |
| 974 dynamic handleRequest(http_request_mojom.HttpRequest request,[Function respons
eFactory = null]) { |
| 975 return impl.handleRequest(request,responseFactory); |
| 976 } |
| 977 } |
| 978 |
928 | 979 |
929 | 980 |
OLD | NEW |