1 karl 1.16 //%2005////////////////////////////////////////////////////////////////////////
|
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 schuur 1.1 //
12 // Permission is hereby granted, free of charge, to any person obtaining a copy
13 // of this software and associated documentation files (the "Software"), to
14 // deal in the Software without restriction, including without limitation the
15 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
16 // sell copies of the Software, and to permit persons to whom the Software is
17 // furnished to do so, subject to the following conditions:
|
18 david.dillard 1.21 //
|
19 schuur 1.1 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
20 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
21 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
22 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
23 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
25 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28 //==============================================================================
29 //
30 // Author: Adrian Schuur, schuur@de.ibm.com
31 //
|
32 david.dillard 1.21 // Modified By: David Dillard, VERITAS Software Corp.
33 // (david.dillard@veritas.com)
|
34 vijay.eli 1.22 // Vijay Eli, IBM, (vijayeli@in.ibm.com) bug#3495
|
35 aruran.ms 1.25 // Aruran, IBM (ashanmug@in.ibm.com) for Bug# 3496
|
36 schuur 1.1 //
37 //%/////////////////////////////////////////////////////////////////////////////
38
|
39 schuur 1.4 #include "CMPI_Version.h"
|
40 schuur 1.2
|
41 schuur 1.1 #include "CMPI_Instance.h"
42 #include "CMPI_Broker.h"
43 #include "CMPI_Value.h"
44 #include "CMPI_String.h"
45
46 #include <Pegasus/Common/InternalException.h>
|
47 konrad.r 1.18 #include <Pegasus/Common/System.h>
|
48 schuur 1.1 #include <string.h>
|
49 dave.sudlik 1.23 #include <new>
|
50 schuur 1.1
51 PEGASUS_USING_STD;
52 PEGASUS_NAMESPACE_BEGIN
53
|
54 konrad.r 1.26 extern int _cmpi_trace;
55
|
56 schuur 1.12 extern "C" {
57
58 static CMPIStatus instRelease(CMPIInstance* eInst) {
59 CIMInstance* inst=(CIMInstance*)eInst->hdl;
60 if (inst) {
61 delete inst;
62 (reinterpret_cast<CMPI_Object*>(eInst))->unlinkAndDelete();
63 }
64 CMReturn(CMPI_RC_OK);
|
65 schuur 1.1 }
66
|
67 schuur 1.12 static CMPIStatus instReleaseNop(CMPIInstance* eInst) {
68 CMReturn(CMPI_RC_OK);
69 }
|
70 schuur 1.1
|
71 konrad.r 1.19 static CMPIInstance* instClone(const CMPIInstance* eInst, CMPIStatus* rc) {
|
72 david.dillard 1.21 if (!eInst->hdl) {
73 if (rc) CMSetStatus(rc, CMPI_RC_ERR_INVALID_PARAMETER);
74 return NULL;
75 }
|
76 schuur 1.12 CIMInstance* inst=(CIMInstance*)eInst->hdl;
|
77 vijay.eli 1.22 try {
78 AutoPtr<CIMInstance> cInst(new CIMInstance(inst->clone()));
79 AutoPtr<CMPI_Object> obj(new CMPI_Object(cInst.get()));
80 cInst.release();
81 obj->unlink();
82 if (rc) CMSetStatus(rc,CMPI_RC_OK);
83 return reinterpret_cast<CMPIInstance *>(obj.release());
|
84 dave.sudlik 1.23 } catch(const PEGASUS_STD(bad_alloc)&) {
|
85 vijay.eli 1.22 if (rc) CMSetStatus(rc, CMPI_RC_ERROR_SYSTEM);
86 return NULL;
87 }
|
88 schuur 1.1 }
89
|
90 konrad.r 1.19 static CMPIData instGetPropertyAt(const CMPIInstance* eInst, CMPICount pos, CMPIString** name,
|
91 schuur 1.12 CMPIStatus* rc) {
92 CIMInstance* inst=(CIMInstance*)eInst->hdl;
93 CMPIData data={0,CMPI_nullValue,{0}};
|
94 schuur 1.1
|
95 david.dillard 1.21 if (!inst) {
96 if (rc) CMSetStatus(rc, CMPI_RC_ERR_INVALID_PARAMETER);
97 return data;
98 }
|
99 konrad.r 1.15
|
100 schuur 1.12 if (pos>inst->getPropertyCount()) {
101 if (rc) CMSetStatus(rc,CMPI_RC_ERR_NOT_FOUND);
102 CMPIData data={0,CMPI_nullValue|CMPI_notFound,{0}};
103 return data;
104 }
105 const CIMProperty& p=inst->getProperty(pos);
106 const CIMValue& v=p.getValue();
107 CIMType pType=p.getType();
108 CMPIType t=type2CMPIType(pType,p.isArray());
|
109 schuur 1.1
|
110 schuur 1.12 value2CMPIData(v,t,&data);
|
111 schuur 1.1
|
112 schuur 1.12 if (name) {
113 String str=p.getName().getString();
114 *name=(CMPIString*)string2CMPIString(str);
115 }
|
116 schuur 1.1
117 if (rc) CMSetStatus(rc,CMPI_RC_OK);
|
118 schuur 1.12 return data;
|
119 schuur 1.1 }
120
|
121 david.dillard 1.21 static CMPIData instGetProperty(const CMPIInstance* eInst, const char *name, CMPIStatus* rc) {
|
122 konrad.r 1.15
123 CMPIData data={0,CMPI_nullValue|CMPI_notFound,{0}};
124
|
125 david.dillard 1.21 if (!eInst->hdl) {
126 if (rc) CMSetStatus(rc, CMPI_RC_ERR_INVALID_PARAMETER);
127 return data;
128 }
|
129 schuur 1.12 CIMInstance* inst=(CIMInstance*)eInst->hdl;
130 Uint32 pos=inst->findProperty(String(name));
131
132 if (pos!=PEG_NOT_FOUND) {
133 if (rc) CMSetStatus(rc,CMPI_RC_OK);
134 return instGetPropertyAt(eInst,pos,NULL,rc);
135 }
136 if (rc) CMSetStatus(rc,CMPI_RC_ERR_NOT_FOUND);
137 return data;
138 }
|
139 schuur 1.1
140
|
141 konrad.r 1.19 static CMPICount instGetPropertyCount(const CMPIInstance* eInst, CMPIStatus* rc) {
|
142 schuur 1.12 CIMInstance* inst=(CIMInstance*)eInst->hdl;
|
143 david.dillard 1.21 if (!inst) {
144 if (rc) CMSetStatus(rc, CMPI_RC_ERR_INVALID_PARAMETER);
145 return 0;
146 }
|
147 schuur 1.12 if (rc) CMSetStatus(rc,CMPI_RC_OK);
148 return inst->getPropertyCount();
|
149 schuur 1.1 }
150
|
151 konrad.r 1.19 static CMPIStatus instSetProperty(const CMPIInstance* eInst, const char *name,
|
152 david.dillard 1.21 const CMPIValue* data, CMPIType type) {
|
153 schuur 1.12 CIMInstance *inst=(CIMInstance*)eInst->hdl;
|
154 david.dillard 1.21 if (!inst) {
155 CMReturn(CMPI_RC_ERR_INVALID_PARAMETER);
156 }
|
157 konrad.r 1.19 char **list=(char**)(reinterpret_cast<const CMPI_Object*>(eInst))->priv;
|
158 schuur 1.12 CMPIrc rc;
159
160 if (list) {
161 while (*list) {
|
162 konrad.r 1.18 if (System::strcasecmp(name,*list)==0) goto ok;
|
163 schuur 1.12 list++;
164 }
165 CMReturn(CMPI_RC_OK);
166 }
167
168 ok:
169 CIMValue v=value2CIMValue(data,type,&rc);
170 CIMName sName(name);
171 Uint32 pos;
172 int count=0;
173
174 if ((pos=inst->findProperty(sName))!=PEG_NOT_FOUND) {
175 CIMProperty cp=inst->getProperty(pos);
176 try {
177 cp.setValue(v);
178 }
|
179 konrad.r 1.20 catch (const TypeMismatchException &) {
|
180 konrad.r 1.26 if (_cmpi_trace) {
|
181 schuur 1.13 cerr<<"-+- TypeMisMatch exception for: "<<name<<endl;
|
182 konrad.r 1.26 if (getenv("PEGASUS_CMPI_CHECKTYPES")!=NULL) {
|
183 schuur 1.12 cerr<<"-+- Aborting because of CMPI_CHECKTYPES"<<endl;
|
184 schuur 1.13 abort();
|
185 konrad.r 1.26 }
186 }
|
187 schuur 1.12 CMReturn(CMPI_RC_ERR_TYPE_MISMATCH);
188 }
|
189 konrad.r 1.19 catch (const Exception &e) {
|
190 konrad.r 1.26 if (_cmpi_trace) {
191 cerr<<"-+- "<<e.getMessage()<<" exception for: "<<name<<endl;
192 if (getenv("PEGASUS_CMPI_CHECKTYPES")!=NULL) {
193 cerr<<"-+- Aborting because of CMPI_CHECKTYPES"<<endl;
194 abort();
195 }
|
196 schuur 1.13 }
|
197 schuur 1.12 CMReturnWithString(CMPI_RC_ERR_FAILED,
|
198 david.dillard 1.21 reinterpret_cast<CMPIString*>(new CMPI_Object(e.getMessage())));
|
199 schuur 1.12 }
200 }
201 else {
202 if (type==CMPI_ref) {
203 CIMObjectPath *ref=(CIMObjectPath*)(data->ref->hdl);
204 inst->addProperty(CIMProperty(sName,v,count,ref->getClassName()));
205 }
206
207 else inst->addProperty(CIMProperty(sName,v,count));
|
208 schuur 1.1 }
|
209 schuur 1.12 CMReturn(CMPI_RC_OK);
|
210 schuur 1.1 }
|
211 schuur 1.12
|
212 vijay.eli 1.22 static CMPIObjectPath* instGetObjectPath(const CMPIInstance* eInst,
213 CMPIStatus* rc) {
|
214 schuur 1.12 CIMInstance* inst=(CIMInstance*)eInst->hdl;
|
215 david.dillard 1.21 if (!inst) {
216 if (rc) CMSetStatus(rc, CMPI_RC_ERR_INVALID_PARAMETER);
217 return NULL;
218 }
|
219 schuur 1.12 const CIMObjectPath &clsRef=inst->getPath();
|
220 vijay.eli 1.22 AutoPtr<CIMObjectPath> objPath(NULL);
221 AutoPtr<CMPI_Object> obj(NULL);
222 try {
223 if (clsRef.getKeyBindings().size()==0) {
224 CIMClass *cc=mbGetClass(CMPI_ThreadContext::getBroker(),clsRef);
225 const CIMObjectPath &ref=inst->buildPath(
226 *(reinterpret_cast<const CIMConstClass*>(cc)));
227 objPath.reset(new CIMObjectPath(ref));
228 }
229 else
230 objPath.reset(new CIMObjectPath(clsRef));
231 obj.reset(new CMPI_Object(objPath.get()));
232 objPath.release();
233 if (rc) CMSetStatus(rc,CMPI_RC_OK);
234 return reinterpret_cast<CMPIObjectPath*> (obj.release());
|
235 dave.sudlik 1.23 } catch(const PEGASUS_STD(bad_alloc)&) {
|
236 vijay.eli 1.22 if (rc) CMSetStatus(rc, CMPI_RC_ERROR_SYSTEM);
237 return NULL;
|
238 schuur 1.1 }
239 }
|
240 vijay.eli 1.22
|
241 konrad.r 1.19 static CMPIStatus instSetObjectPath( CMPIInstance* eInst, const CMPIObjectPath *obj)
242 {
|
243 konrad.r 1.24 CIMInstance* inst=(CIMInstance*)eInst->hdl;
244 if ((inst==NULL) || (obj==NULL)) {
245 CMReturn ( CMPI_RC_ERR_INVALID_PARAMETER);
246 }
247 CIMObjectPath &ref = *(CIMObjectPath*)(obj->hdl);
248 try {
249 inst->setPath(ref);
250 } catch (const TypeMismatchException &e) {
251 CMReturnWithString(CMPI_RC_ERR_FAILED,
252 reinterpret_cast<CMPIString*>(new CMPI_Object(e.getMessage())));
253 }
254 CMReturn ( CMPI_RC_OK);
|
255 konrad.r 1.19 }
|
256 schuur 1.1
|
257 schuur 1.12 static CMPIStatus instSetPropertyFilter(CMPIInstance* eInst,
|
258 konrad.r 1.19 const char** propertyList, const char **keys){
|
259 david.dillard 1.21 if (!eInst->hdl) {
260 CMReturn(CMPI_RC_ERR_INVALID_PARAMETER);
261 }
|
262 konrad.r 1.19
|
263 schuur 1.12 CMPI_Object *inst=reinterpret_cast<CMPI_Object*>(eInst);
264 char **list=(char**)inst->priv; // Thank you Warren !
265 int i,s;
266
267 if (inst->priv) {
268 while (*list) {
269 free (*list);
270 list++;
271 }
272 free(inst->priv);
273 }
274 inst->priv=NULL;
275
276 if (propertyList==NULL) CMReturn(CMPI_RC_OK);
277 if (keys==NULL) CMReturn(CMPI_RC_ERR_FAILED);
278
279 for (s=0,i=0; propertyList[i]; i++,s++);
280 for (i=0; keys[i]; i++,s++);
|
281 aruran.ms 1.25 list = new char*[s+2];
|
282 schuur 1.12 for (s=0,i=0; propertyList[i]; i++,s++) list[s]=strdup(propertyList[i]);
283 for (i=0; keys[i]; i++,s++) list[s]=strdup(keys[i]);
284 list[s]=NULL;
285 inst->priv=(void*)list;
|
286 kumpf 1.6
|
287 schuur 1.12 CMReturn(CMPI_RC_OK);
|
288 schuur 1.1 }
289
|
290 schuur 1.12 static CMPIStatus instSetPropertyFilterIgnore(CMPIInstance* eInst,
|
291 konrad.r 1.19 const char** propertyList, const char **keys){
|
292 david.dillard 1.21 /* We ignore it. */
|
293 konrad.r 1.19 CMReturn ( CMPI_RC_OK);
|
294 schuur 1.12 }
|
295 schuur 1.1
296 }
297
298 static CMPIInstanceFT instance_FT={
299 CMPICurrentVersion,
300 instRelease,
301 instClone,
302 instGetProperty,
303 instGetPropertyAt,
304 instGetPropertyCount,
305 instSetProperty,
306 instGetObjectPath,
307 instSetPropertyFilter,
|
308 konrad.r 1.19 #if defined(CMPI_VER_100)
309 instSetObjectPath,
310 #endif
|
311 schuur 1.1 };
312
313 static CMPIInstanceFT instanceOnStack_FT={
314 CMPICurrentVersion,
315 instReleaseNop,
316 instClone,
317 instGetProperty,
318 instGetPropertyAt,
319 instGetPropertyCount,
320 instSetProperty,
321 instGetObjectPath,
322 instSetPropertyFilterIgnore,
|
323 konrad.r 1.19 #if defined(CMPI_VER_100)
324 instSetObjectPath,
325 #endif
|
326 schuur 1.1 };
327
328 CMPIInstanceFT *CMPI_Instance_Ftab=&instance_FT;
329 CMPIInstanceFT *CMPI_InstanceOnStack_Ftab=&instanceOnStack_FT;
330
331
332 CMPI_InstanceOnStack::CMPI_InstanceOnStack(const CIMInstance& ci) {
333 hdl=(void*)&ci;
334 ft=CMPI_InstanceOnStack_Ftab;
335 }
336
337
338 PEGASUS_NAMESPACE_END
|