cmpiContextArgs.cpp

Go to the documentation of this file.
00001 /*
00002  *
00003  * cmpiContextArgs.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: Combined CMPIContext CMPIArgs support
00019  *
00020  */
00021 
00022 #include "cmpisrv.h"
00023 #include "OW_CIMFwd.hpp"
00024 
00025 // CMPIArgs section
00026 
00027 static CMPIStatus argsRelease(CMPIArgs* eArg)
00028 {
00029    CMReturn(CMPI_RC_OK);
00030 }
00031 
00032 static CMPIStatus argsReleaseNop(CMPIArgs* eArg)
00033 {
00034    CMReturn(CMPI_RC_OK);
00035 }
00036 
00037 static CMPIArgs* argsClone(const CMPIArgs* eArg, CMPIStatus* rc)
00038 {
00039    OpenWBEM::CIMParamValueArray * arg = (OpenWBEM::CIMParamValueArray *)eArg->hdl;
00040    OpenWBEM::CIMParamValueArray * cArg = new OpenWBEM::CIMParamValueArray();
00041    for (long i=0,s=arg->size(); i<s; i++)
00042    {
00043       OpenWBEM::String name = (*arg)[i].getName();
00044       OpenWBEM::CIMValue value = (*arg)[i].getValue();
00045       OpenWBEM::CIMParamValue pv(name,value);
00046       cArg->append(pv);
00047    }
00048    CMPIArgs* neArg=(CMPIArgs*)new CMPI_Object(cArg,CMPI_ObjectPath_Ftab);
00049    CMSetStatus(rc,CMPI_RC_OK);
00050    return neArg;
00051 }
00052 
00053 static long locateArg(const OpenWBEM::CIMParamValueArray &a, const OpenWBEM::String &eName)
00054 {
00055    for (long i = 0, s = a.size(); i < s; i++)
00056    {
00057       const OpenWBEM::String &n = a[i].getName();
00058       if (n.compareToIgnoreCase(eName) == 0)
00059       {
00060          return i;
00061       }
00062    }
00063 
00064    return -1;
00065 }
00066 
00067 static CMPIStatus argsAddArg(CMPIArgs* eArg, const char* name,
00068              const CMPIValue* data, const CMPIType type)
00069 {
00070    OpenWBEM::CIMParamValueArray* arg = (OpenWBEM::CIMParamValueArray *)eArg->hdl;
00071    CMPIrc rc;
00072    OpenWBEM::CIMValue v = value2CIMValue(data, type, &rc);
00073    OpenWBEM::String sName(name);
00074 
00075    long i = locateArg(*arg, sName);
00076    if (i >= 0)
00077    {
00078       arg->remove(i);
00079    }
00080 
00081    arg->append(OpenWBEM::CIMParamValue(sName, v));
00082    CMReturn(CMPI_RC_OK);
00083 }
00084 
00085 static CMPIData argsGetArgAt(const CMPIArgs* eArg, CMPICount pos, CMPIString** name,
00086          CMPIStatus* rc)
00087 {
00088    OpenWBEM::CIMParamValueArray * arg=(OpenWBEM::CIMParamValueArray *)eArg->hdl;
00089    CMPIData data={(CMPIType) 0, CMPI_nullValue, {0} };
00090 
00091    if (pos > arg->size())
00092    {
00093       CMSetStatus(rc,CMPI_RC_ERR_NOT_FOUND);
00094       return data;
00095    }
00096 
00097    OpenWBEM::CIMValue v=(*arg)[pos].getValue();
00098 
00099    if (!v)
00100    {
00101       // Valid request, but the value for the named
00102       // parm is null.
00103       CMSetStatus(rc,CMPI_RC_OK);
00104       return data;
00105    }
00106    
00107    OpenWBEM::CIMDataType pType=v.getType();
00108    CMPIType t=type2CMPIType(pType,v.isArray());
00109 
00110    value2CMPIData(v,t,&data);
00111 
00112    if (name)
00113    {
00114       OpenWBEM::String n=(*arg)[pos].getName();
00115       *name=string2CMPIString(n);
00116    }
00117 
00118    CMSetStatus(rc,CMPI_RC_OK);
00119    return data;
00120 }
00121 
00122 static CMPIData argsGetArg(const CMPIArgs* eArg, const char* name, CMPIStatus* rc)
00123 {
00124    OpenWBEM::CIMParamValueArray *arg = (OpenWBEM::CIMParamValueArray *)eArg->hdl;
00125    OpenWBEM::String eName(name);
00126    long i = locateArg(*arg, eName);
00127 
00128    if (i >= 0)
00129    {
00130       return argsGetArgAt(eArg, i, NULL, rc);
00131    }
00132 
00133    CMPIData data={(CMPIType) 0, CMPI_nullValue, {0} };
00134    CMSetStatus(rc,CMPI_RC_ERR_NOT_FOUND);
00135    return data;
00136 }
00137 
00138 static CMPICount argsGetArgCount(const CMPIArgs* eArg, CMPIStatus* rc)
00139 {
00140    OpenWBEM::CIMParamValueArray * arg=(OpenWBEM::CIMParamValueArray *)eArg->hdl;
00141    CMSetStatus(rc,CMPI_RC_OK);
00142    return arg->size();
00143 }
00144 
00145 
00146 static CMPIArgsFT args_FT={
00147     CMPICurrentVersion,
00148     argsRelease,
00149     argsClone,
00150     argsAddArg,
00151     argsGetArg,
00152     argsGetArgAt,
00153     argsGetArgCount,
00154 };
00155 
00156 CMPIArgsFT *CMPI_Args_Ftab=&args_FT;
00157 
00158 static CMPIArgsFT argsOnStack_FT={
00159     CMPICurrentVersion,
00160     argsReleaseNop,
00161     argsClone,
00162     argsAddArg,
00163     argsGetArg,
00164     argsGetArgAt,
00165     argsGetArgCount,
00166 };
00167 
00168 CMPIArgsFT *CMPI_ArgsOnStack_Ftab=&argsOnStack_FT;
00169 
00170 
00171 
00172 // CMPIContext Session
00173 
00174 static CMPIStatus contextReleaseNop(CMPIContext* eCtx)
00175 {
00176    CMReturn(CMPI_RC_OK);
00177 }
00178 
00179 static CMPIData contextGetEntry(const CMPIContext* eCtx, const char* name, CMPIStatus* rc)
00180 {
00181    return argsGetArg((CMPIArgs*)eCtx,name,rc);
00182 }
00183 
00184 CMPIData contextGetEntryAt(const CMPIContext* eCtx, CMPICount pos,
00185             CMPIString** name, CMPIStatus* rc)
00186 {
00187    return argsGetArgAt((CMPIArgs*)eCtx,pos,name,rc);
00188 }
00189 
00190 static CMPICount contextGetEntryCount(const CMPIContext* eCtx, CMPIStatus* rc)
00191 {
00192    return argsGetArgCount((CMPIArgs*)eCtx,rc);
00193 }
00194 
00195 static CMPIStatus contextAddEntry(const CMPIContext* eCtx, const char* name,
00196                const CMPIValue* data, const CMPIType type)
00197 {
00198    return argsAddArg((CMPIArgs*)eCtx,name,data,type);
00199 }
00200 
00201 
00202 static CMPIContextFT context_FT={
00203     CMPICurrentVersion,
00204     contextReleaseNop,
00205     NULL,      // clone
00206     contextGetEntry,
00207     contextGetEntryAt,
00208     contextGetEntryCount,
00209     contextAddEntry,
00210 };
00211 
00212 CMPIContextFT *CMPI_Context_Ftab=&context_FT;
00213 
00214 static CMPIContextFT contextOnStack_FT={
00215     CMPICurrentVersion,
00216     contextReleaseNop,
00217     NULL,      // clone
00218     contextGetEntry,
00219     contextGetEntryAt,
00220     contextGetEntryCount,
00221     contextAddEntry,
00222 };
00223 
00224 CMPIContextFT *CMPI_ContextOnStack_Ftab=&contextOnStack_FT;
00225 
00226 
00227 CMPI_Context::CMPI_Context(const ::CMPIOperationContext& ct)
00228 {
00229    ctx=(::CMPIOperationContext*)&ct;
00230    hdl=(void*)new OpenWBEM::CIMParamValueArray();
00231    ft=CMPI_Context_Ftab;
00232 }
00233 
00234 CMPI_ContextOnStack::CMPI_ContextOnStack(const ::CMPIOperationContext& ct)
00235 {
00236    ctx=(::CMPIOperationContext*)&ct;
00237    hdl=(void*)new OpenWBEM::CIMParamValueArray();
00238    ft=CMPI_ContextOnStack_Ftab;
00239 }
00240 
00241 CMPI_ContextOnStack::~CMPI_ContextOnStack()
00242 {
00243    delete (OpenWBEM::CIMParamValueArray *)hdl;
00244 }
00245 
00246 CMPI_ArgsOnStack::CMPI_ArgsOnStack(const OpenWBEM::CIMParamValueArray& args)
00247 {
00248    hdl=(void*)&args;
00249    ft=CMPI_ArgsOnStack_Ftab;
00250 }

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