OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Public Member Functions | Protected Attributes | List of all members
ossimDynamicLibrary Class Reference

#include <ossimDynamicLibrary.h>

Inheritance diagram for ossimDynamicLibrary:
ossimReferenced ossimPluginLibrary

Public Member Functions

 ossimDynamicLibrary ()
 
 ossimDynamicLibrary (const ossimString &name)
 
virtual ~ossimDynamicLibrary ()
 
bool isLoaded () const
 
bool load (const ossimString &name)
 
bool load ()
 
void unload ()
 
void * getSymbol (const ossimString &name) const
 
const ossimStringgetName () const
 
- Public Member Functions inherited from ossimReferenced
 ossimReferenced ()
 
 ossimReferenced (const ossimReferenced &)
 
ossimReferencedoperator= (const ossimReferenced &)
 
void ref () const
 increment the reference count by one, indicating that this object has another pointer which is referencing it. More...
 
void unref () const
 decrement the reference count by one, indicating that a pointer to this object is referencing it. More...
 
void unref_nodelete () const
 decrement the reference count by one, indicating that a pointer to this object is referencing it. More...
 
int referenceCount () const
 

Protected Attributes

void * theLibrary
 
ossimString theLibraryName
 

Additional Inherited Members

- Protected Member Functions inherited from ossimReferenced
virtual ~ossimReferenced ()
 

Detailed Description

Definition at line 27 of file ossimDynamicLibrary.h.

Constructor & Destructor Documentation

◆ ossimDynamicLibrary() [1/2]

ossimDynamicLibrary::ossimDynamicLibrary ( )

Definition at line 19 of file ossimDynamicLibrary.cpp.

20  :theLibrary(0)
21 {
22 }

◆ ossimDynamicLibrary() [2/2]

ossimDynamicLibrary::ossimDynamicLibrary ( const ossimString name)

Definition at line 24 of file ossimDynamicLibrary.cpp.

References load().

25 {
26  load(name);
27 }

◆ ~ossimDynamicLibrary()

ossimDynamicLibrary::~ossimDynamicLibrary ( )
virtual

Definition at line 29 of file ossimDynamicLibrary.cpp.

References unload().

30 {
31  unload();
32 }

Member Function Documentation

◆ getName()

const ossimString& ossimDynamicLibrary::getName ( ) const
inline

◆ getSymbol()

void * ossimDynamicLibrary::getSymbol ( const ossimString name) const

Definition at line 93 of file ossimDynamicLibrary.cpp.

References ossimString::c_str(), isLoaded(), and theLibrary.

Referenced by ossimPluginLibrary::finalize(), ossimPluginLibrary::initialize(), and ossimSharedPluginRegistry::registerPlugin().

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 }
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

◆ isLoaded()

bool ossimDynamicLibrary::isLoaded ( ) const
inline

◆ load() [1/2]

bool ossimDynamicLibrary::load ( const ossimString name)

Definition at line 39 of file ossimDynamicLibrary.cpp.

References ossimString::c_str(), ossimString::empty(), ossimFilename::isFile(), isLoaded(), ossimNotify(), ossimNotifyLevel_WARN, theLibrary, theLibraryName, and ossimString::trim().

Referenced by ossimSharedPluginRegistry::registerPlugin().

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 }
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)

◆ load() [2/2]

bool ossimDynamicLibrary::load ( )

Definition at line 34 of file ossimDynamicLibrary.cpp.

References theLibraryName.

Referenced by ossimPluginLibrary::initialize(), and ossimDynamicLibrary().

35 {
36  return load(theLibraryName);
37 }

◆ unload()

void ossimDynamicLibrary::unload ( )

Definition at line 79 of file ossimDynamicLibrary.cpp.

References isLoaded(), and theLibrary.

Referenced by ossimPluginLibrary::finalize(), and ~ossimDynamicLibrary().

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 }

Member Data Documentation

◆ theLibrary

void* ossimDynamicLibrary::theLibrary
protected

Definition at line 58 of file ossimDynamicLibrary.h.

Referenced by getSymbol(), load(), and unload().

◆ theLibraryName

ossimString ossimDynamicLibrary::theLibraryName
protected

Definition at line 60 of file ossimDynamicLibrary.h.

Referenced by load().


The documentation for this class was generated from the following files: