comparison utilities/vampipe-convert.cpp @ 31:b376ab0ce003

Begin server
author Chris Cannam <c.cannam@qmul.ac.uk>
date Tue, 24 May 2016 16:30:01 +0100
parents eb679afcd1bb
children 2d97883d20df
comparison
equal deleted inserted replaced
30:eb679afcd1bb 31:b376ab0ce003
1 1
2 #include "VampJson.h" 2 #include "VampJson.h"
3 #include "VampnProto.h" 3 #include "VampnProto.h"
4
5 #include "bits/RequestOrResponse.h"
4 6
5 #include <iostream> 7 #include <iostream>
6 #include <sstream> 8 #include <sstream>
7 #include <stdexcept> 9 #include <stdexcept>
8 10
9 using namespace std; 11 using namespace std;
10 using namespace json11; 12 using namespace json11;
11 using namespace vampipe; 13 using namespace vampipe;
12
13 // Accepting JSON objects with two fields, "type" and "content". The
14 // "type" string corresponds to the JSON schema filename
15 // (e.g. "outputdescriptor") and the "content" is the JSON object
16 // encoded with that schema.
17
18 class PreservingPluginHandleMapper : public PluginHandleMapper
19 {
20 public:
21 PreservingPluginHandleMapper() : m_handle(0), m_plugin(0) { }
22
23 virtual int32_t pluginToHandle(Vamp::Plugin *p) {
24 if (p == m_plugin) return m_handle;
25 else throw NotFound();
26 }
27
28 virtual Vamp::Plugin *handleToPlugin(int32_t h) {
29 m_handle = h;
30 m_plugin = reinterpret_cast<Vamp::Plugin *>(h);
31 return m_plugin;
32 }
33
34 private:
35 int32_t m_handle;
36 Vamp::Plugin *m_plugin;
37 };
38 14
39 void usage() 15 void usage()
40 { 16 {
41 string myname = "vampipe-convert"; 17 string myname = "vampipe-convert";
42 cerr << "\n" << myname << 18 cerr << "\n" << myname <<
54 "messages and pass them to output.\n\n"; 30 "messages and pass them to output.\n\n";
55 31
56 exit(2); 32 exit(2);
57 } 33 }
58 34
59 class RequestOrResponse
60 {
61 public:
62 enum Direction {
63 Request, Response
64 };
65
66 RequestOrResponse() : // nothing by default
67 direction(Request),
68 type(RRType::NotValid),
69 success(false),
70 finishPlugin(0) { }
71
72 Direction direction;
73 RRType type;
74 bool success;
75 string errorText;
76
77 PreservingPluginHandleMapper mapper;
78
79 vector<Vamp::HostExt::PluginStaticData> listResponse;
80 Vamp::HostExt::LoadRequest loadRequest;
81 Vamp::HostExt::LoadResponse loadResponse;
82 Vamp::HostExt::ConfigurationRequest configurationRequest;
83 Vamp::HostExt::ConfigurationResponse configurationResponse;
84 Vamp::HostExt::ProcessRequest processRequest;
85 Vamp::HostExt::ProcessResponse processResponse;
86 Vamp::Plugin *finishPlugin;
87 Vamp::HostExt::ProcessResponse finishResponse;
88 };
89
90 Json 35 Json
91 convertRequestJson(string input) 36 convertRequestJson(string input)
92 { 37 {
93 string err; 38 string err;
94 Json j = Json::parse(input, err); 39 Json j = Json::parse(input, err);