comparison capnproto/VampnProto.h @ 26:13393bdfc7ef

Start introducing request/response readers to capnp code as well
author Chris Cannam <c.cannam@qmul.ac.uk>
date Tue, 24 May 2016 11:07:59 +0100
parents 5b9690d18241
children cc85c2851605
comparison
equal deleted inserted replaced
25:5b9690d18241 26:13393bdfc7ef
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 43
44 #include "bits/PluginHandleMapper.h" 44 #include "bits/PluginHandleMapper.h"
45 #include "bits/RequestResponseType.h"
45 46
46 namespace vampipe 47 namespace vampipe
47 { 48 {
48 49
49 /** 50 /**
651 buildVampRequest_List(VampRequest::Builder &b) { 652 buildVampRequest_List(VampRequest::Builder &b) {
652 b.getRequest().setList(); 653 b.getRequest().setList();
653 } 654 }
654 655
655 static void 656 static void
656 readVampRequest_List(const VampRequest::Reader &r) {
657 if (r.getRequest().which() != VampRequest::Request::Which::LIST) {
658 throw std::runtime_error("not a list request");
659 }
660 }
661
662 static void
663 buildVampResponse_List(VampResponse::Builder &b, 657 buildVampResponse_List(VampResponse::Builder &b,
664 std::string errorText, 658 std::string errorText,
665 const std::vector<Vamp::HostExt::PluginStaticData> &d) { 659 const std::vector<Vamp::HostExt::PluginStaticData> &d) {
666 b.setSuccess(errorText == ""); 660 b.setSuccess(errorText == "");
667 b.setErrorText(errorText); 661 b.setErrorText(errorText);
737 buildVampResponse_Finish(VampResponse::Builder &b, 731 buildVampResponse_Finish(VampResponse::Builder &b,
738 const Vamp::HostExt::ProcessResponse &pr) { 732 const Vamp::HostExt::ProcessResponse &pr) {
739 733
740 buildVampResponse_Process(b, pr); 734 buildVampResponse_Process(b, pr);
741 } 735 }
736
737 static RRType
738 getRequestResponseType(const VampRequest::Reader &r) {
739 switch (r.getRequest().which()) {
740 case VampRequest::Request::Which::LIST:
741 return RRType::List;
742 case VampRequest::Request::Which::LOAD:
743 return RRType::Load;
744 case VampRequest::Request::Which::CONFIGURE:
745 return RRType::Configure;
746 case VampRequest::Request::Which::PROCESS:
747 return RRType::Process;
748 case VampRequest::Request::Which::FINISH:
749 return RRType::Finish;
750 }
751 }
752
753 static RRType
754 getRequestResponseType(const VampResponse::Reader &r) {
755 switch (r.getResponse().which()) {
756 case VampResponse::Response::Which::LIST:
757 return RRType::List;
758 case VampResponse::Response::Which::LOAD:
759 return RRType::Load;
760 case VampResponse::Response::Which::CONFIGURE:
761 return RRType::Configure;
762 case VampResponse::Response::Which::PROCESS:
763 return RRType::Process;
764 case VampResponse::Response::Which::FINISH:
765 return RRType::Finish;
766 }
767 }
768
769 static void
770 readVampRequest_List(const VampRequest::Reader &r) {
771 if (getRequestResponseType(r) != RRType::List) {
772 throw std::runtime_error("not a list request");
773 }
774 }
775
776 static void
777 readVampResponse_List(std::vector<Vamp::HostExt::PluginStaticData> &v,
778 const VampResponse::Reader &r) {
779 if (getRequestResponseType(r) != RRType::List) {
780 throw std::runtime_error("not a list response");
781 }
782 v.clear();
783 if (r.getSuccess()) {
784 for (const auto &p: r.getResponse().getList().getPlugins()) {
785 Vamp::HostExt::PluginStaticData psd;
786 readPluginStaticData(psd, p);
787 v.push_back(psd);
788 }
789 }
790 }
791
742 }; 792 };
743 793
744 } 794 }
745 795
746 796