comparison quick-test.cpp @ 2:4d6e60a7c80e

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