cmpiBrokerEnc.cpp

Go to the documentation of this file.
00001 /*
00002  *
00003  * cmpiBrokerEnc.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: CMPIBroker Encapsulated type factory support
00019  *
00020  */
00021 
00022 #include "cmpisrv.h"
00023 #include "OW_CIMException.hpp"
00024 #include "OW_CIMProperty.hpp"
00025 #include "OW_CIMObjectPath.hpp"
00026 #include "OW_ProviderEnvironmentIFC.hpp"
00027 #include "OW_Logger.hpp"
00028 
00029 namespace
00030 {
00031    const OpenWBEM::String COMPONENT_NAME("ow.provider.cmpi.ifc");
00032 }
00033 
00034 #define CM_LOGGER() \
00035 (* static_cast<OpenWBEM::ProviderEnvironmentIFCRef *>(CMPI_ThreadContext::getBroker()->hdl))->getLogger(COMPONENT_NAME)
00036 
00037 // Factory section
00038 
00039 static CMPIInstance* mbEncNewInstance(const CMPIBroker*, const CMPIObjectPath* eCop,
00040                    CMPIStatus *rc)
00041 {
00042    OW_LOG_DEBUG(CM_LOGGER(), "CMPIBrokerEnc: mbEncNewInstance()");
00043 
00044    OpenWBEM::CIMObjectPath * cop = static_cast<OpenWBEM::CIMObjectPath *>(eCop->hdl);
00045 
00046    OpenWBEM::AutoPtr<OpenWBEM::CIMClass> cls(mbGetClass(0,*cop));
00047 
00048    OpenWBEM::CIMInstance ci;
00049 
00050    if (cls.get() && *cls)
00051    {
00052       //CMPIContext *ctx=CMPI_ThreadContext::getContext();
00053       //CMPIFlags flgs = ctx->ft->getEntry(
00054       //    ctx,CMPIInvocationFlags,rc).value.uint32;
00055       ci = cls->newInstance();
00056 
00057       /* cloning without include qualifiers means
00058                 losing key properties */
00059       //ci = ci.clone(((flgs & CMPI_FLAG_LocalOnly)!=0),
00060       //              ((flgs & CMPI_FLAG_IncludeQualifiers)!=0),
00061       //              ((flgs & CMPI_FLAG_IncludeClassOrigin)!=0));
00062    }
00063    else
00064       ci.setClassName(cop->getClassName());
00065 
00066    CMPIInstance * neInst = (CMPIInstance *)new CMPI_Object(
00067                new OpenWBEM::CIMInstance(ci));
00068    CMSetStatus(rc,CMPI_RC_OK);
00069    return neInst;
00070 }
00071 
00072 static CMPIObjectPath* mbEncNewObjectPath(const CMPIBroker*, const char *ns, const char *cls,
00073               CMPIStatus *rc)
00074 {
00075    OW_LOG_DEBUG(CM_LOGGER(), "CMPIBrokerEnc: mbEncNewObjectPath()");
00076    OpenWBEM::String className(cls);
00077    OpenWBEM::String nameSpace(ns);
00078    OpenWBEM::CIMObjectPath * cop = new OpenWBEM::CIMObjectPath(className,nameSpace);
00079 
00080    CMPIObjectPath * nePath = (CMPIObjectPath*)new CMPI_Object(cop);
00081    CMSetStatus(rc,CMPI_RC_OK);
00082    return nePath;
00083 }
00084 
00085 static CMPIArgs* mbEncNewArgs(const CMPIBroker*, CMPIStatus *rc)
00086 {
00087    CMSetStatus(rc,CMPI_RC_OK);
00088    return (CMPIArgs*)new CMPI_Object(new OpenWBEM::Array<OpenWBEM::CIMParamValue>());
00089 }
00090 
00091 static CMPIString* mbEncNewString(const CMPIBroker*, const char *cStr, CMPIStatus *rc)
00092 {
00093    CMSetStatus(rc,CMPI_RC_OK);
00094    return (CMPIString*)new CMPI_Object(cStr);
00095 }
00096 
00097 CMPIString* mbIntNewString(char *s) {
00098    return mbEncNewString(NULL,s,NULL);
00099 }
00100 
00101 static CMPIArray* mbEncNewArray(const CMPIBroker*, CMPICount count, CMPIType type,
00102                         CMPIStatus *rc)
00103 {
00104    OW_LOG_DEBUG(CM_LOGGER(), "CMPIBrokerEnc: mbEncNewArray()");
00105    CMSetStatus(rc,CMPI_RC_OK);
00106    CMPIData * dta = new CMPIData[count+1];
00107    dta->type = type;
00108    dta->value.uint32 = count;
00109    for (unsigned int i=1; i<=count; i++)
00110    {
00111       dta[i].type = type;
00112       dta[i].state = CMPI_nullValue;
00113       dta[i].value.uint64 = 0;
00114    }
00115 
00116    return (CMPIArray *)new CMPI_Object(dta);
00117 }
00118 
00119 extern CMPIDateTime *newDateTime();
00120 
00121 static CMPIDateTime* mbEncNewDateTime(const CMPIBroker*, CMPIStatus *rc)
00122 {
00123    CMSetStatus(rc,CMPI_RC_OK);
00124    return newDateTime();
00125 }
00126 
00127 extern CMPIDateTime *newDateTime(CMPIUint64,CMPIBoolean);
00128 
00129 static CMPIDateTime* mbEncNewDateTimeFromBinary(const CMPIBroker*,
00130     CMPIUint64 time, CMPIBoolean interval ,CMPIStatus *rc)
00131 {
00132    CMSetStatus(rc,CMPI_RC_OK);
00133    return newDateTime(time,interval);
00134 }
00135 
00136 extern CMPIDateTime *newDateTime(const char*);
00137 
00138 static CMPIDateTime* mbEncNewDateTimeFromString(const CMPIBroker*,
00139        const char *t ,CMPIStatus *rc)
00140 {
00141    CMSetStatus(rc,CMPI_RC_OK);
00142    return newDateTime(t);
00143 }
00144 
00145 static CMPIString* mbEncToString(const CMPIBroker *, const void * o, CMPIStatus * rc)
00146 {
00147    CMPI_Object *obj = (CMPI_Object*)o;
00148    OpenWBEM::String str;
00149 
00150    if (obj == NULL)
00151    {
00152       str.format("** Null object ptr (0x%p) **", o);
00153       CMSetStatus(rc, CMPI_RC_ERR_FAILED);
00154       return (CMPIString*) new CMPI_Object(str);
00155    }
00156 
00157    if (obj->hdl == NULL)
00158    {
00159       str.format("** Null object hdl (*0x%p) **", o);
00160       CMSetStatus(rc, CMPI_RC_ERR_FAILED);
00161       return (CMPIString*) new CMPI_Object(str);
00162    }
00163 
00164    if (obj->ftab == (void*)CMPI_Instance_Ftab
00165       || obj->ftab == (void*)CMPI_InstanceOnStack_Ftab)
00166    {
00167       str.format("** Object not supported (%p) **", o);
00168       CMSetStatus(rc,CMPI_RC_ERR_FAILED);
00169       return (CMPIString*) new CMPI_Object(str);
00170    }
00171    else if (obj->ftab == (void*)CMPI_ObjectPath_Ftab
00172           || obj->ftab == (void*)CMPI_ObjectPathOnStack_Ftab)
00173    {
00174       str = ((OpenWBEM::CIMObjectPath*)obj->hdl)->toString();
00175    }
00176    else if (obj->ftab == (void*) CMPI_String_Ftab)
00177    {
00178       str = *((OpenWBEM::String*) obj->hdl);
00179    }
00180    /*
00181    else if (obj->ftab==(void*)CMPI_SelectExp_Ftab ||
00182       obj->ftab==(void*)CMPI_SelectCondDoc_Ftab ||
00183       obj->ftab==(void*)CMPI_SelectCondCod_Ftab ||
00184       obj->ftab==(void*)CMPI_SubCond_Ftab ||
00185       obj->ftab==(void*)CMPI_Predicate_Ftab)
00186    {
00187       sprintf(msg,"** Object not supported (0x%p) **",o);
00188       CMSetStatus(rc,CMPI_RC_ERR_FAILED);
00189       return (CMPIString*) new CMPI_Object(msg);
00190    }
00191    */
00192    else
00193    {
00194       str.format("** Object not recognized (0x%p) **", o);
00195       CMSetStatus(rc, CMPI_RC_ERR_FAILED);
00196       return (CMPIString*) new CMPI_Object(str);
00197    }
00198 
00199    return (CMPIString*) new CMPI_Object(str);
00200 }
00201 
00202 static CMPIBoolean mbEncClassPathIsA(const CMPIBroker *, const CMPIObjectPath *eCp,
00203                const char *type, CMPIStatus *rc)
00204 {
00205    OpenWBEM::CIMObjectPath* cop=static_cast<OpenWBEM::CIMObjectPath *>(eCp->hdl);
00206 
00207    OpenWBEM::String tcn(type);
00208 
00209    if (tcn == cop->getClassName()) return 1;
00210 
00211    OpenWBEM::AutoPtr<OpenWBEM::CIMClass> cc(mbGetClass(0,*cop));
00212    OpenWBEM::CIMObjectPath  scp(*cop);
00213    scp.setClassName(cc->getSuperClass());
00214                                                             
00215    for (; !scp.getClassName().empty(); )
00216    {
00217       cc=mbGetClass(0,scp);
00218       if (cc->getName()==tcn) return 1;
00219       scp.setClassName(cc->getSuperClass());
00220    };
00221    return 0;
00222 }
00223 
00224 CMPIBoolean mbEncIsOfType(const CMPIBroker *mb, const void *o, const char *type, CMPIStatus *rc)
00225 {
00226    CMPI_Object *obj=(CMPI_Object*)o;
00227    char msg[128];
00228    if (obj==NULL) {
00229       sprintf(msg,"** Null object ptr (%p) **",o);
00230       CMSetStatusWithChars(mb,rc,CMPI_RC_ERR_FAILED,msg);
00231       return 0;
00232    }
00233                                                             
00234    CMSetStatus(rc,CMPI_RC_OK);
00235 
00236    if (obj->ftab==(void*)CMPI_Instance_Ftab &&
00237       strcmp(type,"CMPIInstance")==0) return 1;
00238    if (obj->ftab!=(void*)CMPI_ObjectPath_Ftab &&
00239       strcmp(type,"CMPIObjectPath")==0) return 1;
00240    /* if (obj->ftab!=(void*)CMPI_SelectExp_Ftab &&
00241       strcmp(type,"CMPISelectExp")==0) return 1;
00242    if (obj->ftab!=(void*)CMPI_SelectCondDoc_Ftab &&
00243       strcmp(type,"CMPISelectCondDoc")==0) return 1;
00244    if (obj->ftab!=(void*)CMPI_SelectCondCod_Ftab &&
00245       strcmp(type,"CMPISelectCondCod")==0) return 1;
00246    if (obj->ftab!=(void*)CMPI_SubCond_Ftab &&
00247       strcmp(type,"CMPISubCond")==0) return 1;
00248    if (obj->ftab!=(void*)CMPI_Predicate_Ftab &&
00249       strcmp(type,"CMPIPredicate")==0) return 1;
00250    */
00251     if (obj->ftab!=(void*)CMPI_Array_Ftab &&
00252       strcmp(type,"CMPIArray")==0) return 1;
00253                                                             
00254    sprintf(msg,"** Object not recognized (%p) **",o);
00255    CMSetStatusWithChars(mb,rc,CMPI_RC_ERR_FAILED,msg);
00256    return 0;
00257 }
00258 
00259 
00260 static CMPIString* mbEncGetType(const CMPIBroker *mb, const void *o, CMPIStatus *rc)
00261 {
00262    CMPI_Object *obj=(CMPI_Object*)o;
00263    char msg[128];
00264    if (obj==NULL) {
00265       sprintf(msg,"** Null object ptr (%p) **",o);
00266       CMSetStatusWithChars(mb,rc,CMPI_RC_ERR_FAILED,msg);
00267       return NULL;
00268    }
00269                                                             
00270    CMSetStatus(rc,CMPI_RC_OK);
00271                                                             
00272    if (obj->ftab==(void*)CMPI_Instance_Ftab)
00273       return mb->eft->newString(mb,const_cast<char*>("CMPIInstance"),rc);
00274    if (obj->ftab!=(void*)CMPI_ObjectPath_Ftab)
00275       return mb->eft->newString(mb,const_cast<char*>("CMPIObjectPath"),rc);
00276    /* if (obj->ftab!=(void*)CMPI_SelectExp_Ftab)
00277       return mb->eft->newString(mb,"CMPISelectExp",rc);
00278    if (obj->ftab!=(void*)CMPI_SelectCondDoc_Ftab)
00279       return mb->eft->newString(mb,"CMPISelectCondDo",rc);
00280    if (obj->ftab!=(void*)CMPI_SelectCondCod_Ftab)
00281       return mb->eft->newString(mb,"CMPISelectCondCod",rc);
00282    if (obj->ftab!=(void*)CMPI_SubCond_Ftab)
00283       return mb->eft->newString(mb,"CMPISubCond",rc);
00284    if (obj->ftab!=(void*)CMPI_Predicate_Ftab)
00285       return mb->eft->newString(mb,"CMPIPredicate",rc);
00286    */
00287    if (obj->ftab!=(void*)CMPI_Array_Ftab)
00288       return mb->eft->newString(mb,const_cast<char*>("CMPIArray"),rc);
00289                                                             
00290    sprintf(msg,"** Object not recognized (%p) **",o);
00291    CMSetStatusWithChars(mb,rc,CMPI_RC_ERR_FAILED,msg);
00292    return NULL;
00293 }
00294 
00295 #if defined (CMPI_VER_85)
00296 #if 0 // need to port to OW
00297 static Formatter::Arg formatValue(va_list *argptr, CMPIStatus *rc) {
00298                                                             
00299    CMPIValue *val=va_arg(*argptr,CMPIValue*);
00300    CMPIType type=va_arg(*argptr,int);
00301    CMSetStatus(rc,CMPI_RC_OK);
00302                                                             
00303    if ((type & (CMPI_UINT|CMPI_SINT))==CMPI_UINT) {
00304     CMPIUint64 u64;
00305      switch (type) {
00306      case CMPI_uint8:  u64=(CMPIUint64)val->uint8;  break;
00307      case CMPI_uint16: u64=(CMPIUint64)val->uint16; break;
00308      case CMPI_uint32: u64=(CMPIUint64)val->uint32; break;
00309      case CMPI_uint64: u64=(CMPIUint64)val->uint64; break;
00310      }
00311      return Formatter::Arg(u64);
00312    }
00313    else if ((type & (CMPI_UINT|CMPI_SINT))==CMPI_SINT) {
00314    CMPISint64 s64;
00315     switch (type) {
00316      case CMPI_sint8:  s64=(CMPISint64)val->sint8;  break;
00317      case CMPI_sint16: s64=(CMPISint64)val->sint16; break;
00318      case CMPI_sint32: s64=(CMPISint64)val->sint32; break;
00319      case CMPI_sint64: s64=(CMPISint64)val->sint64; break;
00320      }
00321      return Formatter::Arg(s64);
00322    }
00323    else if (type==CMPI_chars) return Formatter::Arg((const char*)val);
00324    else if (type==CMPI_string)
00325      return Formatter::Arg((const char*)CMGetCharsPtr(val->string,NULL));
00326    else if (type==CMPI_real32)  return Formatter::Arg((CMPIReal64)val->real32);
00327                                                             
00328    else if (type==CMPI_real64)  return Formatter::Arg(val->real64);
00329    else if (type==CMPI_boolean) return Formatter::Arg((Boolean)val->boolean);
00330                                                             
00331    CMSetStatus(rc,CMPI_RC_ERR_INVALID_PARAMETER);
00332    return Formatter::Arg((Boolean)0);
00333 }
00334 #endif // #if 0
00335 
00336 CMPIString* mbEncGetMessage(const CMPIBroker *, const char *msgId, const char *defMsg,
00337          CMPIStatus* rc, unsigned int count, ...) {
00338 #if 0 
00339    MessageLoaderParms parms(msgId,defMsg);
00340    //cout<<"::: mbEncGetMessage() count: "<<count<<endl;
00341    if (count>0) {
00342      va_list argptr;
00343      va_start(argptr,count);
00344      for (;;) {
00345        if (count>0) parms.arg0=formatValue(&argptr,rc);
00346        else break;
00347        if (count>1) parms.arg1=formatValue(&argptr,rc);
00348        else break;
00349        if (count>2) parms.arg2=formatValue(&argptr,rc);
00350        else break;
00351        if (count>3) parms.arg3=formatValue(&argptr,rc);
00352        else break;
00353        if (count>4) parms.arg4=formatValue(&argptr,rc);
00354        else break;
00355        if (count>5) parms.arg5=formatValue(&argptr,rc);
00356        else break;
00357        if (count>6) parms.arg6=formatValue(&argptr,rc);
00358        else break;
00359        if (count>7) parms.arg7=formatValue(&argptr,rc);
00360        else break;
00361        if (count>8) parms.arg8=formatValue(&argptr,rc);
00362        else break;
00363        if (count>9) parms.arg9=formatValue(&argptr,rc);
00364        break;
00365      }
00366    }
00367    String nMsg=MessageLoader::getMessage(parms);
00368    return string2CMPIString(nMsg);
00369 #endif // #if 0
00370    return string2CMPIString(OpenWBEM::String(defMsg)); 
00371 }
00372 #endif
00373 
00374 // TODO logMessage() and trace()
00375 
00376 CMPIStatus mbEncLogMessage(const CMPIBroker* mb, int severity, 
00377                      const char* id, const char* text, 
00378                      const CMPIString* string)
00379 {
00380    // TODO
00381    CMPIStatus rc; 
00382    rc.rc = CMPI_RC_ERR_METHOD_NOT_AVAILABLE; 
00383    return rc; 
00384 }
00385 
00386 CMPIStatus mbEncTrace(const CMPIBroker* mb, int level, const char* component, 
00387                  const char* text, const CMPIString* string)
00388 {
00389    // TODO
00390    CMPIStatus rc; 
00391    rc.rc = CMPI_RC_ERR_METHOD_NOT_AVAILABLE; 
00392    return rc; 
00393 }
00394 
00395 
00396 static CMPIBrokerEncFT brokerEnc_FT={
00397 CMPICurrentVersion,
00398    mbEncNewInstance,
00399    mbEncNewObjectPath,
00400    mbEncNewArgs,
00401    mbEncNewString,
00402    mbEncNewArray,
00403    mbEncNewDateTime,
00404    mbEncNewDateTimeFromBinary,
00405    mbEncNewDateTimeFromString,
00406    NULL,
00407    mbEncClassPathIsA,
00408    mbEncToString,
00409    mbEncIsOfType,
00410    mbEncGetType,
00411 #if defined (CMPI_VER_85)
00412    mbEncGetMessage,
00413    mbEncLogMessage, 
00414    mbEncTrace
00415 #endif
00416 };
00417 
00418 CMPIBrokerEncFT *CMPI_BrokerEnc_Ftab=&brokerEnc_FT;

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