forked from ossimlabs/ossim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathossimDynamicLibrary.cpp
More file actions
105 lines (92 loc) · 2.52 KB
/
Copy pathossimDynamicLibrary.cpp
File metadata and controls
105 lines (92 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//*******************************************************************
//
// LICENSE: LGPL
//
// See LICENSE.txt file in the top level directory for more details.
//
// Author: Garrett Potts
//
//*********************************************************************
// $Id: ossimDynamicLibrary.cpp 20694 2012-03-19 12:22:05Z dburken $
#include <ossim/plugin/ossimDynamicLibrary.h>
#include <ossim/plugin/ossimSharedObjectBridge.h>
#include <ossim/base/ossimTrace.h>
#include <ossim/base/ossimNotifyContext.h>
// Static trace for debugging.
static ossimTrace traceDebug(ossimString("ossimDynamicLibrary:debug"));
ossimDynamicLibrary::ossimDynamicLibrary()
:theLibrary(0)
{
}
ossimDynamicLibrary::ossimDynamicLibrary(const ossimString& name)
{
load(name);
}
ossimDynamicLibrary::~ossimDynamicLibrary()
{
unload();
}
bool ossimDynamicLibrary::load()
{
return load(theLibraryName);
}
bool ossimDynamicLibrary::load(const ossimString& name)
{
ossimFilename libraryName = name.trim();
if(libraryName.empty()||!libraryName.isFile())
return false;
# if defined(__WIN32__) || defined(_WIN32)
theLibrary = LoadLibrary(libraryName.c_str());
# else
//theLibrary = dlopen(libraryName.c_str(), RTLD_LAZY|RTLD_LOCAL);
// Use of RTLD_GLOBAL fixes CSM3 plugin with MSP loading CSM plugins, but requires unique
// variable and method names in all *PluginInit.cpp code.
theLibrary = dlopen(libraryName.c_str(), RTLD_LAZY|RTLD_GLOBAL);
#endif
if (isLoaded())
{
theLibraryName = libraryName;
}
else
{
ossimNotify(ossimNotifyLevel_WARN)<<"ossimDynamicLibrary:"<<__LINE__
<< " Failed to load library: " << name << std::endl;
#if !defined(__WIN32__) && !defined(_WIN32)
ossimNotify(ossimNotifyLevel_WARN) << dlerror() << std::endl;
#endif
}
if (traceDebug())
{
if (isLoaded())
{
ossimNotify(ossimNotifyLevel_DEBUG)<<"ossimDynamicLibrary:"<<__LINE__
<< " Loaded library: " << name << std::endl;
}
}
return isLoaded();
}
void ossimDynamicLibrary::unload()
{
if(isLoaded())
{
#if defined(__WIN32__) || defined(_WIN32)
FreeLibrary(theLibrary);
// #else HAVE_DLFCN_H
#else
dlclose(theLibrary);
#endif
theLibrary = 0;
}
}
void *ossimDynamicLibrary::getSymbol(const ossimString& name) const
{
if(isLoaded())
{
#if defined(__WIN32__) || defined(_WIN32)
return (void*)GetProcAddress( (HINSTANCE)theLibrary, name.c_str());
#else
return dlsym(theLibrary, name.c_str());
#endif
}
return (void*)0;
}