00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "../sharedlibrary.h"
00023 #include <dlfcn.h>
00024 #include <iostream>
00025
00026 using namespace salt;
00027
00028 bool
00029 SharedLibrary::Open(const std::string &libName)
00030 {
00031 if (mLibHandle)
00032 {
00033 Close();
00034 }
00035 #if INIT_DEBUG
00036 std::cerr << "(SharedLibrary) Opening " << libName + ".so\n";
00037 #endif
00038 mLibHandle = ::dlopen((libName + ".so").c_str(), RTLD_LAZY);
00039
00040 if (mLibHandle == NULL)
00041 {
00042 std::cerr << "(SharedLibrary) ERROR: dlopen faild for " << libName
00043 << " with: \n\t" << dlerror() << std::endl;
00044 }
00045
00046 return (mLibHandle!=NULL);
00047 }
00048
00049 void*
00050 SharedLibrary::GetProcAddress(const std::string &procName)
00051 {
00052 if (mLibHandle)
00053 {
00054 return ::dlsym(mLibHandle, procName.c_str());
00055 }
00056 return NULL;
00057 }
00058
00059 void
00060 SharedLibrary::Close()
00061 {
00062 if (mLibHandle)
00063 {
00064 ::dlclose(mLibHandle);
00065 mLibHandle = NULL;
00066 }
00067 }