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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2