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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2