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

  1 martin 1.25 //%LICENSE////////////////////////////////////////////////////////////////
  2             // 
  3             // Licensed to The Open Group (TOG) under one or more contributor license
  4             // agreements.  Refer to the OpenPegasusNOTICE.txt file distributed with
  5             // this work for additional information regarding copyright ownership.
  6             // Each contributor licenses this file to you under the OpenPegasus Open
  7             // Source License; you may not use this file except in compliance with the
  8             // License.
  9             // 
 10             // Permission is hereby granted, free of charge, to any person obtaining a
 11             // copy of this software and associated documentation files (the "Software"),
 12             // to deal in the Software without restriction, including without limitation
 13             // the rights to use, copy, modify, merge, publish, distribute, sublicense,
 14             // and/or sell copies of the Software, and to permit persons to whom the
 15             // Software is furnished to do so, subject to the following conditions:
 16             // 
 17             // The above copyright notice and this permission notice shall be included
 18             // in all copies or substantial portions of the Software.
 19             // 
 20             // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 21             // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
 22 martin 1.25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 23             // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 24             // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 25             // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 26             // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 27 karl   1.6  // 
 28 martin 1.25 //////////////////////////////////////////////////////////////////////////
 29 schuur 1.1  //
 30             //%/////////////////////////////////////////////////////////////////////////////
 31             
 32             #ifndef Pegasus_CMPIProvider_h
 33             #define Pegasus_CMPIProvider_h
 34             
 35             #include "CMPI_Object.h"
 36             #include "CMPI_Broker.h"
 37 konrad.r 1.9  #include "CMPI_Version.h"
 38 schuur   1.1  #include <Pegasus/Common/Config.h>
 39 konrad.r 1.11 #include <Pegasus/Common/Thread.h>
 40 mike     1.13 #include <Pegasus/Common/List.h>
 41 mike     1.15 #include <Pegasus/Common/Mutex.h>
 42 konrad.r 1.11 #include <Pegasus/Provider/CIMOMHandle.h>
 43 schuur   1.1  #include <Pegasus/Provider/CIMOMHandle.h>
 44               #include <Pegasus/Provider/CIMInstanceProvider.h>
 45               #include <Pegasus/Provider/CIMAssociationProvider.h>
 46               #include <Pegasus/Provider/CIMMethodProvider.h>
 47               
 48 schuur   1.4  #include <Pegasus/ProviderManager2/CMPI/Linkage.h>
 49 ms.aruran 1.21 #include <Pegasus/Common/Tracer.h>
 50 schuur    1.1  
 51                PEGASUS_NAMESPACE_BEGIN
 52                
 53                class CMPIProviderModule;
 54                class CMPIResolverModule;
 55                
 56 konrad.r  1.11 #ifndef _CMPI_Broker_H_
 57 venkat.puvvada 1.19     struct CMPI_Broker;
 58 konrad.r       1.11 #endif
 59                     
 60 schuur         1.1  #define CMPI_MIType_Instance    1
 61                     #define CMPI_MIType_Association 2
 62                     #define CMPI_MIType_Method      4
 63                     #define CMPI_MIType_Property    8
 64                     #define CMPI_MIType_Indication 16
 65                     
 66 konrad.r       1.9  /* Ver 1.00 CMPI spec - which added a new parameter. */
 67                     #ifdef CMPI_VER_100
 68                     
 69 venkat.puvvada 1.19 typedef CMPIInstanceMI* (*CREATE_INST_MI) (const CMPIBroker*,
 70                         const CMPIContext*,  CMPIStatus *rc);
 71                     typedef CMPIAssociationMI* (*CREATE_ASSOC_MI) (const CMPIBroker*,
 72                         const CMPIContext*,  CMPIStatus *rc);
 73                     typedef CMPIMethodMI* (*CREATE_METH_MI) (const CMPIBroker*,
 74                         const CMPIContext*,  CMPIStatus *rc);
 75                     typedef CMPIPropertyMI* (*CREATE_PROP_MI) (const CMPIBroker*,
 76                         const CMPIContext*,  CMPIStatus *rc);
 77                     typedef CMPIIndicationMI*   (*CREATE_IND_MI) (const CMPIBroker*,
 78                         const CMPIContext*,  CMPIStatus *rc);
 79                     
 80                     typedef CMPIInstanceMI* (*CREATE_GEN_INST_MI) (const CMPIBroker*,
 81                         const CMPIContext*,const char*,  CMPIStatus *rc);
 82                     typedef CMPIAssociationMI* (*CREATE_GEN_ASSOC_MI) (const CMPIBroker*,
 83                         const CMPIContext*,const char*, CMPIStatus *rc);
 84                     typedef CMPIMethodMI*       (*CREATE_GEN_METH_MI) (const CMPIBroker*,
 85                         const CMPIContext*,const char*, CMPIStatus *rc);
 86                     typedef CMPIPropertyMI*    (*CREATE_GEN_PROP_MI) (const CMPIBroker*,
 87                         const CMPIContext*,const char*, CMPIStatus *rc);
 88                     typedef CMPIIndicationMI*  (*CREATE_GEN_IND_MI) (const CMPIBroker*,
 89                         const CMPIContext*,const char*,  CMPIStatus *rc);
 90 schuur         1.1  
 91 konrad.r       1.9  #else
 92 venkat.puvvada 1.19 typedef CMPIInstanceMI*     (*CREATE_INST_MI)(CMPIBroker*,CMPIContext*);
 93                     typedef CMPIAssociationMI*  (*CREATE_ASSOC_MI)(CMPIBroker*,CMPIContext*);
 94                     typedef CMPIMethodMI*       (*CREATE_METH_MI)(CMPIBroker*,CMPIContext*);
 95                     typedef CMPIPropertyMI*     (*CREATE_PROP_MI)(CMPIBroker*,CMPIContext*);
 96                     typedef CMPIIndicationMI*   (*CREATE_IND_MI)(CMPIBroker*,CMPIContext*);
 97                     
 98                     typedef CMPIInstanceMI* (*CREATE_GEN_INST_MI) (CMPIBroker*,
 99                         CMPIContext*,const char*);
