HMSBEAGLE  1.0.0
LibtoolSharedLibrary.h
1 
11 #ifndef __LIBTOOLSHAREDLIBRARY_H__
12 #define __LIBTOOLSHAREDLIBRARY_H__
13 
14 #ifdef HAVE_CONFIG_H
15 #include "libhmsbeagle/config.h"
16 #endif
17 
18 #include "libhmsbeagle/plugin/SharedLibrary.h"
19 
20 #ifdef HAVE_LIBLTDL
21 
22 // use libtool-devel library loading
23 #include <ltdl.h>
24 #include <iostream>
25 
26 
27 namespace beagle {
28 namespace plugin {
29 
30 class UnixSharedLibrary : public SharedLibrary
31 {
32  public:
33  UnixSharedLibrary(const char* name);
34  ~UnixSharedLibrary();
35 
36  void* findSymbol(const char* name);
37 
38  private:
39  lt_dlhandle m_handle;
40 };
41 
42 UnixSharedLibrary::UnixSharedLibrary(const char* name)
43  : m_handle(0)
44 {
45  lt_dlinit();
46  std::string libname = "lib";
47  libname += name;
48 
49  m_handle = lt_dlopenext(libname.c_str());
50  if (m_handle == 0)
51  {
52  const char* s = lt_dlerror();
53  throw SharedLibraryException(s?s:"Exact Error Not Reported");
54  }
55 }
56 UnixSharedLibrary::~UnixSharedLibrary() {
57  lt_dlclose(m_handle);
58  lt_dlexit();
59 }
60 
61 void* UnixSharedLibrary::findSymbol(const char* name)
62 {
63  void* sym = lt_dlsym(m_handle,name);
64  if (sym == 0)
65  throw SharedLibraryException("Symbol Not Found");
66  else
67  return sym;
68 }
69 
70 } // namespace plugin
71 } // namespace beagle
72 
73 #endif // HAVE_LIBLTDL
74 
75 #endif // __LIBTOOLSHAREDLIBRARY_H__
76