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 = shl_load(filepath, BIND_DEFERRED, 0L);
00036 if (lib == NULL)
00037 {
00038 std::cerr << "Error loading the lib: ";
00039 perror("");
00040 std::cerr << std::endl;
00041 return valid_lib = false;
00042 }
00043
00044 file_path = filepath;
00045 return valid_lib = true;
00046 }
00047
00048 void* DynLib::getFunction(const char* func)
00049 {
00050 if (!valid_lib)
00051 {
00052 std::cerr << "Cannot getFunction out of invalid lib\n";
00053 return 0;
00054 }
00055
00056 void* func_ptr;
00057 if (shl_findsym(&lib, func, TYPE_UNDEFINED, func_ptr) != 0)
00058 {
00059 std::cerr << "Could not load function: " << func << ". Error message: ";
00060 perror("");
00061 std::cerr << std::endl;
00062 valid_lib = false;
00063 return 0;
00064 }
00065 return func_ptr;
00066 }
00067
00068 void DynLib::unloadLibrary()
00069 {
00070 if (lib)
00071 {
00072 if (shl_unload(lib) != 0)
00073 {
00074 std::cerr << "Error closing lib: ";
00075 perror("");
00076 std::cerr << std::endl;
00077 }
00078 }
00079 lib = NULL;
00080 valid_lib = false;
00081 }
00082
00083 bool DynLib::parsePath( const std::string &path, std::string &return_dir, std::string &return_pattern )
00084 {}
00085
00086
00087
00088 std::list < std::string > DynLib::enumPlatformDirectory( const std::string& path )
00089 {}
00090