moduleLoaderDLL.cpp
Go to the documentation of this file.
00001 #include "moduleLoaderDLL.h"
00002 #include <assert.h>
00003 
00004 ModuleLoaderDLL::ModuleLoaderDLL()
00005 {
00006 
00007 }
00008 
00009 ModuleLoaderDLL::~ModuleLoaderDLL()
00010 {
00011    // _openLibs should have been filled in getFunction
00012    // now we might want to close them
00013 }
00014 
00015 bool startsWith(const std::string & str, const std::string substr)
00016 {
00017    return (str.find(substr) == 0);
00018 }
00019 
00020 bool endsWith(const std::string & str, const std::string substr)
00021 {
00022    size_t pos = str.rfind(substr);
00023    if(pos == std::string::npos) // doesnt even contain it
00024       return false;
00025 
00026    size_t len = str.length();
00027    size_t elen = substr.length();
00028    // at end means: Pos found + length of end equal length of full string.
00029    if( pos + elen == len ) {
00030       return true;
00031    }
00032 
00033    // not at end
00034    return false;
00035 }
00036 
00041 string ModuleLoaderDLL::soToDll(const string & libname)
00042 {
00043    if(!endsWith(libname, ".so"))    // not .so - something custom or even .dll -> do nothing
00044      return libname;
00045    // it ends with ".so" -> replace it
00046    string res = libname.substr(0, libname.length() - 2);
00047    res += "dll";
00048    if(startsWith(res, "lib")) {
00049       res = res.substr(3);
00050    }
00051 
00052    return res;
00053 }
00054 
00055 void* ModuleLoaderDLL::getFunction(string fnString)
00056 {
00057    string libName = extractLibName(fnString);
00058    libName = soToDll(libName);
00059    if(libName.empty())
00060       return NULL;
00061    void* libHandle = NULL;
00062    if(_openLibs.find(libName) != _openLibs.end()) {
00063       libHandle = _openLibs[libName];
00064    } else { // need to open the lib
00065       // not implemented yet: open lib
00066       assert(false);
00067       _openLibs[libName] = libHandle;
00068    }
00069  
00070    string fnName = extractFunctionName(fnString);
00071    if(fnName.empty())
00072       return NULL;
00073 
00074    // not implemented yet: retrieve function pointer
00075    assert(false);
00076 
00077    return NULL;
00078 }
00079 


tfd_modules
Author(s): Maintained by Christian Dornhege (see AUTHORS file).
autogenerated on Mon Oct 6 2014 07:52:06