OW_NPIProviderIFCUtils.hpp

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 #ifndef OW_NPI_PROFIDER_IFC_UTILS_HPP_
00031 #define OW_NPI_PROFIDER_IFC_UTILS_HPP_
00032 #include "OW_config.h"
00033 #include "OW_CIMInstance.hpp"
00034 #include "OW_CIMParamValue.hpp"
00035 #include "OW_CIMObjectPath.hpp"
00036 #include "NPIExternal.hpp"
00037 
00038 namespace OW_NAMESPACE
00039 {
00040 
00041 class NPIVectorFreer
00042 {
00043 public:
00044    NPIVectorFreer(::Vector v) : m_vector(v)
00045    {
00046    }
00047    ~NPIVectorFreer()
00048    {
00049       int n = ::VectorSize(0,m_vector);
00050       for (int i=0; i < n; i++)
00051       {
00052          void * p = ::_VectorGet(0, m_vector, i);
00053          free (p);
00054       }
00055    }
00056 private:
00057    ::Vector m_vector;
00058 };
00059 class NPIHandleFreer
00060 {
00061 public:
00062    NPIHandleFreer(::NPIHandle& h) : m_handle(h)
00063    {
00064 //printf("Garbage array created\n");
00065    }
00066    ~NPIHandleFreer()
00067    {
00068       // delete perlcontext garbage first
00069       UInt32 sz = ((NPIContext *)(m_handle.context))->garbage.size();
00070 //printf("Garbage array size is %x\n", sz);
00071       for (int i= sz-1; i>=0; i--)
00072       {
00073            NPIGarbageType pgt =
00074           ((NPIContext *)(m_handle.context))->garbageType[i];
00075 //printf("Delete Entry %x, Type %x\n", i, pgt);
00076         void * obj_ptr = ((NPIContext *)(m_handle.context))->garbage[i];
00077         switch (pgt)
00078         {
00079           case VECTOR:
00080             delete(static_cast<charVect *>(obj_ptr));
00081             break;
00082           case CIM_VALUE:
00083             delete(static_cast<CIMValue *>(obj_ptr));
00084             break;
00085           case CIM_QUALIFIER:
00086            //delete(static_cast<CIMQualifier *>(
00087            //       ((NPIContext *)(m_handle.context))->garbage[i]) );
00088             break;
00089           case CIM_PARAMVALUE:
00090             delete(static_cast<CIMParamValue *>(obj_ptr));
00091             break;
00092           case CIM_PROPERTY:
00093             delete(static_cast<CIMProperty *>(obj_ptr));
00094             break;
00095           case CIM_INSTANCE:
00096             delete(static_cast<CIMInstance *>(obj_ptr));
00097             break;
00098           case CIM_OBJECTPATH:
00099             delete(static_cast<CIMObjectPath *>(obj_ptr));
00100             break;
00101           case CIM_CLASS:
00102             delete(static_cast<CIMClass *>(obj_ptr));
00103             break;
00104           default:
00105             break;
00106         }
00107       }
00108       ((NPIContext *)(m_handle.context))->garbage.clear();
00109       ((NPIContext *)(m_handle.context))->garbageType.clear();
00110       if (m_handle.providerError != NULL)
00111       {
00112          free(const_cast<void*>(static_cast<const void*>(m_handle.providerError)));
00113       }
00114    }
00115 private:
00116    ::NPIHandle& m_handle;
00117 };
00118 
00119 } // end namespace OW_NAMESPACE
00120 
00121 #endif

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