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

  1 schuur 1.1 //%2003////////////////////////////////////////////////////////////////////////
  2            //
  3            // 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            //
  8            // Permission is hereby granted, free of charge, to any person obtaining a copy
  9            // of this software and associated documentation files (the "Software"), to
 10            // deal in the Software without restriction, including without limitation the
 11            // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 12            // sell copies of the Software, and to permit persons to whom the Software is
 13            // furnished to do so, subject to the following conditions:
 14            //
 15            // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 16            // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 17            // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 18            // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 19            // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 20            // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 21            // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 22 schuur 1.1 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 23            //
 24            //==============================================================================
 25            //
 26            // Author:      Adrian Schuur, schuur@de.ibm.com
 27            //
 28            // Modified By:
 29            //
 30            //%/////////////////////////////////////////////////////////////////////////////
 31            
 32 schuur 1.2 #define CMPI_VER_86 1
 33            
 34 schuur 1.1 #include "CMPI_Instance.h"
 35            #include "CMPI_Broker.h"
 36            #include "CMPI_Value.h"
 37            #include "CMPI_String.h"
 38            
 39            #include <Pegasus/Common/InternalException.h>
 40            #ifdef PEGASUS_PLATFORM_ZOS_ZSERIES_IBM
 41            #include <strings.h>       // for strcasecmp
 42            #endif
 43            #include <string.h>
 44            
 45            PEGASUS_USING_STD;
 46            PEGASUS_NAMESPACE_BEGIN
 47            
 48            static CMPIStatus instRelease(CMPIInstance* eInst) {
 49            //   cout<<"--- instRelease()"<<endl;
 50               CIMInstance* inst=(CIMInstance*)eInst->hdl;
 51               if (inst) {
 52                  delete inst;
 53                  ((CMPI_Object*)eInst)->unlinkAndDelete();
 54               }
 55 schuur 1.1    CMReturn(CMPI_RC_OK);
 56            }
 57            
 58            static CMPIStatus instReleaseNop(CMPIInstance* eInst) {
 59               CMReturn(CMPI_RC_OK);
 60            }
 61            
 62            static CMPIInstance* instClone(CMPIInstance* eInst, CMPIStatus* rc) {
 63               CIMInstance* inst=(CIMInstance*)eInst->hdl;
 64               CIMInstance* cInst=new CIMInstance(inst->clone());
 65               CMPIInstance* neInst=(CMPIInstance*)new CMPI_Object(cInst);//,CMPI_Instance_Ftab);
 66               if (rc) CMSetStatus(rc,CMPI_RC_OK);
 67               return neInst;
 68            }
 69            
 70            static CMPIData instGetPropertyAt(CMPIInstance* eInst, CMPICount pos, CMPIString** name,
 71                                        CMPIStatus* rc) {
 72               CIMInstance* inst=(CIMInstance*)eInst->hdl;
 73               CMPIData data={0,0,{0}};
 74            
 75               if (pos>inst->getPropertyCount()) {
 76 schuur 1.1      if (rc) CMSetStatus(rc,CMPI_RC_ERR_NOT_FOUND);
 77                  return data;
 78               }
 79               const CIMProperty& p=inst->getProperty(pos);
 80               const CIMValue& v=p.getValue();
 81               CIMType pType=p.getType();
 82               CMPIType t=type2CMPIType(pType,p.isArray());
 83            
 84               value2CMPIData(v,t,&data);
 85            
 86               if (name) {
 87 schuur 1.2       String str=p.getName().getString();
 88 schuur 1.1       *name=(CMPIString*)string2CMPIString(str);
 89               }
 90            
 91               if (rc) CMSetStatus(rc,CMPI_RC_OK);
 92               return data;
 93            }
 94            
 95            static CMPIData instGetProperty(CMPIInstance* eInst, char* name, CMPIStatus* rc) {
 96               CIMInstance* inst=(CIMInstance*)eInst->hdl;
 97               Uint32 pos=inst->findProperty(String(name));
 98            
 99               if (pos!=PEG_NOT_FOUND) {
100                  if (rc) CMSetStatus(rc,CMPI_RC_OK);
101                  return instGetPropertyAt(eInst,pos,NULL,rc);
102               }
103               CMPIData data={0,0,{0}};
104               if (rc) CMSetStatus(rc,CMPI_RC_ERR_NOT_FOUND);
105               return data;
106            }
107            
108            
109 schuur 1.1 static CMPICount instGetPropertyCount(CMPIInstance* eInst, CMPIStatus* rc) {
110               CIMInstance* inst=(CIMInstance*)eInst->hdl;
111               if (rc) CMSetStatus(rc,CMPI_RC_OK);
112               return inst->getPropertyCount();
113            }
114            
115            #define PEGASUS_CIM_EXCEPTION(CODE, EXTRA_MESSAGE) \
116                TraceableCIMException(CODE, EXTRA_MESSAGE, __FILE__, __LINE__)
117            
118            
119            static CMPIStatus instSetProperty(CMPIInstance* eInst, char* name,
120                                      CMPIValue* data, CMPIType type) {
121               CIMInstance *inst=(CIMInstance*)eInst->hdl;
122               char **list=(char**)((CMPI_Object*)eInst)->priv;
123               CMPIrc rc;
124            
125               if (list) {
126                  while (*list) {
127                     if (strcasecmp(name,*list)==0) goto ok;
128                     list++;
129                  }
130 schuur 1.1       CMReturn(CMPI_RC_OK);
131               }
132            
133              ok:
134               CIMValue v=value2CIMValue(data,type,&rc);
135               CIMName sName(name);
136               Uint32 pos;
137               int count=0;
138            
139               if ((pos=inst->findProperty(sName))!=PEG_NOT_FOUND) {
140                  CIMProperty cp=inst->getProperty(pos);
141                  try {
142                     cp.setValue(v);
143                  }
144                  catch (TypeMismatchException &e) {
145                     cerr<<"-+- TypeMisMatch exception for: "<<name<<endl;
146            	 if (getenv("CMPI_CHECKTYPES")!=NULL) {
147                        cerr<<"-+- Aborting because of CMPI_CHECKTYPES"<<endl;
148            	    abort();
149            	 }
150                     CMReturn(CMPI_RC_ERR_TYPE_MISMATCH);
151 schuur 1.1       }
152                  catch (Exception &e) {
153                     cerr<<"-+- "<<e.getMessage()<<" exception for: "<<name<<endl;
154            	 if (getenv("CMPI_CHECKTYPES")!=NULL) {
155                     cerr<<"-+- Aborting because of CMPI_CHECKTYPES"<<endl;
156            	    abort();
157            	 }
158                     CMReturnWithString(CMPI_RC_ERR_FAILED,
159            	     (CMPIString*)new CMPI_Object(e.getMessage()));
160                  }
161               }
162               else {
163                  if (type==CMPI_ref) {
164                    CIMObjectPath *ref=(CIMObjectPath*)(data->ref->hdl);
165                    inst->addProperty(CIMProperty(sName,v,count,ref->getClassName()));
166                  }
167            
168                  else inst->addProperty(CIMProperty(sName,v,count));
169               }
170               CMReturn(CMPI_RC_OK);
171            }
172 schuur 1.1 
173            static CMPIObjectPath* instGetObjectPath(CMPIInstance* eInst, CMPIStatus* rc) {
174               CIMInstance* inst=(CIMInstance*)eInst->hdl;
175               const CIMObjectPath &clsRef=inst->getPath();
176               CMPIObjectPath *cop=NULL;
177               if (clsRef.getKeyBindings().size()==0) {
178                  CIMClass *cc=mbGetClass(CMPI_ThreadContext::getBroker(),clsRef);
179                  const CIMObjectPath &ref=inst->buildPath((const CIMConstClass&)*cc);
180                  cop=(CMPIObjectPath*)new CMPI_Object(new CIMObjectPath(ref));
181               }
182               else cop=(CMPIObjectPath*)new CMPI_Object(new CIMObjectPath(clsRef));
183               if (rc) CMSetStatus(rc,CMPI_RC_OK);
184               return cop;
185            }
186            
187            static CMPIStatus instSetPropertyFilter(CMPIInstance* eInst,
188                        char** propertyList, char **keys){
189               CMPI_Object *inst=(CMPI_Object*)eInst;
190               char **list=(char**)inst->priv;    // Thank you Warren !
191               int i,s;
192            
193 schuur 1.1    if (inst->priv) {
194                  while (*list) {
195                     free (*list);
196                     list++;
197                  }
198                  free(inst->priv);
199               }
200               inst->priv=NULL;
201            
202               if (propertyList==NULL) CMReturn(CMPI_RC_OK);
203               if (keys==NULL) CMReturn(CMPI_RC_ERR_FAILED);
204            
205               for (s=0,i=0; propertyList[i]; i++,s++);
206               for (i=0; keys[i]; i++,s++);
207               list=(char**)malloc((s+2)*sizeof(char*));
208               for (s=0,i=0; propertyList[i]; i++,s++) list[s]=strdup(propertyList[i]);
209               for (i=0; keys[i]; i++,s++) list[s]=strdup(keys[i]);
210               list[s]=NULL;
211               inst->priv=(void*)list;
212            
213               CMReturn(CMPI_RC_OK);
214 schuur 1.1 }
215            
216            static CMPIStatus instSetPropertyFilterIgnore(CMPIInstance* eInst,
217                        char** propertyList, char **keys){
218               CMReturn(CMPI_RC_OK);
219            }
220            
221            static CMPIInstanceFT instance_FT={
222                 CMPICurrentVersion,
223                 instRelease,
224                 instClone,
225                 instGetProperty,
226                 instGetPropertyAt,
227                 instGetPropertyCount,
228                 instSetProperty,
229                 instGetObjectPath,
230                 instSetPropertyFilter,
231            };
232            
233            static CMPIInstanceFT instanceOnStack_FT={
234                 CMPICurrentVersion,
235 schuur 1.1      instReleaseNop,
236                 instClone,
237                 instGetProperty,
238                 instGetPropertyAt,
239                 instGetPropertyCount,
240                 instSetProperty,
241                 instGetObjectPath,
242                 instSetPropertyFilterIgnore,
243            };
244            
245            CMPIInstanceFT *CMPI_Instance_Ftab=&instance_FT;
246            CMPIInstanceFT *CMPI_InstanceOnStack_Ftab=&instanceOnStack_FT;
247            
248            
249            CMPI_InstanceOnStack::CMPI_InstanceOnStack(const CIMInstance& ci) {
250                  hdl=(void*)&ci;
251                  ft=CMPI_InstanceOnStack_Ftab;
252               }
253            
254            
255            PEGASUS_NAMESPACE_END
256 schuur 1.1 
257            
258            
259            
260            
261            
262            
263            
264            
265            
266            
267            
268            
269            
270            
271            

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2