1 karl 1.11 //%2004////////////////////////////////////////////////////////////////////////
|
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 schuur 1.1 //
10 // Permission is hereby granted, free of charge, to any person obtaining a copy
11 // of this software and associated documentation files (the "Software"), to
12 // deal in the Software without restriction, including without limitation the
13 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
14 // sell copies of the Software, and to permit persons to whom the Software is
15 // furnished to do so, subject to the following conditions:
|
16 karl 1.11 //
|
17 schuur 1.1 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
18 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
19 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
20 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
21 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
23 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 //
26 //==============================================================================
27 //
28 // Author: Chip Vincent (cvincent@us.ibm.com)
29 //
30 // Modified By: Yi Zhou, Hewlett-Packard Company(yi_zhou@hp.com)
31 // Mike Day, IBM (mdday@us.ibm.com)
32 // Adrian Schuur, schuur@de.ibm.com
|
33 dj.gorey 1.7 // Dan Gorey, IBM djgorey@us.ibm.com
|
34 schuur 1.1 //
35 //%/////////////////////////////////////////////////////////////////////////////
36
|
37 schuur 1.5 #include "CMPI_Version.h"
|
38 schuur 1.3
|
39 schuur 1.1 #include "CMPIProvider.h"
40
41 #include "CMPI_Object.h"
42 #include "CMPI_Broker.h"
43 #include "CMPI_ContextArgs.h"
44 #include "CMPI_Ftabs.h"
45
46 #include <Pegasus/Common/Tracer.h>
47 #include <Pegasus/ProviderManager2/CMPI/CMPIProvider.h>
48 #include <Pegasus/ProviderManager2/CMPI/CMPIProviderModule.h>
49
|
50 schuur 1.4 PEGASUS_USING_STD;
|
51 schuur 1.1 PEGASUS_NAMESPACE_BEGIN
52
53
54 // set current operations to 1 to prevent an unload
55 // until the provider has had a chance to initialize
56 CMPIProvider::CMPIProvider(const String & name,
57 CMPIProviderModule *module,
58 ProviderVector *mv)
|
59 schuur 1.9 : _status(UNINITIALIZED), _module(module), _cimom_handle(0), _name(name),
60 _no_unload(0), _rm(0)
|
61 schuur 1.1 {
62 _current_operations = 1;
|
63 schuur 1.8 if (mv) miVector=*mv;
|
64 schuur 1.1 noUnload=false;
65 }
66
67 CMPIProvider::CMPIProvider(CMPIProvider *pr)
|
68 schuur 1.9 : _status(UNINITIALIZED), _module(pr->_module), _cimom_handle(0), _name(pr->_name),
69 _no_unload(0), _rm(0)
|
70 schuur 1.1 {
71 _current_operations = 1;
72 miVector=pr->miVector;
73 _cimom_handle=new CIMOMHandle();
74 noUnload=pr->noUnload;
75 }
76
77 CMPIProvider::~CMPIProvider(void)
78 {
79
80 }
81
|
82 dj.gorey 1.7 CMPIProvider::Status CMPIProvider::getStatus(void)
|
83 schuur 1.1 {
|
84 dj.gorey 1.7 AutoMutex lock(_statusMutex);
|
85 schuur 1.1 return(_status);
86 }
87
|
88 dj.gorey 1.7 void CMPIProvider::set(CMPIProviderModule *&module,
89 ProviderVector cmpiProvider,
90 CIMOMHandle *&cimomHandle)
91 {
92 _module = module;
93 miVector = cmpiProvider;
94 _cimom_handle = cimomHandle;
95 }
96
97 void CMPIProvider::reset()
98 {
99 _module = 0;
100 _cimom_handle = 0;
101 _no_unload = 0;
102 _status = UNINITIALIZED;
103 }
104
|
105 schuur 1.1 CMPIProviderModule *CMPIProvider::getModule(void) const
106 {
107 return(_module);
108 }
109
110 String CMPIProvider::getName(void) const
111 {
112 return(_name);
113 }
114
115 void CMPIProvider::initialize(CIMOMHandle & cimom,
116 ProviderVector & miVector,
117 String & name,
118 CMPI_Broker & broker)
119 {
120 broker.hdl=new CIMOMHandle(cimom);
121 broker.bft=CMPI_Broker_Ftab;
122 broker.eft=CMPI_BrokerEnc_Ftab;
|
123 schuur 1.9 broker.xft=CMPI_BrokerExt_Ftab;
|
124 schuur 1.1 broker.clsCache=NULL;
125 broker.name=name;
|
126 schuur 1.2
|
127 schuur 1.1 const OperationContext opc;
128 CMPI_ContextOnStack eCtx(opc);
129
130 if (miVector.genericMode) {
131 CString mName=name.getCString();
132 if (miVector.miTypes & CMPI_MIType_Instance)
133 miVector.instMI=miVector.createGenInstMI(&broker,&eCtx,mName);
134 if (miVector.miTypes & CMPI_MIType_Association)
135 miVector.assocMI=miVector.createGenAssocMI(&broker,&eCtx,mName);
136 if (miVector.miTypes & CMPI_MIType_Method)
137 miVector.methMI=miVector.createGenMethMI(&broker,&eCtx,mName);
138 if (miVector.miTypes & CMPI_MIType_Property)
139 miVector.propMI=miVector.createGenPropMI(&broker,&eCtx,mName);
140 if (miVector.miTypes & CMPI_MIType_Indication)
141 miVector.indMI=miVector.createGenIndMI(&broker,&eCtx,mName);
142 }
143 else {
144 if (miVector.miTypes & CMPI_MIType_Instance)
145 miVector.instMI=miVector.createInstMI(&broker,&eCtx);
146 if (miVector.miTypes & CMPI_MIType_Association)
147 miVector.assocMI=miVector.createAssocMI(&broker,&eCtx);
148 schuur 1.1 if (miVector.miTypes & CMPI_MIType_Method)
149 miVector.methMI=miVector.createMethMI(&broker,&eCtx);
150 if (miVector.miTypes & CMPI_MIType_Property)
151 miVector.propMI=miVector.createPropMI(&broker,&eCtx);
152 if (miVector.miTypes & CMPI_MIType_Indication)
153 miVector.indMI=miVector.createIndMI(&broker,&eCtx);
154 }
155 }
156
157 void CMPIProvider::initialize(CIMOMHandle & cimom)
158 {
159
|
160 dj.gorey 1.7 if(_status == UNINITIALIZED)
161 {
|
162 konrad.r 1.11.2.1 String compoundName;
163 if (_location.size() == 0)
164 compoundName= _name;
165 else
166 compoundName=_location+":"+_name;
|
167 schuur 1.9 try {
168 // yield before a potentially lengthy operation.
|
169 schuur 1.1 pegasus_yield();
|
170 schuur 1.9 CMPIProvider::initialize(cimom,miVector,compoundName,broker);
|
171 dj.gorey 1.7 if (miVector.miTypes & CMPI_MIType_Method) {
172 if (miVector.methMI->ft->miName==NULL) noUnload=true;
173 }
174 }
|
175 schuur 1.9 catch(...) {
|
176 dj.gorey 1.7 _current_operations = 0;
177 throw;
178 }
179 _status = INITIALIZED;
180 _current_operations = 0;
181 }
|
182 schuur 1.1 }
183
184 Boolean CMPIProvider::tryTerminate(void)
185 {
|
186 dj.gorey 1.7 Boolean terminated = false;
187
188 if(_status == INITIALIZED)
189 {
|
190 schuur 1.1 if(false == unload_ok())
191 {
192 return false;
193 }
194
195 Status savedStatus=_status;
196
197 // yield before a potentially lengthy operation.
198 pegasus_yield();
199 try
200 {
201 if (noUnload==false) {
202 terminate();
203 if (noUnload==true) {
204 _status=savedStatus;
205 return false;
206 }
207 terminated=true;
|
208 dj.gorey 1.7 }
|
209 schuur 1.1 }
210 catch(...)
211 {
|
212 dj.gorey 1.7 PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4,
|
213 schuur 1.1 "Exception caught in CMPIProviderFacade::tryTerminate() for " +
214 _name);
215 terminated = false;
216
217 }
|
218 dj.gorey 1.7 if(terminated == true)
219 {
220 _status = UNINITIALIZED;
|
221 schuur 1.1 }
|
222 dj.gorey 1.7 }
223 return terminated;
|
224 schuur 1.1 }
225
226 void CMPIProvider::_terminate(void)
227 {
228 if (broker.clsCache) {
229 ClassCache::Iterator i=broker.clsCache->start();
230 for (; i; i++) {
|
231 schuur 1.10 delete i.value(); }
|
232 schuur 1.1 delete broker.clsCache;
|
233 schuur 1.10 broker.clsCache=NULL;
|
234 schuur 1.1 }
235
236 const OperationContext opc;
237 CMPIStatus rc={CMPI_RC_OK,NULL};
238 CMPI_ContextOnStack eCtx(opc);
239
240 if (miVector.miTypes & CMPI_MIType_Instance) {
241 rc=miVector.instMI->ft->cleanup(miVector.instMI,&eCtx);
242 if (rc.rc==CMPI_RC_ERR_NOT_SUPPORTED) noUnload=true;
243 }
244 if (miVector.miTypes & CMPI_MIType_Association) {
245 rc=miVector.assocMI->ft->cleanup(miVector.assocMI,&eCtx);
246 if (rc.rc==CMPI_RC_ERR_NOT_SUPPORTED) noUnload=true;
247 }
248 if (miVector.miTypes & CMPI_MIType_Method) {
249 rc=miVector.methMI->ft->cleanup(miVector.methMI,&eCtx);
250 if (rc.rc==CMPI_RC_ERR_NOT_SUPPORTED) noUnload=true;
251 }
252 if (miVector.miTypes & CMPI_MIType_Property) {
253 rc=miVector.propMI->ft->cleanup(miVector.propMI,&eCtx);
254 if (rc.rc==CMPI_RC_ERR_NOT_SUPPORTED) noUnload=true;
255 schuur 1.1 }
256 if (miVector.miTypes & CMPI_MIType_Indication) {
257 rc=miVector.indMI->ft->cleanup(miVector.indMI,&eCtx);
258 if (rc.rc==CMPI_RC_ERR_NOT_SUPPORTED) noUnload=true;
259 }
260
261 }
262
263
264 void CMPIProvider::terminate(void)
265 {
|
266 dj.gorey 1.7 Status savedStatus=_status;
267 if(_status == INITIALIZED)
268 {
269 // yield before a potentially lengthy operation.
270 pegasus_yield();
271 try
|
272 schuur 1.1 {
|
273 dj.gorey 1.7 _terminate();
274 if (noUnload==true) {
|
275 schuur 1.1 _status=savedStatus;
|
276 dj.gorey 1.7 return;
277 }
278 }
279 catch(...)
280 {
281 PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4,
|
282 schuur 1.1 "Exception caught in CMPIProviderFacade::Terminate for " +
283 _name);
|
284 dj.gorey 1.7 throw;
|
285 schuur 1.1 }
|
286 dj.gorey 1.7 }
287 _status = UNINITIALIZED;
|
288 schuur 1.1 }
289
290 Boolean CMPIProvider::operator == (const void *key) const
291 {
292 if( (void *)this == key)
293 return true;
294 return false;
295 }
296
297 Boolean CMPIProvider::operator == (const CMPIProvider &prov) const
298 {
299 if(String::equalNoCase(_name, prov._name))
300 return true;
301 return false;
302 }
303
304 void CMPIProvider::get_idle_timer(struct timeval *t)
305 {
306 if(t && _cimom_handle)
307 _cimom_handle->get_idle_timer(t);
308 }
309 schuur 1.1
310 void CMPIProvider::update_idle_timer(void)
311 {
312 if(_cimom_handle)
313 _cimom_handle->update_idle_timer();
314 }
315
316 Boolean CMPIProvider::pending_operation(void)
317 {
318 if(_cimom_handle)
319 return _cimom_handle->pending_operation();
320 return false;
321 }
322
323
324 Boolean CMPIProvider::unload_ok(void)
325 {
326 if (noUnload==true) return false;
327 if(_no_unload.value() )
328 return false;
329
330 schuur 1.1 if(_cimom_handle)
331 return _cimom_handle->unload_ok();
332 return true;
333 }
334
335 // force provider manager to keep in memory
336 void CMPIProvider::protect(void)
337 {
338 _no_unload++;
339 }
340
341 // allow provider manager to unload when idle
342 void CMPIProvider::unprotect(void)
343 {
344 _no_unload--;
345 }
346
347 PEGASUS_NAMESPACE_END
|