OW_NPIInstanceProviderProxy.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 * Copyright (C) 2001-2004 Vintela, Inc. All 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 #include "OW_config.h"
00031 #include "OW_FTABLERef.hpp"
00032 #include "OW_NPIInstanceProviderProxy.hpp"
00033 #include "NPIExternal.hpp"
00034 #include "OW_CIMClass.hpp"
00035 #include "OW_CIMException.hpp"
00036 #include "OW_Format.hpp"
00037 #include "OW_NPIProviderIFCUtils.hpp"
00038 #include "OW_Logger.hpp"
00039 #include "OW_ResultHandlerIFC.hpp"
00040 
00041 namespace OW_NAMESPACE
00042 {
00043 
00044 // debugging
00045 #define DDD(X) // X
00046 using namespace WBEMFlags;
00047 namespace
00048 {
00049    const String COMPONENT_NAME("ow.provider.npi.ifc");
00050 }
00051 
00053 NPIInstanceProviderProxy::~NPIInstanceProviderProxy()
00054 {
00055 }
00057 void
00058 NPIInstanceProviderProxy::enumInstanceNames(
00059       const ProviderEnvironmentIFCRef& env,
00060       const String& ns,
00061       const String& className,
00062       CIMObjectPathResultHandlerIFC& result,
00063       const CIMClass& cimClass )
00064 {
00065       OW_LOG_DEBUG(env->getLogger(COMPONENT_NAME), "NPIInstanceProviderProxy::enumInstanceNames()");
00066       if (m_ftable->fp_enumInstanceNames!= NULL)
00067       {
00068       ::NPIHandle _npiHandle = { 0, 0, 0, 0, m_ftable->npicontext};
00069          NPIHandleFreer nhf(_npiHandle);
00070          ProviderEnvironmentIFCRef env2(env);
00071          _npiHandle.thisObject = static_cast<void *>(&env2);
00072          //  may the arguments must be copied verbatim
00073          //  to avoid locking problems
00074          CIMClass cimClass2(cimClass);
00075          ::CIMClass _cc = { static_cast<void *> (&cimClass2)};
00076          CIMObjectPath cop(className, ns);
00077          ::CIMObjectPath _cop = { static_cast<void *> (&cop)};
00078          ::Vector v =
00079             m_ftable->fp_enumInstanceNames(&_npiHandle,_cop,true,_cc);
00080          if (_npiHandle.errorOccurred)
00081          {
00082             OW_THROWCIMMSG(CIMException::FAILED,
00083                _npiHandle.providerError);
00084          }
00085          ::CIMObjectPath my_cop;
00086          for (int i=0,n=VectorSize(&_npiHandle,v); i < n; i++)
00087          {
00088             my_cop.ptr = _VectorGet(&_npiHandle,v,i);
00089             CIMObjectPath ow_cop(*
00090                static_cast<CIMObjectPath *>(my_cop.ptr) );
00091             ow_cop.setClassName(cimClass.getName());
00092       result.handle(ow_cop);
00093          }
00094       }
00095       else
00096       {
00097          OW_THROWCIMMSG(CIMException::FAILED, "Provider does not support enumInstanceNames");
00098       }
00099 }
00101 void
00102 NPIInstanceProviderProxy::enumInstances(
00103    const ProviderEnvironmentIFCRef& env,
00104    const String& ns,
00105    const String& className,
00106    CIMInstanceResultHandlerIFC& result,
00107    ELocalOnlyFlag localOnly,
00108    EDeepFlag deep,
00109    EIncludeQualifiersFlag includeQualifiers,
00110    EIncludeClassOriginFlag includeClassOrigin,
00111    const StringArray* propertyList,
00112    const CIMClass& requestedClass,
00113    const CIMClass& cimClass )
00114 {
00115    OW_LOG_DEBUG(env->getLogger(COMPONENT_NAME), "NPIInstanceProviderProxy::enumInstances()");
00116    if (m_ftable->fp_enumInstances == NULL)
00117    {
00118       OW_THROWCIMMSG(CIMException::FAILED, "Provider does not support enumInstances");
00119    }
00120    ::NPIHandle _npiHandle = { 0, 0, 0, 0, m_ftable->npicontext};
00121    NPIHandleFreer nhf(_npiHandle);
00122    ProviderEnvironmentIFCRef env2(env);
00123    _npiHandle.thisObject = static_cast<void *>(&env2);
00124    //  may the arguments must be copied verbatim
00125    //  to avoid locking problems
00126    CIMClass cimClass2(cimClass);
00127    ::CIMClass _cc = { static_cast<void *> (&cimClass2)};
00128    CIMObjectPath cop(className, ns);
00129    ::CIMObjectPath _cop = { static_cast<void *> (&cop)};
00130    int de = deep;
00131    int lo = localOnly;
00132    ::Vector v =
00133    m_ftable->fp_enumInstances(&_npiHandle, _cop, de, _cc, lo);
00134    if (_npiHandle.errorOccurred)
00135    {
00136       OW_THROWCIMMSG(CIMException::FAILED,
00137       _npiHandle.providerError);
00138    }
00139    ::CIMInstance my_inst;
00140    for (int i=0,n=VectorSize(&_npiHandle,v); i < n; i++)
00141    {
00142       my_inst.ptr = _VectorGet(&_npiHandle,v,i);
00143       CIMInstance ow_inst(*
00144       static_cast<CIMInstance *>(my_inst.ptr) );
00145       ow_inst.setClassName(cimClass.getName());
00146       result.handle(ow_inst.clone(localOnly,deep,includeQualifiers,
00147          includeClassOrigin,propertyList,requestedClass,cimClass));
00148    }
00149 }
00150    
00152 CIMInstance
00153 NPIInstanceProviderProxy::getInstance(
00154    const ProviderEnvironmentIFCRef &env,
00155    const String& ns,
00156    const CIMObjectPath& instanceName,
00157    ELocalOnlyFlag localOnly,
00158    EIncludeQualifiersFlag includeQualifiers,
00159    EIncludeClassOriginFlag includeClassOrigin,
00160    const StringArray* propertyList,
00161    const CIMClass& cimClass)
00162 {
00163    CIMInstance rval(CIMNULL);
00164    OW_LOG_DEBUG(env->getLogger(COMPONENT_NAME), "NPIInstanceProviderProxy::getInstance()");
00165    if (m_ftable->fp_getInstance != NULL)
00166    {
00167       ::NPIHandle _npiHandle = { 0, 0, 0, 0, m_ftable->npicontext};
00168       NPIHandleFreer nhf(_npiHandle);
00169       ProviderEnvironmentIFCRef env2(env);
00170       _npiHandle.thisObject = static_cast<void *>(&env2);
00171       //  may the arguments must be copied verbatim
00172       //  to avoid locking problems
00173       CIMClass cimClass2(cimClass);
00174       ::CIMClass _cc = { static_cast<void *> (&cimClass2)};
00175       CIMObjectPath cop(instanceName);
00176       cop.setNameSpace(ns);
00177       ::CIMObjectPath _cop = { static_cast<void *> (&cop)};
00178       int lo = localOnly;
00179       ::CIMInstance my_inst =
00180          m_ftable->fp_getInstance(&_npiHandle, _cop, _cc, lo);
00181       if (_npiHandle.errorOccurred)
00182       {
00183          OW_THROWCIMMSG(CIMException::FAILED,
00184             _npiHandle.providerError);
00185       }
00186       CIMInstance ow_inst(*
00187          static_cast<CIMInstance *>(my_inst.ptr));
00188       ow_inst.setClassName(cimClass.getName());
00189       rval = ow_inst;
00190       rval = rval.clone(localOnly,includeQualifiers,includeClassOrigin,propertyList);
00191    }
00192    else
00193    {
00194       OW_THROWCIMMSG(CIMException::FAILED, "Provider does not support getInstance");
00195    }
00196    return rval;
00197 }
00198 #ifndef OW_DISABLE_INSTANCE_MANIPULATION
00199 
00200 CIMObjectPath
00201 NPIInstanceProviderProxy::createInstance(
00202    const ProviderEnvironmentIFCRef &env,
00203    const String& ns,
00204    const CIMInstance& cimInstance)
00205 {
00206       CIMObjectPath rval(CIMNULL);
00207       OW_LOG_DEBUG(env->getLogger(COMPONENT_NAME), "NPIInstanceProviderProxy::createInstance()");
00208       if (m_ftable->fp_createInstance != NULL)
00209       {
00210       ::NPIHandle _npiHandle = { 0, 0, 0, 0, m_ftable->npicontext};
00211          NPIHandleFreer nhf(_npiHandle);
00212          ProviderEnvironmentIFCRef env2(env);
00213          _npiHandle.thisObject = static_cast<void *>(&env2);
00214          //  may the arguments must be copied verbatim
00215          //  to avoid locking problems
00216          CIMInstance cimInstance2(cimInstance);
00217          ::CIMInstance _ci = { static_cast<void *> (&cimInstance2)};
00218          CIMObjectPath cop(ns, cimInstance);
00219          ::CIMObjectPath _cop = { static_cast<void *> (const_cast<CIMObjectPath*>(&cop))};
00220          ::CIMObjectPath _rcop =
00221             m_ftable->fp_createInstance(&_npiHandle, _cop, _ci);
00222          if (_npiHandle.errorOccurred)
00223          {
00224             OW_THROWCIMMSG(CIMException::FAILED,
00225                _npiHandle.providerError);
00226          }
00227          rval = *(static_cast<CIMObjectPath *>(_rcop.ptr) );
00228       }
00229       else
00230       {
00231          OW_THROWCIMMSG(CIMException::FAILED, "Provider does not support createInstance");
00232       }
00233       return rval;
00234 }
00236 void
00237 NPIInstanceProviderProxy::modifyInstance(
00238    const ProviderEnvironmentIFCRef &env,
00239    const String& ns,
00240    const CIMInstance& modifiedInstance,
00241    const CIMInstance& previousInstance,
00242    EIncludeQualifiersFlag includeQualifiers,
00243    const StringArray* propertyList,
00244    const CIMClass& theClass)
00245 {
00246    OW_LOG_DEBUG(env->getLogger(COMPONENT_NAME), "NPIInstanceProviderProxy::modifyInstance()");
00247    if (m_ftable->fp_setInstance != NULL)
00248    {
00249       ::NPIHandle _npiHandle = { 0, 0, 0, 0, m_ftable->npicontext};
00250       NPIHandleFreer nhf(_npiHandle);
00251       ProviderEnvironmentIFCRef env2(env);
00252       _npiHandle.thisObject = static_cast<void *>(&env2);
00253       //  may the arguments must be copied verbatim
00254       //  to avoid locking problems
00255       CIMInstance newInst(modifiedInstance.createModifiedInstance(
00256          previousInstance, includeQualifiers, propertyList, theClass));
00257       ::CIMInstance _ci = { static_cast<void *> (&newInst)};
00258       CIMObjectPath cop(ns, modifiedInstance);
00259       ::CIMObjectPath _cop = { static_cast<void *> (&cop)};
00260       m_ftable->fp_setInstance(&_npiHandle, _cop, _ci);
00261       if (_npiHandle.errorOccurred)
00262       {
00263          OW_THROWCIMMSG(CIMException::FAILED,
00264             _npiHandle.providerError);
00265       }
00266    }
00267    else
00268    {
00269       OW_THROWCIMMSG(CIMException::FAILED, "Provider does not support modifyInstance");
00270    }
00271 }
00273 void
00274 NPIInstanceProviderProxy::deleteInstance(
00275    const ProviderEnvironmentIFCRef &env,
00276    const String& ns, const CIMObjectPath& cop)
00277 {
00278    OW_LOG_DEBUG(env->getLogger(COMPONENT_NAME), "NPIInstanceProviderProxy::deleteInstance()");
00279    if (m_ftable->fp_deleteInstance!= NULL)
00280    {
00281       ::NPIHandle _npiHandle = { 0, 0, 0, 0, m_ftable->npicontext};
00282       NPIHandleFreer nhf(_npiHandle);
00283       ProviderEnvironmentIFCRef env2(env);
00284       _npiHandle.thisObject = static_cast<void *>(&env2);
00285       //  may the arguments must be copied verbatim
00286       //  to avoid locking problems
00287       CIMObjectPath copWithNS(cop);
00288       copWithNS.setNameSpace(ns);
00289       ::CIMObjectPath _cop = { static_cast<void *> (&copWithNS)};
00290       m_ftable->fp_deleteInstance(&_npiHandle, _cop);
00291       if (_npiHandle.errorOccurred)
00292       {
00293          OW_THROWCIMMSG(CIMException::FAILED,
00294             _npiHandle.providerError);
00295       }
00296    }
00297    else
00298    {
00299       OW_THROWCIMMSG(CIMException::FAILED, "Provider does not support deleteInstance");
00300    }
00301 }
00302 #endif // #ifndef OW_DISABLE_INSTANCE_MANIPULATION
00303 
00304 } // end namespace OW_NAMESPACE
00305 

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