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

  1 chip  1.1 //%/////////////////////////////////////////////////////////////////////////////
  2           //
  3 kumpf 1.19 // 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.19 // 
 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 kumpf 1.8  // Modified By: Yi Zhou, Hewlett-Packard Company(yi_zhou@hp.com)
 27 chip  1.1  //
 28            //%/////////////////////////////////////////////////////////////////////////////
 29            
 30 chip  1.4  #include "ProviderManager.h"
 31            
 32 kumpf 1.6  #include <Pegasus/Common/Constants.h>
 33 kumpf 1.3  #include <Pegasus/Common/Tracer.h>
 34 kumpf 1.7  #include <Pegasus/Common/PegasusVersion.h>
 35 chip  1.1  
 36 chip  1.9  #include "MutexLock.h"
 37            
 38 chip  1.1  PEGASUS_NAMESPACE_BEGIN
 39            
 40            ProviderManager::ProviderManager(void)
 41            {
 42            }
 43            
 44 chip  1.4  ProviderManager::~ProviderManager(void)
 45 chip  1.1  {
 46 kumpf 1.18     String fileName;
 47                String providerName;
 48            
 49 chip  1.4      // terminate all providers
 50                for(Uint32 i = 0, n = _providers.size(); i < n; i++)
 51                {
 52 chip  1.9          try
 53                    {
 54 kumpf 1.18             //_providers[i].terminate();
 55            	    providerName = _providers[i].getName();
 56            	    fileName = _providers[i].getModule().getFileName();
 57            
 58            	    unloadProvider(fileName, providerName);
 59 chip  1.9          }
 60                    catch(...)
 61                    {
 62                    }
 63 chip  1.4      }
 64 chip  1.1  }
 65            
 66 chip  1.2  Provider ProviderManager::getProvider(
 67 chip  1.4      const String & fileName,
 68 sage  1.16     const String & providerName,
 69 kumpf 1.17     const String & interfaceName)
 70 chip  1.1  {
 71 chip  1.13     // check list for requested provider and return if found
 72                for(Uint32 i = 0, n = _providers.size(); i < n; i++)
 73 chip  1.10     {
 74 chip  1.13         if(String::equalNoCase(providerName, _providers[i].getName()))
 75 chip  1.9          {
 76 chip  1.13             return(_providers[i]);
 77 chip  1.9          }
 78 chip  1.4      }
 79            
 80 sage  1.16     loadProvider(fileName, providerName, interfaceName);
 81 chip  1.13 
 82 sage  1.16     return(getProvider(fileName, providerName, interfaceName));
 83 chip  1.9  }
 84            
 85            void ProviderManager::loadProvider(
 86                const String & fileName,
 87 sage  1.16     const String & providerName,
 88 kumpf 1.17     const String & interfaceName)
 89 chip  1.9  {
 90                MutexLock lock(_mutex);
 91            
 92 sage  1.16     //_loadProvider(fileName, providerName, interfaceName);
 93            
 94 chip  1.13     // NOTE:
 95                // check the list before attempting to load the provider
 96                // to prevent multiple threads from attempting to load
 97                // a provider during its initialization.
 98 kumpf 1.12 
 99 chip  1.13     // check list for requested provider and do nothing if found
100                for(Uint32 i = 0, n = _providers.size(); i < n; i++)
101                {
102                    if(String::equalNoCase(providerName, _providers[i].getName()))
103                    {
104                        return;
105                    }
106                }
107 kumpf 1.18 
108                Uint32 refCount = 0;
109            
110                // get reference count 
111                _getRefCount(fileName, refCount);
112            
113                refCount = refCount + 1;
114            
115 chip  1.4      // create provider module
116 kumpf 1.18     Provider provider(providerName, fileName, interfaceName, refCount);
117            
118 chip  1.4  
119 chip  1.9      // ATTN: need optimization - create CIMOMHandle once
120            
121 chip  1.4      // create a CIMOMHandle
122 kumpf 1.6      MessageQueue * queue = MessageQueue::lookup(PEGASUS_QUEUENAME_PROVIDERMANAGER_CPP);
123 chip  1.4  
124                PEGASUS_ASSERT(queue != 0);
125            
126                MessageQueueService * service = dynamic_cast<MessageQueueService *>(queue);
127            
128                PEGASUS_ASSERT(service != 0);
129 chip  1.1  
130 chip  1.4      CIMOMHandle _cimom(service);
131 chip  1.1  
132 chip  1.4      // initialize provider
133                provider.initialize(_cimom);
134 chip  1.1  
135 kumpf 1.18     // if module is already in the array, remove the old module, add the new module in 
136                if (refCount > 1)
137                {
138            	// module is already in the array
139            	_updateRefCount(fileName, refCount);	
140                }
141                else
142                {
143            	// module is not in the array, create the module and add it in the array
144            	ProviderModule module(fileName, refCount);
145                	_modules.append(module);
146                } 
147 chip  1.4      _providers.append(provider);
148 chip  1.1  }
149 sage  1.16 
150            
151            #if 0
152            Provider ProviderManager::_loadProvider(
153                const String & fileName,
154                const String & providerName,
155                const String & interfaceName = String::EMPTY)
156            {
157                // NOTE: _loadProvider SHOULD ONLY BE CALLED AFTER OBTAINING THE LOCK
158                //
159            #endif
160 chip  1.1  
161 chip  1.9  void ProviderManager::unloadProvider(
162                const String & fileName,
163                const String & providerName)
164 chip  1.1  {
165 chip  1.9      MutexLock lock(_mutex);
166            
167 kumpf 1.8      // check list for requested provider and return if found
168 chip  1.4      for(Uint32 i = 0, n = _providers.size(); i < n; i++)
169                {
170 chip  1.9          if(String::equalNoCase(providerName, _providers[i].getName()))
171                    {
172 chip  1.10             Provider provider(_providers[i]);
173 chip  1.4  
174 chip  1.9              _providers.remove(i);
175 chip  1.10 
176 kumpf 1.18 	    // get module reference count
177            	    Uint32 refCount = 0;
178            
179             	    _getRefCount(fileName, refCount);
180            
181            	    // if refCount is greater than 1, just terminate provider, not unload
182             	    // otherwise, terminate and unload
183            	    if (refCount > 1)
184            	    {
185            		provider.terminate();
186                	    }
187            	    else
188            	    {
189                        	provider.terminate();
190            		provider.getModule().unloadModule();
191            	    }
192            	    
193            	    // update reference count
194            	    _updateRefCount(fileName, refCount - 1);
195            
196            	    return;
197 chip  1.9          }
198 chip  1.4      }
199 chip  1.1  }
200            
201 chip  1.15 void ProviderManager::shutdownAllProviders(void)
202 kumpf 1.14 {
203                //
204                // terminate all providers
205                //
206                //for (Uint32 i = 0, n = _providers.size(); i < n; i++)
207                //for(Uint32 i = _providers.size(); i > 0;)
208            
209                Uint32 numProviders = _providers.size();
210            
211                while (numProviders > 0)
212                {
213            	try
214            	{
215 chip  1.15 	    //_providers[0].terminateProvider();
216            	    _providers[0].terminate();
217 kumpf 1.14 
218            	    _providers.remove(0);
219                        numProviders--;
220            	}
221            	catch(...)
222            	{
223 kumpf 1.21             // may want to log to Pegasus log in the future
224 kumpf 1.18 	}
225                }
226            }
227            
228            void ProviderManager::_getRefCount(const String & fileName, Uint32 & refCount)
229            {
230                for(Uint32 i = 0, n = _modules.size(); i < n; i++)
231                {
232            	if(String::equalNoCase(fileName, _modules[i].getFileName()))
233            	{
234            	    refCount = _modules[i].getRefCount();
235            
236            	    return;
237            	}
238                }
239            }
240            
241            void ProviderManager::_updateRefCount(const String & fileName, const Uint32 & refCount)
242            {
243                for(Uint32 i = 0, n = _modules.size(); i < n; i++)
244                {
245 kumpf 1.18 	if(String::equalNoCase(fileName, _modules[i].getFileName()))
246            	{
247            	    // remove the module from array
248            	    _modules.remove(i);
249            
250            	    // if reference count is none zero, update the array
251            	    if ( refCount > 0 )
252            	    {
253            	    	// Add the module to the array
254            	    	ProviderModule module(fileName, refCount);
255            	    	_modules.append(module);
256            	    }
257            	    return;
258 kumpf 1.14 	}
259                }
260            }
261            
262 chip  1.1  // ATTN: disabled temporarily
263            /*
264            PEGASUS_THREAD_RETURN PEGASUS_THREAD_CDECL ProviderManager::monitorThread(void * arg)
265            {
266 chip  1.4      Thread * thread = reinterpret_cast<Thread *>(arg);
267 chip  1.1  
268 chip  1.4      ProviderManager * _this = reinterpret_cast<ProviderManager *>(thread->get_parm());
269 chip  1.1  
270 chip  1.4      // check provider list every 30 seconds for providers to unload
271                for(Uint32 timeout = 0; true; timeout += 30)
272                {
273 chip  1.9      thread->sleep(30000);
274            
275                // check each provider for timeouts less than the current timeout
276                //for(Uint32 i = 0, n = _this->_providers.size(); i < n; i++)
277 chip  1.1  
278 chip  1.9      // start with highest entry to prevent out-of-bounds
279                // exception in case a removed entry - Markus
280 chip  1.1  
281 chip  1.9      for(Uint32 i = _this->_providers.size(); i > 0;)
282                {
283                    // We want to count down to 0, but Uint32 will never go < 0
284                    i--;
285            
286                    // get provider timeout
287 chip  1.1  
288 chip  1.9          #if defined(PEGASUS_OS_HPUX)
289                    Uint32 provider_timeout = 0xffffffff;
290                    #else
291                    Uint32 provider_timeout = 30;
292                    #endif
293            
294                    if((provider_timeout != 0xffffffff) && (provider_timeout <= timeout))
295                    {
296 kumpf 1.20         PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL2,
297                        "Unloading provider for " + _this->_providers[i].getClassName() +
298                            " in " + _this->_providers[i].getProviderName());
299 chip  1.9          void * mypr = (void *)_this->_providers[i].getProvider();
300            
301                    _this->_providers[i].getProvider()->terminate();
302                    _this->_providers.remove(i);
303                    }
304                }
305 chip  1.4      }
306 chip  1.1  
307 kumpf 1.20     PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL2,
308                    "Provider monitor stopped");
309 chip  1.1  
310 chip  1.4      return(0);
311 chip  1.1  }
312            */
313            
314            PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2