OW_PerlInstanceProviderProxy.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_PerlInstanceProviderProxy.hpp"
00033 #include "NPIExternal.hpp"
00034 #include "OW_CIMClass.hpp"
00035 #include "OW_CIMException.hpp"
00036 #include "OW_Format.hpp"
00037 #include "OW_Logger.hpp"
00038 #include "OW_ResultHandlerIFC.hpp"
00039 #include "OW_NPIProviderIFCUtils.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.perlnpi.ifc");
00050 }
00051 
00053 PerlInstanceProviderProxy::~PerlInstanceProviderProxy()
00054 {
00055 }
00057 void
00058 PerlInstanceProviderProxy::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), "PerlInstanceProviderProxy::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       // the vector and its contents are
00081          //  deleted by the global garbage collector (npiHandle)
00082          if (_npiHandle.errorOccurred)
00083          {
00084             OW_THROWCIMMSG(CIMException::FAILED,
00085                _npiHandle.providerError);
00086          }
00087          ::CIMObjectPath my_cop;
00088          for (int i=0,n=VectorSize(&_npiHandle,v); i < n; i++)
00089          {
00090             my_cop.ptr = _VectorGet(&_npiHandle,v,i);
00091             CIMObjectPath ow_cop(*
00092                static_cast<CIMObjectPath *>(my_cop.ptr) );
00093             ow_cop.setClassName(cimClass.getName());
00094       result.handle(ow_cop);
00095          }
00096          //printf("Leaving enumInstanceNames\n");
00097       }
00098       else
00099       {
00100          OW_THROWCIMMSG(CIMException::FAILED, "Provider does not support enumInstanceNames");
00101       }
00102 }
00104 void
00105 PerlInstanceProviderProxy::enumInstances(
00106    const ProviderEnvironmentIFCRef& env,
00107    const String& ns,
00108    const String& className,
00109    CIMInstanceResultHandlerIFC& result,
00110    ELocalOnlyFlag localOnly,
00111    EDeepFlag deep,
00112    EIncludeQualifiersFlag includeQualifiers,
00113    EIncludeClassOriginFlag includeClassOrigin,
00114    const StringArray* propertyList,
00115    const CIMClass& requestedClass,
00116    const CIMClass& cimClass )
00117 {
00118    OW_LOG_DEBUG(env->getLogger(COMPONENT_NAME), "PerlInstanceProviderProxy::enumInstances()");
00119    if (m_ftable->fp_enumInstances == NULL)
00120    {
00121       OW_THROWCIMMSG(CIMException::FAILED, "Provider does not support enumInstances");
00122    }
00123    ::NPIHandle _npiHandle = { 0, 0, 0, 0, m_ftable->npicontext};
00124    NPIHandleFreer nhf(_npiHandle);
00125    ProviderEnvironmentIFCRef env2(env);
00126    _npiHandle.thisObject = static_cast<void *>(&env2);
00127    //  may the arguments must be copied verbatim
00128    //  to avoid locking problems
00129    CIMClass cimClass2(cimClass);
00130    ::CIMClass _cc = { static_cast<void *> (&cimClass2)};
00131    CIMObjectPath cop(className, ns);
00132    ::CIMObjectPath _cop = { static_cast<void *> (&cop)};
00133    int de = deep;
00134    int lo = localOnly;
00135    ::Vector v =
00136    m_ftable->fp_enumInstances(&_npiHandle, _cop, de, _cc, lo);
00137    //NPIVectorFreer vf1(v);
00138    if (_npiHandle.errorOccurred)
00139    {
00140       OW_THROWCIMMSG(CIMException::FAILED,
00141       _npiHandle.providerError);
00142    }
00143    ::CIMInstance my_inst;
00144    for (int i=0,n=VectorSize(&_npiHandle,v); i < n; i++)
00145    {
00146       my_inst.ptr = _VectorGet(&_npiHandle,v,i);
00147       CIMInstance ow_inst(*
00148       static_cast<CIMInstance *>(my_inst.ptr) );
00149 // FIXME
00150       ow_inst.setClassName(cimClass.getName());
00151       result.handle(ow_inst.clone(localOnly,deep,includeQualifiers,
00152          includeClassOrigin,propertyList,requestedClass,cimClass));
00153    }
00154 }
00155    
00157 CIMInstance
00158 PerlInstanceProviderProxy::getInstance(const ProviderEnvironmentIFCRef &env,
00159    const String& ns,
00160    const CIMObjectPath& instanceName,
00161    ELocalOnlyFlag localOnly,
00162    EIncludeQualifiersFlag includeQualifiers,
00163    EIncludeClassOriginFlag includeClassOrigin,
00164    const StringArray* propertyList,
00165    const CIMClass& cimClass)
00166 {
00167       CIMInstance rval;
00168       OW_LOG_DEBUG(env->getLogger(COMPONENT_NAME), "PerlInstanceProviderProxy::getInstance()");
00169       if (m_ftable->fp_getInstance != NULL)
00170       {
00171       ::NPIHandle _npiHandle = { 0, 0, 0, 0, m_ftable->npicontext};
00172          NPIHandleFreer nhf(_npiHandle);
00173          ProviderEnvironmentIFCRef env2(env);
00174          _npiHandle.thisObject = static_cast<void *>(&env2);
00175          //  may the arguments must be copied verbatim
00176          //  to avoid locking problems
00177          CIMClass cimClass2(cimClass);
00178          ::CIMClass _cc = { static_cast<void *> (&cimClass2)};
00179          CIMObjectPath cop(instanceName);
00180          cop.setNameSpace(ns);
00181          ::CIMObjectPath _cop = { static_cast<void *> (&cop)};
00182          int lo = localOnly;
00183          ::CIMInstance my_inst =
00184             m_ftable->fp_getInstance(&_npiHandle, _cop, _cc, lo);
00185          if (_npiHandle.errorOccurred)
00186          {
00187             OW_THROWCIMMSG(CIMException::FAILED,
00188                _npiHandle.providerError);
00189          }
00190          CIMInstance ow_inst(*
00191             static_cast<CIMInstance *>(my_inst.ptr));
00192 // FIXME:
00193          ow_inst.setClassName(cimClass.getName());
00194          rval = ow_inst;
00195          rval = rval.clone(localOnly,includeQualifiers,includeClassOrigin,propertyList);
00196       }
00197       else
00198       {
00199          OW_THROWCIMMSG(CIMException::FAILED, "Provider does not support getInstance");
00200       }
00201       return rval;
00202 }
00203 #ifndef OW_DISABLE_INSTANCE_MANIPULATION
00204 
00205 CIMObjectPath
00206 PerlInstanceProviderProxy::createInstance(
00207    const ProviderEnvironmentIFCRef &env, const String& ns,
00208    const CIMInstance& cimInstance)
00209 {
00210       CIMObjectPath rval;
00211       OW_LOG_DEBUG(env->getLogger(COMPONENT_NAME), "PerlInstanceProviderProxy::createInstance()");
00212       if (m_ftable->fp_createInstance != NULL)
00213       {
00214       ::NPIHandle _npiHandle = { 0, 0, 0, 0, m_ftable->npicontext};
00215          NPIHandleFreer nhf(_npiHandle);
00216          ProviderEnvironmentIFCRef env2(env);
00217          _npiHandle.thisObject = static_cast<void *>(&env2);
00218          //  may the arguments must be copied verbatim
00219          //  to avoid locking problems
00220          CIMInstance cimInstance2(cimInstance);
00221          ::CIMInstance _ci = { static_cast<void *> (&cimInstance2)};
00222          CIMObjectPath cop(ns, cimInstance);
00223          ::CIMObjectPath _cop = { static_cast<void *> (const_cast<CIMObjectPath*>(&cop))};
00224          ::CIMObjectPath _rcop =
00225             m_ftable->fp_createInstance(&_npiHandle, _cop, _ci);
00226          if (_npiHandle.errorOccurred)
00227          {
00228             OW_THROWCIMMSG(CIMException::FAILED,
00229                _npiHandle.providerError);
00230          }
00231          rval = *(static_cast<CIMObjectPath *>(_rcop.ptr) );
00232       }
00233       else
00234       {
00235          OW_THROWCIMMSG(CIMException::FAILED, "Provider does not support createInstance");
00236       }
00237       return rval;
00238 }
00240 void
00241 PerlInstanceProviderProxy::modifyInstance(const ProviderEnvironmentIFCRef &env,
00242    const String& ns,
00243    const CIMInstance& modifiedInstance,
00244    const CIMInstance& previousInstance,
00245    EIncludeQualifiersFlag includeQualifiers,
00246    const StringArray* propertyList,
00247    const CIMClass& theClass)
00248 {
00249    OW_LOG_DEBUG(env->getLogger(COMPONENT_NAME), "PerlInstanceProviderProxy::modifyInstance()");
00250    if (m_ftable->fp_setInstance != NULL)
00251    {
00252          ::NPIHandle _npiHandle = { 0, 0, 0, 0, m_ftable->npicontext};
00253       NPIHandleFreer nhf(_npiHandle);
00254       ProviderEnvironmentIFCRef env2(env);
00255       _npiHandle.thisObject = static_cast<void *>(&env2);
00256       //  may the arguments must be copied verbatim
00257       //  to avoid locking problems
00258       CIMInstance newInst(modifiedInstance.createModifiedInstance(
00259          previousInstance, includeQualifiers, propertyList, theClass));
00260       ::CIMInstance _ci = { static_cast<void *> (&newInst)};
00261       CIMObjectPath cop(ns, modifiedInstance);
00262       ::CIMObjectPath _cop = { static_cast<void *> (&cop)};
00263       m_ftable->fp_setInstance(&_npiHandle, _cop, _ci);
00264       if (_npiHandle.errorOccurred)
00265       {
00266          OW_THROWCIMMSG(CIMException::FAILED,
00267             _npiHandle.providerError);
00268       }
00269    }
00270    else
00271    {
00272       OW_THROWCIMMSG(CIMException::FAILED, "Provider does not support modifyInstance");
00273    }
00274 }
00276 void
00277 PerlInstanceProviderProxy::deleteInstance(const ProviderEnvironmentIFCRef &env,
00278    const String& ns, const CIMObjectPath& cop)
00279 {
00280    OW_LOG_DEBUG(env->getLogger(COMPONENT_NAME), "PerlInstanceProviderProxy::deleteInstance()");
00281    if (m_ftable->fp_deleteInstance!= NULL)
00282    {
00283       ::NPIHandle _npiHandle = { 0, 0, 0, 0, m_ftable->npicontext};
00284       NPIHandleFreer nhf(_npiHandle);
00285       ProviderEnvironmentIFCRef env2(env);
00286       _npiHandle.thisObject = static_cast<void *>(&env2);
00287       //  may the arguments must be copied verbatim
00288       //  to avoid locking problems
00289       CIMObjectPath copWithNS(cop);
00290       copWithNS.setNameSpace(ns);
00291       ::CIMObjectPath _cop = { static_cast<void *> (&copWithNS)};
00292       m_ftable->fp_deleteInstance(&_npiHandle, _cop);
00293       if (_npiHandle.errorOccurred)
00294       {
00295          OW_THROWCIMMSG(CIMException::FAILED,
00296             _npiHandle.providerError);
00297       }
00298    }
00299    else
00300    {
00301       OW_THROWCIMMSG(CIMException::FAILED, "Provider does not support deleteInstance");
00302    }
00303 }
00304 #endif // #ifndef OW_DISABLE_INSTANCE_MANIPULATION
00305 
00306 } // end namespace OW_NAMESPACE
00307 

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