(file) Return to ProviderModule.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / ProviderManager2 / Default

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2