annotate quick-test.cpp @ 71:4f16ceb503c4
Some JSON fixes and a quick test program
author |
Chris Cannam <c.cannam@qmul.ac.uk> |
date |
Tue, 23 Aug 2016 12:04:49 +0100 |
parents |
|
children |
3a5a6535d50d |
rev |
line source |
c@71
|
1
|
c@71
|
2 #include <iostream>
|
c@71
|
3 #include <dlfcn.h>
|
c@71
|
4
|
c@71
|
5 using namespace std;
|
c@71
|
6
|
c@71
|
7 int main(int argc, char **argv)
|
c@71
|
8 {
|
c@71
|
9 string example = "./example.so";
|
c@71
|
10
|
c@71
|
11 void *lib = dlopen(example.c_str(), RTLD_LAZY | RTLD_LOCAL);
|
c@71
|
12 if (!lib) {
|
c@71
|
13 cerr << "failed to open " + example + ": " << dlerror() << endl;
|
c@71
|
14 return 1;
|
c@71
|
15 }
|
c@71
|
16
|
c@71
|
17 typedef const char *(*RequestFn)(const char *);
|
c@71
|
18 RequestFn reqFn = (RequestFn)dlsym(lib, "vampipeRequestJson");
|
c@71
|
19 if (!reqFn) {
|
c@71
|
20 cerr << "failed to find request function in " +
|
c@71
|
21 example + ": " << dlerror() << endl;
|
c@71
|
22 return 1;
|
c@71
|
23 }
|
c@71
|
24
|
c@71
|
25 typedef void (*FreeFn)(const char *);
|
c@71
|
26 FreeFn freeFn = (FreeFn)dlsym(lib, "vampipeFreeJson");
|
c@71
|
27 if (!freeFn) {
|
c@71
|
28 cerr << "failed to find free function in " +
|
c@71
|
29 example + ": " << dlerror() << endl;
|
c@71
|
30 return 1;
|
c@71
|
31 }
|
c@71
|
32
|
c@71
|
33 string listRequest = "{\"type\": \"list\"}";
|
c@71
|
34 const char *listResponse = reqFn(listRequest.c_str());
|
c@71
|
35 cout << listResponse << endl;
|
c@71
|
36 freeFn(listResponse);
|
c@71
|
37 }
|
c@71
|
38
|