1 karl 1.12 //%2006////////////////////////////////////////////////////////////////////////
|
2 schuur 1.1 //
|
3 karl 1.6 // 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.7 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 karl 1.12 // 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 karl 1.6 //
|
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 karl 1.6 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
28 schuur 1.1 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30 //==============================================================================
31 //
32 // Author: Chip Vincent (cvincent@us.ibm.com)
33 //
34 // Modified By: Yi Zhou, Hewlett-Packard Company(yi_zhou@hp.com)
35 // Mike Day, IBM (mdday@us.ibm.com)
36 // Adrian Schuur, schuur@de.ibm.com
|
37 dj.gorey 1.3 // Dan Gorey, IBM djgorey@us.ibm.com
|
38 schuur 1.1 //
39 //%/////////////////////////////////////////////////////////////////////////////
40
41 #ifndef Pegasus_CMPIProvider_h
42 #define Pegasus_CMPIProvider_h
43
44 #include "CMPI_Object.h"
45 #include "CMPI_Broker.h"
|
46 konrad.r 1.9 #include "CMPI_Version.h"
|
47 schuur 1.1 #include <Pegasus/Common/Config.h>
|
48 konrad.r 1.11 #include <Pegasus/Common/Thread.h>
|
49 mike 1.13 #include <Pegasus/Common/List.h>
|
50 mike 1.15 #include <Pegasus/Common/Mutex.h>
|
51 konrad.r 1.11 #include <Pegasus/Provider/CIMOMHandle.h>
|
52 schuur 1.1 #include <Pegasus/Provider/CIMOMHandle.h>
53 #include <Pegasus/Provider/CIMInstanceProvider.h>
54 #include <Pegasus/Provider/CIMAssociationProvider.h>
55 #include <Pegasus/Provider/CIMMethodProvider.h>
56 #include <Pegasus/ProviderManager2/CMPI/CMPIResolverModule.h>
57
|
58 schuur 1.4 #include <Pegasus/ProviderManager2/CMPI/Linkage.h>
|
59 schuur 1.1
60 PEGASUS_NAMESPACE_BEGIN
61
62 class CMPIProviderModule;
63 class CMPIResolverModule;
64
|
65 konrad.r 1.11 #ifndef _CMPI_Broker_H_
66 struct CMPI_Broker;
67 #endif
68
|
69 schuur 1.1 #define CMPI_MIType_Instance 1
70 #define CMPI_MIType_Association 2
71 #define CMPI_MIType_Method 4
72 #define CMPI_MIType_Property 8
73 #define CMPI_MIType_Indication 16
74
|
75 konrad.r 1.9 /* Ver 1.00 CMPI spec - which added a new parameter. */
76 #ifdef CMPI_VER_100
77
78 typedef CMPIInstanceMI* (*CREATE_INST_MI)(const CMPIBroker*,const CMPIContext*, CMPIStatus *rc);
79 typedef CMPIAssociationMI* (*CREATE_ASSOC_MI)(const CMPIBroker*,const CMPIContext*, CMPIStatus *rc);
80 typedef CMPIMethodMI* (*CREATE_METH_MI)(const CMPIBroker*,const CMPIContext*, CMPIStatus *rc);
81 typedef CMPIPropertyMI* (*CREATE_PROP_MI)(const CMPIBroker*,const CMPIContext*, CMPIStatus *rc);
82 typedef CMPIIndicationMI* (*CREATE_IND_MI)(const CMPIBroker*,const CMPIContext*, CMPIStatus *rc);
83
84 typedef CMPIInstanceMI* (*CREATE_GEN_INST_MI)(const CMPIBroker*,const CMPIContext*,const char*, CMPIStatus *rc);
85 typedef CMPIAssociationMI* (*CREATE_GEN_ASSOC_MI)(const CMPIBroker*,const CMPIContext*,const char*, CMPIStatus *rc);
86 typedef CMPIMethodMI* (*CREATE_GEN_METH_MI)(const CMPIBroker*,const CMPIContext*,const char*, CMPIStatus *rc);
87 typedef CMPIPropertyMI* (*CREATE_GEN_PROP_MI)(const CMPIBroker*,const CMPIContext*,const char*, CMPIStatus *rc);
88 typedef CMPIIndicationMI* (*CREATE_GEN_IND_MI)(const CMPIBroker*,const CMPIContext*,const char*, CMPIStatus *rc);
|
89 schuur 1.1
|
90 konrad.r 1.9 #else
|
91 schuur 1.1 typedef CMPIInstanceMI* (*CREATE_INST_MI)(CMPIBroker*,CMPIContext*);
92 typedef CMPIAssociationMI* (*CREATE_ASSOC_MI)(CMPIBroker*,CMPIContext*);
93 typedef CMPIMethodMI* (*CREATE_METH_MI)(CMPIBroker*,CMPIContext*);
94 typedef CMPIPropertyMI* (*CREATE_PROP_MI)(CMPIBroker*,CMPIContext*);
95 typedef CMPIIndicationMI* (*CREATE_IND_MI)(CMPIBroker*,CMPIContext*);
96
97 typedef CMPIInstanceMI* (*CREATE_GEN_INST_MI)(CMPIBroker*,CMPIContext*,const char*);
98 typedef CMPIAssociationMI* (*CREATE_GEN_ASSOC_MI)(CMPIBroker*,CMPIContext*,const char*);
99 typedef CMPIMethodMI* (*CREATE_GEN_METH_MI)(CMPIBroker*,CMPIContext*,const char*);
100 typedef CMPIPropertyMI* (*CREATE_GEN_PROP_MI)(CMPIBroker*,CMPIContext*,const char*);
101 typedef CMPIIndicationMI* (*CREATE_GEN_IND_MI)(CMPIBroker*,CMPIContext*,const char*);
|
102 konrad.r 1.9 #endif
|
103 schuur 1.1
|
104 konrad.r 1.10 #define _Generic_Create_InstanceMI "_Generic_Create_InstanceMI"
105 #define _Generic_Create_AssociationMI "_Generic_Create_AssociationMI"
106 #define _Generic_Create_MethodMI "_Generic_Create_MethodMI"
107 #define _Generic_Create_PropertyMI "_Generic_Create_PropertyMI"
108 #define _Generic_Create_IndicationMI "_Generic_Create_IndicationMI"
109
110 #define _Create_InstanceMI "_Create_InstanceMI"
111 #define _Create_AssociationMI "_Create_AssociationMI"
112 #define _Create_MethodMI "_Create_MethodMI"
113 #define _Create_PropertyMI "_Create_PropertyMI"
114 #define _Create_IndicationMI "_Create_IndicationMI"
115
|
116 schuur 1.1 struct ProviderVector {
117 int miTypes;
118 int genericMode;
119 CMPIInstanceMI *instMI;
120 CMPIAssociationMI *assocMI;
121 CMPIMethodMI *methMI;
122 CMPIPropertyMI *propMI;
123 CMPIIndicationMI *indMI;
124 CREATE_INST_MI createInstMI;
125 CREATE_ASSOC_MI createAssocMI;
126 CREATE_METH_MI createMethMI;
127 CREATE_PROP_MI createPropMI;
128 CREATE_IND_MI createIndMI;
129 CREATE_GEN_INST_MI createGenInstMI;
130 CREATE_GEN_ASSOC_MI createGenAssocMI;
131 CREATE_GEN_METH_MI createGenMethMI;
132 CREATE_GEN_PROP_MI createGenPropMI;
133 CREATE_GEN_IND_MI createGenIndMI;
134 };
135
136 // The CMPIProvider class represents the logical provider extracted from a
137 schuur 1.1 // provider module. It is wrapped in a facade to stabalize the interface
138 // and is directly tied to a module.
139
|
140 schuur 1.4 class PEGASUS_CMPIPM_LINKAGE CMPIProvider :
|
141 schuur 1.1 public virtual CIMProvider
142 {
143 public:
144
145 enum Status
146 {
|
147 dj.gorey 1.3 UNINITIALIZED,
148 INITIALIZED
|
149 schuur 1.1 };
150
151 public:
152
153
154 class pm_service_op_lock {
155 private:
156 pm_service_op_lock(void);
157 public:
158 pm_service_op_lock(CMPIProvider *provider) : _provider(provider)
159 { _provider->protect(); }
160 ~pm_service_op_lock(void)
161 { _provider->unprotect(); }
162 CMPIProvider * _provider;
163 };
164
165 // typedef CMPIProviderFacade Base;
166
167 CMPIProvider(CMPIProvider*);
168
169 virtual ~CMPIProvider(void);
170 schuur 1.1
171 virtual void initialize(CIMOMHandle & cimom);
|
172 konrad.r 1.9
|
173 schuur 1.5 void setLocation(String loc) { _location=loc; }
|
174 schuur 1.1
175 virtual Boolean tryTerminate(void);
176 virtual void terminate(void);
177
|
178 dj.gorey 1.3 Status getStatus(void);
|
179 schuur 1.1 String getName(void) const;
180 void setResolver(CMPIResolverModule *rm) { _rm=rm; }
181
|
182 dj.gorey 1.3 void reset();
183
|
184 konrad.r 1.11 // Monitors threads that the provider has allocated.
185
186 /*
187 * Adds the thread to the watch list. The watch list is monitored when the
188 * provider is terminated and if any of the threads have not cleaned up by
189 * that time, they are forcifully terminated and cleaned up.
190 *
191 * @argument t Thread is not NULL.
192 */
193 void addThreadToWatch(Thread *t);
194 /*
195 // Removes the thread from the watch list and schedule the CMPILocalProviderManager
196 // to delete the thread. The CMPILocalProviderManager after deleting the thread calls
197 // the CMPIProvider' "cleanupThread". The CMPILocalProviderManager notifies this
198 // CMPIProvider object when the thread is truly dead by calling "threadDeleted" function.
199 //
200 // Note that this function is called from the thread that finished with
201 // running the providers function, and returns immediately while scheduling the
202 // a cleanup procedure. If you want to wait until the thread is truly deleted,
203 // call 'waitUntilThreadsDone' - but DO NOT do it in the the thread that
204 // the Thread owns - you will wait forever.
205 konrad.r 1.11 //
206 // @argument t Thread that is not NULL and finished with running the provider function.
207 */
208 void removeThreadFromWatch(Thread *t);
209
210 /*
211 * Remove the thread from the list of threads that are being deleted
212 * by the CMPILocalProviderManager.
213 *
214 * @argument t Thread which has been previously provided to 'removeThreadFromWatch' function.
215 */
216 void threadDelete(Thread *t);
217 /*
218 * Check if the Thread is owner by this CMPIProvider object .
219 *
220 * @argument t Thread that is not NULL.
221 */
222 Boolean isThreadOwner( Thread *t);
223
|
224 schuur 1.1 CMPIProviderModule *getModule(void) const;
225
226 virtual void get_idle_timer(struct timeval *);
227 virtual void update_idle_timer(void);
228 virtual Boolean pending_operation(void);
229 virtual Boolean unload_ok(void);
230
231 // force provider manager to keep in memory
232 virtual void protect(void);
233 // allow provider manager to unload when idle
234 virtual void unprotect(void);
235
|
236 carolann.graves 1.8 /**
237 Increments the count of current subscriptions for this provider, and
238 determines if there were no current subscriptions before the increment.
239 If there were no current subscriptions before the increment, the first
240 subscription has been created, and the provider's enableIndications
241 method should be called.
242
243 @return True, if before the increment there were no current
244 subscriptions for this provider;
245 False, otherwise
246 */
247 Boolean testIfZeroAndIncrementSubscriptions ();
248
249 /**
250 Decrements the count of current subscriptions for this provider, and
251 determines if there are no current subscriptions after the decrement.
252 If there are no current subscriptions after the decrement, the last
253 subscription has been deleted, and the provider's disableIndications
254 method should be called.
255
256 @return True, if after the decrement there are no current subscriptions
257 carolann.graves 1.8 for this provider;
258 False, otherwise
259 */
260 Boolean decrementSubscriptionsAndTestIfZero ();
261
262 /**
263 Determines if there are current subscriptions for this provider.
264
265 @return True, if there is at least one current subscription
266 for this provider;
267 False, otherwise
268 */
269 Boolean testSubscriptions ();
270
271 /**
272 Resets the count of current subscriptions for the indication provider.
273 */
274 void resetSubscriptions ();
275
276 /**
277 Sets the provider instance for the provider.
278 carolann.graves 1.8
279 Note: the provider instance is set only for an indication provider, and
280 is set when a Create Subscription request is processed for the provider.
281
282 @param instance the Provider CIMInstance for the provider
283 */
284 void setProviderInstance (const CIMInstance & instance);
285
286 /**
287 Gets the provider instance for the provider.
288
289 Note: the provider instance is set only for an indication provider, and
290 only if a Create Subscription request has been processed for the
291 provider.
292
293 @return the Provider CIMInstance for the provider
294 */
295 CIMInstance getProviderInstance ();
296
|
297 schuur 1.1 protected:
|
298 schuur 1.5 String _location;
|
299 schuur 1.1 Status _status;
300 CMPIProviderModule *_module;
301 ProviderVector miVector;
302 CMPI_Broker broker;
303 Boolean noUnload;
304
305 private:
|
306 konrad.r 1.9 virtual void _terminate(Boolean term);
307 CMPIProvider(const String & name,
308 CMPIProviderModule *module,
309 ProviderVector *mv);
310
311 static void initialize(CIMOMHandle & cimom,
312 ProviderVector & miVector,
|
313 konrad.r 1.11 String & name,
|
314 konrad.r 1.9 CMPI_Broker & broker);
|
315 konrad.r 1.11
316 /*
317 * Wait until all finished provider threads have been cleaned and deleted.
318 * Note: This should NEVER be called from the thread that IS the Thread object that was
319 * is finished and called 'removeThreadFromWatch()' . If you do it, you will
320 * wait forever.
321 */
322 void waitUntilThreadsDone();
|
323 konrad.r 1.9
324 void set(CMPIProviderModule *&module,
325 ProviderVector base,
326 CIMOMHandle *&cimomHandle);
|
327 konrad.r 1.11
|
328 schuur 1.1 friend class CMPILocalProviderManager;
329 friend class CMPIProviderManager;
330 friend class ProviderManagerService;
|
331 kumpf 1.2 class OpProviderHolder;
332 friend class OpProviderHolder;
|
333 schuur 1.1 CIMOMHandle *_cimom_handle;
334 String _name;
335 AtomicInt _no_unload;
336 CMPIResolverModule *_rm;
337 Uint32 _quantum;
338 AtomicInt _current_operations;
|
339 dj.gorey 1.3 Mutex _statusMutex;
|
340 carolann.graves 1.8
|
341 konrad.r 1.11 /*
342 List of threads which are monitored and cleaned.
343 */
|
344 mike 1.15 List<Thread,Mutex> _threadWatchList;
345 List<Thread,Mutex> _cleanedThreads;
|
346 konrad.r 1.11
347
|
348 carolann.graves 1.8 /**
349 Count of current subscriptions for this provider. Access to this
350 data member is controlled by the _currentSubscriptionsLock.
351 */
352 Uint32 _currentSubscriptions;
353
354 /**
355 A mutex to control access to the _currentSubscriptions member variable.
356 Before any access (test, increment, decrement or reset) of the
357 _currentSubscriptions member variable, the _currentSubscriptionsMutex is
358 first locked.
359 */
360 Mutex _currentSubscriptionsMutex;
361
362 /**
363 The Provider CIMInstance for the provider.
364 The Provider CIMInstance is set only for indication providers, and only
365 if a Create Subscription request has been processed for the provider.
366 The Provider CIMInstance is needed in order to construct the
367 EnableIndicationsResponseHandler to send to the indication provider
368 when the provider's enableIndications() method is called.
369 carolann.graves 1.8 The Provider CIMInstance is needed in the
370 EnableIndicationsResponseHandler in order to construct the Process
371 Indication request when an indication is delivered by the provider.
372 The Provider CIMInstance is needed in the Process Indication request
373 to enable the Indication Service to determine if the provider that
374 generated the indication accepted a matching subscription.
375 */
376 CIMInstance _providerInstance;
|
377 schuur 1.1 //};
378
379
380 //
381 // Used to encapsulate the incrementing/decrementing of the _current_operations
382 // for a CMPIProvider so it won't be unloaded during operations.
383 //
384
385 class OpProviderHolder
386 {
387 private:
388 CMPIProvider* _provider;
389
390 public:
391 OpProviderHolder(): _provider( NULL )
392 {
393 }
394 OpProviderHolder( const OpProviderHolder& p ): _provider( NULL )
395 {
396 SetProvider( p._provider );
397 }
398 schuur 1.1 OpProviderHolder( CMPIProvider* p ): _provider( NULL )
399 {
400 SetProvider( p );
401 }
402 ~OpProviderHolder()
403 {
404 UnSetProvider();
405 }
406 CMPIProvider& GetProvider()
407 {
408 return(*_provider);
409 }
410
411 OpProviderHolder& operator=( const OpProviderHolder& x )
412 {
413 if(this == &x)
414 return(*this);
415 SetProvider( x._provider );
416
417 return(*this);
418 }
419 schuur 1.1
420 void SetProvider( CMPIProvider* p )
421 {
422 UnSetProvider();
423 if(p)
424 {
425 _provider = p;
426 _provider->_current_operations++;
427 }
428 }
429
430 void UnSetProvider()
431 {
432 if(_provider)
433 {
434 _provider->_current_operations--;
435 _provider = NULL;
436 }
437 }
438 };
439 };
440 schuur 1.1
441 PEGASUS_NAMESPACE_END
442
443 #endif
|