OW_GenericHDBRepository.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 
00036 #ifndef OW_GENERICHDBREPOSITORY_HPP_INCLUDE_GUARD_
00037 #define OW_GENERICHDBREPOSITORY_HPP_INCLUDE_GUARD_
00038 #include "OW_config.h"
00039 #include "OW_Types.hpp"
00040 #include "OW_HDB.hpp"
00041 #include "OW_Array.hpp"
00042 #include "OW_MutexLock.hpp"
00043 #include "OW_CIMBase.hpp"
00044 #include "OW_ServiceEnvironmentIFC.hpp"
00045 #include "OW_Logger.hpp"
00046 
00047 namespace OW_NAMESPACE
00048 {
00049 
00050 class HDBHandleLock;
00051 class OW_HDB_API GenericHDBRepository
00052 {
00053 public:
00058    GenericHDBRepository();
00062    virtual ~GenericHDBRepository();
00068    virtual void init(const ServiceEnvironmentIFCRef& env);
00076    virtual void open(const String& path);
00080    virtual void close();
00081 #if !defined(OW_DISABLE_INSTANCE_MANIPULATION) && !defined(OW_DISABLE_NAMESPACE_MANIPULATION)
00082 
00089    virtual int createNameSpace(const String& ns);
00096    void deleteNameSpace(const String& key);
00097 #endif
00098 
00105    bool nameSpaceExists(const String& key);
00109    bool isOpen() { return m_opened; }
00110    void nodeToCIMObject(CIMBase& cimObj, const HDBNode& node);
00111    void getCIMObject(CIMBase& cimObj, const String& key,
00112       HDBHandle hdl);
00113    void updateCIMObject(const CIMBase& cimObj, HDBNode& node,
00114       HDBHandle hdl);
00115    void addCIMObject(const CIMBase& cimObj, const String& key,
00116       HDBNode& parentNode, HDBHandle hdl, UInt32 nodeFlags=0);
00117    void addCIMObject(const CIMBase& cimObj, const String& key,
00118       HDBHandle hdl, UInt32 nodeFlags=0);
00126    HDBHandle getHandle();
00133    void freeHandle(HDBHandle& hdl);
00140    HDBNode getNameSpaceNode(HDBHandleLock& hdl, String key);
00141 
00142    static const String COMPONENT_NAME;
00143 
00144 protected:
00149    void throwIfNotOpen()
00150    {
00151       if (!isOpen())
00152          OW_THROW(HDBException, "Database is not open");
00153    }
00154 
00155 #ifdef OW_WIN32
00156 #pragma warning (push)
00157 #pragma warning (disable: 4251)
00158 #endif
00159 
00160    HDB m_hdb;
00161    bool m_opened;
00162    Mutex m_guard;
00163    Array<HDBHandle> m_handles;
00164    ServiceEnvironmentIFCRef m_env;
00165    enum { MAXHANDLES = 10 };
00166    friend class HDBHandleLock;
00167 
00168 #ifdef OW_WIN32
00169 #pragma warning (pop)
00170 #endif
00171 
00172 };
00181 class OW_HDB_API HDBHandleLock
00182 {
00183 public:
00184    HDBHandleLock(GenericHDBRepository* pr, const HDBHandle& hdl) :
00185       m_pr(pr), m_hdl(hdl) {}
00186    ~HDBHandleLock()
00187    {
00188       try
00189       {
00190          if (m_pr) m_pr->freeHandle(m_hdl);
00191       }
00192       catch (...)
00193       {
00194          // don't let exceptions escape
00195       }
00196    }
00197    HDBHandle* operator->() { return &m_hdl; }
00198    HDBHandle& operator*() { return m_hdl; }
00199    HDBHandle getHandle() { return m_hdl; }
00200 private:
00201    GenericHDBRepository* m_pr;
00202    HDBHandle m_hdl;
00203 };
00204 static const UInt32 HDBNSNODE_FLAG = 0x40000000;
00205 static const UInt32 HDBCLSNODE_FLAG = 0x20000000;
00206 static const UInt32 HDBCLSASSOCNODE_FLAG = 0x08000000;
00207 
00208 } // end namespace OW_NAMESPACE
00209 
00210 #endif

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