1 karl 1.4 //%2003////////////////////////////////////////////////////////////////////////
|
2 chip 1.1 //
|
3 karl 1.4 // 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 // IBM Corp.; EMC Corporation, The Open Group.
|
7 chip 1.1 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to
10 // deal in the Software without restriction, including without limitation the
11 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12 // sell copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
|
14 karl 1.4 //
|
15 chip 1.1 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
16 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
17 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
18 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
19 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 //
24 //==============================================================================
25 //
26 // Author: Chip Vincent (cvincent@us.ibm.com)
27 //
28 // Modified By:
29 // Nag Boranna, Hewlett-Packard Company(nagaraja_boranna@hp.com)
30 // Yi Zhou, Hewlett-Packard Company(yi_zhou@hp.com)
31 // Mike Day, IBM (mdday@us.ibm.com)
32 // Adrian Schuur, IBM (schuur@de.ibm.com)
33 //
34 //%/////////////////////////////////////////////////////////////////////////////
35
36 chip 1.1 #include "ProviderModule.h"
37
38 #include <Pegasus/Common/Destroyer.h>
39 #include <Pegasus/Common/FileSystem.h>
40 #include <Pegasus/Common/MessageLoader.h> //l10n
|
41 chip 1.3
42 #ifdef PEGASUS_OS_OS400
43 #include "CreateProviderOS400SystemState.h"
44 #endif
|
45 chip 1.1
46 PEGASUS_NAMESPACE_BEGIN
47
48 ProviderModule::ProviderModule(const String & fileName, const String & interfaceName)
49 : _fileName(fileName),
50 _interfaceName(interfaceName),
51 _ref_count(0),
52 _library(0)
53 {
54 _interfaceFileName=String::EMPTY;
55 if(_interfaceName.size()>0)
56 {
57 #ifdef PEGASUS_OS_TYPE_WINDOWS
58 _interfaceFileName=_interfaceName+String("Adapter.dll");
59 #elif defined(PEGASUS_OS_HPUX)
|
60 konrad.r 1.5 _interfaceFileName =
61 String("lib")+interfaceName+String("Adapter.sl");
|
62 chip 1.1 #elif defined(PEGASUS_OS_OS400)
63 _interfaceFileName=interfaceName+String("Adapter");
|
64 dudhe.girish 1.6 #elif defined(PEGASUS_OS_DARWIN)
65 _interfaceFileName= String("lib")+interfaceName+String("Adapter.dylib");
|
66 chip 1.1 #else
|
67 konrad.r 1.5 _interfaceFileName= String("lib")+interfaceName+String("Adapter.so");
|
68 chip 1.1 #endif
|
69 konrad.r 1.5
70 _interfaceFileName = FileSystem::getAbsoluteFileName(
71 ConfigManager::getHomedPath(ConfigManager::getInstance()->getCurrentValue("providerDir")), _interfaceFileName);
72
|
73 chip 1.1 }
74 }
75
76 ProviderModule::ProviderModule(const String & fileName,
77 const String & providerName,
78 const String & interfaceName,
79 const Uint32 & refCount)
80 : _fileName(fileName),
81 _library(0),
82 _providerName(providerName),
83 _interfaceName(interfaceName),
84 _provider(0),
85 _refCount(refCount)
86
87 {
88 // currently without interface registration
89 _interfaceFileName = String::EMPTY;
90
91 if(_interfaceName.size() > 0)
92 if(!( String::equalNoCase(_interfaceName, "C++Standard") ||
93 String::equalNoCase(_interfaceName, "C++Default") ||
94 chip 1.1 String::equalNoCase(_interfaceName, "PG_DefaultC++") ))
95 {
96 #ifdef PEGASUS_OS_TYPE_WINDOWS
97 _interfaceFileName = _interfaceName + String(".dll");
98 #elif defined(PEGASUS_OS_HPUX)
|
99 konrad.r 1.5 _interfaceFileName = String("lib") + _interfaceName + String(".sl");
|
100 chip 1.1 #elif defined(PEGASUS_OS_OS400)
101 _interfaceFileName = _interfaceName;
|
102 dudhe.girish 1.6 #elif defined(PEGASUS_OS_DARWIN)
103 _interfaceFileName = String("lib") + _interfaceName + String(".dylib");
|
104 chip 1.1 #else
|
105 konrad.r 1.5 _interfaceFileName = String("lib") + _interfaceName + String(".so");
|
106 chip 1.1 #endif
|
107 konrad.r 1.5
108 _interfaceFileName = FileSystem::getAbsoluteFileName(
109 ConfigManager::getHomedPath(ConfigManager::getInstance()->getCurrentValue("providerDir")), _interfaceFileName);
110
|
111 chip 1.1 }
112 }
113
114 ProviderModule::ProviderModule(const ProviderModule & pm)
115 : _fileName(pm._fileName),
116 _library(pm._library),
117 _providerName(pm._providerName),
118 _interfaceName(pm._interfaceName),
119 _interfaceFileName(pm._interfaceFileName),
120 _provider(pm._provider),
121 _refCount(pm._refCount)
122 {
123 }
124
125 ProviderModule::~ProviderModule(void)
126 {
127 }
128
129 CIMProvider *ProviderModule::load(const String & providerName)
130 {
131 CIMProvider *provider = 0;
132 chip 1.1
133 // dynamically load the provider library
134 if(_library == 0)
135 {
136 _library = System::loadDynamicLibrary((const char *)_fileName.getCString());
137 }
138
139 if(_library == 0)
140 {
141
142 // ATTN: does unload() need to be called?
143 //l10n
144 //String errorString = "Cannot load library, error: " + System::dynamicLoadError();
145 //throw Exception("ProviderLoadFailure (" + _fileName + ":" + providerName + "):" + errorString);
146 throw Exception(MessageLoaderParms("ProviderManager.ProviderModule.CANNOT_LOAD_LIBRARY",
|
147 chip 1.3 "ProviderLoadFailure ($0:$1):Cannot load library, error: $2",
|
148 chip 1.1 _fileName,
149 providerName,
150 System::dynamicLoadError()));
151 }
152
153 // find libray entry point
154 CIMProvider * (*createProvider)(const String &) = 0;
155
156 createProvider = (CIMProvider * (*)(const String &))System::loadDynamicSymbol(
157 _library, "PegasusCreateProvider");
158
159 if(createProvider == 0)
160 {
161 //l10n
162 //String errorString = "entry point not found.";
163 //throw Exception("ProviderLoadFailure (" + _fileName + ":" + providerName + "):" + errorString);
|
164 chip 1.3
|
165 chip 1.1 throw Exception(MessageLoaderParms("ProviderManager.ProviderModule.ENTRY_POINT_NOT_FOUND",
|
166 chip 1.3 "ProviderLoadFailure ($0:$1):entry point not found.",
|
167 chip 1.1 _fileName,
168 providerName));
169 }
170
171 // invoke the provider entry point
|
172 chip 1.3 #ifndef PEGASUS_OS_OS400
|
173 chip 1.1 provider = createProvider(providerName);
|
174 chip 1.3 #else
175 // On OS/400, need to call a layer of code that does platform-specific
176 // checks before calling the provider
177 provider = OS400_CreateProvider(providerName.getCString(), createProvider, _fileName);
178 #endif
179
|
180 chip 1.1
181 // test for the appropriate interface
182 if(dynamic_cast<CIMProvider *>(provider) == 0)
183 {
184 //l10n
185 //String errorString = "provider is not a CIMProvider.";
186 //throw Exception("ProviderLoadFailure (" + _fileName + ":" + providerName + "):" + errorString);
187 throw Exception(MessageLoaderParms("ProviderManager.ProviderModule.PROVIDER_IS_NOT_A",
|
188 chip 1.3 "ProviderLoadFailure ($0:$1):provider is not a CIMProvider.",
|
189 chip 1.1 _fileName,
|
190 chip 1.3 providerName));
|
191 chip 1.1 }
192 _ref_count++;
193 return(provider);
194 }
195
196 void ProviderModule::unloadModule(void)
197 {
198 _ref_count--;
199 if(_ref_count.value() > 0)
200 return;
201 _ref_count = 0;
202 if(_library != 0)
203 {
204 System::unloadDynamicLibrary(_library);
205 _library = 0;
206 }
207 }
208
209 Boolean ProviderModule::operator == (const void *key) const
210 {
211 String *prov = reinterpret_cast<String *>(const_cast<void *>(key));
212 chip 1.1 if(String::equalNoCase(_fileName, *prov))
213 return(true);
214 return(false);
215 }
216
217 Boolean ProviderModule::operator == (const ProviderModule &pm) const
218 {
219 if(String::equalNoCase(_fileName, pm._fileName))
220 return(true);
221 return(false);
222 }
223
224 PEGASUS_NAMESPACE_END
|