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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2