OW_PerlAssociatorProviderProxy.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_PerlAssociatorProviderProxy.hpp"
00032 #include "NPIExternal.hpp"
00033 #include "OW_CIMException.hpp"
00034 #include "OW_Format.hpp"
00035 #include "OW_Logger.hpp"
00036 #include "OW_ResultHandlerIFC.hpp"
00037 #include "OW_NPIProviderIFCUtils.hpp"
00038 
00039 namespace OW_NAMESPACE
00040 {
00041 
00042 using namespace WBEMFlags;
00043 namespace
00044 {
00045    const String COMPONENT_NAME("ow.provider.perlnpi.ifc");
00046 }
00047 
00049 void
00050 PerlAssociatorProviderProxy::associatorNames(
00051    const ProviderEnvironmentIFCRef &env,
00052    CIMObjectPathResultHandlerIFC& result,
00053    const String& ns,
00054    const CIMObjectPath& objectName,
00055    const String& assocClass,
00056    const String& resultClass,
00057    const String& role,
00058    const String& resultRole)
00059 {
00060    OW_LOG_DEBUG(env->getLogger(COMPONENT_NAME), "PerlAssociatorProviderProxy::associatorNames()");
00061    if (m_ftable->fp_associatorNames != NULL)
00062    {
00063       ::NPIHandle _npiHandle = { 0, 0, 0, 0, m_ftable->npicontext};
00064    NPIHandleFreer nhf(_npiHandle);
00065    ProviderEnvironmentIFCRef env2(env);
00066       _npiHandle.thisObject = static_cast<void *>(&env2);
00067       //  may the arguments must be copied verbatim
00068       //  to avoid locking problems
00069       // initialize association class
00070       CIMObjectPath assocName2(assocClass);
00071       ::CIMObjectPath _assoc = { static_cast<void *> (&assocName2)};
00072       // initialize path
00073       CIMObjectPath objectNameWithNS(objectName);
00074       objectNameWithNS.setNameSpace(ns);
00075       ::CIMObjectPath _path = { static_cast<void *> (&objectNameWithNS)};
00076       ::Vector v =
00077          m_ftable->fp_associatorNames(&_npiHandle, _assoc, _path,
00078             resultClass.empty() ? 0 : resultClass.c_str(),
00079             role.empty() ? 0 : role.c_str(),
00080             resultRole.empty() ? 0 : resultRole.c_str());
00081       if (_npiHandle.errorOccurred)
00082       {
00083          OW_THROWCIMMSG(CIMException::FAILED, _npiHandle.providerError);
00084       }
00085       ::CIMObjectPath cop;
00086       for (int i=::VectorSize(&_npiHandle, v) - 1; i >= 0; i--)
00087       {
00088          cop.ptr = ::_VectorGet(&_npiHandle,v,i);
00089          CIMObjectPath ow_cop(*
00090             static_cast<CIMObjectPath *>(cop.ptr) );
00091       result.handle(ow_cop);
00092       }
00093    }
00094    else
00095    {
00096       OW_THROWCIMMSG(CIMException::FAILED, "Provider does not support associatorNames");
00097    }
00098 }
00100 void
00101 PerlAssociatorProviderProxy::associators(
00102       const ProviderEnvironmentIFCRef &env,
00103       CIMInstanceResultHandlerIFC& result,
00104       const String& ns,
00105       const CIMObjectPath& objectName,
00106       const String& assocClass,
00107       const String& resultClass,
00108       const String& role,
00109       const String& resultRole,
00110       EIncludeQualifiersFlag includeQualifiers,
00111       EIncludeClassOriginFlag includeClassOrigin,
00112       const StringArray *propertyList)
00113 {
00114    OW_LOG_DEBUG(env->getLogger(COMPONENT_NAME), "PerlAssociatorProviderProxy::associators()");
00115    if (m_ftable->fp_associators != NULL)
00116    {
00117       ::NPIHandle _npiHandle = { 0, 0, 0, 0, m_ftable->npicontext};
00118    NPIHandleFreer nhf(_npiHandle);
00119    ProviderEnvironmentIFCRef env2(env);
00120       _npiHandle.thisObject = static_cast<void *>(&env2);
00121       //  may the arguments must be copied verbatim
00122       //  to avoid locking problems
00123       // initialize association class
00124    CIMObjectPath assocName2(assocClass);
00125       ::CIMObjectPath _assoc = { static_cast<void *> (&assocName2)};
00126       // initialize path
00127    CIMObjectPath objectNameWithNS(objectName);
00128    objectNameWithNS.setNameSpace(ns);
00129       ::CIMObjectPath _path = { static_cast<void *> (&objectNameWithNS)};
00130       int _plLen = 0;
00131       std::vector<const char *> _propertyList;
00132       if (propertyList)
00133       {
00134          _plLen = propertyList->size();
00135          for (int i = 0; i < _plLen; i++)
00136             _propertyList.push_back((*propertyList)[i].allocateCString());
00137       }
00138       ::Vector v =
00139          m_ftable->fp_associators(&_npiHandle, _assoc, _path,
00140             resultClass.empty() ? 0 : resultClass.c_str(),
00141             role.empty() ? 0 : role.c_str(),
00142             resultRole.empty() ? 0 : resultRole.c_str(),
00143             includeQualifiers, includeClassOrigin,
00144             _plLen > 0 ? &_propertyList[0] : 0, _plLen);
00145       // free the strings in _propertyList
00146       for (std::vector<const char*>::iterator i = _propertyList.begin();
00147           i != _propertyList.end(); ++i)
00148       {
00149          free(const_cast<void*>(static_cast<const void*>(*i)));
00150       }
00151       if (_npiHandle.errorOccurred)
00152       {
00153          OW_THROWCIMMSG(CIMException::FAILED, _npiHandle.providerError);
00154       }
00155       int n = ::VectorSize(&_npiHandle,v);
00156       OW_LOG_DEBUG(env->getLogger(COMPONENT_NAME), Format("PerlAssociatorProviderProxy::"
00157          "associators() got %1 associator instances", n - 1));
00158       ::CIMInstance my_inst;
00159       //we need  a localOnly flag here
00160       //as local_only cannot be specified in associators calls we assume 'NO'
00161       ELocalOnlyFlag localOnly = E_NOT_LOCAL_ONLY;
00162       for (int i=0; i < n; i++)
00163       {
00164          my_inst.ptr = _VectorGet(&_npiHandle,v,i);
00165          CIMInstance ow_inst(*
00166             static_cast<CIMInstance *>(my_inst.ptr) );
00167          // result.handle(ow_inst);
00168          //
00169          // we clone our instance to set the property list & includequalifier stuff
00170          //
00171          result.handle( ow_inst.clone(localOnly,includeQualifiers,
00172             includeClassOrigin,propertyList) );
00173       }
00174    }
00175    else
00176    {
00177       OW_THROWCIMMSG(CIMException::FAILED, "Provider does not support associators");
00178    }
00179 }
00181 void
00182 PerlAssociatorProviderProxy::references(
00183       const ProviderEnvironmentIFCRef &env,
00184       CIMInstanceResultHandlerIFC& result,
00185       const String& ns,
00186       const CIMObjectPath& objectName,
00187       const String& resultClass,
00188       const String& role,
00189       EIncludeQualifiersFlag includeQualifiers,
00190       EIncludeClassOriginFlag includeClassOrigin,
00191       const StringArray *propertyList)
00192 {
00193    OW_LOG_DEBUG(env->getLogger(COMPONENT_NAME), "PerlAssociatorProviderProxy::references()");
00194    if (m_ftable->fp_references != NULL)
00195    {
00196       ::NPIHandle _npiHandle = { 0, 0, 0, 0, m_ftable->npicontext};
00197    NPIHandleFreer nhf(_npiHandle);
00198    ProviderEnvironmentIFCRef env2(env);
00199       _npiHandle.thisObject = static_cast<void *>(&env2);
00200       //  may the arguments must be copied verbatim
00201       //  to avoid locking problems
00202       // initialize association class
00203    CIMObjectPath assocName2(resultClass);
00204       ::CIMObjectPath _assoc = { static_cast<void *> (&assocName2)};
00205       // initialize path
00206    CIMObjectPath objectNameWithNS(objectName);
00207    objectNameWithNS.setNameSpace(ns);
00208       ::CIMObjectPath _path = { static_cast<void *> (&objectNameWithNS)};
00209       int _plLen = 0;
00210       std::vector<const char *> _propertyList;
00211       if (propertyList)
00212       {
00213          _plLen = propertyList->size();
00214          for (int i = 0; i < _plLen; i++)
00215             _propertyList.push_back((*propertyList)[i].allocateCString());
00216       }
00217       ::Vector v =
00218          m_ftable->fp_references(&_npiHandle, _assoc, _path,
00219             role.empty() ? 0 : role.c_str(),
00220             includeQualifiers, includeClassOrigin,
00221             _plLen > 0 ? &_propertyList[0] : 0, _plLen);
00222       // free the strings in _propertyList
00223       for (std::vector<const char*>::iterator i = _propertyList.begin();
00224           i != _propertyList.end(); ++i)
00225       {
00226          free(const_cast<void*>(static_cast<const void*>(*i)));
00227       }
00228       if (_npiHandle.errorOccurred)
00229       {
00230          OW_THROWCIMMSG(CIMException::FAILED, _npiHandle.providerError);
00231       }
00232       int n = ::VectorSize(&_npiHandle,v);
00233       OW_LOG_DEBUG(env->getLogger(COMPONENT_NAME), Format("PerlAssociatorProviderProxy::"
00234          "references() got %1 associator instances", n - 1));
00235       //we need  a localOnly flag here
00236       //as local_only cannot be specified in associators calls we assume 'NO'
00237       ELocalOnlyFlag localOnly = E_NOT_LOCAL_ONLY;
00238       ::CIMInstance my_inst;
00239       for (int i=0; i < n; i++)
00240       {
00241          my_inst.ptr = _VectorGet(&_npiHandle,v,i);
00242          CIMInstance ow_inst(*
00243             static_cast<CIMInstance *>(my_inst.ptr) );
00244          // result.handle(ow_inst);
00245          //
00246          // we clone our instance to set the property list & includequalifier stuff
00247          //
00248          result.handle( ow_inst.clone(localOnly,includeQualifiers,
00249             includeClassOrigin,propertyList) );
00250       }
00251    }
00252    else
00253    {
00254       OW_THROWCIMMSG(CIMException::FAILED, "Provider does not support references");
00255    }
00256 }
00258 void
00259 PerlAssociatorProviderProxy::referenceNames(
00260       const ProviderEnvironmentIFCRef &env,
00261       CIMObjectPathResultHandlerIFC& result,
00262       const String& ns,
00263       const CIMObjectPath& objectName,
00264       const String& resultClass,
00265       const String& role)
00266 {
00267    OW_LOG_DEBUG(env->getLogger(COMPONENT_NAME), "PerlAssociatorProviderProxy::referenceNames()");
00268    if (m_ftable->fp_referenceNames != NULL)
00269    {
00270       ::NPIHandle _npiHandle = { 0, 0, 0, 0, m_ftable->npicontext};
00271    NPIHandleFreer nhf(_npiHandle);
00272    ProviderEnvironmentIFCRef env2(env);
00273       _npiHandle.thisObject = static_cast<void *>(&env2);
00274       //  may the arguments must be copied verbatim
00275       //  to avoid locking problems
00276       // initialize association class
00277    CIMObjectPath assocName2(resultClass);
00278       ::CIMObjectPath _assoc = { static_cast<void *> (&assocName2)};
00279       // initialize path
00280    CIMObjectPath objectNameWithNS(objectName);
00281    objectNameWithNS.setNameSpace(ns);
00282       ::CIMObjectPath _path = { static_cast<void *> (&objectNameWithNS)};
00283       ::Vector v =
00284          m_ftable->fp_referenceNames(&_npiHandle, _assoc, _path,
00285                role.empty() ? 0 : role.c_str());
00286       if (_npiHandle.errorOccurred)
00287       {
00288          OW_THROWCIMMSG(CIMException::FAILED, _npiHandle.providerError);
00289       }
00290       ::CIMObjectPath my_cop;
00291       for (int i=::VectorSize(&_npiHandle, v) - 1; i >= 0; i--)
00292       {
00293          my_cop.ptr = _VectorGet(&_npiHandle,v,i);
00294          CIMObjectPath ow_cop(*
00295             static_cast<CIMObjectPath*>(my_cop.ptr) );
00296       result.handle(ow_cop);
00297       }
00298    }
00299    else
00300    {
00301       OW_THROWCIMMSG(CIMException::FAILED, "Provider does not support referenceNames");
00302    }
00303 }
00304 
00305 } // end namespace OW_NAMESPACE
00306 

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