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

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