Mercurial > hg > piper-cpp
comparison utilities/json-to-capnp.cpp @ 20:7ca64f74add2
Add and use PreservingPluginHandleMapper -- removing the constant variant, which was a misstep
author | Chris Cannam <c.cannam@qmul.ac.uk> |
---|---|
date | Fri, 20 May 2016 11:08:53 +0100 |
parents | f379b0e9a8e1 |
children | dff96610ac05 |
comparison
equal
deleted
inserted
replaced
19:f379b0e9a8e1 | 20:7ca64f74add2 |
---|---|
1 | 1 |
2 #include "VampJson.h" | 2 #include "VampJson.h" |
3 #include "VampnProto.h" | 3 #include "VampnProto.h" |
4 | |
5 #include "bits/ConstantPluginHandleMapper.h" | |
6 | 4 |
7 #include <iostream> | 5 #include <iostream> |
8 #include <sstream> | 6 #include <sstream> |
9 #include <stdexcept> | 7 #include <stdexcept> |
10 | 8 |
35 throw VampJson::Failure("object expected for payload field"); | 33 throw VampJson::Failure("object expected for payload field"); |
36 } | 34 } |
37 return j; | 35 return j; |
38 } | 36 } |
39 | 37 |
38 class PreservingPluginHandleMapper : public PluginHandleMapper | |
39 { | |
40 public: | |
41 PreservingPluginHandleMapper() : m_handle(0), m_plugin(0) { } | |
42 | |
43 virtual int32_t pluginToHandle(Vamp::Plugin *p) { | |
44 if (p == m_plugin) return m_handle; | |
45 else throw NotFound(); | |
46 } | |
47 | |
48 virtual Vamp::Plugin *handleToPlugin(int32_t h) { | |
49 m_handle = h; | |
50 m_plugin = reinterpret_cast<Vamp::Plugin *>(1); | |
51 return m_plugin; | |
52 } | |
53 | |
54 private: | |
55 int32_t m_handle; | |
56 Vamp::Plugin *m_plugin; | |
57 }; | |
58 | |
40 void | 59 void |
41 handle_input(::capnp::MallocMessageBuilder &message, string input) | 60 handle_input(::capnp::MallocMessageBuilder &message, string input) |
42 { | 61 { |
43 string err; | 62 string err; |
44 | 63 |
48 | 67 |
49 if (type == "basic") { | 68 if (type == "basic") { |
50 throw VampJson::Failure("can't convert Basic block on its own"); | 69 throw VampJson::Failure("can't convert Basic block on its own"); |
51 | 70 |
52 } else if (type == "configurationrequest") { | 71 } else if (type == "configurationrequest") { |
53 throw VampJson::Failure("not implemented yet"); ///!!! | 72 |
73 auto req = message.initRoot<ConfigurationRequest>(); | |
74 PreservingPluginHandleMapper mapper; | |
75 VampnProto::buildConfigurationRequest | |
76 (req, VampJson::toConfigurationRequest(payload, mapper), mapper); | |
54 | 77 |
55 } else if (type == "configurationresponse") { | 78 } else if (type == "configurationresponse") { |
56 throw VampJson::Failure("not implemented yet"); ///!!! | 79 throw VampJson::Failure("not implemented yet"); ///!!! |
57 | 80 |
58 } else if (type == "feature") { | 81 } else if (type == "feature") { |