cmpiObjectPath.cpp

Go to the documentation of this file.
00001 
00002 /*
00003  *
00004  * cmpiObjectPath.cpp
00005  *
00006  * Copyright (c) 2002, International Business Machines
00007  *
00008  * THIS FILE IS PROVIDED UNDER THE TERMS OF THE COMMON PUBLIC LICENSE
00009  * ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE
00010  * CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT.
00011  *
00012  * You can obtain a current copy of the Common Public License from
00013  * http://oss.software.ibm.com/developerworks/opensource/license-cpl.html
00014  *
00015  * Author:        Adrian Schuur <schuur@de.ibm.com>
00016  *
00017  * Contributor:   Markus Mueller <sedgewick_de@yahoo.de>
00018  *
00019  * Description: CMPIObjectPath support
00020  *
00021  */
00022 
00023 
00024 #include <iostream>
00025 #include "cmpisrv.h"
00026 
00027 static CMPIStatus refRelease(CMPIObjectPath* eRef)
00028 {
00029 
00030    OpenWBEM::CIMObjectPath* ref=(OpenWBEM::CIMObjectPath*)eRef->hdl;
00031    if (ref)
00032    {
00033       delete ref;
00034       ((CMPI_Object*)eRef)->unlinkAndDelete();
00035    }
00036    CMReturn(CMPI_RC_OK);
00037 }
00038 
00039 static CMPIStatus refReleaseNop(CMPIObjectPath* eRef)
00040 {
00041    CMReturn(CMPI_RC_OK);
00042 }
00043 
00044 static CMPIObjectPath* refClone(const CMPIObjectPath* eRef, CMPIStatus* rc)
00045 {
00046    OpenWBEM::CIMObjectPath *ref=(OpenWBEM::CIMObjectPath*)eRef->hdl;
00047    //OpenWBEM::CIMObjectPath *nRef=new OpenWBEM::CIMObjectPath(ref->getClassName(),
00048    //                                       ref->getNameSpace());
00049    //nRef->setHost(ref->getHost());
00050    //nRef->setKeys(ref->getKeys());
00051    OpenWBEM::CIMObjectPath *nRef = new OpenWBEM::CIMObjectPath(* ref);
00052    CMPIObjectPath* neRef=(CMPIObjectPath*)new CMPI_Object(nRef,CMPI_ObjectPath_Ftab);
00053 
00054    CMSetStatus(rc,CMPI_RC_OK);
00055    return neRef;
00056 }
00057 
00058 static CMPIStatus refSetNameSpace(CMPIObjectPath* eRef, const char* ns)
00059 {
00060    OpenWBEM::CIMObjectPath* ref=(OpenWBEM::CIMObjectPath*)eRef->hdl;
00061    ref->setNameSpace(OpenWBEM::String(ns));
00062    CMReturn(CMPI_RC_OK);
00063 }
00064 
00065 static CMPIString* refGetNameSpace(const CMPIObjectPath* eRef, CMPIStatus* rc)
00066 {
00067    OpenWBEM::CIMObjectPath* ref=(OpenWBEM::CIMObjectPath*)eRef->hdl;
00068    const OpenWBEM::String &ns=ref->getNameSpace();
00069    CMPIString *eNs=string2CMPIString(ns);
00070    CMSetStatus(rc,CMPI_RC_OK);
00071    return eNs;
00072 }
00073 
00074 static CMPIStatus refSetClassName(CMPIObjectPath * eRef,const char * cl)
00075 {
00076    OpenWBEM::CIMObjectPath* ref=(OpenWBEM::CIMObjectPath*)eRef->hdl;
00077    ref->setClassName(OpenWBEM::String(cl));
00078    CMReturn(CMPI_RC_OK);
00079 }
00080 
00081 static CMPIString* refGetClassName(const CMPIObjectPath* eRef, CMPIStatus* rc)
00082 {
00083    OpenWBEM::CIMObjectPath * ref=(OpenWBEM::CIMObjectPath*)eRef->hdl;
00084    const OpenWBEM::String &cn=ref->getClassName();
00085    CMPIString* eCn=string2CMPIString(cn);
00086    CMSetStatus(rc,CMPI_RC_OK);
00087    return eCn;
00088 }
00089 
00090 
00091 static long locateKey(const OpenWBEM::CIMPropertyArray &kb, const OpenWBEM::String& eName)
00092 {
00093    for (unsigned long i=0,s=kb.size(); i<s; i++)
00094    {
00095       const OpenWBEM::String &n=kb[i].getName();
00096       if (n.equalsIgnoreCase(eName))
00097       {
00098          return i;
00099       }
00100    }
00101    return -1;
00102 }
00103 
00104 static CMPIStatus refAddKey(CMPIObjectPath* eRef, const char* name,
00105    const CMPIValue* data, const CMPIType type)
00106 {
00107    OpenWBEM::CIMObjectPath* ref=(OpenWBEM::CIMObjectPath*)eRef->hdl;
00108    OpenWBEM::CIMPropertyArray keyBindings=ref->getKeys();
00109    OpenWBEM::String key(name);
00110    CMPIrc rc;
00111 
00112    long i = locateKey(keyBindings, key);
00113    if (i >= 0)
00114    {
00115       keyBindings.remove(i);
00116       ref->setKeys(keyBindings);
00117    }
00118 
00119    OpenWBEM::CIMValue val = value2CIMValue(data,type,&rc);
00120    ref->setKeyValue(key, val);
00121    CMReturn(CMPI_RC_OK);
00122 }
00123 
00124 static CMPIData refGetKey(const CMPIObjectPath* eRef, const char* name, CMPIStatus* rc)
00125 {
00126    OpenWBEM::CIMObjectPath* ref=(OpenWBEM::CIMObjectPath*)eRef->hdl;
00127    const OpenWBEM::String eName(name);
00128    OpenWBEM::CIMProperty cpr = ref->getKey(eName);
00129    CMPIData data = {(CMPIType) 0, CMPI_nullValue, {0} };
00130 
00131    CMSetStatus(rc,CMPI_RC_OK);
00132 
00133    if (cpr)
00134    {
00135       OpenWBEM::CIMValue cv = cpr.getValue();
00136       value2CMPIData(cv, type2CMPIType(cv.getType(), cv.isArray()), &data);
00137       return data;
00138    }
00139 
00140    CMSetStatus(rc,CMPI_RC_ERR_NOT_FOUND);
00141    return data;
00142 }
00143 
00144 static CMPIData refGetKeyAt(const CMPIObjectPath* eRef, unsigned pos, CMPIString** name,
00145    CMPIStatus* rc)
00146 {
00147    OpenWBEM::CIMObjectPath* ref=(OpenWBEM::CIMObjectPath*)eRef->hdl;
00148    const OpenWBEM::CIMPropertyArray &akb=ref->getKeys();
00149    CMPIData data={(CMPIType) 0, CMPI_nullValue, {0} };
00150    CMSetStatus(rc,CMPI_RC_OK);
00151 
00152    if (pos >= akb.size())
00153    {
00154       CMSetStatus(rc,CMPI_RC_ERR_NOT_FOUND);
00155       return data;
00156    }
00157 
00158    OpenWBEM::CIMValue cv = akb[pos].getValue();
00159    value2CMPIData(cv, type2CMPIType(cv.getType(),cv.isArray()) ,&data);
00160 
00161    if (name)
00162    {
00163       const OpenWBEM::String &n=akb[pos].getName();
00164       *name=string2CMPIString(n);
00165    }
00166    return data;
00167 }
00168 
00169 static CMPICount refGetKeyCount(const CMPIObjectPath* eRef, CMPIStatus* rc)
00170 {
00171    OpenWBEM::CIMObjectPath* ref=(OpenWBEM::CIMObjectPath*)eRef->hdl;
00172    const OpenWBEM::CIMPropertyArray &akb=ref->getKeys();
00173    CMSetStatus(rc,CMPI_RC_OK);
00174    return akb.size();
00175 }
00176 
00177 static CMPIStatus refSetNameSpaceFromObjectPath(CMPIObjectPath* eRef,
00178    const CMPIObjectPath* eSrc)
00179 {
00180    OpenWBEM::CIMObjectPath* ref=(OpenWBEM::CIMObjectPath*)eRef->hdl;
00181    OpenWBEM::CIMObjectPath* src=(OpenWBEM::CIMObjectPath*)eSrc->hdl;
00182    ref->setNameSpace(src->getNameSpace());
00183    CMReturn(CMPI_RC_OK);
00184 }
00185 
00186 #if 0
00187 static CMPIBoolean refClassPathIsA(CMPIObjectPath *eRef,
00188    char * classname, CMPIStatus * rc)
00189 {
00190    return false;
00191 }
00192 #endif
00193 
00194 #if defined(CMPI_VER_86)
00195 
00200 static      CMPIString *refToString(const CMPIObjectPath* op, CMPIStatus *rc)
00201 {
00202    rc->rc = CMPI_RC_ERR_METHOD_NOT_AVAILABLE; 
00203    CMPIString* rval = new CMPIString; 
00204    //TODO
00205    return rval; 
00206 }
00207 #endif
00208 
00209 static CMPIObjectPathFT objectPath_FT={
00210    CMPICurrentVersion,
00211    refRelease,
00212    refClone,
00213    refSetNameSpace,
00214    refGetNameSpace,
00215    NULL,    // setHostName
00216    NULL,    // getHostName
00217    refSetClassName,
00218    refGetClassName,
00219    refAddKey,
00220    refGetKey,
00221    refGetKeyAt,
00222    refGetKeyCount,
00223    refSetNameSpaceFromObjectPath,
00224    NULL,    //refSetHostAndNameSpaceFromObjectPath,
00225    //refClassPathIsA,
00226    // no qualifier support yet
00227    NULL,
00228    NULL,
00229    NULL,
00230    NULL,
00231    refToString // toString
00232 };
00233 
00234 CMPIObjectPathFT *CMPI_ObjectPath_Ftab=&objectPath_FT;
00235 
00236 static CMPIObjectPathFT objectPathOnStack_FT={
00237    CMPICurrentVersion,
00238    refReleaseNop,
00239    refClone,
00240    refSetNameSpace,
00241    refGetNameSpace,
00242    NULL,    // setHostName
00243    NULL,    // getHostName
00244    refSetClassName,
00245    refGetClassName,
00246    refAddKey,
00247    refGetKey,
00248    refGetKeyAt,
00249    refGetKeyCount,
00250    refSetNameSpaceFromObjectPath,
00251    NULL,    //refSetHostAndNameSpaceFromObjectPath,
00252    //refClassPathIsA,
00253    // no qualifier support yet
00254    NULL,
00255    NULL,
00256    NULL,
00257    NULL,
00258    NULL // toString
00259 };
00260 
00261 CMPIObjectPathFT *CMPI_ObjectPathOnStack_Ftab=&objectPathOnStack_FT;
00262 
00263 
00264 CMPI_ObjectPathOnStack::CMPI_ObjectPathOnStack(const OpenWBEM::CIMObjectPath& cop)
00265 {
00266    hdl=(void*)&cop;
00267    ft=CMPI_ObjectPathOnStack_Ftab;
00268 }

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