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

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

Issue 1948003003: Dart: Wait to handle events on a Stub until it makes sense to do it. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Add test 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;
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 impl.requireVersion(requiredVersion); 614 impl.requireVersion(requiredVersion);
615 } 615 }
616 616
617 String toString() { 617 String toString() {
618 return "HttpServerProxy($impl)"; 618 return "HttpServerProxy($impl)";
619 } 619 }
620 } 620 }
621 621
622 622
623 class HttpServerStub extends bindings.Stub { 623 class HttpServerStub extends bindings.Stub {
624 HttpServer _impl = null; 624 HttpServer _impl;
625 625
626 HttpServerStub.fromEndpoint( 626 HttpServerStub.fromEndpoint(
627 core.MojoMessagePipeEndpoint endpoint, [this._impl]) 627 core.MojoMessagePipeEndpoint endpoint, [HttpServer impl])
628 : super.fromEndpoint(endpoint); 628 : super.fromEndpoint(endpoint, autoBegin: impl != null) {
629 _impl = impl;
630 }
629 631
630 HttpServerStub.fromHandle(core.MojoHandle handle, [this._impl]) 632 HttpServerStub.fromHandle(
631 : super.fromHandle(handle); 633 core.MojoHandle handle, [HttpServer impl])
634 : super.fromHandle(handle, autoBegin: impl != null) {
635 _impl = impl;
636 }
632 637
633 HttpServerStub.unbound() : super.unbound(); 638 HttpServerStub.unbound() : super.unbound();
634 639
635 static HttpServerStub newFromEndpoint( 640 static HttpServerStub newFromEndpoint(
636 core.MojoMessagePipeEndpoint endpoint) { 641 core.MojoMessagePipeEndpoint endpoint) {
637 assert(endpoint.setDescription("For HttpServerStub")); 642 assert(endpoint.setDescription("For HttpServerStub"));
638 return new HttpServerStub.fromEndpoint(endpoint); 643 return new HttpServerStub.fromEndpoint(endpoint);
639 } 644 }
640 645
641 646
642 HttpServerSetHandlerResponseParams _httpServerSetHandlerResponseParamsFactory( bool success) { 647 HttpServerSetHandlerResponseParams _httpServerSetHandlerResponseParamsFactory( bool success) {
643 var result = new HttpServerSetHandlerResponseParams(); 648 var result = new HttpServerSetHandlerResponseParams();
644 result.success = success; 649 result.success = success;
645 return result; 650 return result;
646 } 651 }
647 HttpServerGetPortResponseParams _httpServerGetPortResponseParamsFactory(int po rt) { 652 HttpServerGetPortResponseParams _httpServerGetPortResponseParamsFactory(int po rt) {
648 var result = new HttpServerGetPortResponseParams(); 653 var result = new HttpServerGetPortResponseParams();
649 result.port = port; 654 result.port = port;
650 return result; 655 return result;
651 } 656 }
652 657
653 dynamic handleMessage(bindings.ServiceMessage message) { 658 dynamic handleMessage(bindings.ServiceMessage message) {
654 if (bindings.ControlMessageHandler.isControlMessage(message)) { 659 if (bindings.ControlMessageHandler.isControlMessage(message)) {
655 return bindings.ControlMessageHandler.handleMessage(this, 660 return bindings.ControlMessageHandler.handleMessage(this,
656 0, 661 0,
657 message); 662 message);
658 } 663 }
659 assert(_impl != null); 664 if (_impl == null) {
665 throw new core.MojoApiError("$this has no implementation set");
666 }
660 switch (message.header.type) { 667 switch (message.header.type) {
661 case _httpServerMethodSetHandlerName: 668 case _httpServerMethodSetHandlerName:
662 var params = _HttpServerSetHandlerParams.deserialize( 669 var params = _HttpServerSetHandlerParams.deserialize(
663 message.payload); 670 message.payload);
664 var response = _impl.setHandler(params.pattern,params.handler,_httpServe rSetHandlerResponseParamsFactory); 671 var response = _impl.setHandler(params.pattern,params.handler,_httpServe rSetHandlerResponseParamsFactory);
665 if (response is Future) { 672 if (response is Future) {
666 return response.then((response) { 673 return response.then((response) {
667 if (response != null) { 674 if (response != null) {
668 return buildResponseWithId( 675 return buildResponseWithId(
669 response, 676 response,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 break; 709 break;
703 default: 710 default:
704 throw new bindings.MojoCodecError("Unexpected message name"); 711 throw new bindings.MojoCodecError("Unexpected message name");
705 break; 712 break;
706 } 713 }
707 return null; 714 return null;
708 } 715 }
709 716
710 HttpServer get impl => _impl; 717 HttpServer get impl => _impl;
711 set impl(HttpServer d) { 718 set impl(HttpServer d) {
712 assert(_impl == null); 719 if (d == null) {
720 throw new core.MojoApiError("$this: Cannot set a null implementation");
721 }
722 if (isBound && (_impl == null)) {
723 beginHandlingEvents();
724 }
713 _impl = d; 725 _impl = d;
714 } 726 }
715 727
728 @override
729 void bind(core.MojoMessagePipeEndpoint endpoint) {
730 super.bind(endpoint);
731 if (!isOpen && (_impl != null)) {
732 beginHandlingEvents();
733 }
734 }
735
716 String toString() { 736 String toString() {
717 var superString = super.toString(); 737 var superString = super.toString();
718 return "HttpServerStub($superString)"; 738 return "HttpServerStub($superString)";
719 } 739 }
720 740
721 int get version => 0; 741 int get version => 0;
722 742
723 static service_describer.ServiceDescription _cachedServiceDescription; 743 static service_describer.ServiceDescription _cachedServiceDescription;
724 static service_describer.ServiceDescription get serviceDescription { 744 static service_describer.ServiceDescription get serviceDescription {
725 if (_cachedServiceDescription == null) { 745 if (_cachedServiceDescription == null) {
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 impl.requireVersion(requiredVersion); 891 impl.requireVersion(requiredVersion);
872 } 892 }
873 893
874 String toString() { 894 String toString() {
875 return "HttpHandlerProxy($impl)"; 895 return "HttpHandlerProxy($impl)";
876 } 896 }
877 } 897 }
878 898
879 899
880 class HttpHandlerStub extends bindings.Stub { 900 class HttpHandlerStub extends bindings.Stub {
881 HttpHandler _impl = null; 901 HttpHandler _impl;
882 902
883 HttpHandlerStub.fromEndpoint( 903 HttpHandlerStub.fromEndpoint(
884 core.MojoMessagePipeEndpoint endpoint, [this._impl]) 904 core.MojoMessagePipeEndpoint endpoint, [HttpHandler impl])
885 : super.fromEndpoint(endpoint); 905 : super.fromEndpoint(endpoint, autoBegin: impl != null) {
906 _impl = impl;
907 }
886 908
887 HttpHandlerStub.fromHandle(core.MojoHandle handle, [this._impl]) 909 HttpHandlerStub.fromHandle(
888 : super.fromHandle(handle); 910 core.MojoHandle handle, [HttpHandler impl])
911 : super.fromHandle(handle, autoBegin: impl != null) {
912 _impl = impl;
913 }
889 914
890 HttpHandlerStub.unbound() : super.unbound(); 915 HttpHandlerStub.unbound() : super.unbound();
891 916
892 static HttpHandlerStub newFromEndpoint( 917 static HttpHandlerStub newFromEndpoint(
893 core.MojoMessagePipeEndpoint endpoint) { 918 core.MojoMessagePipeEndpoint endpoint) {
894 assert(endpoint.setDescription("For HttpHandlerStub")); 919 assert(endpoint.setDescription("For HttpHandlerStub"));
895 return new HttpHandlerStub.fromEndpoint(endpoint); 920 return new HttpHandlerStub.fromEndpoint(endpoint);
896 } 921 }
897 922
898 923
899 HttpHandlerHandleRequestResponseParams _httpHandlerHandleRequestResponseParams Factory(http_response_mojom.HttpResponse response) { 924 HttpHandlerHandleRequestResponseParams _httpHandlerHandleRequestResponseParams Factory(http_response_mojom.HttpResponse response) {
900 var result = new HttpHandlerHandleRequestResponseParams(); 925 var result = new HttpHandlerHandleRequestResponseParams();
901 result.response = response; 926 result.response = response;
902 return result; 927 return result;
903 } 928 }
904 929
905 dynamic handleMessage(bindings.ServiceMessage message) { 930 dynamic handleMessage(bindings.ServiceMessage message) {
906 if (bindings.ControlMessageHandler.isControlMessage(message)) { 931 if (bindings.ControlMessageHandler.isControlMessage(message)) {
907 return bindings.ControlMessageHandler.handleMessage(this, 932 return bindings.ControlMessageHandler.handleMessage(this,
908 0, 933 0,
909 message); 934 message);
910 } 935 }
911 assert(_impl != null); 936 if (_impl == null) {
937 throw new core.MojoApiError("$this has no implementation set");
938 }
912 switch (message.header.type) { 939 switch (message.header.type) {
913 case _httpHandlerMethodHandleRequestName: 940 case _httpHandlerMethodHandleRequestName:
914 var params = _HttpHandlerHandleRequestParams.deserialize( 941 var params = _HttpHandlerHandleRequestParams.deserialize(
915 message.payload); 942 message.payload);
916 var response = _impl.handleRequest(params.request,_httpHandlerHandleRequ estResponseParamsFactory); 943 var response = _impl.handleRequest(params.request,_httpHandlerHandleRequ estResponseParamsFactory);
917 if (response is Future) { 944 if (response is Future) {
918 return response.then((response) { 945 return response.then((response) {
919 if (response != null) { 946 if (response != null) {
920 return buildResponseWithId( 947 return buildResponseWithId(
921 response, 948 response,
(...skipping 12 matching lines...) Expand all
934 break; 961 break;
935 default: 962 default:
936 throw new bindings.MojoCodecError("Unexpected message name"); 963 throw new bindings.MojoCodecError("Unexpected message name");
937 break; 964 break;
938 } 965 }
939 return null; 966 return null;
940 } 967 }
941 968
942 HttpHandler get impl => _impl; 969 HttpHandler get impl => _impl;
943 set impl(HttpHandler d) { 970 set impl(HttpHandler d) {
944 assert(_impl == null); 971 if (d == null) {
972 throw new core.MojoApiError("$this: Cannot set a null implementation");
973 }
974 if (isBound && (_impl == null)) {
975 beginHandlingEvents();
976 }
945 _impl = d; 977 _impl = d;
946 } 978 }
947 979
980 @override
981 void bind(core.MojoMessagePipeEndpoint endpoint) {
982 super.bind(endpoint);
983 if (!isOpen && (_impl != null)) {
984 beginHandlingEvents();
985 }
986 }
987
948 String toString() { 988 String toString() {
949 var superString = super.toString(); 989 var superString = super.toString();
950 return "HttpHandlerStub($superString)"; 990 return "HttpHandlerStub($superString)";
951 } 991 }
952 992
953 int get version => 0; 993 int get version => 0;
954 994
955 static service_describer.ServiceDescription _cachedServiceDescription; 995 static service_describer.ServiceDescription _cachedServiceDescription;
956 static service_describer.ServiceDescription get serviceDescription { 996 static service_describer.ServiceDescription get serviceDescription {
957 if (_cachedServiceDescription == null) { 997 if (_cachedServiceDescription == null) {
958 _cachedServiceDescription = new _HttpHandlerServiceDescription(); 998 _cachedServiceDescription = new _HttpHandlerServiceDescription();
959 } 999 }
960 return _cachedServiceDescription; 1000 return _cachedServiceDescription;
961 } 1001 }
962 } 1002 }
963 1003
964 1004
965 1005
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698