100                     typedef CMPIAssociationMI* (*CREATE_GEN_ASSOC_MI) (CMPIBroker*,
101                         CMPIContext*,const char*);
102                     typedef CMPIMethodMI*       (*CREATE_GEN_METH_MI) (CMPIBroker*,
103                         CMPIContext*,const char*);
104                     typedef CMPIPropertyMI*    (*CREATE_GEN_PROP_MI) (CMPIBroker*,
105                         CMPIContext*,const char*);
106                     typedef CMPIIndicationMI*  (*CREATE_GEN_IND_MI) (CMPIBroker*,
107                         CMPIContext*,const char*);
108 konrad.r       1.9  #endif
109 schuur         1.1  
110 konrad.r       1.10 #define _Generic_Create_InstanceMI "_Generic_Create_InstanceMI"
111                     #define _Generic_Create_AssociationMI "_Generic_Create_AssociationMI"
112                     #define _Generic_Create_MethodMI "_Generic_Create_MethodMI"
113                     #define _Generic_Create_PropertyMI "_Generic_Create_PropertyMI"
114                     #define _Generic_Create_IndicationMI "_Generic_Create_IndicationMI"
115                     
116                     #define _Create_InstanceMI "_Create_InstanceMI"
117                     #define _Create_AssociationMI "_Create_AssociationMI"
118                     #define _Create_MethodMI "_Create_MethodMI"
119                     #define _Create_PropertyMI "_Create_PropertyMI"
120                     #define _Create_IndicationMI "_Create_IndicationMI"
121                     
122 venkat.puvvada 1.19 struct ProviderVector
123                     {
124                         int miTypes;
125                         int genericMode;
126                         CMPIInstanceMI *instMI;
127                         CMPIAssociationMI *assocMI;
128                         CMPIMethodMI *methMI;
129                         CMPIPropertyMI *propMI;
130                         CMPIIndicationMI *indMI;
131                         CREATE_INST_MI createInstMI;
132                         CREATE_ASSOC_MI createAssocMI;
133                         CREATE_METH_MI createMethMI;
134                         CREATE_PROP_MI createPropMI;
135                         CREATE_IND_MI createIndMI;
136                         CREATE_GEN_INST_MI createGenInstMI;
137                         CREATE_GEN_ASSOC_MI createGenAssocMI;
138                         CREATE_GEN_METH_MI createGenMethMI;
139                         CREATE_GEN_PROP_MI createGenPropMI;
140                         CREATE_GEN_IND_MI createGenIndMI;
141 schuur         1.1  };
142                     
143                     // The CMPIProvider class represents the logical provider extracted from a
144                     // provider module. It is wrapped in a facade to stabalize the interface
145                     // and is directly tied to a module.
146                     
147 schuur         1.4  class PEGASUS_CMPIPM_LINKAGE CMPIProvider :
148 venkat.puvvada 1.19 public virtual CIMProvider
149 schuur         1.1  {
150                     public:
151                     
152                         enum Status
153                         {
154 dj.gorey       1.3          UNINITIALIZED,
155                             INITIALIZED
156 schuur         1.1      };
157                     
158                     public:
159                     
160                     
161 venkat.puvvada 1.19     class pm_service_op_lock
162                         {
163 schuur         1.1      private:
164 venkat.puvvada 1.19         pm_service_op_lock();
165 schuur         1.1      public:
166 venkat.puvvada 1.19         pm_service_op_lock(CMPIProvider *provider) : _provider(provider)
167                             {
168                                 _provider->protect();
169                             }
170                             ~pm_service_op_lock()
171                             {
172                                 _provider->unprotect();
173                             }
174                             CMPIProvider * _provider;
175 schuur         1.1      };
176                     
177 venkat.puvvada 1.19     //  typedef CMPIProviderFacade Base;
178 schuur         1.1  
179 venkat.puvvada 1.23     CMPIProvider(
180                             const String & name,
181                             CMPIProviderModule *module,
182                             ProviderVector *mv);
183                     
184 venkat.puvvada 1.19     virtual ~CMPIProvider();
185 schuur         1.1  
186                         virtual void initialize(CIMOMHandle & cimom);
187 konrad.r       1.9  
188 venkat.puvvada 1.19     void setLocation(String loc)
189                         {
190                             _location=loc;
191                         }
192 schuur         1.1  
193 venkat.puvvada 1.19     virtual Boolean tryTerminate();
194                         virtual void terminate();
195 schuur         1.1  
196 venkat.puvvada 1.19     Status getStatus();
197                         String getName() const;
198 venkat.puvvada 1.23     String getNameWithType() const;
199 schuur         1.1  
200 dj.gorey       1.3      void reset();
201                     
202 konrad.r       1.11     // Monitors threads that the provider has allocated.
203                     
204 venkat.puvvada 1.19     /* 
205 konrad.r       1.11      * Adds the thread to the watch list. The watch list is monitored when the
206                          * provider is terminated and if any of the threads have not cleaned up by
207                          * that time, they are forcifully terminated and cleaned up.
208                          *
209                          * @argument t Thread is not NULL.
210                          */
211                         void addThreadToWatch(Thread *t);
212 venkat.puvvada 1.19     /*
213                         // Removes the thread from the watch list and schedule the 
214                         // CMPILocalProviderManager to delete the thread. The  
215                         // CMPILocalProviderManager after deleting the thread calls the 
216                         // CMPIProvider' "cleanupThread". The CMPILocalProviderManager notifies
217                         // this CMPIProvider object when the thread is truly dead by calling 
218                         // "threadDeleted" function.
219                         //
220                         // Note that this function is called from the thread that finished with
221                         // running the providers function, and returns immediately while scheduling
222                         // the a cleanup procedure. If you want to wait until the thread is truly 
223                         // deleted, call 'waitUntilThreadsDone' - but DO NOT do it in the the 
224                         // thread that the Thread owns - you will wait forever.
225                         //
226                         // @argument t Thread that is not NULL and finished with running the 
227                            provider function.
228                         */
229 konrad.r       1.11     void removeThreadFromWatch(Thread *t);
230                     
231 venkat.puvvada 1.19     /*
232                         * Remove the thread from the list of threads that are being deleted
233                         * by the CMPILocalProviderManager.
234                         *
235                         * @argument t Thread which has been previously provided to 
236                         * 'removeThreadFromWatch' function.
237                         */
238                         void threadDelete(Thread *t);
239                         /*
240                         * Check if the Thread is owner by this CMPIProvider object.
241                         *
242                         * @argument t Thread that is not NULL.
243                         */
244                         Boolean isThreadOwner( Thread *t); 
245 konrad.r       1.11 
246 venkat.puvvada 1.19     CMPIProviderModule *getModule() const;
247 schuur         1.1  
248                         virtual void get_idle_timer(struct timeval *);
249 venkat.puvvada 1.19     virtual void update_idle_timer();
250                         virtual Boolean unload_ok();
251 schuur         1.1  
252                     //   force provider manager to keep in memory
253 venkat.puvvada 1.19     virtual void protect();
254 schuur         1.1  // allow provider manager to unload when idle
255 venkat.puvvada 1.19     virtual void unprotect();
256 schuur         1.1  
257 carolann.graves 1.8      /**
258                              Increments the count of current subscriptions for this provider, and
259                              determines if there were no current subscriptions before the increment.
260                              If there were no current subscriptions before the increment, the first
261                              subscription has been created, and the provider's enableIndications
262                              method should be called.
263                      
264                              @return  True, if before the increment there were no current
265                                             subscriptions for this provider;
266                                       False, otherwise
267                           */
268                          Boolean testIfZeroAndIncrementSubscriptions ();
269                      
270                          /**
271                              Decrements the count of current subscriptions for this provider, and
272                              determines if there are no current subscriptions after the decrement.
273                              If there are no current subscriptions after the decrement, the last
274                              subscription has been deleted, and the provider's disableIndications
275                              method should be called.
276                      
277                              @return  True, if after the decrement there are no current subscriptions
278 carolann.graves 1.8                         for this provider;
279                                       False, otherwise
280                           */
281                          Boolean decrementSubscriptionsAndTestIfZero ();
282                      
283                          /**
284                              Determines if there are current subscriptions for this provider.
285                      
286                              @return  True, if there is at least one current subscription
287                                             for this provider;
288                                       False, otherwise
289                           */
290                          Boolean testSubscriptions ();
291                      
292                          /**
293                              Resets the count of current subscriptions for the indication provider.
294                           */
295                          void resetSubscriptions ();
296                      
297                          /**
298                              Sets the provider instance for the provider.
299 carolann.graves 1.8  
300                              Note: the provider instance is set only for an indication provider, and
301 venkat.puvvada  1.19         is set when a Create Subscription request is processed for the
302                              provider.
303 carolann.graves 1.8  
304                              @param  instance  the Provider CIMInstance for the provider
305                           */
306                          void setProviderInstance (const CIMInstance & instance);
307                      
308                          /**
309                              Gets the provider instance for the provider.
310                      
311                              Note: the provider instance is set only for an indication provider, and
312                              only if a Create Subscription request has been processed for the
313                              provider.
314                      
315                              @return  the Provider CIMInstance for the provider
316                           */
317                          CIMInstance getProviderInstance ();
318                      
319 venkat.puvvada  1.23     void incCurrentOperations();
320                          void decCurrentOperations();
321                          int getCurrentOperations();
322                      
323                          CIMOMHandle *getCIMOMHandle();
324                          CMPI_Broker *getBroker();
325                      
326                          CMPIInstanceMI *getInstMI();
327                          CMPIMethodMI *getMethMI();
328                          CMPIAssociationMI *getAssocMI();
329                          CMPIPropertyMI *getPropMI();
330                          CMPIIndicationMI *getIndMI();
331                          
332                          CMPIProviderModule *getModule();
333                          Uint32 getQuantum();
334                          void setQuantum(Uint32 quantum);
335                          Mutex &getStatusMutex();
336                      
337                          void set(
338                              CMPIProviderModule *&module,
339                              ProviderVector base,
340 venkat.puvvada  1.23         CIMOMHandle *&cimomHandle);
341                      
342 schuur          1.1  protected:
343 schuur          1.5      String _location;
344 schuur          1.1      Status _status;
345                          CMPIProviderModule *_module;
346 venkat.puvvada  1.23     ProviderVector _miVector;
347                          CMPI_Broker _broker;
348 venkat.puvvada  1.22     CMPIrc unloadStatus;
349 schuur          1.1  
350                      private:
351 konrad.r        1.9      virtual void _terminate(Boolean term);
352                      
353 venkat.puvvada  1.19     static void initialize(
354                              CIMOMHandle & cimom,
355                              ProviderVector & miVector,
356                              String & name,
357                              CMPI_Broker & broker);
358                      
359                          /*
360                           * Wait until all finished provider threads have been cleaned and deleted.
361                           * Note: This should NEVER be called from the thread that IS the Thread 
362                           * object that was is finished and called 'removeThreadFromWatch()' . If  
363                           * you do it, you will wait forever.
364                           */
365 konrad.r        1.11     void waitUntilThreadsDone();
366 konrad.r        1.9  
367 kumpf           1.2      class OpProviderHolder;
368 schuur          1.1      CIMOMHandle *_cimom_handle;
369                          String _name;
370                          AtomicInt _no_unload;
371                          Uint32 _quantum;
372                          AtomicInt _current_operations;
373 dj.gorey        1.3      Mutex _statusMutex;
374 venkat.puvvada  1.24     Mutex _removeThreadMutex;
375 carolann.graves 1.8  
376 kumpf           1.17     struct timeval _idleTime;
377                          Mutex _idleTimeMutex;
378                      
379 venkat.puvvada  1.19     /*
380                              List of threads which are monitored and cleaned.
381                          */
382 mike            1.15     List<Thread,Mutex> _threadWatchList;
383                          List<Thread,Mutex> _cleanedThreads;
384 konrad.r        1.11 
385                      
386 carolann.graves 1.8      /**
387                              Count of current subscriptions for this provider.  Access to this
388                              data member is controlled by the _currentSubscriptionsLock.
389                           */
390                          Uint32 _currentSubscriptions;
391                      
392                          /**
393                              A mutex to control access to the _currentSubscriptions member variable.
394                              Before any access (test, increment, decrement or reset) of the
395 venkat.puvvada  1.19         _currentSubscriptions member variable, the _currentSubscriptionsMutex
396                              is first locked.
397 carolann.graves 1.8       */
398                          Mutex _currentSubscriptionsMutex;
399                      
400                          /**
401                              The Provider CIMInstance for the provider.
402                              The Provider CIMInstance is set only for indication providers, and only
403                              if a Create Subscription request has been processed for the provider.
404                              The Provider CIMInstance is needed in order to construct the
405                              EnableIndicationsResponseHandler to send to the indication provider
406                              when the provider's enableIndications() method is called.
407                              The Provider CIMInstance is needed in the
408                              EnableIndicationsResponseHandler in order to construct the Process
409                              Indication request when an indication is delivered by the provider.
410                              The Provider CIMInstance is needed in the Process Indication request
411                              to enable the Indication Service to determine if the provider that
412                              generated the indication accepted a matching subscription.
413                           */
414                          CIMInstance _providerInstance;
415 venkat.puvvada  1.23 };
416 schuur          1.1  
417                      
418                      //
419                      // Used to encapsulate the incrementing/decrementing of the _current_operations
420                      // for a CMPIProvider so it won't be unloaded during operations.
421                      //
422                      
423 venkat.puvvada  1.23 class OpProviderHolder
424                      {
425                      private:
426                          CMPIProvider* _provider;
427                      
428                      public:
429                          OpProviderHolder(): _provider( NULL )
430                          {
431                          }
432                          OpProviderHolder( const OpProviderHolder& p ): _provider( NULL )
433 venkat.puvvada  1.19     {
434 venkat.puvvada  1.23         SetProvider( p._provider );
435                          }
436                          OpProviderHolder( CMPIProvider* p ): _provider( NULL )
437                          {
438                              SetProvider( p );
439                          }
440                          ~OpProviderHolder()
441                          {
442                              UnSetProvider();
443                          }
444                          CMPIProvider& GetProvider()
445                          {
446                              return(*_provider);
447                          }
448                          OpProviderHolder& operator=( const OpProviderHolder& x )
449                          {
450                              if (this == &x)
451 venkat.puvvada  1.19         {
452                                  return(*this);
453                              }
454 venkat.puvvada  1.23         SetProvider( x._provider );
455                              return(*this);
456                          }
457 venkat.puvvada  1.19 
458 venkat.puvvada  1.23     void SetProvider( CMPIProvider* p )
459                          {
460                              PEG_METHOD_ENTER(
461                                  TRC_CMPIPROVIDERINTERFACE,
462                                  "OpProviderHolder::SetProvider()");
463                              UnSetProvider();
464                              if (p)
465 venkat.puvvada  1.19         {
466 venkat.puvvada  1.23             _provider = p;
467                                  _provider->incCurrentOperations();
468 venkat.puvvada  1.19         }
469 venkat.puvvada  1.23         PEG_METHOD_EXIT();
470                          }
471 venkat.puvvada  1.19 
472 venkat.puvvada  1.23     void UnSetProvider()
473                          {
474                              PEG_METHOD_ENTER(
475                                  TRC_CMPIPROVIDERINTERFACE,
476                                  "OpProviderHolder::UnSetProvider()");
477                              if (_provider)
478 venkat.puvvada  1.19         {
479 venkat.puvvada  1.23             _provider->decCurrentOperations();
480                                  _provider = NULL;
481 venkat.puvvada  1.19         }
482 venkat.puvvada  1.23         PEG_METHOD_EXIT();
483                          }
484 schuur          1.1  };
485                      
486                      PEGASUS_NAMESPACE_END
487                      
488                      #endif
489 venkat.puvvada  1.19     

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2