Mercurial > hg > piper-vamp-js
annotate quick-test.cpp @ 4:3a5a6535d50d
Simple test script (and associated fixes) for the JS code
author | Chris Cannam |
---|---|
date | Wed, 24 Aug 2016 10:50:40 +0100 |
parents | 4d6e60a7c80e |
children | 2a4685f230ac |
rev | line source |
---|---|
Chris@2 | 1 |
Chris@2 | 2 #include <iostream> |
Chris@2 | 3 #include <dlfcn.h> |
Chris@2 | 4 |
Chris@2 | 5 using namespace std; |
Chris@2 | 6 |
Chris@2 | 7 int main(int argc, char **argv) |
Chris@2 | 8 { |
Chris@2 | 9 string example = "./example.so"; |
Chris@2 | 10 |
Chris@2 | 11 void *lib = dlopen(example.c_str(), RTLD_LAZY | RTLD_LOCAL); |
Chris@2 | 12 if (!lib) { |
Chris@2 | 13 cerr << "failed to open " + example + ": " << dlerror() << endl; |
Chris@2 | 14 return 1; |
Chris@2 | 15 } |
Chris@2 | 16 |
Chris@2 | 17 typedef const char *(*RequestFn)(const char *); |
Chris@2 | 18 RequestFn reqFn = (RequestFn)dlsym(lib, "vampipeRequestJson"); |
Chris@2 | 19 if (!reqFn) { |
Chris@2 | 20 cerr << "failed to find request function in " + |
Chris@2 | 21 example + ": " << dlerror() << endl; |
Chris@2 | 22 return 1; |
Chris@2 | 23 } |
Chris@2 | 24 |
Chris@2 | 25 typedef void (*FreeFn)(const char *); |
Chris@2 | 26 FreeFn freeFn = (FreeFn)dlsym(lib, "vampipeFreeJson"); |
Chris@2 | 27 if (!freeFn) { |
Chris@2 | 28 cerr << "failed to find free function in " + |
Chris@2 | 29 example + ": " << dlerror() << endl; |
Chris@2 | 30 return 1; |
Chris@2 | 31 } |
Chris@2 | 32 |
Chris@2 | 33 string listRequest = "{\"type\": \"list\"}"; |
Chris@2 | 34 const char *listResponse = reqFn(listRequest.c_str()); |
Chris@2 | 35 cout << listResponse << endl; |
Chris@2 | 36 freeFn(listResponse); |
Chris@4 | 37 |
Chris@4 | 38 string loadRequest = "{\"type\":\"load\",\"content\": {\"pluginKey\":\"vamp-example-plugins:zerocrossing\",\"inputSampleRate\":44100,\"adapterFlags\":[\"AdaptAllSafe\"]}}"; |
Chris@4 | 39 const char *loadResponse = reqFn(loadRequest.c_str()); |
Chris@4 | 40 cout << loadResponse << endl; |
Chris@4 | 41 freeFn(loadResponse); |
Chris@2 | 42 } |
Chris@2 | 43 |