21 #include <boost/version.hpp> 22 #include <boost/regex.hpp> 23 #include <boost/tokenizer.hpp> 25 #if (BOOST_VERSION <= 103301) 26 #include <boost/filesystem/path.hpp> 27 #include <boost/filesystem/operations.hpp> 29 #include <boost/filesystem.hpp> 34 using namespace boost;
40 const char* DLLSFX =
".dll";
41 const char* PATH_DELIMITER =
";";
42 typedef HINSTANCE DllHandle;
43 inline DllHandle loadDll(
const char*
filename) {
return LoadLibrary(filename); }
44 inline void* resolveDllSymbol(DllHandle handle,
const char* symbol) {
return GetProcAddress(handle, symbol); }
45 inline void unloadDll(DllHandle handle) { FreeLibrary(handle); }
49 const char* DLLSFX =
".dylib";
51 const char* DLLSFX =
".so";
53 const char* PATH_DELIMITER =
":";
54 typedef void* DllHandle;
55 inline DllHandle loadDll(
const char*
filename) {
return dlopen(filename, RTLD_LAZY); }
56 inline void* resolveDllSymbol(DllHandle handle,
const char* symbol) {
return dlsym(handle, symbol); }
57 inline void unloadDll(DllHandle handle) { dlclose(handle); }
60 typedef std::map<std::string, BodyCustomizerInterface*> NameToInterfaceMap;
61 NameToInterfaceMap customizerRepository;
62 bool pluginLoadingFunctionsCalled =
false;
64 inline string toNativePathString(
const filesystem::path& path) {
65 #if (BOOST_VERSION <= 103301) 66 return path.native_file_string();
67 #elif (BOOST_VERSION < 104600) 68 return path.file_string();
82 && customizerInterface->
create 83 && customizerInterface->
destroy;
96 DllHandle dll = loadDll(filename.c_str());
103 if(!getCustomizerInterface){
106 customizerInterface = getCustomizerInterface(bodyInterface);
108 if(customizerInterface){
111 cerr <<
"Body customizer \"" << filename <<
"\" is incomatible and cannot be loaded.";
113 cerr <<
"Loading body customizer \"" << filename <<
"\" for ";
117 for(
int i=0; names[
i]; ++
i){
121 string name(names[
i]);
123 customizerRepository[
name] = customizerInterface;
133 return (customizerInterface != 0);
149 pluginLoadingFunctionsCalled =
true;
152 #if (BOOST_VERSION < 104600) 153 filesystem::path pluginPath(pathString, filesystem::native);
155 if(filesystem::exists(pluginPath)){
157 if(!filesystem::is_directory(pluginPath)){
162 regex pluginNamePattern(
string(
".+Customizer") + DLLSFX);
163 filesystem::directory_iterator end;
165 for(filesystem::directory_iterator it(pluginPath); it != end; ++it){
166 const filesystem::path& filepath = *it;
167 if(!filesystem::is_directory(filepath)){
168 if(regex_match(filepath.leaf(), pluginNamePattern)){
177 #elif (BOOST_VERSION >= 105000) 178 filesystem::path pluginPath(pathString, (
void *)filesystem::native);
180 if(filesystem::exists(pluginPath)){
182 if(!filesystem::is_directory(pluginPath)){
187 regex pluginNamePattern(
string(
".+Customizer") + DLLSFX);
188 filesystem::directory_iterator end;
190 for(filesystem::directory_iterator it(pluginPath); it != end; ++it){
191 const filesystem::path& filepath = *it;
192 if(!filesystem::is_directory(filepath)){
193 if(regex_match(filepath.filename().string(), pluginNamePattern)){
203 filesystem3::path pluginPath(pathString, (
void *)filesystem3::native);
205 if(filesystem3::exists(pluginPath)){
207 if(!filesystem3::is_directory(pluginPath)){
212 regex pluginNamePattern(
string(
".+Customizer") + DLLSFX);
213 filesystem3::directory_iterator end;
215 for(filesystem3::directory_iterator it(pluginPath); it != end; ++it){
216 const filesystem3::path& filepath = *it;
217 if(!filesystem3::is_directory(filepath)){
218 if(regex_match(filepath.filename().string(), pluginNamePattern)){
246 if(!pluginLoadingFunctionsCalled){
248 pluginLoadingFunctionsCalled =
true;
250 char* pathListEnv =
getenv(
"HRPMODEL_CUSTOMIZER_PATH");
253 char_separator<char> sep(PATH_DELIMITER);
254 string pathList(pathListEnv);
255 tokenizer< char_separator<char> > paths(pathList, sep);
256 tokenizer< char_separator<char> >::iterator p;
257 for(p = paths.begin(); p != paths.end(); ++p){
265 filesystem::path customizerPath =
266 filesystem::path(info.dli_fname).branch_path().branch_path() / OPENHRP_RELATIVE_SHARE_DIR /
"customizer";
270 string customizerPath(OPENHRP_SHARE_DIR);
271 customizerPath.append(
"/customizer");
291 NameToInterfaceMap::iterator p = customizerRepository.find(modelName);
292 if(p != customizerRepository.end()){
293 customizerInterface = p->second;
296 return customizerInterface;
static bool checkInterface(BodyCustomizerInterface *customizerInterface)
Modifications controlling boost library behavior.
png_infop png_charpp name
static const int BODY_CUSTOMIZER_INTERFACE_VERSION
static BodyInterface * bodyInterface()
static bool loadCustomizerDll(BodyInterface *bodyInterface, const std::string filename)
BodyCustomizerCreateFunc create
static BodyInterface * bodyInterface
BodyCustomizerDestroyFunc destroy
BodyCustomizerInterface *(* GetBodyCustomizerInterfaceFunc)(BodyInterface *bodyInterface)
The definitions of the body customizer interface for increasing binary compatibility.
char * getenv(const char *name)
BodyCustomizerGetTargetModelNamesFunc getTargetModelNames
HRPMODEL_API int loadBodyCustomizers(const std::string pathString, BodyInterface *bodyInterface)
HRPMODEL_API BodyCustomizerInterface * findBodyCustomizer(std::string modelName)