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

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

Issue 1964193002: Dart: Refactors Proxies (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Address comments 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 sensors_mojom; 5 library sensors_mojom;
6 import 'dart:async'; 6 import 'dart:async';
7 import 'package:mojo/bindings.dart' as bindings; 7 import 'package:mojo/bindings.dart' as bindings;
8 import 'package:mojo/core.dart' as core; 8 import 'package:mojo/core.dart' as core;
9 import 'package:mojo/mojo/bindings/types/service_describer.mojom.dart' as servic e_describer; 9 import 'package:mojo/mojo/bindings/types/service_describer.mojom.dart' as servic e_describer;
10 10
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 responseFactory(null); 527 responseFactory(null);
528 } 528 }
529 529
530 abstract class SensorListener { 530 abstract class SensorListener {
531 static const String serviceName = null; 531 static const String serviceName = null;
532 void onAccuracyChanged(int accuracy); 532 void onAccuracyChanged(int accuracy);
533 void onSensorChanged(SensorData data); 533 void onSensorChanged(SensorData data);
534 } 534 }
535 535
536 536
537 class _SensorListenerProxyImpl extends bindings.Proxy { 537 class _SensorListenerProxyControl extends bindings.ProxyMessageHandler
538 _SensorListenerProxyImpl.fromEndpoint( 538 implements bindings.ProxyControl {
539 _SensorListenerProxyControl.fromEndpoint(
539 core.MojoMessagePipeEndpoint endpoint) : super.fromEndpoint(endpoint); 540 core.MojoMessagePipeEndpoint endpoint) : super.fromEndpoint(endpoint);
540 541
541 _SensorListenerProxyImpl.fromHandle(core.MojoHandle handle) : 542 _SensorListenerProxyControl.fromHandle(
542 super.fromHandle(handle); 543 core.MojoHandle handle) : super.fromHandle(handle);
543 544
544 _SensorListenerProxyImpl.unbound() : super.unbound(); 545 _SensorListenerProxyControl.unbound() : super.unbound();
545
546 static _SensorListenerProxyImpl newFromEndpoint(
547 core.MojoMessagePipeEndpoint endpoint) {
548 assert(endpoint.setDescription("For _SensorListenerProxyImpl"));
549 return new _SensorListenerProxyImpl.fromEndpoint(endpoint);
550 }
551 546
552 service_describer.ServiceDescription get serviceDescription => 547 service_describer.ServiceDescription get serviceDescription =>
553 new _SensorListenerServiceDescription(); 548 new _SensorListenerServiceDescription();
554 549
550 String get serviceName => SensorListener.serviceName;
551
552 @override
555 void handleResponse(bindings.ServiceMessage message) { 553 void handleResponse(bindings.ServiceMessage message) {
556 switch (message.header.type) { 554 switch (message.header.type) {
557 default: 555 default:
558 proxyError("Unexpected message type: ${message.header.type}"); 556 proxyError("Unexpected message type: ${message.header.type}");
559 close(immediate: true); 557 close(immediate: true);
560 break; 558 break;
561 } 559 }
562 } 560 }
563 561
562 @override
564 String toString() { 563 String toString() {
565 var superString = super.toString(); 564 var superString = super.toString();
566 return "_SensorListenerProxyImpl($superString)"; 565 return "_SensorListenerProxyControl($superString)";
567 } 566 }
568 } 567 }
569 568
570 569
571 class _SensorListenerProxyCalls implements SensorListener { 570 class SensorListenerProxy extends bindings.Proxy
572 _SensorListenerProxyImpl _proxyImpl; 571 implements SensorListener {
572 SensorListenerProxy.fromEndpoint(
573 core.MojoMessagePipeEndpoint endpoint)
574 : super(new _SensorListenerProxyControl.fromEndpoint(endpoint));
573 575
574 _SensorListenerProxyCalls(this._proxyImpl); 576 SensorListenerProxy.fromHandle(core.MojoHandle handle)
575 void onAccuracyChanged(int accuracy) { 577 : super(new _SensorListenerProxyControl.fromHandle(handle));
576 if (!_proxyImpl.isBound) {
577 _proxyImpl.proxyError("The Proxy is closed.");
578 return;
579 }
580 var params = new _SensorListenerOnAccuracyChangedParams();
581 params.accuracy = accuracy;
582 _proxyImpl.sendMessage(params, _sensorListenerMethodOnAccuracyChangedName) ;
583 }
584 void onSensorChanged(SensorData data) {
585 if (!_proxyImpl.isBound) {
586 _proxyImpl.proxyError("The Proxy is closed.");
587 return;
588 }
589 var params = new _SensorListenerOnSensorChangedParams();
590 params.data = data;
591 _proxyImpl.sendMessage(params, _sensorListenerMethodOnSensorChangedName);
592 }
593 }
594 578
579 SensorListenerProxy.unbound()
580 : super(new _SensorListenerProxyControl.unbound());
595 581
596 class SensorListenerProxy implements bindings.ProxyBase { 582 static SensorListenerProxy newFromEndpoint(
597 final bindings.Proxy impl; 583 core.MojoMessagePipeEndpoint endpoint) {
598 SensorListener ptr; 584 assert(endpoint.setDescription("For SensorListenerProxy"));
599 585 return new SensorListenerProxy.fromEndpoint(endpoint);
600 SensorListenerProxy(_SensorListenerProxyImpl proxyImpl) :
601 impl = proxyImpl,
602 ptr = new _SensorListenerProxyCalls(proxyImpl);
603
604 SensorListenerProxy.fromEndpoint(
605 core.MojoMessagePipeEndpoint endpoint) :
606 impl = new _SensorListenerProxyImpl.fromEndpoint(endpoint) {
607 ptr = new _SensorListenerProxyCalls(impl);
608 }
609
610 SensorListenerProxy.fromHandle(core.MojoHandle handle) :
611 impl = new _SensorListenerProxyImpl.fromHandle(handle) {
612 ptr = new _SensorListenerProxyCalls(impl);
613 }
614
615 SensorListenerProxy.unbound() :
616 impl = new _SensorListenerProxyImpl.unbound() {
617 ptr = new _SensorListenerProxyCalls(impl);
618 } 586 }
619 587
620 factory SensorListenerProxy.connectToService( 588 factory SensorListenerProxy.connectToService(
621 bindings.ServiceConnector s, String url, [String serviceName]) { 589 bindings.ServiceConnector s, String url, [String serviceName]) {
622 SensorListenerProxy p = new SensorListenerProxy.unbound(); 590 SensorListenerProxy p = new SensorListenerProxy.unbound();
623 s.connectToService(url, p, serviceName); 591 s.connectToService(url, p, serviceName);
624 return p; 592 return p;
625 } 593 }
626 594
627 static SensorListenerProxy newFromEndpoint( 595
628 core.MojoMessagePipeEndpoint endpoint) { 596 void onAccuracyChanged(int accuracy) {
629 assert(endpoint.setDescription("For SensorListenerProxy")); 597 if (!ctrl.isBound) {
630 return new SensorListenerProxy.fromEndpoint(endpoint); 598 ctrl.proxyError("The Proxy is closed.");
599 return;
600 }
601 var params = new _SensorListenerOnAccuracyChangedParams();
602 params.accuracy = accuracy;
603 ctrl.sendMessage(params,
604 _sensorListenerMethodOnAccuracyChangedName);
631 } 605 }
632 606 void onSensorChanged(SensorData data) {
633 String get serviceName => SensorListener.serviceName; 607 if (!ctrl.isBound) {
634 608 ctrl.proxyError("The Proxy is closed.");
635 Future close({bool immediate: false}) => impl.close(immediate: immediate); 609 return;
636 610 }
637 Future responseOrError(Future f) => impl.responseOrError(f); 611 var params = new _SensorListenerOnSensorChangedParams();
638 612 params.data = data;
639 Future get errorFuture => impl.errorFuture; 613 ctrl.sendMessage(params,
640 614 _sensorListenerMethodOnSensorChangedName);
641 int get version => impl.version;
642
643 Future<int> queryVersion() => impl.queryVersion();
644
645 void requireVersion(int requiredVersion) {
646 impl.requireVersion(requiredVersion);
647 }
648
649 String toString() {
650 return "SensorListenerProxy($impl)";
651 } 615 }
652 } 616 }
653 617
654 618
655 class SensorListenerStub extends bindings.Stub { 619 class SensorListenerStub extends bindings.Stub {
656 SensorListener _impl; 620 SensorListener _impl;
657 621
658 SensorListenerStub.fromEndpoint( 622 SensorListenerStub.fromEndpoint(
659 core.MojoMessagePipeEndpoint endpoint, [SensorListener impl]) 623 core.MojoMessagePipeEndpoint endpoint, [SensorListener impl])
660 : super.fromEndpoint(endpoint, autoBegin: impl != null) { 624 : super.fromEndpoint(endpoint, autoBegin: impl != null) {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 dynamic getAllTypeDefinitions([Function responseFactory]) => 715 dynamic getAllTypeDefinitions([Function responseFactory]) =>
752 responseFactory(null); 716 responseFactory(null);
753 } 717 }
754 718
755 abstract class SensorService { 719 abstract class SensorService {
756 static const String serviceName = "sensors::SensorService"; 720 static const String serviceName = "sensors::SensorService";
757 void addListener(SensorType type, Object listener); 721 void addListener(SensorType type, Object listener);
758 } 722 }
759 723
760 724
761 class _SensorServiceProxyImpl extends bindings.Proxy { 725 class _SensorServiceProxyControl extends bindings.ProxyMessageHandler
762 _SensorServiceProxyImpl.fromEndpoint( 726 implements bindings.ProxyControl {
727 _SensorServiceProxyControl.fromEndpoint(
763 core.MojoMessagePipeEndpoint endpoint) : super.fromEndpoint(endpoint); 728 core.MojoMessagePipeEndpoint endpoint) : super.fromEndpoint(endpoint);
764 729
765 _SensorServiceProxyImpl.fromHandle(core.MojoHandle handle) : 730 _SensorServiceProxyControl.fromHandle(
766 super.fromHandle(handle); 731 core.MojoHandle handle) : super.fromHandle(handle);
767 732
768 _SensorServiceProxyImpl.unbound() : super.unbound(); 733 _SensorServiceProxyControl.unbound() : super.unbound();
769
770 static _SensorServiceProxyImpl newFromEndpoint(
771 core.MojoMessagePipeEndpoint endpoint) {
772 assert(endpoint.setDescription("For _SensorServiceProxyImpl"));
773 return new _SensorServiceProxyImpl.fromEndpoint(endpoint);
774 }
775 734
776 service_describer.ServiceDescription get serviceDescription => 735 service_describer.ServiceDescription get serviceDescription =>
777 new _SensorServiceServiceDescription(); 736 new _SensorServiceServiceDescription();
778 737
738 String get serviceName => SensorService.serviceName;
739
740 @override
779 void handleResponse(bindings.ServiceMessage message) { 741 void handleResponse(bindings.ServiceMessage message) {
780 switch (message.header.type) { 742 switch (message.header.type) {
781 default: 743 default:
782 proxyError("Unexpected message type: ${message.header.type}"); 744 proxyError("Unexpected message type: ${message.header.type}");
783 close(immediate: true); 745 close(immediate: true);
784 break; 746 break;
785 } 747 }
786 } 748 }
787 749
750 @override
788 String toString() { 751 String toString() {
789 var superString = super.toString(); 752 var superString = super.toString();
790 return "_SensorServiceProxyImpl($superString)"; 753 return "_SensorServiceProxyControl($superString)";
791 } 754 }
792 } 755 }
793 756
794 757
795 class _SensorServiceProxyCalls implements SensorService { 758 class SensorServiceProxy extends bindings.Proxy
796 _SensorServiceProxyImpl _proxyImpl; 759 implements SensorService {
760 SensorServiceProxy.fromEndpoint(
761 core.MojoMessagePipeEndpoint endpoint)
762 : super(new _SensorServiceProxyControl.fromEndpoint(endpoint));
797 763
798 _SensorServiceProxyCalls(this._proxyImpl); 764 SensorServiceProxy.fromHandle(core.MojoHandle handle)
799 void addListener(SensorType type, Object listener) { 765 : super(new _SensorServiceProxyControl.fromHandle(handle));
800 if (!_proxyImpl.isBound) {
801 _proxyImpl.proxyError("The Proxy is closed.");
802 return;
803 }
804 var params = new _SensorServiceAddListenerParams();
805 params.type = type;
806 params.listener = listener;
807 _proxyImpl.sendMessage(params, _sensorServiceMethodAddListenerName);
808 }
809 }
810 766
767 SensorServiceProxy.unbound()
768 : super(new _SensorServiceProxyControl.unbound());
811 769
812 class SensorServiceProxy implements bindings.ProxyBase { 770 static SensorServiceProxy newFromEndpoint(
813 final bindings.Proxy impl; 771 core.MojoMessagePipeEndpoint endpoint) {
814 SensorService ptr; 772 assert(endpoint.setDescription("For SensorServiceProxy"));
815 773 return new SensorServiceProxy.fromEndpoint(endpoint);
816 SensorServiceProxy(_SensorServiceProxyImpl proxyImpl) :
817 impl = proxyImpl,
818 ptr = new _SensorServiceProxyCalls(proxyImpl);
819
820 SensorServiceProxy.fromEndpoint(
821 core.MojoMessagePipeEndpoint endpoint) :
822 impl = new _SensorServiceProxyImpl.fromEndpoint(endpoint) {
823 ptr = new _SensorServiceProxyCalls(impl);
824 }
825
826 SensorServiceProxy.fromHandle(core.MojoHandle handle) :
827 impl = new _SensorServiceProxyImpl.fromHandle(handle) {
828 ptr = new _SensorServiceProxyCalls(impl);
829 }
830
831 SensorServiceProxy.unbound() :
832 impl = new _SensorServiceProxyImpl.unbound() {
833 ptr = new _SensorServiceProxyCalls(impl);
834 } 774 }
835 775
836 factory SensorServiceProxy.connectToService( 776 factory SensorServiceProxy.connectToService(
837 bindings.ServiceConnector s, String url, [String serviceName]) { 777 bindings.ServiceConnector s, String url, [String serviceName]) {
838 SensorServiceProxy p = new SensorServiceProxy.unbound(); 778 SensorServiceProxy p = new SensorServiceProxy.unbound();
839 s.connectToService(url, p, serviceName); 779 s.connectToService(url, p, serviceName);
840 return p; 780 return p;
841 } 781 }
842 782
843 static SensorServiceProxy newFromEndpoint(
844 core.MojoMessagePipeEndpoint endpoint) {
845 assert(endpoint.setDescription("For SensorServiceProxy"));
846 return new SensorServiceProxy.fromEndpoint(endpoint);
847 }
848 783
849 String get serviceName => SensorService.serviceName; 784 void addListener(SensorType type, Object listener) {
850 785 if (!ctrl.isBound) {
851 Future close({bool immediate: false}) => impl.close(immediate: immediate); 786 ctrl.proxyError("The Proxy is closed.");
852 787 return;
853 Future responseOrError(Future f) => impl.responseOrError(f); 788 }
854 789 var params = new _SensorServiceAddListenerParams();
855 Future get errorFuture => impl.errorFuture; 790 params.type = type;
856 791 params.listener = listener;
857 int get version => impl.version; 792 ctrl.sendMessage(params,
858 793 _sensorServiceMethodAddListenerName);
859 Future<int> queryVersion() => impl.queryVersion();
860
861 void requireVersion(int requiredVersion) {
862 impl.requireVersion(requiredVersion);
863 }
864
865 String toString() {
866 return "SensorServiceProxy($impl)";
867 } 794 }
868 } 795 }
869 796
870 797
871 class SensorServiceStub extends bindings.Stub { 798 class SensorServiceStub extends bindings.Stub {
872 SensorService _impl; 799 SensorService _impl;
873 800
874 SensorServiceStub.fromEndpoint( 801 SensorServiceStub.fromEndpoint(
875 core.MojoMessagePipeEndpoint endpoint, [SensorService impl]) 802 core.MojoMessagePipeEndpoint endpoint, [SensorService impl])
876 : super.fromEndpoint(endpoint, autoBegin: impl != null) { 803 : super.fromEndpoint(endpoint, autoBegin: impl != null) {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
945 static service_describer.ServiceDescription get serviceDescription { 872 static service_describer.ServiceDescription get serviceDescription {
946 if (_cachedServiceDescription == null) { 873 if (_cachedServiceDescription == null) {
947 _cachedServiceDescription = new _SensorServiceServiceDescription(); 874 _cachedServiceDescription = new _SensorServiceServiceDescription();
948 } 875 }
949 return _cachedServiceDescription; 876 return _cachedServiceDescription;
950 } 877 }
951 } 878 }
952 879
953 880
954 881
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698