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

  1 karl  1.25 //%2006////////////////////////////////////////////////////////////////////////
  2 schuur 1.1  //
  3 karl   1.11 // 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             // 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.14 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 10             // EMC Corporation; VERITAS Software Corporation; The Open Group.
 11 karl   1.25 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 12             // EMC Corporation; Symantec Corporation; The Open Group.
 13 schuur 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 dave.sudlik 1.31 //
 21 schuur      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 schuur      1.5  #include "CMPI_Version.h"
 35 schuur      1.3  
 36 schuur      1.1  #include "CMPIProvider.h"
 37                  
 38                  #include "CMPI_Object.h"
 39                  #include "CMPI_Broker.h"
 40                  #include "CMPI_ContextArgs.h"
 41                  #include "CMPI_Ftabs.h"
 42                  
 43 kumpf       1.30 #include <Pegasus/Common/Time.h>
 44 schuur      1.1  #include <Pegasus/ProviderManager2/CMPI/CMPIProvider.h>
 45                  #include <Pegasus/ProviderManager2/CMPI/CMPIProviderModule.h>
 46 konrad.r    1.22 #include <Pegasus/ProviderManager2/CMPI/CMPILocalProviderManager.h>
 47 schuur      1.1  
 48 schuur      1.4  PEGASUS_USING_STD;
 49 schuur      1.1  PEGASUS_NAMESPACE_BEGIN
 50                  
 51 venkat.puvvada 1.54 static const char _MSG_CANNOT_INIT_API_KEY[] =
 52                         "ProviderManager.CMPI.CMPIProvider.CANNOT_INIT_API";
 53                     static const char _MSG_CANNOT_INIT_API[] = 
 54                         "Error initializing CMPI MI $0, the following MI"
 55                             " factory function(s) returned an error: $1";
 56                     
 57                     
 58 schuur         1.1  // set current operations to 1 to prevent an unload
 59                     // until the provider has had a chance to initialize
 60 venkat.puvvada 1.41 CMPIProvider::CMPIProvider(
 61                         const String & name,
 62 venkat.puvvada 1.39     CMPIProviderModule *module,
 63                         ProviderVector *mv)
 64 venkat.puvvada 1.41     : _status(UNINITIALIZED), _module(module), _cimom_handle(0), _name(name),
 65 s.kodali       1.43     _no_unload(0),  _threadWatchList(), _cleanedThreads()
 66 schuur         1.1  {
 67 ms.aruran      1.44     PEG_METHOD_ENTER(
 68                             TRC_CMPIPROVIDERINTERFACE,
 69                             "CMPIProvider::CMPIProvider()");
 70 venkat.puvvada 1.41     _current_operations = 1;
 71                         _currentSubscriptions = 0;
 72 venkat.puvvada 1.54     _broker.hdl =0;
 73                         _broker.provider = this;
 74                         if (mv)
 75                         { 
 76                             _miVector = *mv;
 77                         }
 78 venkat.puvvada 1.45     unloadStatus = CMPI_RC_DO_NOT_UNLOAD;
 79 venkat.puvvada 1.41     Time::gettimeofday(&_idleTime);
 80 ms.aruran      1.44     PEG_METHOD_EXIT();
 81 schuur         1.1  }
 82                     
 83                     CMPIProvider::~CMPIProvider(void)
 84                     {
 85                     }
 86                     
 87 venkat.puvvada 1.41 CMPIProvider::Status CMPIProvider::getStatus()
 88 schuur         1.1  {
 89 dj.gorey       1.7      AutoMutex lock(_statusMutex);
 90 schuur         1.1      return(_status);
 91                     }
 92                     
 93 venkat.puvvada 1.41 void CMPIProvider::set(
 94                         CMPIProviderModule *&module,
 95                         ProviderVector cmpiProvider,
 96                         CIMOMHandle *&cimomHandle)
 97 dj.gorey       1.7  {
 98                         _module = module;
 99 venkat.puvvada 1.54     _miVector = cmpiProvider;
100 dj.gorey       1.7      _cimom_handle = cimomHandle;
101                     }
102                     
103                     void CMPIProvider::reset()
104                     {
105                         _module = 0;
106                         _cimom_handle = 0;
107                         _no_unload = 0;
108                         _status = UNINITIALIZED;
109 venkat.puvvada 1.55     unloadStatus = CMPI_RC_DO_NOT_UNLOAD;
110 dj.gorey       1.7  }
111                     
112 venkat.puvvada 1.41 CMPIProviderModule *CMPIProvider::getModule() const
113 schuur         1.1  {
114                         return(_module);
115                     }
116                     
117 venkat.puvvada 1.41 String CMPIProvider::getName() const
118 schuur         1.1  {
119 konrad.r       1.20     return(_name.subString(1,PEG_NOT_FOUND));
120                     }
121 venkat.puvvada 1.54 
122                     String CMPIProvider::getNameWithType() const
123                     {
124                         return(_name);
125                     }
126                     
127 venkat.puvvada 1.41 void setError(
128                         ProviderVector &miVector,
129                         String &error,
130                         const String &realProviderName,
131                         const char *generic,
132 dave.sudlik    1.46     const char *spec,
133                         const CMPIString *optMsg)
134 venkat.puvvada 1.41 {
135 ms.aruran      1.44     PEG_METHOD_ENTER(TRC_CMPIPROVIDERINTERFACE, "CMPIProvider:setError()");
136 venkat.puvvada 1.41     if (error.size() > 0)
137                         {
138 dave.sudlik    1.46         error.append("; ");
139 venkat.puvvada 1.41     }
140 dave.sudlik    1.46 
141                         String MItype;
142 venkat.puvvada 1.41     if (miVector.genericMode)
143                         {
144 dave.sudlik    1.46         MItype.append(generic);
145                         }
146                         else
147                         {
148                             MItype.append(realProviderName);
149                             MItype.append(spec);
150                         }
151                     
152 dave.sudlik    1.47     if (optMsg && CMGetCharsPtr(optMsg,NULL))
153 dave.sudlik    1.46     {
154                             MessageLoaderParms mlp(
155                                 "ProviderManager.CMPI.CMPIProvider.MESSAGE_WAS",
156                                 "$0, message was: $1",
157                                 MItype,
158                                 CMGetCharsPtr(optMsg,NULL));
159                     
160                             error.append(MessageLoader::getMessage(mlp));
161 venkat.puvvada 1.41     }
162                         else
163                         {
164 dave.sudlik    1.46         error.append(MItype);
165 venkat.puvvada 1.41     }
166 ms.aruran      1.44     PEG_METHOD_EXIT();
167 venkat.puvvada 1.41 }
168                     
169                     void CMPIProvider::initialize(
170                         CIMOMHandle & cimom,
171                         ProviderVector & miVector,
172                         String & name,
173                         CMPI_Broker & broker)
174 schuur         1.1  {
175 ms.aruran      1.44     PEG_METHOD_ENTER(TRC_CMPIPROVIDERINTERFACE, "CMPIProvider::initialize()");
176 mark.hamzy     1.38     broker.hdl=& cimom;
177                         broker.bft=CMPI_Broker_Ftab;
178                         broker.eft=CMPI_BrokerEnc_Ftab;
179                         broker.xft=CMPI_BrokerExt_Ftab;
180                         broker.mft=NULL;    // CMPI memory services not supported
181 mark.hamzy     1.24 
182 mark.hamzy     1.38     broker.name=name;
183 schuur         1.2  
184 venkat.puvvada 1.54     miVector.instMI = NULL;
185                         miVector.assocMI = NULL;
186                         miVector.methMI = NULL;
187                         miVector.propMI = NULL;
188                         miVector.indMI = NULL;
189 schuur         1.1  
190 ms.aruran      1.44     PEG_METHOD_EXIT();
191 schuur         1.1  }
192                     
193                     void CMPIProvider::initialize(CIMOMHandle & cimom)
194                     {
195 ms.aruran      1.44     PEG_METHOD_ENTER(TRC_CMPIPROVIDERINTERFACE, "CMPIProvider::initialize()");
196 konrad.r       1.20     String providername(getName());
197 schuur         1.1  
198 venkat.puvvada 1.41     if (_status == UNINITIALIZED)
199                         {
200                             String compoundName;
201                             if (_location.size() == 0)
202                             {
203 venkat.puvvada 1.54             compoundName = providername;
204 venkat.puvvada 1.41         }
205 venkat.puvvada 1.54         else
206 venkat.puvvada 1.41         {
207 venkat.puvvada 1.54             compoundName = _location + ":" + providername;
208 venkat.puvvada 1.41         }
209 venkat.puvvada 1.54         CMPIProvider::initialize(cimom,_miVector,compoundName,_broker);
210 venkat.puvvada 1.41         _status = INITIALIZED;
211 dj.gorey       1.7          _current_operations = 0;
212 venkat.puvvada 1.41     }
213 ms.aruran      1.44     PEG_METHOD_EXIT();
214 venkat.puvvada 1.41 }
215                     
216                     Boolean CMPIProvider::tryTerminate()
217                     {
218 ms.aruran      1.44     PEG_METHOD_ENTER(
219                             TRC_CMPIPROVIDERINTERFACE,
220                             "CMPIProvider::tryTerminate()");
221                     
222 venkat.puvvada 1.41     Boolean terminated = false;
223                     
224                         if (_status == INITIALIZED)
225                         {
226                             if (false == unload_ok())
227                             {
228 ms.aruran      1.44             PEG_METHOD_EXIT();
229 venkat.puvvada 1.41             return false;
230                             }
231                     
232                             Status savedStatus=_status;
233                     
234                             try
235                             {
236 venkat.puvvada 1.45             if (unloadStatus != CMPI_RC_OK)
237 venkat.puvvada 1.41             {
238                                     // False means that the CIMServer is not shutting down.
239                                     _terminate(false);
240 venkat.puvvada 1.45                 if (unloadStatus != CMPI_RC_OK)
241 venkat.puvvada 1.41                 {
242                                         _status=savedStatus;
243 ms.aruran      1.44                     PEG_METHOD_EXIT();
244 venkat.puvvada 1.41                     return false;
245                                     }
246                                     terminated=true;
247                                 }
248                             }
249                             catch (...)
250                             {
251 ms.aruran      1.44             PEG_TRACE_STRING(
252                                     TRC_PROVIDERMANAGER,
253 marek          1.53                 Tracer::LEVEL1,
254 venkat.puvvada 1.41                 "Exception caught in CMPIProviderFacade::tryTerminate() for " +
255                                     getName());
256                                 terminated = false;
257                     
258                             }
259                             if (terminated == true)
260                             {
261                                 _status = UNINITIALIZED;
262                             }
263                         }
264 ms.aruran      1.44     PEG_METHOD_EXIT();
265 venkat.puvvada 1.41     return terminated;
266 schuur         1.1  }
267                     
268 konrad.r       1.22 /*
269 dave.sudlik    1.31  Terminates the CMPIProvider by cleaning its class cache and
270 konrad.r       1.22  calling its cleanup funtions.
271                     
272                      @argument terminating When set to false, the provider may resist terminating.
273 venkat.puvvada 1.39       If true, provider MUST clean up.
274 dave.sudlik    1.31 */
275 konrad.r       1.16 void CMPIProvider::_terminate(Boolean terminating)
276 schuur         1.1  {
277 ms.aruran      1.44     PEG_METHOD_ENTER(TRC_CMPIPROVIDERINTERFACE, "CMPIProvider::_terminate()");
278 schuur         1.1      const OperationContext opc;
279                         CMPIStatus rc={CMPI_RC_OK,NULL};
280                         CMPI_ContextOnStack eCtx(opc);
281 venkat.puvvada 1.54     CMPI_ThreadContext thr(&_broker,&eCtx);
282 konrad.r       1.16 /*
283 venkat.puvvada 1.39  @param terminating When true, the terminating argument indicates that the MB
284                          is in the process of terminating and that cleanup must be done. When
285                          set to false, the MI may respond with
286                          CMPI_IRC_DO_NOT_UNLOAD, or CMPI_IRC_NEVER_UNLOAD,
287                          indicating that unload will interfere with current MI processing.
288                          @return Function return status. The following CMPIrc codes shall
289                          be recognized:
290 konrad.r       1.16         CMPI_RC_OK Operation successful.
291                             CMPI_RC_ERR_FAILED Unspecific error occurred.
292                             CMPI_RC_DO_NOT_UNLOAD Operation successful - do not unload now.
293                             CMPI_RC_NEVER_UNLOAD Operation successful - never unload.
294                     */
295 dave.sudlik    1.48     unloadStatus = CMPI_RC_OK;
296 venkat.puvvada 1.54     if (_miVector.instMI)
297 venkat.puvvada 1.41     {
298 venkat.puvvada 1.54         rc=_miVector.instMI->ft->cleanup(_miVector.instMI,&eCtx, terminating);
299 venkat.puvvada 1.45         unloadStatus = rc.rc;
300 venkat.puvvada 1.41     }
301 venkat.puvvada 1.54     if (_miVector.assocMI)
302 venkat.puvvada 1.41     {
303 venkat.puvvada 1.54         rc=_miVector.assocMI->ft->cleanup(_miVector.assocMI,&eCtx, terminating);
304 venkat.puvvada 1.45         if (unloadStatus == CMPI_RC_OK)
305 venkat.puvvada 1.41         {
306 venkat.puvvada 1.45             unloadStatus = rc.rc;
307 venkat.puvvada 1.41         }
308                         }
309 venkat.puvvada 1.54     if (_miVector.methMI)
310 venkat.puvvada 1.41     {
311 venkat.puvvada 1.54         rc=_miVector.methMI->ft->cleanup(_miVector.methMI,&eCtx, terminating);
312 venkat.puvvada 1.45         if (unloadStatus == CMPI_RC_OK)
313 venkat.puvvada 1.41         {
314 venkat.puvvada 1.45             unloadStatus = rc.rc;
315 venkat.puvvada 1.41         }
316                         }
317 venkat.puvvada 1.54     if (_miVector.propMI)
318 venkat.puvvada 1.41     {
319 venkat.puvvada 1.54         rc=_miVector.propMI->ft->cleanup(_miVector.propMI,&eCtx, terminating);
320 venkat.puvvada 1.45         if (unloadStatus == CMPI_RC_OK)
321 venkat.puvvada 1.41         {
322 venkat.puvvada 1.45             unloadStatus = rc.rc;
323 venkat.puvvada 1.41         }
324                         }
325 venkat.puvvada 1.54     if (_miVector.indMI)
326 venkat.puvvada 1.41     {
327 venkat.puvvada 1.54         rc=_miVector.indMI->ft->cleanup(_miVector.indMI,&eCtx, terminating);
328 venkat.puvvada 1.45         if (unloadStatus == CMPI_RC_OK)
329 venkat.puvvada 1.41         {
330 venkat.puvvada 1.45             unloadStatus = rc.rc;
331 venkat.puvvada 1.41         }
332 dave.sudlik    1.31     }
333 dave.sudlik    1.26 
334 marek          1.52     if (unloadStatus == CMPI_RC_OK || terminating)
335 konrad.r       1.22     {
336 venkat.puvvada 1.41         // Check the thread list to make sure the thread has been de-allocated
337                             if (_threadWatchList.size() != 0)
338                             {
339 marek          1.53             PEG_TRACE((TRC_PROVIDERMANAGER, Tracer::LEVEL4,
340 venkat.puvvada 1.41                 "There are %d provider threads in %s that have to be cleaned "
341                                     "up.",
342                                     _threadWatchList.size(), (const char *)getName().getCString()));
343                     
344                                 // Walk through the list and terminate the threads. After they are
345                                 // terminated, put them back on the watch list, call the cleanup
346                                 //  function and wait until the cleanup is completed.
347                                 while (_threadWatchList.size() > 0)
348                                 {
349 venkat.puvvada 1.39                 // Remove the thread from the watch list and kill it.
350 mike           1.27                 Thread *t = _threadWatchList.remove_front();
351 konrad.r       1.22 
352 venkat.puvvada 1.41                 /* If this a non-production build, DO NOT do the cancellation.
353                                        This is done so that the provider developer will notice 
354                                        incorrect behaviour when unloading his/her provider and 
355                                        hopefully fix that.
356                                     */
357 konrad.r       1.22 #if !defined(PEGASUS_DEBUG)
358 venkat.puvvada 1.41 # if defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU)
359                                     Logger::put(Logger::STANDARD_LOG, System::CIMSERVER,
360                                         Logger::WARNING,
361                                         "Provider thread in $0 did not exit after cleanup function."
362                                         " Attempting to terminate it.",
363                                         (const char *)getName().getCString());
364 venkat.puvvada 1.39                 t->cancel();
365 venkat.puvvada 1.41 # else
366                                     // Every other OS that we do not want to do cancellation for.
367                                     Logger::put(Logger::STANDARD_LOG, System::CIMSERVER,
368                                         Logger::WARNING,
369                                         "Provider thread in $0 did not exit after cleanup"
370                                         " function. Ignoring it.",
371                                         (const char *)getName().getCString());
372                     # endif
373 dave.sudlik    1.31 #else
374 venkat.puvvada 1.41                 // For the non-release
375                                     Logger::put(Logger::STANDARD_LOG, System::CIMSERVER,
376                                         Logger::WARNING,
377                                         "Provider thread in $0 did not exit after cleanup"
378                                         " function. Ignoring it.",
379                                         (const char *)getName().getCString());
380 venkat.puvvada 1.39                 // The cancellation is disabled so that when the join happends
381                                     // the CIMServer will hang. This should help the provider
382                                     //   writer to fix his/her providers.
383                                     //t->cancel();
384 konrad.r       1.22 #endif
385 venkat.puvvada 1.39                 //  and perform the normal  cleanup procedure
386                                     _threadWatchList.insert_back(t);
387                                     removeThreadFromWatch(t);
388 venkat.puvvada 1.41             }
389 venkat.puvvada 1.39         }
390 venkat.puvvada 1.41         // threadWatchList size ZERO doesn't mean that all threads have
391                             //  been cleaned-up. While unloading communication libraries,
392                             //  Threads waiting for MB UP calls might have
393                             // just got removed from watchlist and not cleaned.
394 dave.sudlik    1.31 
395 venkat.puvvada 1.41         // Wait until all of the threads have been cleaned.
396                             waitUntilThreadsDone();
397 marek          1.51 
398 konrad.r       1.22     }
399 ms.aruran      1.44     PEG_METHOD_EXIT();
400 schuur         1.1  }
401                     
402                     
403 konrad.r       1.16 void CMPIProvider::terminate()
404 schuur         1.1  {
405 ms.aruran      1.44     PEG_METHOD_ENTER(
406                             TRC_CMPIPROVIDERINTERFACE,
407                             "CMPIProvider::terminate()");
408 venkat.puvvada 1.41     Status savedStatus=_status;
409                         if (_status == INITIALIZED)
410                         {
411                             try
412                             {
413                     
414                                 _terminate(true);
415 venkat.puvvada 1.45             if (unloadStatus != CMPI_RC_OK)
416 venkat.puvvada 1.41             {
417                                     _status=savedStatus;
418 ms.aruran      1.44                 PEG_METHOD_EXIT();
419 venkat.puvvada 1.41                 return;
420                                 }
421                             }
422                             catch (...)
423                             {
424 ms.aruran      1.44             PEG_TRACE_STRING(
425                                     TRC_PROVIDERMANAGER,
426 marek          1.53                 Tracer::LEVEL1,
427 venkat.puvvada 1.41                 "Exception caught in CMPIProviderFacade::Terminate for " +
428                                     getName());
429                                 throw;
430                             }
431 schuur         1.1      }
432 venkat.puvvada 1.41     _status = UNINITIALIZED;
433 ms.aruran      1.44     PEG_METHOD_EXIT();
434 schuur         1.1  }
435                     
436 konrad.r       1.22 /*
437                      * Wait until all finished provider threads have been cleaned and deleted.
438 venkat.puvvada 1.39  * Note: This should NEVER be called from the thread that 
439                      * IS the Thread object that was is finished and called 
440                      * 'removeThreadFromWatch()' . If you do it, you will
441 konrad.r       1.22  * wait forever.
442                      */
443 ms.aruran      1.44 void CMPIProvider::waitUntilThreadsDone()
444 konrad.r       1.22 {
445 venkat.puvvada 1.39     while (_cleanedThreads.size() > 0)
446                         {
447                             Threads::yield();
448                         }
449 konrad.r       1.22 }
450                     /*
451                      * Check if the Thread is owner by this CMPIProvider object.
452                      *
453                      * @argument t Thread that is not NULL.
454                      */
455 ms.aruran      1.44 Boolean CMPIProvider::isThreadOwner(Thread *t)
456 konrad.r       1.22 {
457 venkat.puvvada 1.39     PEGASUS_ASSERT ( t != NULL );
458 venkat.puvvada 1.41     if (_cleanedThreads.contains(t))
459 ms.aruran      1.44     {
460 venkat.puvvada 1.39         return true;
461 ms.aruran      1.44     }
462 venkat.puvvada 1.41     if (!_threadWatchList.contains(t))
463 ms.aruran      1.44     {
464 venkat.puvvada 1.39         return true;
465 ms.aruran      1.44     }
466 venkat.puvvada 1.39     return false;
467 konrad.r       1.22 }
468                     /*
469                      * Remove the thread from the list of threads that are being deleted
470                      * by the CMPILocalProviderManager.
471                      *
472 venkat.puvvada 1.39  * @argument t Thread which has been previously provided
473                      * to 'removeThreadFromWatch' function.
474 konrad.r       1.22  */
475 ms.aruran      1.44 void CMPIProvider::threadDelete(Thread *t)
476 konrad.r       1.22 {
477 venkat.puvvada 1.39     PEGASUS_ASSERT ( _cleanedThreads.contains(t) );
478                         PEGASUS_ASSERT ( !_threadWatchList.contains(t) );
479                         _cleanedThreads.remove( t );
480 konrad.r       1.22 }
481                     
482 venkat.puvvada 1.41 /*
483                     // Removes the thread from the watch list and schedule the
484                     // CMPILocalProviderManager to delete the thread. The 
485                     // CMPILocalProviderManager after deleting the thread calls
486                     // the CMPIProvider' "cleanupThread". The CMPILocalProviderManager 
487                     // notifies this CMPIProvider object when the thread
488                     // is truly dead by calling "threadDeleted" function.
489                     //
490                     // Note that this function is called from the thread that finished with
491                     // running the providers function, and returns immediately while scheduling
492                     // the a cleanup procedure. If you want to wait until the thread is truly
493                     //  deleted, call 'waitUntilThreadsDone' - but DO NOT do it in the the thread
494                     // that the Thread owns - you will wait forever.
495                     //
496                     // @argument t Thread that is not NULL and finished with running
497                     //  the provider function.
498                     */
499 ms.aruran      1.44 void CMPIProvider::removeThreadFromWatch(Thread *t)
500 konrad.r       1.22 {
501 ms.aruran      1.44     PEG_METHOD_ENTER(
502                             TRC_CMPIPROVIDERINTERFACE,
503                             "CMPIProvider::removeThreadFromWatch()");
504 venkat.puvvada 1.39     PEGASUS_ASSERT( t != 0 );
505 konrad.r       1.22 
506 kavita.gupta   1.55.4.1     // Note: After MI returned true from cleanup() method , there might be some
507                             // threads running in MI. CMPILocalProviderManager::cleanupThread() called 
508                             // below will take care of joining the running threads in MI.
509                             {
510                                 AutoMutex mtx(_removeThreadMutex);
511                                 if (_threadWatchList.contains(t))
512                                 {
513                                     // Remove it from the watched list
514                                     _threadWatchList.remove(t);            
515                                 }
516                                 else
517                                 {
518                                     // This thread already has been removed from watch list.
519                                     PEG_METHOD_EXIT();
520                                     return;
521                                 }
522                             }
523 konrad.r       1.22     
524 kavita.gupta   1.55.4.1     
525                             PEGASUS_ASSERT (!_cleanedThreads.contains (t));
526 dave.sudlik    1.31     
527 venkat.puvvada 1.39         // Add the thread to the CMPIProvider's list.
528                             // We use this list to keep track of threads that are
529                             // being cleaned (this way 'waitUntilThreadsDone' can stall until the
530                             // threads are truly deleted).
531                             _cleanedThreads.insert_back(t);
532 konrad.r       1.22     
533 venkat.puvvada 1.39         CMPILocalProviderManager::cleanupThread(t, this);
534 ms.aruran      1.44         PEG_METHOD_EXIT();
535 konrad.r       1.22     }
536                         
537 dave.sudlik    1.31     /*
538 konrad.r       1.22      * Adds the thread to the watch list. The watch list is monitored when the
539                          * provider is terminated and if any of the threads have not cleaned up by
540                          * that time, they are forcifully terminated and cleaned up.
541                          *
542                          * @argument t Thread is not NULL.
543                         */
544 ms.aruran      1.44     void CMPIProvider::addThreadToWatch(Thread *t)
545 konrad.r       1.22     {
546 venkat.puvvada 1.39         PEGASUS_ASSERT( t != 0 );
547 konrad.r       1.22     
548 mike           1.27         _threadWatchList.insert_back(t);
549 konrad.r       1.22     }
550 schuur         1.1      
551                         void CMPIProvider::get_idle_timer(struct timeval *t)
552                         {
553 kumpf          1.30         PEGASUS_ASSERT(t != 0);
554                             AutoMutex lock(_idleTimeMutex);
555                             memcpy(t, &_idleTime, sizeof(struct timeval));
556 schuur         1.1      }
557                         
558 venkat.puvvada 1.41     void CMPIProvider::update_idle_timer()
559 schuur         1.1      {
560 kumpf          1.30         AutoMutex lock(_idleTimeMutex);
561                             Time::gettimeofday(&_idleTime);
562 schuur         1.1      }
563                         
564 venkat.puvvada 1.45     /*
565                          * This method returns "false" if there are any requests pending with
566                          * the provider or Provider has returned CMPI_RC_NEVER_UNLOAD in the last
567                          * cleanup() invocation cyle.
568                         */
569 venkat.puvvada 1.41     Boolean CMPIProvider::unload_ok()
570 schuur         1.1      {
571 ms.aruran      1.44         PEG_METHOD_ENTER(TRC_CMPIPROVIDERINTERFACE, "CMPIProvider::unload_ok()");
572 venkat.puvvada 1.45         if (unloadStatus == CMPI_RC_NEVER_UNLOAD)
573 ms.aruran      1.44         {
574                                 PEG_METHOD_EXIT();
575                                 return false;
576                             }
577 venkat.puvvada 1.41         if (_no_unload.get())
578 ms.aruran      1.44         {
579                                 PEG_METHOD_EXIT();
580 venkat.puvvada 1.41             return false;
581 ms.aruran      1.44         }
582 venkat.puvvada 1.42         // Do not call CIMOMHandle::unload_ok here. 
583                             // CIMOMHandle::unload_ok method tests for _providerUnloadProtect
584                             // and if zero returns true. _providerUnloadProtect is
585                             // incremented when CIMOMHandle::disallowProviderUnload()
586                             // is called and decremented when
587                             // CIMOMHandle::allowProviderUnload() is called. There is
588                             // no way these functions are called from CMPI Providers.(Bug 6642)
589 ms.aruran      1.44         PEG_METHOD_EXIT();
590 venkat.puvvada 1.41         return true;
591 schuur         1.1      }
592                         
593                         //   force provider manager to keep in memory
594 venkat.puvvada 1.41     void CMPIProvider::protect()
595 dave.sudlik    1.31     {
596 venkat.puvvada 1.41         _no_unload++;
597 schuur         1.1      }
598                         
599 dave.sudlik    1.31     // allow provider manager to unload when idle
600 venkat.puvvada 1.41     void CMPIProvider::unprotect()
601 dave.sudlik    1.31     {
602 venkat.puvvada 1.41         _no_unload--;
603 schuur         1.1      }
604                         
605 carolann.graves 1.15     Boolean CMPIProvider::testIfZeroAndIncrementSubscriptions ()
606                          {
607                              AutoMutex lock (_currentSubscriptionsMutex);
608                              Boolean isZero = (_currentSubscriptions == 0);
609                              _currentSubscriptions++;
610                          
611                              return isZero;
612                          }
613                          
614                          Boolean CMPIProvider::decrementSubscriptionsAndTestIfZero ()
615                          {
616                              AutoMutex lock (_currentSubscriptionsMutex);
617                              _currentSubscriptions--;
618                              Boolean isZero = (_currentSubscriptions == 0);
619                          
620                              return isZero;
621                          }
622                          
623                          Boolean CMPIProvider::testSubscriptions ()
624                          {
625                              AutoMutex lock (_currentSubscriptionsMutex);
626 carolann.graves 1.15         Boolean currentSubscriptions = (_currentSubscriptions > 0);
627                          
628                              return currentSubscriptions;
629                          }
630                          
631                          void CMPIProvider::resetSubscriptions ()
632                          {
633                              AutoMutex lock (_currentSubscriptionsMutex);
634                              _currentSubscriptions = 0;
635                          }
636                          
637                          void CMPIProvider::setProviderInstance (const CIMInstance & instance)
638                          {
639                              _providerInstance = instance;
640                          }
641                          
642                          CIMInstance CMPIProvider::getProviderInstance ()
643                          {
644                              return _providerInstance;
645                          }
646                          
647 venkat.puvvada  1.54     void CMPIProvider::incCurrentOperations ()
648                          {
649                              _current_operations++;
650                          }
651                          
652                          int CMPIProvider::getCurrentOperations ()
653                          {
654                              return _current_operations.get();
655                          }
656                          
657                          void CMPIProvider::decCurrentOperations ()
658                          {
659                              _current_operations--;
660                          }
661                          
662                          CIMOMHandle *CMPIProvider::getCIMOMHandle()
663                          {
664                              return _cimom_handle;
665                          }
666                          
667                          CMPI_Broker *CMPIProvider::getBroker()
668 venkat.puvvada  1.54     {
669                              return &_broker;
670                          }
671                          
672                          CMPIInstanceMI *CMPIProvider::getInstMI()
673                          {
674                              if (_miVector.instMI == NULL)
675                              {
676                                  AutoMutex mtx(_statusMutex);
677                                  if (_miVector.instMI == NULL)
678                                  {
679                                      const OperationContext opc;
680                                      CMPI_ContextOnStack eCtx(opc);
681                                      CMPIStatus rc = {CMPI_RC_OK, NULL};
682                                      String providerName = _broker.name;
683                                      CMPIInstanceMI *mi = NULL;
684                          
685                                      PEGASUS_ASSERT(_miVector.miTypes & CMPI_MIType_Instance);
686                                      if (_miVector.genericMode)
687                                      {
688                                          mi = _miVector.createGenInstMI(
689 venkat.puvvada  1.54                         &_broker,
690                                              &eCtx, 
691                                              (const char *)providerName.getCString(),
692                                              &rc);
693                                      }
694                                      else 
695                                      {
696                                          mi = _miVector.createInstMI(&_broker, &eCtx, &rc);
697                                      }
698                          
699                                      if (!mi || rc.rc != CMPI_RC_OK) 
700                                      {
701                                          String error;
702                                          setError(
703                                              _miVector,
704                                              error,
705                                              getName(),
706                                              _Generic_Create_InstanceMI,
707                                              _Create_InstanceMI,
708                                              rc.msg);
709                          
710 venkat.puvvada  1.54                     throw Exception(
711                                              MessageLoaderParms(
712                                                  _MSG_CANNOT_INIT_API_KEY,
713                                                  _MSG_CANNOT_INIT_API,
714                                                  getName(),
715                                                  error));
716                                      }
717                                      _miVector.instMI = mi;
718                                  }
719                              }    
720                          
721                              return _miVector.instMI;
722                          }
723                          
724                          CMPIMethodMI *CMPIProvider::getMethMI()
725                          {
726                              if (_miVector.methMI == NULL)
727                              {
728                                  AutoMutex mtx(_statusMutex);
729                                  if (_miVector.methMI == NULL)
730                                  {
731 venkat.puvvada  1.54                 const OperationContext opc;
732                                      CMPI_ContextOnStack eCtx(opc);
733                                      CMPIStatus rc = {CMPI_RC_OK, NULL};
734                                      String providerName = _broker.name;
735                                      CMPIMethodMI *mi;
736                                      PEGASUS_ASSERT(_miVector.miTypes & CMPI_MIType_Method);
737                                      if (_miVector.genericMode) 
738                                      {
739                                          mi = _miVector.createGenMethMI(
740                                              &_broker,
741                                              &eCtx, 
742                                              (const char *)providerName.getCString(),
743                                              &rc);
744                                      }
745                                      else 
746                                      {
747                                          mi = _miVector.createMethMI(&_broker, &eCtx, &rc);
748                                      }
749                                      if (!mi || rc.rc != CMPI_RC_OK) 
750                                      {
751                                          String error;
752 venkat.puvvada  1.54                     setError(
753                                              _miVector,
754                                              error,
755                                              getName(),
756                                              _Generic_Create_MethodMI,
757                                              _Create_MethodMI,
758                                              rc.msg);
759                          
760                                          throw Exception(
761                                              MessageLoaderParms(
762                                                  _MSG_CANNOT_INIT_API_KEY,
763                                                  _MSG_CANNOT_INIT_API,
764                                                  getName(),
765                                                  error));
766                                      }
767                                      _miVector.methMI = mi;
768                                  }
769                              }
770                              
771                              return _miVector.methMI;
772                          }
773 venkat.puvvada  1.54     
774                          CMPIAssociationMI *CMPIProvider::getAssocMI()
775                          {
776                              if (_miVector.assocMI == NULL)
777                              {
778                                  AutoMutex mtx(_statusMutex);
779                                  if (_miVector.assocMI == NULL)
780                                  {
781                                      const OperationContext opc;
782                                      CMPI_ContextOnStack eCtx(opc);
783                                      CMPIStatus rc = {CMPI_RC_OK, NULL};
784                                      String providerName = _broker.name;
785                                      CMPIAssociationMI *mi;
786                                      PEGASUS_ASSERT(_miVector.miTypes & CMPI_MIType_Association);
787                                      if (_miVector.genericMode)
788                                      {
789                                          mi = _miVector.createGenAssocMI(
790                                              &_broker,
791                                              &eCtx, 
792                                              (const char *)providerName.getCString(),
793                                              &rc);
794 venkat.puvvada  1.54                 } 
795                                      else 
796                                      {
797                                          mi = _miVector.createAssocMI(&_broker, &eCtx, &rc);
798                                      }
799                          
800                                      if (!mi || rc.rc != CMPI_RC_OK) 
801                                      {
802                                          String error;
803                                          setError(
804                                              _miVector,
805                                              error,
806                                              getName(),
807                                              _Generic_Create_AssociationMI,
808                                              _Create_AssociationMI,
809                                              rc.msg);
810                          
811                                          throw Exception(
812                                              MessageLoaderParms(
813                                                  _MSG_CANNOT_INIT_API_KEY,
814                                                  _MSG_CANNOT_INIT_API,
815 venkat.puvvada  1.54                             getName(),
816                                                  error));
817                                      }
818                                      _miVector.assocMI = mi;
819                                  }
820                              }
821                              
822                              return _miVector.assocMI;
823                          }
824                          
825                          CMPIPropertyMI *CMPIProvider::getPropMI()
826                          {
827                              if (_miVector.propMI == NULL)
828                              {
829                                  AutoMutex mtx(_statusMutex);
830                                  if (_miVector.propMI == NULL)
831                                  {
832                                      const OperationContext opc;
833                                      CMPI_ContextOnStack eCtx(opc);
834                                      CMPIStatus rc = {CMPI_RC_OK, NULL};
835                                      String providerName = _broker.name;
836 venkat.puvvada  1.54                 CMPIPropertyMI *mi;
837                                      PEGASUS_ASSERT(_miVector.miTypes & CMPI_MIType_Property);
838                          
839                                      if (_miVector.genericMode) 
840                                      {
841                                          mi = _miVector.createGenPropMI(
842                                              &_broker,
843                                              &eCtx, 
844                                              (const char *)providerName.getCString(),
845                                              &rc);
846                                      }
847                                      else 
848                                      {
849                                          mi = _miVector.createPropMI(&_broker, &eCtx, &rc);
850                                      }
851                          
852                                      if (!mi || rc.rc != CMPI_RC_OK)
853                                      {
854                                          String error;
855                                          setError(
856                                              _miVector,
857 venkat.puvvada  1.54                         error,
858                                              getName(),
859                                              _Generic_Create_PropertyMI,
860                                              _Create_PropertyMI,
861                                              rc.msg);
862                          
863                                          throw Exception(
864                                              MessageLoaderParms(
865                                                  _MSG_CANNOT_INIT_API_KEY,
866                                                  _MSG_CANNOT_INIT_API,
867                                                  getName(),
868                                                  error));
869                                      }
870                                      _miVector.propMI = mi;
871                                  }
872                              }
873                              
874                              return _miVector.propMI;
875                          }
876                          
877                          CMPIIndicationMI *CMPIProvider::getIndMI()
878 venkat.puvvada  1.54     {
879                              if (_miVector.indMI == NULL)
880                              {
881                                  AutoMutex mtx(_statusMutex);
882                                  if (_miVector.indMI == NULL)
883                                  {
884                                      const OperationContext opc;
885                                      CMPI_ContextOnStack eCtx(opc);
886                                      CMPIStatus rc = {CMPI_RC_OK, NULL};
887                                      String providerName = _broker.name;
888                                      CMPIIndicationMI *mi;
889                                      PEGASUS_ASSERT(_miVector.miTypes & CMPI_MIType_Indication);
890                                      if (_miVector.genericMode)
891                                      {
892                                          mi = _miVector.createGenIndMI(
893                                              &_broker,
894                                              &eCtx, 
895                                              (const char *)providerName.getCString(),
896                                              &rc);
897                                      }
898                                      else 
899 venkat.puvvada  1.54                 {
900                                          mi = _miVector.createIndMI(&_broker, &eCtx, &rc);
901                                      }
902                          
903                                      if (!mi || rc.rc != CMPI_RC_OK) 
904                                      {
905                                          String error;
906                                          setError(
907                                              _miVector,
908                                              error,
909                                              getName(),
910                                              _Generic_Create_IndicationMI,
911                                              _Create_IndicationMI,
912                                              rc.msg);
913                          
914                                          throw Exception(
915                                              MessageLoaderParms(
916                                                  _MSG_CANNOT_INIT_API_KEY,
917                                                  _MSG_CANNOT_INIT_API,
918                                                  getName(),
919                                                  error));
920 venkat.puvvada  1.54                 }
921                                      _miVector.indMI = mi;
922                                  }
923                              }
924                              
925                              return _miVector.indMI;
926                          }
927                          
928                          CMPIProviderModule *CMPIProvider::getModule()
929                          {
930                              return _module;
931                          }
932                          
933                          Uint32 CMPIProvider::getQuantum()
934                          {
935                              AutoMutex mutex(_statusMutex);  
936                              return _quantum;
937                          }
938                          
939                          void CMPIProvider::setQuantum(Uint32 quantum)
940                          {
941 venkat.puvvada  1.54         AutoMutex mutex(_statusMutex);  
942                              _quantum = quantum;
943                          }
944                          
945                          Mutex &CMPIProvider::getStatusMutex()
946                          {
947                              return _statusMutex;
948                          }
949                          
950 schuur          1.1      PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2