[thin_dump] --format custom=<shared lib>
Allow people to use their own emitters held in a shared library. Put a trivial emitter in contrib/ as an example.
This commit is contained in:
29
thin-provisioning/shared_library_emitter.cc
Normal file
29
thin-provisioning/shared_library_emitter.cc
Normal file
@@ -0,0 +1,29 @@
|
||||
#include "thin-provisioning/shared_library_emitter.h"
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <stdexcept>
|
||||
|
||||
using namespace std;
|
||||
using namespace thin_provisioning;
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
||||
emitter::ptr
|
||||
thin_provisioning::create_custom_emitter(string const &shared_lib, ostream &out)
|
||||
{
|
||||
emitter::ptr (*create_fn)(ostream &out);
|
||||
void *handle = dlopen(shared_lib.c_str(), RTLD_LAZY);
|
||||
if (!handle)
|
||||
throw runtime_error(dlerror());
|
||||
|
||||
dlerror(); // Clear any existing error
|
||||
create_fn = reinterpret_cast<emitter::ptr (*)(ostream &)>(dlsym(handle, "create_emitter"));
|
||||
|
||||
char *error = dlerror();
|
||||
if (error)
|
||||
throw runtime_error(error);
|
||||
|
||||
return create_fn(out);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------
|
Reference in New Issue
Block a user