1 karl 1.15 //%2006////////////////////////////////////////////////////////////////////////
|
2 chip 1.1 //
|
3 karl 1.9 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
|
6 karl 1.5 // IBM Corp.; EMC Corporation, The Open Group.
|
7 karl 1.9 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
|
9 karl 1.10 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 karl 1.15 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
|
13 chip 1.1 //
14 // Permission is hereby granted, free of charge, to any person obtaining a copy
15 // of this software and associated documentation files (the "Software"), to
16 // deal in the Software without restriction, including without limitation the
17 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
18 // sell copies of the Software, and to permit persons to whom the Software is
19 // furnished to do so, subject to the following conditions:
|
20 karl 1.9 //
|
21 chip 1.1 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
22 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
23 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
24 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
25 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
27 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30 //==============================================================================
31 //
32 //%/////////////////////////////////////////////////////////////////////////////
33
|
34 kumpf 1.17 #include <Pegasus/Common/PegasusAssert.h>
|
35 chip 1.1 #include "DynamicLibrary.h"
36
37 #if defined(PEGASUS_OS_TYPE_WINDOWS)
38 # include "DynamicLibraryWindows.cpp"
|
39 mateus.baur 1.14 #elif defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_HPUX_USE_DLOPEN)
|
40 kumpf 1.13 # include "DynamicLibraryHPUX.cpp"
|
41 kumpf 1.17 #elif defined(PEGASUS_OS_TYPE_UNIX) || defined(PEGASUS_OS_VMS)
42 # include "DynamicLibraryPOSIX.cpp"
|
43 chip 1.1 #else
44 # error "Unsupported platform"
45 #endif
46
47 PEGASUS_NAMESPACE_BEGIN
48
|
49 kumpf 1.17 DynamicLibrary::DynamicLibrary()
50 : _handle(0),
51 _referenceCount(0)
|
52 chip 1.3 {
53 }
54
|
55 kumpf 1.17 DynamicLibrary::DynamicLibrary(const DynamicLibrary& library)
56 : _fileName(library._fileName),
57 _handle(0),
58 _referenceCount(0)
|
59 chip 1.3 {
60 // load the module again, if necessary. this effectively increments the
61 // operating system's reference count for the module.
|
62 kumpf 1.17 if (library.isLoaded())
|
63 chip 1.3 {
|
64 kumpf 1.17 if (load())
65 {
66 _referenceCount = library._referenceCount;
67 }
|
68 chip 1.3 }
69 }
70
|
71 kumpf 1.17 DynamicLibrary::DynamicLibrary(const String& fileName)
72 : _fileName(fileName),
73 _handle(0),
74 _referenceCount(0)
|
75 chip 1.3 {
76 }
77
|
78 kumpf 1.16 DynamicLibrary::~DynamicLibrary()
|
79 chip 1.3 {
|
80 kumpf 1.17 // Unload the module, if necessary, to keep the operating system's
81 // reference count accurate. One call to _unload() takes care of it
82 // no matter how high _referenceCount is.
83
84 if (_referenceCount > 0)
|
85 chip 1.3 {
|
86 kumpf 1.17 PEGASUS_ASSERT(_handle != 0);
87 _unload();
|
88 chip 1.3 }
89 }
90
|
91 kumpf 1.17 DynamicLibrary& DynamicLibrary::operator=(const DynamicLibrary& library)
|
92 chip 1.3 {
|
93 kumpf 1.16 if (this == &library)
|
94 chip 1.3 {
|
95 kumpf 1.16 return *this;
|
96 chip 1.3 }
97
|
98 kumpf 1.17 while (isLoaded())
|
99 chip 1.4 {
100 unload();
101 }
102
|
103 chip 1.3 _fileName = library._fileName;
104
105 // load the module again, if necessary. this effectively increments the
106 // operating system's reference count for the module.
|
107 kumpf 1.16 if (library.isLoaded())
|
108 chip 1.3 {
|
109 kumpf 1.17 if (load())
110 {
111 _referenceCount = library._referenceCount;
112 }
|
113 chip 1.3 }
114
|
115 kumpf 1.16 return *this;
116 }
117
|
118 kumpf 1.17 Boolean DynamicLibrary::isLoaded() const
119 {
120 return _handle != 0;
121 }
122
123 Boolean DynamicLibrary::load()
124 {
125 AutoMutex lock(_loadMutex);
126
127 Boolean loaded = true;
128
129 if (_referenceCount == 0)
130 {
131 PEGASUS_ASSERT(_handle == 0);
132 loaded = _load();
133 }
134
135 if (loaded)
136 {
137 PEGASUS_ASSERT(_handle != 0);
138 _referenceCount++;
139 kumpf 1.17 }
140
141 return loaded;
142 }
143
|
144 kumpf 1.16 const String& DynamicLibrary::getLoadErrorMessage() const
145 {
146 return _loadErrorMessage;
|
147 chip 1.3 }
148
|
149 kumpf 1.17 void DynamicLibrary::unload()
|
150 chip 1.3 {
|
151 kumpf 1.17 AutoMutex lock(_loadMutex);
152
153 PEGASUS_ASSERT(_referenceCount > 0);
154 PEGASUS_ASSERT(_handle != 0);
155
156 _referenceCount--;
157
158 if (_referenceCount == 0)
159 {
160 _unload();
161 _handle = 0;
162 _loadErrorMessage.clear();
163 }
|
164 chip 1.3 }
165
|
166 kumpf 1.17 const String& DynamicLibrary::getFileName() const
|
167 chip 1.3 {
|
168 kumpf 1.17 return _fileName;
|
169 chip 1.3 }
170
|
171 chip 1.1 PEGASUS_NAMESPACE_END
|