1 karl 1.28 //%2006////////////////////////////////////////////////////////////////////////
|
2 schuur 1.1 //
|
3 karl 1.14 // 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 schuur 1.1 // IBM Corp.; EMC Corporation, The Open Group.
|
7 karl 1.14 // 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.16 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 karl 1.28 // 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.28 //
|
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 r.kieninger 1.27 #include <Pegasus/Common/CIMNameUnchecked.h>
|
35 mike 1.29 #include <Pegasus/Common/AutoPtr.h>
|
36 schuur 1.4 #include "CMPI_Version.h"
|
37 schuur 1.2
|
38 schuur 1.1 #include "CMPI_Instance.h"
39 #include "CMPI_Broker.h"
40 #include "CMPI_Value.h"
41 #include "CMPI_String.h"
42
43 #include <Pegasus/Common/InternalException.h>
|
44 konrad.r 1.18 #include <Pegasus/Common/System.h>
|
45 mike 1.29 #include <Pegasus/Common/Mutex.h>
|
46 schuur 1.1 #include <string.h>
|
47 dave.sudlik 1.23 #include <new>
|
48 schuur 1.1
49 PEGASUS_USING_STD;
50 PEGASUS_NAMESPACE_BEGIN
51
|
52 konrad.r 1.26 extern int _cmpi_trace;
53
|
54 schuur 1.12 extern "C" {
55
56 static CMPIStatus instRelease(CMPIInstance* eInst) {
57 CIMInstance* inst=(CIMInstance*)eInst->hdl;
58 if (inst) {
59 delete inst;
60 (reinterpret_cast<CMPI_Object*>(eInst))->unlinkAndDelete();
|
61 venkat.puvvada 1.33 CMReturn(CMPI_RC_OK);
62 }
63 else
64 {
65 CMReturn(CMPI_RC_ERR_INVALID_HANDLE);
|
66 schuur 1.12 }
|
67 schuur 1.1 }
68
|
69 schuur 1.12 static CMPIStatus instReleaseNop(CMPIInstance* eInst) {
70 CMReturn(CMPI_RC_OK);
71 }
|
72 schuur 1.1
|
73 konrad.r 1.19 static CMPIInstance* instClone(const CMPIInstance* eInst, CMPIStatus* rc) {
|
74 david.dillard 1.21 if (!eInst->hdl) {
75 if (rc) CMSetStatus(rc, CMPI_RC_ERR_INVALID_PARAMETER);
76 return NULL;
77 }
|
78 schuur 1.12 CIMInstance* inst=(CIMInstance*)eInst->hdl;
|
79 vijay.eli 1.22 try {
80 AutoPtr<CIMInstance> cInst(new CIMInstance(inst->clone()));
81 AutoPtr<CMPI_Object> obj(new CMPI_Object(cInst.get()));
82 cInst.release();
83 obj->unlink();
84 if (rc) CMSetStatus(rc,CMPI_RC_OK);
85 return reinterpret_cast<CMPIInstance *>(obj.release());
|
86 dave.sudlik 1.23 } catch(const PEGASUS_STD(bad_alloc)&) {
|
87 vijay.eli 1.22 if (rc) CMSetStatus(rc, CMPI_RC_ERROR_SYSTEM);
88 return NULL;
89 }
|
90 schuur 1.1 }
91
|
92 konrad.r 1.19 static CMPIData instGetPropertyAt(const CMPIInstance* eInst, CMPICount pos, CMPIString** name,
|
93 schuur 1.12 CMPIStatus* rc) {
94 CIMInstance* inst=(CIMInstance*)eInst->hdl;
95 CMPIData data={0,CMPI_nullValue,{0}};
|
96 schuur 1.1
|
97 venkat.puvvada 1.33 if (!inst)
98 {
99 CMSetStatus(rc, CMPI_RC_ERR_INVALID_HANDLE);
100 return data;
|
101 david.dillard 1.21 }
|
102 konrad.r 1.15
|
103 schuur 1.12 if (pos>inst->getPropertyCount()) {
|
104 venkat.puvvada 1.33 CMSetStatus(rc, CMPI_RC_ERR_NO_SUCH_PROPERTY);
|
105 schuur 1.12 CMPIData data={0,CMPI_nullValue|CMPI_notFound,{0}};
106 return data;
107 }
108 const CIMProperty& p=inst->getProperty(pos);
109 const CIMValue& v=p.getValue();
110 CIMType pType=p.getType();
111 CMPIType t=type2CMPIType(pType,p.isArray());
|
112 schuur 1.1
|
113 schuur 1.12 value2CMPIData(v,t,&data);
|
114 schuur 1.1
|
115 schuur 1.12 if (name) {
116 String str=p.getName().getString();
117 *name=(CMPIString*)string2CMPIString(str);
118 }
|
119 schuur 1.1
120 if (rc) CMSetStatus(rc,CMPI_RC_OK);
|
121 schuur 1.12 return data;
|
122 schuur 1.1 }
123
|
124 venkat.puvvada 1.33 static CMPIData instGetProperty(const CMPIInstance* eInst,
125 const char *name, CMPIStatus* rc)
126 {
|
127 konrad.r 1.15
128 CMPIData data={0,CMPI_nullValue|CMPI_notFound,{0}};
129
|
130 venkat.puvvada 1.33 if (!eInst->hdl)
131 {
132 CMSetStatus(rc, CMPI_RC_ERR_INVALID_HANDLE);
133 return data;
134 }
135 if (!name)
136 {
137 CMSetStatus(rc, CMPI_RC_ERR_INVALID_PARAMETER);
138 return data;
|
139 david.dillard 1.21 }
|
140 schuur 1.12 CIMInstance* inst=(CIMInstance*)eInst->hdl;
141 Uint32 pos=inst->findProperty(String(name));
142
143 if (pos!=PEG_NOT_FOUND) {
144 if (rc) CMSetStatus(rc,CMPI_RC_OK);
145 return instGetPropertyAt(eInst,pos,NULL,rc);
146 }
|
147 venkat.puvvada 1.33 CMSetStatus(rc, CMPI_RC_ERR_NO_SUCH_PROPERTY);
|
148 schuur 1.12 return data;
149 }
|
150 schuur 1.1
151
|
152 venkat.puvvada 1.33 static CMPICount instGetPropertyCount(const CMPIInstance* eInst,
153 CMPIStatus* rc)
154 {
|
155 schuur 1.12 CIMInstance* inst=(CIMInstance*)eInst->hdl;
|
156 venkat.puvvada 1.33 if (!inst)
157 {
158 CMSetStatus(rc, CMPI_RC_ERR_INVALID_HANDLE);
159 return 0;
|
160 david.dillard 1.21 }
|
161 schuur 1.12 if (rc) CMSetStatus(rc,CMPI_RC_OK);
162 return inst->getPropertyCount();
|
163 schuur 1.1 }
164
|
165 dave.sudlik 1.31 static CMPIStatus instSetPropertyWithOrigin(const CMPIInstance* eInst,
166 const char* name, const CMPIValue* data, const CMPIType type,
167 const char* origin)
168 {
|
169 schuur 1.12 CIMInstance *inst=(CIMInstance*)eInst->hdl;
|
170 venkat.puvvada 1.33 if (!inst)
171 {
172 CMReturn(CMPI_RC_ERR_INVALID_HANDLE);
|
173 david.dillard 1.21 }
|
174 konrad.r 1.19 char **list=(char**)(reinterpret_cast<const CMPI_Object*>(eInst))->priv;
|
175 schuur 1.12 CMPIrc rc;
176
177 if (list) {
178 while (*list) {
|
179 konrad.r 1.18 if (System::strcasecmp(name,*list)==0) goto ok;
|
180 schuur 1.12 list++;
181 }
182 CMReturn(CMPI_RC_OK);
183 }
184
185 ok:
186 CIMValue v=value2CIMValue(data,type,&rc);
|
187 r.kieninger 1.27 CIMNameUnchecked sName(name);
|
188 schuur 1.12 Uint32 pos;
189 int count=0;
190
191 if ((pos=inst->findProperty(sName))!=PEG_NOT_FOUND) {
192 CIMProperty cp=inst->getProperty(pos);
193 try {
194 cp.setValue(v);
|
195 dave.sudlik 1.31 if (origin)
196 {
197 CIMName oName(origin);
198 cp.setClassOrigin(oName);
199 }
|
200 schuur 1.12 }
|
201 konrad.r 1.20 catch (const TypeMismatchException &) {
|
202 konrad.r 1.26 if (_cmpi_trace) {
|
203 schuur 1.13 cerr<<"-+- TypeMisMatch exception for: "<<name<<endl;
|
204 konrad.r 1.26 if (getenv("PEGASUS_CMPI_CHECKTYPES")!=NULL) {
|
205 schuur 1.12 cerr<<"-+- Aborting because of CMPI_CHECKTYPES"<<endl;
|
206 schuur 1.13 abort();
|
207 konrad.r 1.26 }
208 }
|
209 schuur 1.12 CMReturn(CMPI_RC_ERR_TYPE_MISMATCH);
210 }
|
211 dave.sudlik 1.31 catch (const InvalidNameException &) {
212 if (_cmpi_trace) {
213 cerr<<"-+- InvalidName exception for: "<<origin<<endl;
214 }
215 CMReturn(CMPI_RC_ERR_INVALID_PARAMETER);
216 }
|
217 konrad.r 1.19 catch (const Exception &e) {
|
218 konrad.r 1.26 if (_cmpi_trace) {
219 cerr<<"-+- "<<e.getMessage()<<" exception for: "<<name<<endl;
220 if (getenv("PEGASUS_CMPI_CHECKTYPES")!=NULL) {
221 cerr<<"-+- Aborting because of CMPI_CHECKTYPES"<<endl;
222 abort();
223 }
|
224 schuur 1.13 }
|
225 schuur 1.12 CMReturnWithString(CMPI_RC_ERR_FAILED,
|
226 david.dillard 1.21 reinterpret_cast<CMPIString*>(new CMPI_Object(e.getMessage())));
|
227 schuur 1.12 }
228 }
229 else {
|
230 dave.sudlik 1.31 if (type==CMPI_ref)
231 {
232 CIMObjectPath *ref=(CIMObjectPath*)(data->ref->hdl);
233 if (origin)
234 {
235 CIMName oName(origin);
236 inst->addProperty(CIMProperty(sName,v,count,
237 ref->getClassName(),oName));
238 }
239 else
240 {
241 inst->addProperty(CIMProperty(sName,v,count,
242 ref->getClassName()));
243 }
244 }
245 else
246 {
247 if (origin)
248 {
249 CIMName oName(origin);
250 inst->addProperty(CIMProperty(sName,v,count,CIMName(),oName));
251 dave.sudlik 1.31 }
252 else
253 {
254 inst->addProperty(CIMProperty(sName,v,count));
255 }
|
256 schuur 1.12 }
|
257 schuur 1.1 }
|
258 schuur 1.12 CMReturn(CMPI_RC_OK);
|
259 schuur 1.1 }
|
260 schuur 1.12
|
261 dave.sudlik 1.31 static CMPIStatus instSetProperty(const CMPIInstance* eInst,
262 const char *name, const CMPIValue* data, CMPIType type)
263 {
264 return instSetPropertyWithOrigin(eInst, name, data, type, NULL);
265 }
266
|
267 vijay.eli 1.22 static CMPIObjectPath* instGetObjectPath(const CMPIInstance* eInst,
|
268 venkat.puvvada 1.33 CMPIStatus* rc)
269 {
|
270 schuur 1.12 CIMInstance* inst=(CIMInstance*)eInst->hdl;
|
271 venkat.puvvada 1.33 if (!inst)
272 {
273 CMSetStatus(rc, CMPI_RC_ERR_INVALID_HANDLE);
|
274 david.dillard 1.21 return NULL;
275 }
|
276 schuur 1.12 const CIMObjectPath &clsRef=inst->getPath();
|
277 vijay.eli 1.22 AutoPtr<CIMObjectPath> objPath(NULL);
278 AutoPtr<CMPI_Object> obj(NULL);
279 try {
280 if (clsRef.getKeyBindings().size()==0) {
281 CIMClass *cc=mbGetClass(CMPI_ThreadContext::getBroker(),clsRef);
|
282 dave.sudlik 1.30 // It seems that when converting the CIMInstnace to XML form, we miss
283 // CIMObjectPath from it. When we don't have namespace we may not get
284 // class, so make ObjectPath with class-name only.
285 // TODO: This will create problems when passing the EmbeddedInstances
286 // as arguements to MethodProviders, where it needs to get ObjectPath
287 // from instance. Shall we need to include CIMObjectPath in CIMInstance
288 // while converting to XML form ??? ...
289 if (!cc)
290 {
291 objPath.reset(new CIMObjectPath(clsRef));
292 }
293 else
294 {
295 const CIMObjectPath &ref=inst->buildPath(
296 *(reinterpret_cast<const CIMConstClass*>(cc)));
297 objPath.reset(new CIMObjectPath(ref));
298 }
|
299 vijay.eli 1.22 }
300 else
301 objPath.reset(new CIMObjectPath(clsRef));
302 obj.reset(new CMPI_Object(objPath.get()));
303 objPath.release();
304 if (rc) CMSetStatus(rc,CMPI_RC_OK);
305 return reinterpret_cast<CMPIObjectPath*> (obj.release());
|
306 dave.sudlik 1.23 } catch(const PEGASUS_STD(bad_alloc)&) {
|
307 vijay.eli 1.22 if (rc) CMSetStatus(rc, CMPI_RC_ERROR_SYSTEM);
308 return NULL;
|
309 schuur 1.1 }
310 }
|
311 vijay.eli 1.22
|
312 dave.sudlik 1.31 static CMPIStatus instSetObjectPath(CMPIInstance* eInst, const CMPIObjectPath *obj)
|
313 konrad.r 1.19 {
|
314 konrad.r 1.24 CIMInstance* inst=(CIMInstance*)eInst->hdl;
|
315 venkat.puvvada 1.33 if (inst==NULL)
316 {
317 CMReturn(CMPI_RC_ERR_INVALID_HANDLE);
318 }
319 if (obj==NULL)
320 {
|
321 konrad.r 1.24 CMReturn ( CMPI_RC_ERR_INVALID_PARAMETER);
322 }
|
323 venkat.puvvada 1.33
|
324 konrad.r 1.24 CIMObjectPath &ref = *(CIMObjectPath*)(obj->hdl);
325 try {
326 inst->setPath(ref);
327 } catch (const TypeMismatchException &e) {
328 CMReturnWithString(CMPI_RC_ERR_FAILED,
329 reinterpret_cast<CMPIString*>(new CMPI_Object(e.getMessage())));
330 }
331 CMReturn ( CMPI_RC_OK);
|
332 konrad.r 1.19 }
|
333 schuur 1.1
|
334 schuur 1.12 static CMPIStatus instSetPropertyFilter(CMPIInstance* eInst,
|
335 venkat.puvvada 1.33 const char** propertyList, const char **keys)
336 {
337 if (!eInst->hdl)
338 {
339 CMReturn(CMPI_RC_ERR_INVALID_HANDLE);
|
340 david.dillard 1.21 }
|
341 konrad.r 1.19
|
342 schuur 1.12 CMPI_Object *inst=reinterpret_cast<CMPI_Object*>(eInst);
343 char **list=(char**)inst->priv; // Thank you Warren !
344 int i,s;
345
346 if (inst->priv) {
347 while (*list) {
348 free (*list);
349 list++;
350 }
351 free(inst->priv);
352 }
353 inst->priv=NULL;
354
355 if (propertyList==NULL) CMReturn(CMPI_RC_OK);
356 if (keys==NULL) CMReturn(CMPI_RC_ERR_FAILED);
357
358 for (s=0,i=0; propertyList[i]; i++,s++);
359 for (i=0; keys[i]; i++,s++);
|
360 marek 1.32 list = (char**) calloc(s+1, sizeof(char*));
|
361 schuur 1.12 for (s=0,i=0; propertyList[i]; i++,s++) list[s]=strdup(propertyList[i]);
362 for (i=0; keys[i]; i++,s++) list[s]=strdup(keys[i]);
363 inst->priv=(void*)list;
|
364 kumpf 1.6
|
365 schuur 1.12 CMReturn(CMPI_RC_OK);
|
366 schuur 1.1 }
367
|
368 schuur 1.12 static CMPIStatus instSetPropertyFilterIgnore(CMPIInstance* eInst,
|
369 konrad.r 1.19 const char** propertyList, const char **keys){
|
370 david.dillard 1.21 /* We ignore it. */
|
371 konrad.r 1.19 CMReturn ( CMPI_RC_OK);
|
372 schuur 1.12 }
|
373 schuur 1.1
|
374 dave.sudlik 1.31
|
375 schuur 1.1 }
376
377 static CMPIInstanceFT instance_FT={
378 CMPICurrentVersion,
379 instRelease,
380 instClone,
381 instGetProperty,
382 instGetPropertyAt,
383 instGetPropertyCount,
384 instSetProperty,
385 instGetObjectPath,
386 instSetPropertyFilter,
|
387 konrad.r 1.19 #if defined(CMPI_VER_100)
388 instSetObjectPath,
389 #endif
|
390 dave.sudlik 1.31 #if defined(CMPI_VER_200)
391 instSetPropertyWithOrigin,
392 #endif
|
393 schuur 1.1 };
394
395 static CMPIInstanceFT instanceOnStack_FT={
396 CMPICurrentVersion,
397 instReleaseNop,
398 instClone,
399 instGetProperty,
400 instGetPropertyAt,
401 instGetPropertyCount,
402 instSetProperty,
403 instGetObjectPath,
404 instSetPropertyFilterIgnore,
|
405 konrad.r 1.19 #if defined(CMPI_VER_100)
406 instSetObjectPath,
407 #endif
|
408 dave.sudlik 1.31 #if defined(CMPI_VER_200)
409 instSetPropertyWithOrigin,
410 #endif
|
411 schuur 1.1 };
412
413 CMPIInstanceFT *CMPI_Instance_Ftab=&instance_FT;
414 CMPIInstanceFT *CMPI_InstanceOnStack_Ftab=&instanceOnStack_FT;
415
416
417 CMPI_InstanceOnStack::CMPI_InstanceOnStack(const CIMInstance& ci) {
418 hdl=(void*)&ci;
419 ft=CMPI_InstanceOnStack_Ftab;
420 }
421
422
423 PEGASUS_NAMESPACE_END
|