Page MenuHomec4science

BackendLoader.cpp
No OneTemporary

File Metadata

Created
Fri, Jun 7, 10:04

BackendLoader.cpp

/**
* \file BackendLoader.cpp
*
* \date Jun 21, 2012
* \author Alexandre Tuleu
*/
#include "BackendLoader.h"
#include <liboncilla/exceptions/LoadingError.h>
#include <biorob-cpp/os/Env.h>
namespace rci {
namespace oncilla {
const char * BackendLoader::FORCE_MODULE_ENV_NAME = "LIBONCILLA_FORCE_BACKEND";
BackendLoader::BackendLoader(){
typedef PluginLoader<OncillaBackend> PL;
d_loader.SetHint((PL::LoadingHint) (PL::IsCMakeModuleObject | PL::ResolveAllSymbols));
if(os::Env::IsSet(FORCE_MODULE_ENV_NAME)){
d_loader.SetFilename(os::Env::Get(FORCE_MODULE_ENV_NAME));
} else {
//adds the different variants. first try to open simulation backend, if not
//found, will try to open HW backend ...
//if not found will fire a std::runtime_error
//library predix and suffix are determined from platform bx biorob-cpp/PluginLoader
d_loader.AppendVariant("oncilla-webots");
d_loader.AppendVariant("oncilla-hw");
// backend should be compiled using the cross-platform MODULE target of CMake
// and to avoid unexpected jitter, we resolve all symbols at opening.
}
}
BackendLoader::~BackendLoader(){}
const OncillaBackend::Ptr & BackendLoader::SuitableBackend(){
if(d_loadedBackend){
return d_loadedBackend;
}
try{
//try to loads backend from constructor order
d_loadedBackend = d_loader.LoadPlugin();
} catch (const std::runtime_error & e) {
//PluginLoader fire a std::runtime error with all the
//dlopen / dlsym error messages, we propagate this error with a nice
//specific wrapper arround std::runtime_error (could be useful
// for higher level to recover from that error)
throw LoadingError(e.what());
}
return d_loadedBackend;
}
} /* namespace oncilla */
} /* namespace rci */

Event Timeline