OW_AssocDb2.hpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 * Copyright (C) 2001 Center 7, 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 Center 7 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 Center 7, 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_ASSOCDB2_HPP_INCLUDE_GUARD_
00031 #define OW_ASSOCDB2_HPP_INCLUDE_GUARD_
00032 #include "OW_config.h"
00033 #include "OW_Types.hpp"
00034 #include "OW_Array.hpp"
00035 #include "OW_String.hpp"
00036 #include "OW_File.hpp"
00037 #include "OW_MutexLock.hpp"
00038 #include "OW_CIMFwd.hpp"
00039 #include "OW_ServiceEnvironmentIFC.hpp"
00040 #include "OW_SortedVectorSet.hpp"
00041 #include "OW_CIMObjectPath.hpp"
00042 #include "OW_ResultHandlerIFC.hpp"
00043 #include "OW_dbDatabase.hpp"
00044 
00045 #include <db.h>
00046 
00047 namespace OW_NAMESPACE
00048 {
00049 
00053 class AssocDbEntry2
00054 {
00055 public:
00056    AssocDbEntry2(std::istream& istrm);
00057    AssocDbEntry2()
00058       : m_objectName(CIMNULL)
00059       , m_offset(-1L)
00060    {}
00061    AssocDbEntry2(const CIMObjectPath& objectName,
00062       const String& role,
00063       const String& resultRole);
00064    struct entry
00065    {
00066       entry ()
00067          : m_associatedObject(CIMNULL)
00068          , m_associationPath(CIMNULL)
00069       {}
00070       String m_assocClass;
00071       String m_resultClass;
00072       CIMObjectPath m_associatedObject; // value for associtor(Name)s
00073       CIMObjectPath m_associationPath;  // value for reference(Name)s
00074       
00075       void writeObject(std::ostream& ostrm) const;
00076       void readObject(std::istream& istrm);
00077    };
00078    void writeObject(std::ostream& ostrm) const;
00079    void readObject(std::istream& istrm);
00080    Int32 getOffset() const { return m_offset; }
00081    void setOffset(Int32 offset) { m_offset = offset; }
00082    static String makeKey(const CIMObjectPath& objectName, const String& role,
00083       const String& resultRole);
00084    
00085    String makeKey() const;
00086 private:
00087    struct dummy
00088    {
00089       void nonnull() {};
00090    };
00091    typedef void (dummy::*safe_bool)();
00092 public:
00093    operator safe_bool () const
00094       {  return (m_objectName) ? &dummy::nonnull : 0; }
00095    safe_bool operator!() const
00096       {  return (m_objectName) ? 0: &dummy::nonnull; }
00097 public:
00098    CIMObjectPath m_objectName; // part 1 of key
00099    String m_role; // part 2 of key
00100    String m_resultRole; // part 3 of key
00101    Array<entry> m_entries;
00102    Int32 m_offset;
00103 };
00104 std::ostream& operator << (std::ostream& ostrm, const AssocDbEntry2& arg);
00105 typedef Array<AssocDbEntry2> AssocDbEntry2Array;
00106 bool operator==(const AssocDbEntry2::entry& lhs, const AssocDbEntry2::entry& rhs);
00108 class AssocDb2;
00110 typedef ResultHandlerIFC<AssocDbEntry2::entry> AssocDbEntry2ResultHandlerIFC;
00111    
00112 class AssocDb2
00113 {
00114 public:
00118    AssocDb2(ServiceEnvironmentIFCRef env);
00122    ~AssocDb2();
00126    void open(const String& fileName, ::DB_ENV* env, ::DB_TXN* txn);
00130    void close();
00138    bool hasAssocEntries(const String& ns, const CIMObjectPath& instanceName);
00143    void addEntry(const CIMObjectPath& objectName,
00144       const String& assocClassName, const String& resultClass,
00145       const String& role, const String& resultRole,
00146       const CIMObjectPath& associatedObject,
00147       const CIMObjectPath& assocClassPath);
00155    void addEntries(const String& ns, const CIMInstance& assocInstance);
00156    void addEntries(const String& ns, const CIMClass& assocClass);
00161    void deleteEntry(const CIMObjectPath& objectName,
00162       const String& assocClassName, const String& resultClass,
00163       const String& role, const String& resultRole,
00164       const CIMObjectPath& associatedObject,
00165       const CIMObjectPath& assocClassPath);
00173    void deleteEntries(const String& ns, const CIMInstance& assocInstance);
00174    void deleteEntries(const String& ns, const CIMClass& assocClass);
00184    void getAllEntries(const CIMObjectPath& objectName,
00185       const SortedVectorSet<String>* passocClasses,
00186       const SortedVectorSet<String>* presultClasses,
00187       const String& role,
00188       const String& resultRole,
00189       AssocDbEntry2ResultHandlerIFC& result);
00190 private:
00191    AssocDbEntry2 findEntry(const String& objectKey);
00192    void deleteEntry(const AssocDbEntry2& entry);
00193    void addEntry(const AssocDbEntry2& entry);
00194    void addOrDeleteEntries(const String& ns, const CIMInstance& assocInstance, bool add);
00195    void addOrDeleteEntries(const String& ns, const CIMClass& assocClass, bool add);
00196    ServiceEnvironmentIFCRef m_env;
00197    dbDatabase m_db;
00198 };
00199 
00200 } // end namespace OW_NAMESPACE
00201 
00202 #endif

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