cmpiInstance.cpp

Go to the documentation of this file.
00001 /*
00002  *
00003  * cmpiInstance.cpp
00004  *
00005  * Copyright (c) 2002, International Business Machines
00006  *
00007  * THIS FILE IS PROVIDED UNDER THE TERMS OF THE COMMON PUBLIC LICENSE
00008  * ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE
00009  * CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT.
00010  *
00011  * You can obtain a current copy of the Common Public License from
00012  * http://oss.software.ibm.com/developerworks/opensource/license-cpl.html
00013  *
00014  * Author:        Adrian Schuur <schuur@de.ibm.com>
00015  * 
00016  * Contributor:   Markus Mueller <sedgewick_de@yahoo.de>
00017  *
00018  * Description: CMPIInstance support
00019  *
00020  */
00021 
00022 #include "cmpisrv.h"
00023 #include "OW_CIMInstance.hpp"
00024 
00025 // TEST
00026 #include <iostream>
00027 using std::cout;
00028 using std::endl;
00029 
00030 using namespace OpenWBEM::WBEMFlags;
00031 
00032 static CMPIStatus instRelease(CMPIInstance* eInst)
00033 {
00034    //cout<<"--- instRelease()"<<endl;
00035    OpenWBEM::CIMInstance* inst=(OpenWBEM::CIMInstance*)eInst->hdl;
00036    if(inst)
00037    {
00038       delete inst;
00039       ((CMPI_Object*)eInst)->unlinkAndDelete();
00040    }
00041    CMReturn(CMPI_RC_OK);
00042 }
00043 
00044 static CMPIStatus instReleaseNop(CMPIInstance* eInst)
00045 {
00046    (void) eInst;
00047    CMReturn(CMPI_RC_OK);
00048 }
00049 
00050 static CMPIInstance* instClone(const CMPIInstance* eInst, CMPIStatus* rc)
00051 {
00052    OpenWBEM::CIMInstance* inst=(OpenWBEM::CIMInstance*)eInst->hdl;
00053    OpenWBEM::CIMInstance* cInst=new OpenWBEM::CIMInstance(inst->clone(E_NOT_LOCAL_ONLY, E_INCLUDE_QUALIFIERS, E_INCLUDE_CLASS_ORIGIN));
00054    CMPIInstance* neInst=(CMPIInstance*)new CMPI_Object(cInst,CMPI_Instance_Ftab);
00055    CMSetStatus(rc,CMPI_RC_OK);
00056    return neInst;
00057 }
00058 
00059 static CMPIData instGetPropertyAt(const CMPIInstance* eInst, CMPICount pos, CMPIString** name,
00060    CMPIStatus* rc)
00061 {
00062    OpenWBEM::CIMInstance* inst=(OpenWBEM::CIMInstance*)eInst->hdl;
00063    CMPIData data={(CMPIType) 0, CMPI_nullValue, {0} };
00064 
00065    const OpenWBEM::CIMPropertyArray& p=inst->getProperties();
00066 
00067    if(pos >= p.size())
00068    {
00069       CMSetStatus(rc,CMPI_RC_ERR_NOT_FOUND);
00070       return data;
00071    }
00072    OpenWBEM::CIMValue v=p[pos].getValue();
00073    CMPIrc rrc;
00074         if(!v)
00075    {
00076        rrc = CMPI_RC_OK;
00077    }
00078    else
00079    {
00080        OpenWBEM::CIMDataType pType=v.getType();
00081 
00082        CMPIType t=type2CMPIType(pType,v.isArray());
00083 
00084        rrc = value2CMPIData(v,t,&data);
00085    }
00086    if(name)
00087    {
00088       OpenWBEM::String str=p[pos].getName();
00089       *name=string2CMPIString(str);
00090    }
00091 
00092    CMSetStatus(rc, rrc);
00093    return data;
00094 }
00095 
00096 static CMPIData instGetProperty(const CMPIInstance* eInst, const char* name, CMPIStatus* rc)
00097 {
00098    OpenWBEM::CIMInstance* inst=(OpenWBEM::CIMInstance*)eInst->hdl;
00099    CMPIData data={(CMPIType) 0, CMPI_nullValue, {0} };
00100 
00101    const OpenWBEM::CIMProperty& p = inst->getProperty(OpenWBEM::String(name));
00102 
00103    if(p)
00104    {
00105       const OpenWBEM::CIMValue& v=p.getValue();
00106       OpenWBEM::CIMDataType pType=v.getType();
00107       CMPIType t=type2CMPIType(pType,v.isArray());
00108 
00109       CMPIrc rrc=value2CMPIData(v,t,&data);
00110       CMSetStatus(rc,rrc);
00111       return data;
00112    }
00113    CMSetStatus(rc,CMPI_RC_ERR_NOT_FOUND);
00114    return data;
00115 }
00116 
00117 
00118 static CMPICount instGetPropertyCount(const CMPIInstance* eInst, CMPIStatus* rc)
00119 {
00120    OpenWBEM::CIMInstance* inst=(OpenWBEM::CIMInstance*)eInst->hdl;
00121    const OpenWBEM::CIMPropertyArray& p=inst->getProperties();
00122    CMSetStatus(rc,CMPI_RC_OK);
00123    return p.size();
00124 }
00125 
00126 static CMPIStatus instSetProperty(const CMPIInstance* eInst, const char* name,
00127    const CMPIValue* data, CMPIType type)
00128 {
00129    OpenWBEM::CIMInstance *inst = (OpenWBEM::CIMInstance*)eInst->hdl;
00130    char **list = (char**)((CMPI_Object*)eInst)->priv;
00131    CMPIrc rc;
00132 
00133    if(list)
00134    {
00135       while(*list)
00136       {
00137          if(strcasecmp(name,*list) == 0)
00138          {
00139             goto ok;
00140          }
00141 
00142          list++;
00143       }
00144       CMReturn(CMPI_RC_OK);
00145    }
00146 
00147    ok:
00148 
00149    OpenWBEM::CIMValue v = value2CIMValue(data, type, &rc);
00150    OpenWBEM::String sName(name);
00151    inst->setProperty(sName, v);
00152    CMReturn(CMPI_RC_OK);
00153 }
00154 
00155 static CMPIObjectPath* instGetObjectPath(const CMPIInstance* eInst, CMPIStatus* rc)
00156 {
00157    OpenWBEM::CIMInstance* inst = (OpenWBEM::CIMInstance*)eInst->hdl;
00158    OpenWBEM::CIMObjectPath ref("", *inst);
00159    CMPIObjectPath *cop = (CMPIObjectPath*)new CMPI_Object(
00160       new OpenWBEM::CIMObjectPath(ref));
00161    CMSetStatus(rc, CMPI_RC_OK);
00162    return cop;
00163 }
00164 
00165 static CMPIStatus instSetPropertyFilter(CMPIInstance* eInst,
00166    const char** propertyList, const char **keys)
00167 {
00168    CMPI_Object *inst=(CMPI_Object*)eInst;
00169    char **list=(char**)inst->priv;     // Thank you Warren !
00170    int i,s;
00171 
00172    if(inst->priv)
00173    {
00174       while(*list)
00175       {
00176          free (*list);
00177          list++;
00178       }
00179       free(inst->priv);
00180    }
00181    inst->priv=NULL;
00182 
00183    if(propertyList == NULL)
00184    {
00185       CMReturn(CMPI_RC_OK);
00186    }
00187 
00188    if(keys == NULL)
00189    {
00190       CMReturn(CMPI_RC_ERR_FAILED);
00191    }
00192 
00193    for(s = 0, i = 0; propertyList[i]; i++, s++);
00194    for(i = 0; keys[i]; i++, s++);
00195 
00196    list = (char**) malloc( (s+2) * sizeof(char*));
00197 
00198    for(s = 0, i = 0; propertyList[i]; i++,s++)
00199    {
00200       list[s] = strdup(propertyList[i]);
00201    }
00202 
00203    for(i = 0; keys[i]; i++,s++)
00204    {
00205       list[s] = strdup(keys[i]);
00206    }
00207 
00208    list[s] = NULL;
00209    inst->priv = (void*)list;
00210 
00211    CMReturn(CMPI_RC_OK);
00212 }
00213 
00214 static CMPIStatus instSetPropertyFilterIgnore(CMPIInstance* eInst,
00215    const char** propertyList, const char **keys)
00216 {
00217    (void)eInst;
00218    (void)propertyList;
00219    (void)keys;
00220    CMReturn(CMPI_RC_OK);
00221 }
00222 
00223 #if defined(CMPI_VER_100)
00224 static CMPIStatus instSetObjectPath(CMPIInstance* inst, const CMPIObjectPath* op)
00225 {
00226    CMPIStatus rc; 
00227    // TODO
00228    rc.rc = CMPI_RC_ERR_METHOD_NOT_AVAILABLE; 
00229    return rc; 
00230 }
00231 #endif
00232 
00233 
00234 static CMPIInstanceFT instance_FT={
00235    CMPICurrentVersion,
00236    instRelease,
00237    instClone,
00238    instGetProperty,
00239    instGetPropertyAt,
00240    instGetPropertyCount,
00241    instSetProperty,
00242    instGetObjectPath,
00243    instSetPropertyFilter,
00244 #if defined(CMPI_VER_100)
00245    instSetObjectPath,
00246 #endif
00247    // TODO setObjectPath
00248 };
00249 
00250 static CMPIInstanceFT instanceOnStack_FT={
00251    CMPICurrentVersion,
00252    instReleaseNop,
00253    instClone,
00254    instGetProperty,
00255    instGetPropertyAt,
00256    instGetPropertyCount,
00257    instSetProperty,
00258    instGetObjectPath,
00259    instSetPropertyFilterIgnore,
00260 #if defined(CMPI_VER_100)
00261      instSetObjectPath,
00262 #endif
00263    // TODO setObjectPath
00264 };
00265 
00266 CMPIInstanceFT *CMPI_Instance_Ftab=&instance_FT;
00267 CMPIInstanceFT *CMPI_InstanceOnStack_Ftab=&instanceOnStack_FT;
00268 
00269 
00270 CMPI_InstanceOnStack::CMPI_InstanceOnStack(const OpenWBEM::CIMInstance& ci)
00271 {
00272    hdl=(void*)&ci;
00273    ft=CMPI_InstanceOnStack_Ftab;
00274 }

Generated on Thu Feb 9 08:47:49 2006 for openwbem by  doxygen 1.4.6