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

  1 chip  1.1 //%/////////////////////////////////////////////////////////////////////////////
  2           //
  3 kumpf 1.11 // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM,
  4            // The Open Group, Tivoli Systems
  5 chip  1.1  //
  6            // Permission is hereby granted, free of charge, to any person obtaining a copy
  7            // of this software and associated documentation files (the "Software"), to
  8            // deal in the Software without restriction, including without limitation the
  9            // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 10            // sell copies of the Software, and to permit persons to whom the Software is
 11            // furnished to do so, subject to the following conditions:
 12 kumpf 1.11 // 
 13 chip  1.1  // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 14            // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 15            // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 16            // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 17            // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 18            // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 19            // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 20            // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 21            //
 22            //==============================================================================
 23            //
 24            // Author: Chip Vincent (cvincent@us.ibm.com)
 25            //
 26            // Modified By:
 27 chip  1.7  //      Nag Boranna, Hewlett-Packard Company(nagaraja_boranna@hp.com)
 28 kumpf 1.5  //		Yi Zhou, Hewlett-Packard Company(yi_zhou@hp.com)
 29 chip  1.1  //
 30            //%/////////////////////////////////////////////////////////////////////////////
 31            
 32            #include "ProviderModule.h"
 33            
 34            #include <Pegasus/Common/Destroyer.h>
 35            #include <Pegasus/Common/FileSystem.h>
 36 sage  1.8  #include <Pegasus/Provider/CIMInstanceProvider.h>
 37 chip  1.1  
 38            PEGASUS_NAMESPACE_BEGIN
 39            
 40 sage  1.8  ProviderModule::ProviderModule(const String & fileName,
 41 kumpf 1.10                                const Uint32 & refCount)
 42                : _fileName(fileName), _providerName(String::EMPTY),
 43                  _refCount(refCount), _interfaceName(String::EMPTY),
 44                  _library(0), _provider(0)
 45            {
 46            }
 47            
 48            ProviderModule::ProviderModule(const String & fileName,
 49 sage  1.8                                 const String & providerName)
 50                : _fileName(fileName), _providerName(providerName),
 51                  _library(0), _provider(0)
 52 chip  1.1  {
 53            }
 54            
 55 sage  1.8  ProviderModule::ProviderModule(const String & fileName,
 56                                           const String & providerName,
 57 kumpf 1.10                                const String & interfaceName,
 58            			       const Uint32 & refCount)
 59 sage  1.8      : _fileName(fileName), _providerName(providerName),
 60                  _interfaceName(interfaceName),
 61 kumpf 1.10       _refCount(refCount),
 62 sage  1.8        _library(0), _provider(0)
 63            {
 64                // currently without interface registration
 65                _interfaceFilename = String::EMPTY;
 66            
 67                if (_interfaceName.size() > 0)
 68                    if (!( String::equalNoCase(_interfaceName, "C++Standard") ||
 69                           String::equalNoCase(_interfaceName, "C++Default") ||
 70                           String::equalNoCase(_interfaceName, "PG_DefaultC++") ))
 71                    {
 72                        #ifdef PEGASUS_OS_TYPE_WINDOWS
 73                        _interfaceFilename = _interfaceName + String(".dll");
 74                        #elif defined(PEGASUS_OS_HPUX)
 75                        _interfaceFilename = ConfigManager::getHomedPath(
 76                            ConfigManager::getInstance()->getCurrentValue("providerDir"));
 77 kumpf 1.13             _interfaceFilename.append(
 78                            String("/lib") + _interfaceName + String(".sl"));
 79 chuck 1.15             #elif defined(PEGASUS_OS_OS400)
 80                        _interfaceFilename = _interfaceName;
 81 sage  1.8              #else
 82                        _interfaceFilename = ConfigManager::getHomedPath(
 83                            ConfigManager::getInstance()->getCurrentValue("providerDir"));
 84 kumpf 1.13             _interfaceFilename.append(
 85                            String("/lib") + _interfaceName + String(".so"));
 86 sage  1.8              #endif
 87                    }
 88            }
 89            
 90 kumpf 1.6  ProviderModule::ProviderModule(const ProviderModule & pm)
 91                : _fileName(pm._fileName),
 92 sage  1.8        _providerName(pm._providerName),
 93                  _interfaceName(pm._interfaceName),
 94                  _interfaceFilename(pm._interfaceFilename),
 95                  _library(pm._library),
 96 kumpf 1.10       _provider(pm._provider),
 97                  _refCount(pm._refCount)
 98 kumpf 1.6  {
 99            }
