29 #include <boost/algorithm/string.hpp> 38 static std::unique_ptr<T> GetFactory(
const std::string& lib_name)
44 lib_handle = dlopen(lib_name.c_str(), RTLD_NOW);
54 create = (T*(*)()) dlsym(lib_handle,
"create_instance");
55 if((error = dlerror()) != NULL)
57 fprintf(stderr,
"Error in loading library '%s':\n%s", lib_name.c_str(), error);
61 T* instance = ( T* ) create();
62 if(instance !=
nullptr)
64 return std::unique_ptr<T>(instance);
67 fprintf(stderr,
"Error in loading library '%s': obtained pointer is null\n", lib_name.c_str());
81 virtual bool close(){
return true;}
82 virtual bool init(std::string logger_name,
bool compression){
return true;}
83 virtual bool write(
const char* name,
const double* data,
int rows,
int cols,
int slices){
return true;}
91 return std::make_unique<DummyBackend>();
94 return GetFactory<Backend>(
"libmatlogger2-backend-" + type +
".so");
virtual bool write(const char *name, const double *data, int rows, int cols, int slices)
virtual bool init(std::string logger_name, bool compression)
static UniquePtr MakeInstance(std::string type)
std::unique_ptr< Backend > UniquePtr