OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimDynamicLibrary.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 //
3 // LICENSE: LGPL
4 //
5 // See LICENSE.txt file in the top level directory for more details.
6 //
7 // Author: Garrett Potts
8 //
9 //*********************************************************************
10 // $Id: ossimDynamicLibrary.cpp 20694 2012-03-19 12:22:05Z dburken $
13 #include <ossim/base/ossimTrace.h>
15 
16 // Static trace for debugging.
17 static ossimTrace traceDebug(ossimString("ossimDynamicLibrary:debug"));
18 
20  :theLibrary(0)
21 {
22 }
23 
25 {
26  load(name);
27 }
28 
30 {
31  unload();
32 }
33 
35 {
36  return load(theLibraryName);
37 }
38 
40 {
41  ossimFilename libraryName = name.trim();
42  if(libraryName.empty()||!libraryName.isFile())
43  return false;
44 
45 # if defined(__WIN32__) || defined(_WIN32)
46  theLibrary = LoadLibrary(libraryName.c_str());
47 # else
48  //theLibrary = dlopen(libraryName.c_str(), RTLD_LAZY|RTLD_LOCAL);
49  // Use of RTLD_GLOBAL fixes CSM3 plugin with MSP loading CSM plugins, but requires unique
50  // variable and method names in all *PluginInit.cpp code.
51  theLibrary = dlopen(libraryName.c_str(), RTLD_LAZY|RTLD_GLOBAL);
52 #endif
53 
54  if (isLoaded())
55  {
56  theLibraryName = libraryName;
57  }
58  else
59  {
60  ossimNotify(ossimNotifyLevel_WARN)<<"ossimDynamicLibrary:"<<__LINE__
61  << " Failed to load library: " << name << std::endl;
62 #if !defined(__WIN32__) && !defined(_WIN32)
63  ossimNotify(ossimNotifyLevel_WARN) << dlerror() << std::endl;
64 #endif
65  }
66 
67  if (traceDebug())
68  {
69  if (isLoaded())
70  {
71  ossimNotify(ossimNotifyLevel_DEBUG)<<"ossimDynamicLibrary:"<<__LINE__
72  << " Loaded library: " << name << std::endl;
73  }
74  }
75 
76  return isLoaded();
77 }
78 
80 {
81  if(isLoaded())
82  {
83 #if defined(__WIN32__) || defined(_WIN32)
84  FreeLibrary(theLibrary);
85 // #else HAVE_DLFCN_H
86 #else
87  dlclose(theLibrary);
88 #endif
89  theLibrary = 0;
90  }
91 }
92 
94 {
95  if(isLoaded())
96  {
97 #if defined(__WIN32__) || defined(_WIN32)
98  return (void*)GetProcAddress( (HINSTANCE)theLibrary, name.c_str());
99 #else
100  return dlsym(theLibrary, name.c_str());
101 #endif
102  }
103 
104  return (void*)0;
105 }
void * getSymbol(const ossimString &name) const
ossimString trim(const ossimString &valueToTrim=ossimString(" \\)) const
this will strip lead and trailing character passed in.
bool isFile() const
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string&#39;s contents...
Definition: ossimString.h:396
bool empty() const
Definition: ossimString.h:411
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)