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

  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 karl   1.14 // 
 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             // Modified By:
 33             //
 34             //%/////////////////////////////////////////////////////////////////////////////
 35             
 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 schuur   1.1  #include <string.h>
 46               
 47               PEGASUS_USING_STD;
 48               PEGASUS_NAMESPACE_BEGIN
 49               
 50 schuur   1.12 extern "C" {
 51               
 52                  static CMPIStatus instRelease(CMPIInstance* eInst) {
 53                     CIMInstance* inst=(CIMInstance*)eInst->hdl;
 54                     if (inst) {
 55                        delete inst;
 56                        (reinterpret_cast<CMPI_Object*>(eInst))->unlinkAndDelete();
 57                     }
 58                     CMReturn(CMPI_RC_OK);
 59 schuur   1.1     }
 60               
 61 schuur   1.12    static CMPIStatus instReleaseNop(CMPIInstance* eInst) {
 62                     CMReturn(CMPI_RC_OK);
 63                  }
 64 schuur   1.1  
 65 konrad.r 1.19    static CMPIInstance* instClone(const CMPIInstance* eInst, CMPIStatus* rc) {
 66 konrad.r 1.15 	  if (!eInst->hdl)  {
 67               		if (rc) CMSetStatus(rc, CMPI_RC_ERR_INVALID_PARAMETER);
 68               	    return NULL;
 69               	  }
 70 schuur   1.12       CIMInstance* inst=(CIMInstance*)eInst->hdl;
 71                     CIMInstance* cInst=new CIMInstance(inst->clone());
 72                     CMPI_Object* obj=new CMPI_Object(cInst);
 73                     obj->unlink();
 74                     CMPIInstance* neInst=reinterpret_cast<CMPIInstance*>(obj);
 75                     if (rc) CMSetStatus(rc,CMPI_RC_OK);
 76                     return neInst;
 77 schuur   1.1     }
 78               
 79 konrad.r 1.19    static CMPIData instGetPropertyAt(const CMPIInstance* eInst, CMPICount pos, CMPIString** name,
 80 schuur   1.12                               CMPIStatus* rc) {
 81                     CIMInstance* inst=(CIMInstance*)eInst->hdl;
 82                     CMPIData data={0,CMPI_nullValue,{0}};
 83 schuur   1.1  
 84 konrad.r 1.15 	  if (!inst)  {
 85               		if (rc) CMSetStatus(rc, CMPI_RC_ERR_INVALID_PARAMETER);
 86               	    return data;
 87               	  }
 88               
 89 schuur   1.12       if (pos>inst->getPropertyCount()) {
 90                     if (rc) CMSetStatus(rc,CMPI_RC_ERR_NOT_FOUND);
 91                        CMPIData data={0,CMPI_nullValue|CMPI_notFound,{0}};
 92                        return data;
 93                     }
 94                     const CIMProperty& p=inst->getProperty(pos);
 95                     const CIMValue& v=p.getValue();
 96                     CIMType pType=p.getType();
 97                     CMPIType t=type2CMPIType(pType,p.isArray());
 98 schuur   1.1  
 99 schuur   1.12       value2CMPIData(v,t,&data);
100 schuur   1.1  
101 schuur   1.12       if (name) {
102                        String str=p.getName().getString();
103                        *name=(CMPIString*)string2CMPIString(str);
104                     }
105 schuur   1.1  
106                     if (rc) CMSetStatus(rc,CMPI_RC_OK);
107 schuur   1.12       return data;
108 schuur   1.1     }
109               
110 konrad.r 1.19    static CMPIData instGetProperty(const CMPIInstance* eInst, const char *name, CMPIStatus* rc) {
111 konrad.r 1.15 
112                     CMPIData data={0,CMPI_nullValue|CMPI_notFound,{0}};
113               
114               	  if (!eInst->hdl)  {
115               		if (rc) CMSetStatus(rc, CMPI_RC_ERR_INVALID_PARAMETER);
116               	    return data;
117               	  }
118 schuur   1.12       CIMInstance* inst=(CIMInstance*)eInst->hdl;
119                     Uint32 pos=inst->findProperty(String(name));
120               
121                     if (pos!=PEG_NOT_FOUND) {
122                        if (rc) CMSetStatus(rc,CMPI_RC_OK);
123                        return instGetPropertyAt(eInst,pos,NULL,rc);
124                     }
125                     if (rc) CMSetStatus(rc,CMPI_RC_ERR_NOT_FOUND);
126                     return data;
127                  }
128 schuur   1.1  
129               
130 konrad.r 1.19    static CMPICount instGetPropertyCount(const CMPIInstance* eInst, CMPIStatus* rc) {
131 schuur   1.12       CIMInstance* inst=(CIMInstance*)eInst->hdl;
132 konrad.r 1.15 	  if (!inst)  {
133               		if (rc) CMSetStatus(rc, CMPI_RC_ERR_INVALID_PARAMETER);
134               	    return 0;
135               	  }
136 schuur   1.12       if (rc) CMSetStatus(rc,CMPI_RC_OK);
137                     return inst->getPropertyCount();
138 schuur   1.1     }
139               
140 konrad.r 1.19    static CMPIStatus instSetProperty(const CMPIInstance* eInst, const char *name,
141                                          const CMPIValue* data, const CMPIType type) {
142 schuur   1.12       CIMInstance *inst=(CIMInstance*)eInst->hdl;
143 konrad.r 1.15 	  if (!inst)  {
144               	    CMReturn(CMPI_RC_ERR_INVALID_PARAMETER);
145               	  }
146 konrad.r 1.19       char **list=(char**)(reinterpret_cast<const CMPI_Object*>(eInst))->priv;
147 schuur   1.12       CMPIrc rc;
148               
149                     if (list) {
150                        while (*list) {
151 konrad.r 1.18             if (System::strcasecmp(name,*list)==0) goto ok;
152 schuur   1.12             list++;
153                        }
154                        CMReturn(CMPI_RC_OK);
155                     }
156               
157                  ok:
158                     CIMValue v=value2CIMValue(data,type,&rc);
159                     CIMName sName(name);
160                     Uint32 pos;
161                     int count=0;
162               
163                     if ((pos=inst->findProperty(sName))!=PEG_NOT_FOUND) {
164                        CIMProperty cp=inst->getProperty(pos);
165                        try {
166                           cp.setValue(v);
167                        }
168 konrad.r 1.19          catch (const TypeMismatchException &e) {
169 schuur   1.13 #ifdef PEGASUS_DEBUG
170                          cerr<<"-+- TypeMisMatch exception for: "<<name<<endl;
171                          if (getenv("CMPI_CHECKTYPES")!=NULL) {
172 schuur   1.12                cerr<<"-+- Aborting because of CMPI_CHECKTYPES"<<endl;
173 schuur   1.13                abort();
174                           }
175               #endif
176 schuur   1.12             CMReturn(CMPI_RC_ERR_TYPE_MISMATCH);
177                        }
178 konrad.r 1.19          catch (const Exception &e) {
179 schuur   1.13 #ifdef PEGASUS_DEBUG
180 schuur   1.12             cerr<<"-+- "<<e.getMessage()<<" exception for: "<<name<<endl;
181 schuur   1.13             if (getenv("CMPI_CHECKTYPES")!=NULL) {
182                              cerr<<"-+- Aborting because of CMPI_CHECKTYPES"<<endl;
183                              abort();
184                           }
185               #endif
186 schuur   1.12             CMReturnWithString(CMPI_RC_ERR_FAILED,
187                        reinterpret_cast<CMPIString*>(new CMPI_Object(e.getMessage())));
188                        }
189                     }
190                     else {
191                        if (type==CMPI_ref) {
192                        CIMObjectPath *ref=(CIMObjectPath*)(data->ref->hdl);
193                        inst->addProperty(CIMProperty(sName,v,count,ref->getClassName()));
194                        }
195               
196                        else inst->addProperty(CIMProperty(sName,v,count));
197 schuur   1.1        }
198 schuur   1.12       CMReturn(CMPI_RC_OK);
199 schuur   1.1     }
200 schuur   1.12 
201 konrad.r 1.19    static CMPIObjectPath* instGetObjectPath(const CMPIInstance* eInst, CMPIStatus* rc) {
202 schuur   1.12       CIMInstance* inst=(CIMInstance*)eInst->hdl;
203 konrad.r 1.15 	  if (!inst)  {
204               		if (rc) CMSetStatus(rc, CMPI_RC_ERR_INVALID_PARAMETER);
205               	    return NULL;
206               	  }
207 schuur   1.12       const CIMObjectPath &clsRef=inst->getPath();
208                     CMPIObjectPath *cop=NULL;
209                     if (clsRef.getKeyBindings().size()==0) {
210                        CIMClass *cc=mbGetClass(CMPI_ThreadContext::getBroker(),clsRef);
211                        const CIMObjectPath &ref=inst->buildPath(
212                           *(reinterpret_cast<const CIMConstClass*>(cc)));
213                        cop=reinterpret_cast<CMPIObjectPath*>
214                           (new CMPI_Object(new CIMObjectPath(ref)));
215               
216 schuur   1.1        }
217 schuur   1.12       else cop=reinterpret_cast<CMPIObjectPath*>(new CMPI_Object(new CIMObjectPath(clsRef)));
218                     if (rc) CMSetStatus(rc,CMPI_RC_OK);
219                     return cop;
220 schuur   1.1     }
221 konrad.r 1.19    static CMPIStatus instSetObjectPath( CMPIInstance* eInst, const CMPIObjectPath *obj)
222                  {
223               	/* IBMLR: Have not yet implemented this */
224                    CMReturn ( CMPI_RC_ERR_NOT_SUPPORTED);
225                  }
226 schuur   1.1  
227 schuur   1.12    static CMPIStatus instSetPropertyFilter(CMPIInstance* eInst,
228 konrad.r 1.19                const char** propertyList, const char **keys){
229 konrad.r 1.15 	  if (!eInst->hdl)  {
230               	    CMReturn(CMPI_RC_ERR_INVALID_PARAMETER);
231               	  }
232 konrad.r 1.19 
233 schuur   1.12       CMPI_Object *inst=reinterpret_cast<CMPI_Object*>(eInst);
234                     char **list=(char**)inst->priv;    // Thank you Warren !
235                     int i,s;
236               
237                     if (inst->priv) {
238                        while (*list) {
239                           free (*list);
240                           list++;
241                        }
242                        free(inst->priv);
243                     }
244                     inst->priv=NULL;
245               
246                     if (propertyList==NULL) CMReturn(CMPI_RC_OK);
247                     if (keys==NULL) CMReturn(CMPI_RC_ERR_FAILED);
248               
249                     for (s=0,i=0; propertyList[i]; i++,s++);
250                     for (i=0; keys[i]; i++,s++);
251                     list=(char**)malloc((s+2)*sizeof(char*));
252                     for (s=0,i=0; propertyList[i]; i++,s++) list[s]=strdup(propertyList[i]);
253                     for (i=0; keys[i]; i++,s++) list[s]=strdup(keys[i]);
254 schuur   1.12       list[s]=NULL;
255                     inst->priv=(void*)list;
256 kumpf    1.6  
257 schuur   1.12       CMReturn(CMPI_RC_OK);
258 schuur   1.1     }
259               
260 schuur   1.12    static CMPIStatus instSetPropertyFilterIgnore(CMPIInstance* eInst,
261 konrad.r 1.19                const char** propertyList, const char **keys){
262               	/* We ignore it.  */
263                    CMReturn ( CMPI_RC_OK);
264 schuur   1.12    }
265 schuur   1.1  
266               }
267               
268               static CMPIInstanceFT instance_FT={
269                    CMPICurrentVersion,
270                    instRelease,
271                    instClone,
272                    instGetProperty,
273                    instGetPropertyAt,
274                    instGetPropertyCount,
275                    instSetProperty,
276                    instGetObjectPath,
277                    instSetPropertyFilter,
278 konrad.r 1.19 #if defined(CMPI_VER_100)
279                    instSetObjectPath,
280               #endif
281 schuur   1.1  };
282               
283               static CMPIInstanceFT instanceOnStack_FT={
284                    CMPICurrentVersion,
285                    instReleaseNop,
286                    instClone,
287                    instGetProperty,
288                    instGetPropertyAt,
289                    instGetPropertyCount,
290                    instSetProperty,
291                    instGetObjectPath,
292                    instSetPropertyFilterIgnore,
293 konrad.r 1.19 #if defined(CMPI_VER_100)
294                    instSetObjectPath,
295               #endif
296 schuur   1.1  };
297               
298               CMPIInstanceFT *CMPI_Instance_Ftab=&instance_FT;
299               CMPIInstanceFT *CMPI_InstanceOnStack_Ftab=&instanceOnStack_FT;
300               
301               
302               CMPI_InstanceOnStack::CMPI_InstanceOnStack(const CIMInstance& ci) {
303                     hdl=(void*)&ci;
304                     ft=CMPI_InstanceOnStack_Ftab;
305                  }
306               
307               
308               PEGASUS_NAMESPACE_END
309               
310               
311               
312               
313               
314               
315               
316               
317 schuur   1.1  
318               
319               
320               
321               
322               
323               
324               

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2