OW_CMPIInstanceProviderProxy.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 * Copyright (C) 2003-2004 Vintela, Inc. All, IBM Corp. rights reserved.
00003 *
00004 * Redistribution and use in source and binary forms, with or without
00005 * modification, are permitted provided that the following conditions are met:
00006 *
00007 *  - Redistributions of source code must retain the above copyright notice,
00008 *    this list of conditions and the following disclaimer.
00009 *
00010 *  - Redistributions in binary form must reproduce the above copyright notice,
00011 *    this list of conditions and the following disclaimer in the documentation
00012 *    and/or other materials provided with the distribution.
00013 *
00014 *  - Neither the name of Vintela, Inc. nor the names of its
00015 *    contributors may be used to endorse or promote products derived from this
00016 *    software without specific prior written permission.
00017 *
00018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00019 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 * ARE DISCLAIMED. IN NO EVENT SHALL Vintela, Inc. OR THE CONTRIBUTORS
00022 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00023 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00024 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00025 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00026 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00027 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00028 * POSSIBILITY OF SUCH DAMAGE.
00029 *
00030 * Author:        Markus Mueller <sedgewick_de@yahoo.de>
00031 *
00032 *******************************************************************************/
00033 #include "OW_config.h"
00034 #include "OW_CMPIInstanceProviderProxy.hpp"
00035 #include "OW_CIMClass.hpp"
00036 #include "OW_CIMException.hpp"
00037 #include "OW_Format.hpp"
00038 #include "OW_CMPIProviderIFCUtils.hpp"
00039 #include "OW_Logger.hpp"
00040 #include "cmpisrv.h"
00041 #ifdef OW_HAVE_ALLOCA_H
00042 #include <alloca.h>
00043 #endif
00044 #include <stdlib.h> // for alloca() on FreeBSD
00045 
00046 namespace OW_NAMESPACE
00047 {
00048 
00049 // debugging
00050 #define DDD(X) // X
00051 using namespace WBEMFlags;
00052 
00053 namespace
00054 {
00055    const String COMPONENT_NAME("ow.provider.cmpi.ifc");
00056 }
00057 
00059 CMPIInstanceProviderProxy::~CMPIInstanceProviderProxy()
00060 {
00061 }
00062 
00064 void
00065 CMPIInstanceProviderProxy::enumInstanceNames(
00066    const ProviderEnvironmentIFCRef& env,
00067    const String& ns,
00068    const String& className,
00069    CIMObjectPathResultHandlerIFC& result,
00070    const CIMClass& cimClass )
00071 {
00072    OW_LOG_DEBUG(env->getLogger(COMPONENT_NAME), "CMPIInstanceProviderProxy::enumInstanceNames()");
00073 
00074    m_ftable->lastAccessTime.setToCurrent();
00075 
00076    if (m_ftable->miVector.instMI->ft->enumInstanceNames!= NULL)
00077    {
00078       CMPIStatus rc = {CMPI_RC_OK, NULL};
00079       ::CMPIOperationContext context;
00080       ProviderEnvironmentIFCRef env2(env);
00081       ::CMPI_Broker localBroker(m_ftable->broker);
00082       localBroker.hdl = static_cast<void *>(&env2);
00083       CMPI_ContextOnStack eCtx(context);
00084       CMPI_ThreadContext thr(&localBroker, &eCtx);
00085       CIMObjectPath cop(className, ns);
00086       CMPI_ObjectPathOnStack eRef(cop);
00087       CMPI_ResultOnStack eRes(result);
00088       CMPIFlags flgs=0;
00089       eCtx.ft->addEntry(&eCtx, const_cast<char*>(CMPIInvocationFlags),
00090          (CMPIValue*)&flgs,CMPI_uint32);
00091 		::CMPIInstanceMI *mi = m_ftable->miVector.instMI;
00092       rc = m_ftable->miVector.instMI->ft->enumInstanceNames(
00093          mi, &eCtx, &eRes, &eRef);
00094       if (rc.rc == CMPI_RC_OK)
00095       {
00096          return;
00097       }
00098       else
00099       {
00100          OW_THROWCIMMSG(CIMException::ErrNoType(rc.rc), rc.msg ? CMGetCharPtr(rc.msg) : "");
00101       }
00102    }
00103    else
00104    {
00105       OW_THROWCIMMSG(CIMException::FAILED, "Provider does not support enumInstanceNames");
00106    }
00107 }
00109 void
00110 CMPIInstanceProviderProxy::enumInstances(
00111    const ProviderEnvironmentIFCRef& env,
00112    const String& ns,
00113    const String& className,
00114    CIMInstanceResultHandlerIFC& result,
00115    ELocalOnlyFlag localOnly,
00116    EDeepFlag deep,
00117    EIncludeQualifiersFlag includeQualifiers,
00118    EIncludeClassOriginFlag includeClassOrigin,
00119    const StringArray* propertyList,
00120    const CIMClass& requestedClass,
00121    const CIMClass& cimClass )
00122 {
00123    OW_LOG_DEBUG(env->getLogger(COMPONENT_NAME), "CMPIInstanceProviderProxy::enumInstances()");
00124 
00125    m_ftable->lastAccessTime.setToCurrent();
00126 
00127    if (m_ftable->miVector.instMI->ft->enumInstances!= NULL)
00128    {
00129       CMPIStatus rc = {CMPI_RC_OK, NULL};
00130       const char **props = NULL;
00131       int pCount = 0;
00132       ::CMPIOperationContext context;
00133       ProviderEnvironmentIFCRef env2(env);
00134       ::CMPI_Broker localBroker(m_ftable->broker);
00135       localBroker.hdl = static_cast<void *>(&env2);
00136       CMPI_ContextOnStack eCtx(context);
00137       CMPI_ThreadContext thr(&localBroker, &eCtx);
00138       CIMObjectPath cop(className, ns);
00139       CMPI_ObjectPathOnStack eRef(cop);
00140       CMPI_ResultOnStack eRes(result);
00141 
00142       if (propertyList)
00143       {
00144          if (propertyList->size()>0)
00145          {
00146             pCount = propertyList->size();
00147             props = (const char **) alloca(1+pCount*sizeof(char *));
00148 
00149             for (int i = 0; i < pCount; i++)
00150                props[i]= (*propertyList)[i].c_str();
00151 
00152             props[pCount]=NULL;
00153          }
00154       }
00155       CMPIFlags flgs = 0;
00156 
00157       if (includeQualifiers)
00158          flgs |= CMPI_FLAG_IncludeQualifiers;
00159 
00160       if (includeClassOrigin)
00161          flgs |= CMPI_FLAG_IncludeClassOrigin;
00162 
00163       eCtx.ft->addEntry(&eCtx,const_cast<char*>(CMPIInvocationFlags), (CMPIValue*)&flgs,
00164          CMPI_uint32);
00165 
00166 		::CMPIInstanceMI *mi = m_ftable->miVector.instMI;
00167       rc = m_ftable->miVector.instMI->ft->enumInstances(
00168          mi, &eCtx, &eRes, &eRef, props);
00169 
00170       if (rc.rc != CMPI_RC_OK)
00171       {
00172          OW_THROWCIMMSG(CIMException::ErrNoType(rc.rc), rc.msg ? CMGetCharPtr(rc.msg) : "");
00173       }
00174    }
00175    else
00176    {
00177       OW_THROWCIMMSG(CIMException::FAILED, "Provider does not support enumInstances");
00178    }
00179 }
00181 CIMInstance
00182 CMPIInstanceProviderProxy::getInstance(const ProviderEnvironmentIFCRef &env,
00183    const String& ns,
00184    const CIMObjectPath& instanceName,
00185    ELocalOnlyFlag localOnly,
00186    EIncludeQualifiersFlag includeQualifiers,
00187    EIncludeClassOriginFlag includeClassOrigin,
00188    const StringArray* propertyList,
00189    const CIMClass& cimClass)
00190 {
00191    CIMInstance rval;
00192    OW_LOG_DEBUG(env->getLogger(COMPONENT_NAME), "CMPIInstanceProviderProxy::getInstance()");
00193 
00194    m_ftable->lastAccessTime.setToCurrent();
00195 
00196    if (m_ftable->miVector.instMI->ft->getInstance != NULL)
00197    {
00198       CMPIStatus rc = {CMPI_RC_OK, NULL};
00199       const char **props = NULL;
00200       int pCount = 0;
00201       ::CMPIOperationContext context;
00202       ProviderEnvironmentIFCRef env2(env);
00203       ::CMPI_Broker localBroker(m_ftable->broker);
00204       localBroker.hdl = static_cast<void *>(&env2);
00205       CMPI_ContextOnStack eCtx(context);
00206       CMPI_ThreadContext thr(&localBroker, &eCtx);
00207       CIMObjectPath copWithNS(instanceName);
00208       copWithNS.setNameSpace(ns);
00209       CMPI_ObjectPathOnStack eRef(copWithNS);
00210       //CMPI_ResultOnStack eRes(result);
00211       CMPIInstanceValueResultHandler instrh;
00212       CMPI_ResultOnStack eRes(instrh);
00213       if (propertyList)
00214       {
00215          if (propertyList->size() > 0)
00216          {
00217             pCount = propertyList->size();
00218             props = (const char **) alloca(1+pCount*sizeof(char *));
00219 
00220             for (int i = 0; i < pCount; i++)
00221                props[i] = (*propertyList)[i].c_str();
00222 
00223             props[pCount] = NULL;
00224          }
00225       }
00226       CMPIFlags flgs=0;
00227 
00228       if (includeQualifiers)
00229          flgs |= CMPI_FLAG_IncludeQualifiers;
00230 
00231       if (includeClassOrigin)
00232          flgs |= CMPI_FLAG_IncludeClassOrigin;
00233 
00234       eCtx.ft->addEntry(&eCtx,const_cast<char*>(CMPIInvocationFlags), (CMPIValue*)&flgs,
00235          CMPI_uint32);
00236 
00237 		::CMPIInstanceMI *mi = m_ftable->miVector.instMI;
00238 
00239       rc = m_ftable->miVector.instMI->ft->getInstance(
00240          mi, &eCtx, &eRes, &eRef, props);
00241 
00242       if (rc.rc == CMPI_RC_OK)
00243       {
00244          return instrh.getValue();
00245       }
00246       else
00247       {
00248          OW_THROWCIMMSG(CIMException::ErrNoType(rc.rc), rc.msg ? CMGetCharPtr(rc.msg) : "");
00249       }
00250    }
00251    else
00252    {
00253       OW_THROWCIMMSG(CIMException::FAILED, "Provider does not support getInstance");
00254    }
00255    return rval;
00256 }
00257 
00258 #ifndef OW_DISABLE_INSTANCE_MANIPULATION
00259 
00260 void
00261 CMPIInstanceProviderProxy::deleteInstance(const ProviderEnvironmentIFCRef &env,
00262    const String& ns, const CIMObjectPath& cop)
00263 {
00264    OW_LOG_DEBUG(env->getLogger(COMPONENT_NAME), "CMPIInstanceProviderProxy::deleteInstance()");
00265 
00266    m_ftable->lastAccessTime.setToCurrent();
00267 
00268    if (m_ftable->miVector.instMI->ft->deleteInstance!= NULL)
00269    {
00270       CMPIStatus rc = {CMPI_RC_OK, NULL};
00271       ::CMPIOperationContext context;
00272       ProviderEnvironmentIFCRef env2(env);
00273       ::CMPI_Broker localBroker(m_ftable->broker);
00274       localBroker.hdl = static_cast<void *>(&env2);
00275       CMPI_ContextOnStack eCtx(context);
00276       CMPI_ThreadContext thr(&localBroker, &eCtx);
00277       CIMObjectPath copWithNS(cop);
00278       copWithNS.setNameSpace(ns);
00279       CMPI_ObjectPathOnStack eRef(copWithNS);
00280       CMPI_ResultOnStack eRes;
00281       CMPIFlags flgs=0;
00282       eCtx.ft->addEntry(&eCtx,const_cast<char*>(CMPIInvocationFlags),
00283          (CMPIValue*)&flgs,CMPI_uint32);
00284 		::CMPIInstanceMI *mi = m_ftable->miVector.instMI;
00285 
00286       rc = m_ftable->miVector.instMI->ft->deleteInstance(
00287          mi, &eCtx, &eRes, &eRef);
00288 
00289       if (rc.rc != CMPI_RC_OK)
00290       {
00291          OW_THROWCIMMSG(CIMException::ErrNoType(rc.rc), rc.msg ?
00292             CMGetCharPtr(rc.msg) : "");
00293       }
00294    }
00295    else
00296    {
00297       OW_THROWCIMMSG(CIMException::FAILED, "Provider does not support deleteInstance");
00298    }
00299 }
00301 CIMObjectPath
00302    CMPIInstanceProviderProxy::createInstance(
00303    const ProviderEnvironmentIFCRef &env, const String& ns,
00304    const CIMInstance& cimInstance)
00305 {
00306    CIMObjectPath rval;
00307    OW_LOG_DEBUG(env->getLogger(COMPONENT_NAME), Format("CMPIInstanceProviderProxy::createInstance() %1", cimInstance));
00308 
00309    m_ftable->lastAccessTime.setToCurrent();
00310 
00311    if (m_ftable->miVector.instMI->ft->createInstance!= NULL)
00312    {
00313       CMPIStatus rc = {CMPI_RC_OK, NULL};
00314       ::CMPIOperationContext context;
00315       ProviderEnvironmentIFCRef env2(env);
00316       ::CMPI_Broker localBroker(m_ftable->broker);
00317       localBroker.hdl = static_cast<void *>(&env2);
00318       CMPI_ContextOnStack eCtx(context);
00319       CMPI_ThreadContext thr(&localBroker, &eCtx);
00320       CIMObjectPath cop(ns, cimInstance);
00321       CMPI_ObjectPathOnStack eRef(cop);
00322       CMPI_InstanceOnStack eInst(cimInstance);
00323       CMPIObjectPathValueResultHandler coprh;
00324       CMPI_ResultOnStack eRes(coprh);
00325       CMPIFlags flgs=0;
00326       eCtx.ft->addEntry(&eCtx,const_cast<char*>(CMPIInvocationFlags),
00327          (CMPIValue*)&flgs,CMPI_uint32);
00328 		::CMPIInstanceMI *mi = m_ftable->miVector.instMI;
00329 // Cheating
00330       rc = m_ftable->miVector.instMI->ft->createInstance(
00331          mi, &eCtx, &eRes, &eRef, &eInst);
00332       if (rc.rc == CMPI_RC_OK)
00333       {
00334          return coprh.getValue();
00335       }
00336       else
00337       {
00338          OW_THROWCIMMSG(CIMException::ErrNoType(rc.rc), rc.msg ? CMGetCharPtr(rc.msg) : "");
00339       }
00340    }
00341    else
00342    {
00343       OW_THROWCIMMSG(CIMException::FAILED, "Provider does not support createInstance");
00344    }
00345    return rval;
00346 }
00348 void
00349    CMPIInstanceProviderProxy::modifyInstance(const ProviderEnvironmentIFCRef &env,
00350    const String& ns,
00351    const CIMInstance& modifiedInstance,
00352    const CIMInstance& previousInstance,
00353    EIncludeQualifiersFlag includeQualifiers,
00354    const StringArray* propertyList,
00355    const CIMClass& theClass)
00356 {
00357    OW_LOG_DEBUG(env->getLogger(COMPONENT_NAME), "CMPIInstanceProviderProxy::modifyInstance()");
00358 
00359    m_ftable->lastAccessTime.setToCurrent();
00360 
00361    if (m_ftable->miVector.instMI->ft->modifyInstance!= NULL)
00362    {
00363       CMPIStatus rc = {CMPI_RC_OK, NULL};
00364       const char ** props = NULL;
00365       int pCount = 0;
00366       ::CMPIOperationContext context;
00367       ProviderEnvironmentIFCRef env2(env);
00368       ::CMPI_Broker localBroker(m_ftable->broker);
00369       localBroker.hdl = static_cast<void *>(&env2);
00370       CMPI_ContextOnStack eCtx(context);
00371       CMPI_ThreadContext thr(&localBroker, &eCtx);
00372       CIMObjectPath instRef(ns, previousInstance);
00373       CMPI_ObjectPathOnStack eRef(instRef);
00374       CMPI_InstanceOnStack eInst(modifiedInstance);
00375       //CMPI_ResultOnStack eRes(result);
00376       CMPI_ResultOnStack eRes;
00377       CMPIFlags flgs=0;
00378       //if (includeQualifier) flgs|=CMPI_FLAG_IncludeQualifiers;
00379       eCtx.ft->addEntry(&eCtx,const_cast<char*>(CMPIInvocationFlags),
00380          (CMPIValue*)&flgs,CMPI_uint32);
00381 		::CMPIInstanceMI *mi = m_ftable->miVector.instMI;
00382       rc = m_ftable->miVector.instMI->ft->modifyInstance(
00383          mi, &eCtx, &eRes, &eRef, &eInst, props);
00384       if (props && pCount)
00385          for (int i=0;i<pCount;i++) free((char *)props[i]);
00386       if (rc.rc == CMPI_RC_OK) return;
00387       else
00388       {
00389          OW_THROWCIMMSG(CIMException::ErrNoType(rc.rc), rc.msg ? CMGetCharPtr(rc.msg) : "");
00390       }
00391    }
00392    else
00393    {
00394       OW_THROWCIMMSG(CIMException::FAILED, "Provider does not support modifyInstance");
00395    }
00396 }
00397 #endif // #ifndef OW_DISABLE_INSTANCE_MANIPULATION
00398 
00399 } // end namespace OW_NAMESPACE
00400 

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