view quick-test.cpp @ 3:6a792d8838c9

Add prototype emscripten makefile, minor tidying
author Chris Cannam
date Tue, 23 Aug 2016 21:46:49 +0100
parents 4d6e60a7c80e
children 3a5a6535d50d
line wrap: on
line source

#include <iostream>
#include <dlfcn.h>

using namespace std;

int main(int argc, char **argv)
{
    string example = "./example.so";
    
    void *lib = dlopen(example.c_str(), RTLD_LAZY | RTLD_LOCAL);
    if (!lib) {
	cerr << "failed to open " + example + ": " << dlerror() << endl;
	return 1;
    }

    typedef const char *(*RequestFn)(const char *);
    RequestFn reqFn = (RequestFn)dlsym(lib, "vampipeRequestJson");
    if (!reqFn) {
	cerr << "failed to find request function in " +
	    example + ": " << dlerror() << endl;
	return 1;
    }
    
    typedef void (*FreeFn)(const char *);
    FreeFn freeFn = (FreeFn)dlsym(lib, "vampipeFreeJson");
    if (!freeFn) {
	cerr << "failed to find free function in " +
	    example + ": " << dlerror() << endl;
	return 1;
    }

    string listRequest = "{\"type\": \"list\"}";
    const char *listResponse = reqFn(listRequest.c_str());
    cout << listResponse << endl;
    freeFn(listResponse);
}