cmpiArray.cpp

Go to the documentation of this file.
00001 
00002 /*
00003  *
00004  * cmpiArray.cpp
00005  *
00006  * (C) Copyright IBM Corp. 2003
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: CMPIArray support
00020  *              Data/value array support
00021  *
00022  */
00023 
00024 #include "cmpisrv.h"
00025 
00026 static CMPIStatus arrayRelease(CMPIArray* eArray)
00027 {
00028    CMPIData *dta = (CMPIData *)eArray->hdl;
00029    if (dta)
00030    {
00031       if (dta->type & CMPI_ENC)
00032       {
00033          // for (uint i=1; i<=dta->value.uint32; i++)
00034          //{
00035             //if (dta[i].state == 0)
00036                //((CMPIString *)dta[i].value.
00037                // string)->ft->release(
00038                //(CMPIString*)dta[i].value.string);
00039          //}
00040       }
00041       delete[] dta;
00042       ((CMPI_Object *)eArray)->unlinkAndDelete();
00043    }
00044    CMReturn(CMPI_RC_OK);
00045 }
00046 
00047 static CMPIArray* arrayClone(const CMPIArray* eArray, CMPIStatus* rc)
00048 {
00049    CMPIData * dta=(CMPIData *)eArray->hdl;
00050    CMPIData * nDta=new CMPIData[dta->value.uint32+1];
00051    CMPIArray * nArray=(CMPIArray *)new CMPI_Object(nDta, CMPI_Array_Ftab);
00052    CMPIStatus rrc={CMPI_RC_OK, NULL};
00053 
00054    if (dta->type & CMPI_ENC) for (unsigned int i=1; i<=dta->value.uint32; i++)
00055       nDta[i].state=CMPI_nullValue;
00056 
00057    for (unsigned int i=0; i<=dta->value.uint32; i++)
00058    {
00059       nDta[i] = dta[i];
00060       if (dta->type & CMPI_ENC && dta[i].state==0)
00061       {
00062          nDta[i].value.string =
00063             ((CMPIString*)dta[i].value.string)->ft->clone(
00064                (CMPIString *)dta[i].value.string,&rrc);
00065          if (rrc.rc)
00066          {
00067             arrayRelease(nArray);
00068             if (rc) *rc=rrc;
00069             return NULL;
00070          }
00071       }
00072    }
00073 
00074    CMSetStatus(rc, CMPI_RC_OK);
00075    return nArray;
00076 }
00077 
00078 static CMPIData arrayGetElementAt(const CMPIArray* eArray, CMPICount pos,
00079                 CMPIStatus* rc)
00080 {
00081    CMPIData * dta=(CMPIData *)eArray->hdl;
00082    CMSetStatus(rc, CMPI_RC_OK);
00083    if (pos<dta->value.uint32) return dta[pos+1];
00084 
00085    CMPIData data={(CMPIType) 0, CMPI_nullValue, {0} };
00086    CMSetStatus(rc, CMPI_RC_ERR_NOT_FOUND);
00087    return data;
00088 }
00089 
00090 static CMPIStatus arraySetElementAt(CMPIArray* eArray, CMPICount pos,
00091                const CMPIValue *val, CMPIType type)
00092 {
00093    CMPIData * dta=(CMPIData *)eArray->hdl;
00094 
00095    if (pos<dta->value.uint32)
00096    {
00097       if ((dta->type&~CMPI_ARRAY)==type)
00098       {
00099          dta[pos+1].state=0;
00100          dta[pos+1].value=*val;
00101          CMReturn(CMPI_RC_OK);
00102       }
00103       //std::cout<<"--- arraySetElementAt(): "
00104       // << CMPI_RC_ERR_TYPE_MISMATCH is "
00105       // <<(void*)(long)type << " should be "
00106       // <<(void*)(long)dta->type<<std::endl;
00107       CMReturn(CMPI_RC_ERR_TYPE_MISMATCH);
00108    }
00109    CMReturn(CMPI_RC_ERR_NOT_FOUND);
00110 }
00111 
00112 static CMPICount arrayGetSize(const CMPIArray* eArray, CMPIStatus* rc)
00113 {
00114    CMPIData * dta=(CMPIData *)eArray->hdl;
00115    CMSetStatus(rc,CMPI_RC_OK);
00116    return dta->value.uint32;
00117 }
00118 
00119 static CMPIType arrayGetType(const CMPIArray* eArray, CMPIStatus* rc)
00120 {
00121    CMPIData * dta=(CMPIData *)eArray->hdl;
00122    CMSetStatus(rc,CMPI_RC_OK);
00123    return dta->type;
00124 }
00125 
00126 static CMPIArrayFT array_FT={
00127    CMPICurrentVersion,
00128    arrayRelease,
00129    arrayClone,
00130    arrayGetSize,
00131    arrayGetType,
00132    arrayGetElementAt,
00133    arraySetElementAt,
00134 };
00135 
00136 CMPIArrayFT *CMPI_Array_Ftab=&array_FT;
00137 

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