Mercurial > hg > piper-cpp
comparison vamp-capnp/VampnProto.h @ 80:d9e85a65d45b
Inching toward a client
author | Chris Cannam <c.cannam@qmul.ac.uk> |
---|---|
date | Tue, 11 Oct 2016 15:49:28 +0100 |
parents | 5909d5d25733 |
children | 6429a99abcad |
comparison
equal
deleted
inserted
replaced
79:f4497c1da43d | 80:d9e85a65d45b |
---|---|
38 #include <capnp/serialize-packed.h> | 38 #include <capnp/serialize-packed.h> |
39 | 39 |
40 #include <vamp-hostsdk/Plugin.h> | 40 #include <vamp-hostsdk/Plugin.h> |
41 #include <vamp-hostsdk/PluginLoader.h> | 41 #include <vamp-hostsdk/PluginLoader.h> |
42 #include <vamp-hostsdk/PluginStaticData.h> | 42 #include <vamp-hostsdk/PluginStaticData.h> |
43 #include <vamp-hostsdk/PluginConfiguration.h> | |
44 #include <vamp-hostsdk/RequestResponse.h> | |
43 | 45 |
44 #include "vamp-support/PluginHandleMapper.h" | 46 #include "vamp-support/PluginHandleMapper.h" |
45 #include "vamp-support/PluginOutputIdMapper.h" | 47 #include "vamp-support/PluginOutputIdMapper.h" |
46 #include "vamp-support/RequestResponseType.h" | 48 #include "vamp-support/RequestResponseType.h" |
47 | 49 |
558 const PluginHandleMapper &pmapper) { | 560 const PluginHandleMapper &pmapper) { |
559 | 561 |
560 resp.plugin = pmapper.handleToPlugin(r.getHandle()); | 562 resp.plugin = pmapper.handleToPlugin(r.getHandle()); |
561 readExtractorStaticData(resp.staticData, r.getStaticData()); | 563 readExtractorStaticData(resp.staticData, r.getStaticData()); |
562 readConfiguration(resp.defaultConfiguration, | 564 readConfiguration(resp.defaultConfiguration, |
563 r.getDefaultConfiguration()); | 565 r.getDefaultConfiguration()); |
564 } | 566 } |
565 | 567 |
566 static void | 568 static void |
567 buildConfigurationRequest(ConfigurationRequest::Builder &b, | 569 buildConfigurationRequest(ConfigurationRequest::Builder &b, |
568 const Vamp::HostExt::ConfigurationRequest &cr, | 570 const Vamp::HostExt::ConfigurationRequest &cr, |
716 b.getRequest().initList(); | 718 b.getRequest().initList(); |
717 } | 719 } |
718 | 720 |
719 static void | 721 static void |
720 buildRpcResponse_List(RpcResponse::Builder &b, | 722 buildRpcResponse_List(RpcResponse::Builder &b, |
721 const Vamp::HostExt::ListResponse &resp) { | 723 const Vamp::HostExt::ListResponse &resp) { |
722 | 724 |
723 auto r = b.getResponse().initList(); | 725 auto r = b.getResponse().initList(); |
724 auto p = r.initAvailable(resp.available.size()); | 726 auto p = r.initAvailable(resp.available.size()); |
725 for (size_t i = 0; i < resp.available.size(); ++i) { | 727 for (size_t i = 0; i < resp.available.size(); ++i) { |
726 auto pd = p[i]; | 728 auto pd = p[i]; |
728 } | 730 } |
729 } | 731 } |
730 | 732 |
731 static void | 733 static void |
732 buildRpcRequest_Load(RpcRequest::Builder &b, | 734 buildRpcRequest_Load(RpcRequest::Builder &b, |
733 const Vamp::HostExt::LoadRequest &req) { | 735 const Vamp::HostExt::LoadRequest &req) { |
734 auto u = b.getRequest().initLoad(); | 736 auto u = b.getRequest().initLoad(); |
735 buildLoadRequest(u, req); | 737 buildLoadRequest(u, req); |
736 } | 738 } |
737 | 739 |
738 static void | 740 static void |
739 buildRpcResponse_Load(RpcResponse::Builder &b, | 741 buildRpcResponse_Load(RpcResponse::Builder &b, |
740 const Vamp::HostExt::LoadResponse &resp, | 742 const Vamp::HostExt::LoadResponse &resp, |
741 const PluginHandleMapper &pmapper) { | 743 const PluginHandleMapper &pmapper) { |
742 | 744 |
743 if (resp.plugin) { | 745 if (resp.plugin) { |
744 auto u = b.getResponse().initLoad(); | 746 auto u = b.getResponse().initLoad(); |
745 buildLoadResponse(u, resp, pmapper); | 747 buildLoadResponse(u, resp, pmapper); |
746 } else { | 748 } else { |
748 } | 750 } |
749 } | 751 } |
750 | 752 |
751 static void | 753 static void |
752 buildRpcRequest_Configure(RpcRequest::Builder &b, | 754 buildRpcRequest_Configure(RpcRequest::Builder &b, |
753 const Vamp::HostExt::ConfigurationRequest &cr, | 755 const Vamp::HostExt::ConfigurationRequest &cr, |
754 const PluginHandleMapper &pmapper) { | 756 const PluginHandleMapper &pmapper) { |
755 auto u = b.getRequest().initConfigure(); | 757 auto u = b.getRequest().initConfigure(); |
756 buildConfigurationRequest(u, cr, pmapper); | 758 buildConfigurationRequest(u, cr, pmapper); |
757 } | 759 } |
758 | 760 |
759 static void | 761 static void |
760 buildRpcResponse_Configure(RpcResponse::Builder &b, | 762 buildRpcResponse_Configure(RpcResponse::Builder &b, |
761 const Vamp::HostExt::ConfigurationResponse &cr, | 763 const Vamp::HostExt::ConfigurationResponse &cr, |
762 const PluginHandleMapper &pmapper) { | 764 const PluginHandleMapper &pmapper) { |
763 | 765 |
764 if (!cr.outputs.empty()) { | 766 if (!cr.outputs.empty()) { |
765 auto u = b.getResponse().initConfigure(); | 767 auto u = b.getResponse().initConfigure(); |
766 buildConfigurationResponse(u, cr, pmapper); | 768 buildConfigurationResponse(u, cr, pmapper); |
767 } else { | 769 } else { |
770 } | 772 } |
771 } | 773 } |
772 | 774 |
773 static void | 775 static void |
774 buildRpcRequest_Process(RpcRequest::Builder &b, | 776 buildRpcRequest_Process(RpcRequest::Builder &b, |
775 const Vamp::HostExt::ProcessRequest &pr, | 777 const Vamp::HostExt::ProcessRequest &pr, |
776 const PluginHandleMapper &pmapper) { | 778 const PluginHandleMapper &pmapper) { |
777 auto u = b.getRequest().initProcess(); | 779 auto u = b.getRequest().initProcess(); |
778 buildProcessRequest(u, pr, pmapper); | 780 buildProcessRequest(u, pr, pmapper); |
779 } | 781 } |
780 | 782 |
781 static void | 783 static void |
782 buildRpcResponse_Process(RpcResponse::Builder &b, | 784 buildRpcResponse_Process(RpcResponse::Builder &b, |
783 const Vamp::HostExt::ProcessResponse &pr, | 785 const Vamp::HostExt::ProcessResponse &pr, |
784 const PluginHandleMapper &pmapper) { | 786 const PluginHandleMapper &pmapper) { |
785 | 787 |
786 auto u = b.getResponse().initProcess(); | 788 auto u = b.getResponse().initProcess(); |
787 buildProcessResponse(u, pr, pmapper); | 789 buildProcessResponse(u, pr, pmapper); |
788 } | 790 } |
789 | 791 |
790 static void | 792 static void |
791 buildRpcRequest_Finish(RpcRequest::Builder &b, | 793 buildRpcRequest_Finish(RpcRequest::Builder &b, |
792 const Vamp::HostExt::FinishRequest &req, | 794 const Vamp::HostExt::FinishRequest &req, |
793 const PluginHandleMapper &pmapper) { | 795 const PluginHandleMapper &pmapper) { |
794 | 796 |
795 auto u = b.getRequest().initFinish(); | 797 auto u = b.getRequest().initFinish(); |
796 u.setHandle(pmapper.pluginToHandle(req.plugin)); | 798 u.setHandle(pmapper.pluginToHandle(req.plugin)); |
797 } | 799 } |
798 | 800 |
799 static void | 801 static void |
800 buildRpcResponse_Finish(RpcResponse::Builder &b, | 802 buildRpcResponse_Finish(RpcResponse::Builder &b, |
801 const Vamp::HostExt::ProcessResponse &pr, | 803 const Vamp::HostExt::ProcessResponse &pr, |
802 const PluginHandleMapper &pmapper) { | 804 const PluginHandleMapper &pmapper) { |
803 | 805 |
804 auto u = b.getResponse().initFinish(); | 806 auto u = b.getResponse().initFinish(); |
805 buildFinishResponse(u, pr, pmapper); | 807 buildFinishResponse(u, pr, pmapper); |
806 } | 808 } |
807 | 809 |
808 static void | 810 static void |
809 buildRpcResponse_Error(RpcResponse::Builder &b, | 811 buildRpcResponse_Error(RpcResponse::Builder &b, |
810 const std::string &errorText, | 812 const std::string &errorText, |
811 RRType responseType) | 813 RRType responseType) |
812 { | 814 { |
813 std::string type; | 815 std::string type; |
814 | 816 |
815 auto e = b.getResponse().initError(); | 817 auto e = b.getResponse().initError(); |
816 | 818 |
832 e.setMessage(std::string("error in ") + type + " request: " + errorText); | 834 e.setMessage(std::string("error in ") + type + " request: " + errorText); |
833 } | 835 } |
834 | 836 |
835 static void | 837 static void |
836 buildRpcResponse_Exception(RpcResponse::Builder &b, | 838 buildRpcResponse_Exception(RpcResponse::Builder &b, |
837 const std::exception &e, | 839 const std::exception &e, |
838 RRType responseType) | 840 RRType responseType) |
839 { | 841 { |
840 return buildRpcResponse_Error(b, e.what(), responseType); | 842 return buildRpcResponse_Error(b, e.what(), responseType); |
841 } | 843 } |
842 | 844 |
843 static RRType | 845 static RRType |
894 } | 896 } |
895 } | 897 } |
896 | 898 |
897 static void | 899 static void |
898 readRpcResponse_List(Vamp::HostExt::ListResponse &resp, | 900 readRpcResponse_List(Vamp::HostExt::ListResponse &resp, |
899 const RpcResponse::Reader &r) { | 901 const RpcResponse::Reader &r) { |
900 if (getRequestResponseType(r) != RRType::List) { | 902 if (getRequestResponseType(r) != RRType::List) { |
901 throw std::logic_error("not a list response"); | 903 throw std::logic_error("not a list response"); |
902 } | 904 } |
903 resp.available.clear(); | 905 resp.available.clear(); |
904 auto pp = r.getResponse().getList().getAvailable(); | 906 auto pp = r.getResponse().getList().getAvailable(); |
909 } | 911 } |
910 } | 912 } |
911 | 913 |
912 static void | 914 static void |
913 readRpcRequest_Load(Vamp::HostExt::LoadRequest &req, | 915 readRpcRequest_Load(Vamp::HostExt::LoadRequest &req, |
914 const RpcRequest::Reader &r) { | 916 const RpcRequest::Reader &r) { |
915 if (getRequestResponseType(r) != RRType::Load) { | 917 if (getRequestResponseType(r) != RRType::Load) { |
916 throw std::logic_error("not a load request"); | 918 throw std::logic_error("not a load request"); |
917 } | 919 } |
918 readLoadRequest(req, r.getRequest().getLoad()); | 920 readLoadRequest(req, r.getRequest().getLoad()); |
919 } | 921 } |
929 readLoadResponse(resp, r.getResponse().getLoad(), pmapper); | 931 readLoadResponse(resp, r.getResponse().getLoad(), pmapper); |
930 } | 932 } |
931 | 933 |
932 static void | 934 static void |
933 readRpcRequest_Configure(Vamp::HostExt::ConfigurationRequest &req, | 935 readRpcRequest_Configure(Vamp::HostExt::ConfigurationRequest &req, |
934 const RpcRequest::Reader &r, | 936 const RpcRequest::Reader &r, |
935 const PluginHandleMapper &pmapper) { | 937 const PluginHandleMapper &pmapper) { |
936 if (getRequestResponseType(r) != RRType::Configure) { | 938 if (getRequestResponseType(r) != RRType::Configure) { |
937 throw std::logic_error("not a configuration request"); | 939 throw std::logic_error("not a configuration request"); |
938 } | 940 } |
939 readConfigurationRequest(req, r.getRequest().getConfigure(), pmapper); | 941 readConfigurationRequest(req, r.getRequest().getConfigure(), pmapper); |
940 } | 942 } |
941 | 943 |
942 static void | 944 static void |
943 readRpcResponse_Configure(Vamp::HostExt::ConfigurationResponse &resp, | 945 readRpcResponse_Configure(Vamp::HostExt::ConfigurationResponse &resp, |
944 const RpcResponse::Reader &r, | 946 const RpcResponse::Reader &r, |
945 const PluginHandleMapper &pmapper) { | 947 const PluginHandleMapper &pmapper) { |
946 if (getRequestResponseType(r) != RRType::Configure) { | 948 if (getRequestResponseType(r) != RRType::Configure) { |
947 throw std::logic_error("not a configuration response"); | 949 throw std::logic_error("not a configuration response"); |
948 } | 950 } |
949 resp = {}; | 951 resp = {}; |
950 readConfigurationResponse(resp, | 952 readConfigurationResponse(resp, |
952 pmapper); | 954 pmapper); |
953 } | 955 } |
954 | 956 |
955 static void | 957 static void |
956 readRpcRequest_Process(Vamp::HostExt::ProcessRequest &req, | 958 readRpcRequest_Process(Vamp::HostExt::ProcessRequest &req, |
957 const RpcRequest::Reader &r, | 959 const RpcRequest::Reader &r, |
960 const PluginHandleMapper &pmapper) { | |
961 if (getRequestResponseType(r) != RRType::Process) { | |
962 throw std::logic_error("not a process request"); | |
963 } | |
964 readProcessRequest(req, r.getRequest().getProcess(), pmapper); | |
965 } | |
966 | |
967 static void | |
968 readRpcResponse_Process(Vamp::HostExt::ProcessResponse &resp, | |
969 const RpcResponse::Reader &r, | |
958 const PluginHandleMapper &pmapper) { | 970 const PluginHandleMapper &pmapper) { |
959 if (getRequestResponseType(r) != RRType::Process) { | 971 if (getRequestResponseType(r) != RRType::Process) { |
960 throw std::logic_error("not a process request"); | |
961 } | |
962 readProcessRequest(req, r.getRequest().getProcess(), pmapper); | |
963 } | |
964 | |
965 static void | |
966 readRpcResponse_Process(Vamp::HostExt::ProcessResponse &resp, | |
967 const RpcResponse::Reader &r, | |
968 const PluginHandleMapper &pmapper) { | |
969 if (getRequestResponseType(r) != RRType::Process) { | |
970 throw std::logic_error("not a process response"); | 972 throw std::logic_error("not a process response"); |
971 } | 973 } |
972 resp = {}; | 974 resp = {}; |
973 readProcessResponse(resp, r.getResponse().getProcess(), pmapper); | 975 readProcessResponse(resp, r.getResponse().getProcess(), pmapper); |
974 } | 976 } |
975 | 977 |
976 static void | 978 static void |
977 readRpcRequest_Finish(Vamp::HostExt::FinishRequest &req, | 979 readRpcRequest_Finish(Vamp::HostExt::FinishRequest &req, |
978 const RpcRequest::Reader &r, | 980 const RpcRequest::Reader &r, |
981 const PluginHandleMapper &pmapper) { | |
982 if (getRequestResponseType(r) != RRType::Finish) { | |
983 throw std::logic_error("not a finish request"); | |
984 } | |
985 req.plugin = pmapper.handleToPlugin | |
986 (r.getRequest().getFinish().getHandle()); | |
987 } | |
988 | |
989 static void | |
990 readRpcResponse_Finish(Vamp::HostExt::ProcessResponse &resp, | |
991 const RpcResponse::Reader &r, | |
979 const PluginHandleMapper &pmapper) { | 992 const PluginHandleMapper &pmapper) { |
980 if (getRequestResponseType(r) != RRType::Finish) { | 993 if (getRequestResponseType(r) != RRType::Finish) { |
981 throw std::logic_error("not a finish request"); | |
982 } | |
983 req.plugin = pmapper.handleToPlugin | |
984 (r.getRequest().getFinish().getHandle()); | |
985 } | |
986 | |
987 static void | |
988 readRpcResponse_Finish(Vamp::HostExt::ProcessResponse &resp, | |
989 const RpcResponse::Reader &r, | |
990 const PluginHandleMapper &pmapper) { | |
991 if (getRequestResponseType(r) != RRType::Finish) { | |
992 throw std::logic_error("not a finish response"); | 994 throw std::logic_error("not a finish response"); |
993 } | 995 } |
994 resp = {}; | 996 resp = {}; |
995 readFinishResponse(resp, r.getResponse().getFinish(), pmapper); | 997 readFinishResponse(resp, r.getResponse().getFinish(), pmapper); |
996 } | 998 } |