00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019
00020
00021 #include "DynLib.h"
00022
00023 using namespace SOME;
00024
00025 DynLib::DynLib():
00026 lib(NULL)
00027 {}
00028
00029
00030
00031 bool DynLib::loadLibrary(const char* filepath)
00032 {
00033 unloadLibrary();
00034
00035 lib = dlopen(filepath, RTLD_LAZY);
00036 if (lib == NULL)
00037 {
00038
00039
00040
00041 std::cerr << "Could not find the lib: " << dlerror() << std::endl;
00042 return valid_lib = false;
00043 }
00044
00045 dlerror();
00046 file_path = filepath;
00047 return valid_lib = true;
00048 }
00049
00050 void* DynLib::getFunction(const char* func)
00051 {
00052 if (!valid_lib)
00053 {
00054 std::cerr << "Cannot getFunction out of invalid lib\n";
00055 return 0;
00056 }
00057
00058 void* func_ptr = dlsym(lib, func);
00059 const char* error;
00060 error = dlerror();
00061 if (error)
00062 {
00063 std::cerr << "Could not load function: " << func << ". Error message: " << error << std::endl;
00064 valid_lib = false;
00065 return 0;
00066 }
00067 return func_ptr;
00068 }
00069
00070 void DynLib::unloadLibrary()
00071 {
00072 if (lib)
00073 {
00074 if (dlclose(lib) != 0)
00075 std::cerr << "Error closing lib: " << dlerror() << std::endl;
00076 }
00077 lib = NULL;
00078 valid_lib = false;
00079 dlerror();
00080 }
00081
00082 bool DynLib::parsePath( const std::string &path, std::string &return_dir, std::string &return_pattern )
00083 {}
00084
00085
00086
00087 std::list < std::string > DynLib::enumPlatformDirectory( const std::string& path )
00088 {}
00089