100            
101 chip  1.1  ProviderModule::~ProviderModule(void)
102            {
103            }
104            
105            void ProviderModule::load(void)
106            {
107 sage  1.8      // get the interface adapter library first
108 kumpf 1.17     _adapter = 0;
109 sage  1.8      if (_interfaceFilename.size() > 0)
110                {
111                    _adapter = ProviderAdapterManager::get_pamgr()->addAdapter(
112                                                      _interfaceName, _interfaceFilename,
113                                                      _providerName);
114            
115 kumpf 1.16         _provider = dynamic_cast<CIMProvider *>(_adapter);
116 sage  1.8  
117                    if (_provider == NULL)
118                    {
119 kumpf 1.16             String errorString = "ProviderAdapter is no CIMProvider";
120 sage  1.8              throw Exception("ProviderLoadFailure (" + _providerName + "):" +
121                            errorString);
122                    }
123            
124                    return;
125                }
126            
127 chip  1.1      // dynamically load the provider library
128 kumpf 1.14     _library = System::loadDynamicLibrary(_fileName.getCString());
129 chip  1.1  
130                if(_library == 0)
131                {
132 chip  1.7          // ATTN: does unload() need to be called?
133            
134                    String errorString = "Cannot load library, error: " + System::dynamicLoadError();
135                    throw Exception("ProviderLoadFailure (" + _fileName + ":" + _providerName + "):" + errorString);
136 chip  1.1      }
137            
138 kumpf 1.14     // find library entry point
139 kumpf 1.16     CIMProvider * (*createProvider)(const String &) = 0;
140 chip  1.1  
141 kumpf 1.16     createProvider = (CIMProvider * (*)(const String &))System::loadDynamicSymbol(
142 chip  1.7          _library, "PegasusCreateProvider");
143 chip  1.1  
144 chip  1.3      if(createProvider == 0)
145                {
146 chip  1.7          unload();
147 chip  1.1  
148 chip  1.7          String errorString = "entry point not found.";
149                    throw Exception("ProviderLoadFailure (" + _fileName + ":" + _providerName + "):" + errorString);
150 chip  1.3      }
151 chip  1.1  
152 chip  1.3      // invoke the provider entry point
153 kumpf 1.16     CIMProvider * provider = createProvider(_providerName);
154 chip  1.1  
155 chip  1.3      if(provider == 0)
156                {
157 chip  1.7          unload();
158 chip  1.1  
159 chip  1.7          String errorString = "entry point returned null.";
160                    throw Exception("ProviderLoadFailure (" + _fileName + ":" + _providerName + "):" + errorString);
161 chip  1.3      }
162 chip  1.1  
163 chip  1.3      // test for the appropriate interface
164 kumpf 1.16     if(dynamic_cast<CIMProvider *>(provider) == 0)
165 chip  1.3      {
166 chip  1.7          unload();
167 chip  1.1  
168 kumpf 1.16         String errorString = "provider is not a CIMProvider.";
169 chip  1.7          throw Exception("ProviderLoadFailure (" + _fileName + ":" + _providerName + "):" + errorString);
170 chip  1.3      }
171 chip  1.1  
172 chip  1.3      // save provider handle
173                _provider = provider;
174 chip  1.1  
175 chip  1.3      return;
176 chip  1.1  }
177            
178            void ProviderModule::unload(void)
179            {
180 sage  1.8      if(_adapter != 0)
181                {
182                    delete _adapter;
183            
184                    _adapter = 0;
185                }
186            
187 chip  1.7      /*
188                // ATTN: cannot determine if provider is stack or heap based allocated.
189 kumpf 1.16     // the provider should delete, if necessary, during CIMProvider::terminate()
190 sage  1.8  
191 chip  1.1      if(_provider != 0)
192                {
193 sage  1.8  	delete _provider;
194 chip  1.7          delete _provider;
195 kumpf 1.5  
196 sage  1.8  	_provider = 0;
197 chip  1.7          _provider = 0;
198 kumpf 1.5      }
199 chip  1.7      */
200 kumpf 1.5  
201 sage  1.8      if(_library != 0)
202                {
203            	System::unloadDynamicLibrary(_library);
204            
205            	_library = 0;
206                }
207            }
208            
209            void ProviderModule::unloadModule(void)
210            {
211 chip  1.1      if(_library != 0)
212                {
213 chip  1.7          System::unloadDynamicLibrary(_library);
214 chip  1.1  
215 chip  1.7          _library = 0;
216 chip  1.1      }
217            }
218            
219            PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2