HMSBEAGLE  1.0.0
libhmsbeagle/plugin/LibtoolSharedLibrary.h
00001 
00011 #ifndef __LIBTOOLSHAREDLIBRARY_H__
00012 #define __LIBTOOLSHAREDLIBRARY_H__
00013 
00014 #ifdef HAVE_CONFIG_H
00015 #include "libhmsbeagle/config.h"
00016 #endif
00017 
00018 #include "libhmsbeagle/plugin/SharedLibrary.h"
00019 
00020 #ifdef HAVE_LIBLTDL
00021 
00022 // use libtool-devel library loading
00023 #include <ltdl.h>
00024 #include <iostream>
00025 
00026 
00027 namespace beagle {
00028 namespace plugin {
00029 
00030 class UnixSharedLibrary : public SharedLibrary
00031 {
00032   public:
00033     UnixSharedLibrary(const char* name);
00034     ~UnixSharedLibrary();
00035 
00036     void* findSymbol(const char* name);
00037 
00038   private:
00039     lt_dlhandle m_handle;
00040 };
00041 
00042 UnixSharedLibrary::UnixSharedLibrary(const char* name)
00043     : m_handle(0)
00044 {
00045     lt_dlinit();
00046     std::string libname = "lib";
00047     libname += name;    
00048 
00049     m_handle = lt_dlopenext(libname.c_str());
00050     if (m_handle == 0)
00051     {
00052     const char* s = lt_dlerror();
00053     throw SharedLibraryException(s?s:"Exact Error Not Reported");
00054     }
00055 }
00056 UnixSharedLibrary::~UnixSharedLibrary() {
00057         lt_dlclose(m_handle); 
00058         lt_dlexit();
00059 }
00060 
00061 void* UnixSharedLibrary::findSymbol(const char* name)
00062 {
00063     void* sym = lt_dlsym(m_handle,name);
00064     if (sym == 0)
00065     throw SharedLibraryException("Symbol Not Found");
00066     else
00067     return sym;
00068 }
00069 
00070 } // namespace plugin
00071 } // namespace beagle
00072 
00073 #endif  // HAVE_LIBLTDL
00074 
00075 #endif  // __LIBTOOLSHAREDLIBRARY_H__
00076