00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00036 #ifndef OW_ASSOCDB_HPP_INCLUDE_GUARD_
00037 #define OW_ASSOCDB_HPP_INCLUDE_GUARD_
00038 #include "OW_config.h"
00039 #include "OW_Types.hpp"
00040 #include "OW_Index.hpp"
00041 #include "OW_Array.hpp"
00042 #include "OW_String.hpp"
00043 #include "OW_File.hpp"
00044 #include "OW_MutexLock.hpp"
00045 #include "OW_CIMFwd.hpp"
00046 #include "OW_ServiceEnvironmentIFC.hpp"
00047 #include "OW_SortedVectorSet.hpp"
00048 #include "OW_CIMObjectPath.hpp"
00049 #include "OW_ResultHandlerIFC.hpp"
00050 #include "OW_IntrusiveReference.hpp"
00051 #include "OW_IntrusiveCountableBase.hpp"
00052
00053 namespace OW_NAMESPACE
00054 {
00055
00059 struct OW_HDB_API AssocDbEntry
00060 {
00061 AssocDbEntry(std::istream& istrm);
00062 AssocDbEntry()
00063 : m_objectName(CIMNULL)
00064 , m_offset(-1L)
00065 {}
00066
00067 AssocDbEntry(const CIMObjectPath& objectName,
00068 const CIMName& role,
00069 const CIMName& resultRole);
00070
00071 struct entry
00072 {
00073 entry ()
00074 : m_associatedObject(CIMNULL)
00075 , m_associationPath(CIMNULL)
00076 {}
00077 CIMName m_assocClass;
00078 CIMName m_resultClass;
00079 CIMObjectPath m_associatedObject;
00080 CIMObjectPath m_associationPath;
00081
00082 void writeObject(std::ostream& ostrm) const;
00083 void readObject(std::istream& istrm);
00084 };
00085
00086 void writeObject(std::ostream& ostrm) const;
00087 void readObject(std::istream& istrm);
00088 Int32 getOffset() const { return m_offset; }
00089 void setOffset(Int32 offset) { m_offset = offset; }
00090
00091 static String makeKey(const CIMObjectPath& objectName, const CIMName& role,
00092 const CIMName& resultRole);
00093
00094 String makeKey() const;
00095
00096 typedef CIMObjectPath AssocDbEntry::*safe_bool;
00097 operator safe_bool () const
00098 { return m_objectName ? &AssocDbEntry::m_objectName : 0; }
00099 bool operator!() const
00100 { return !m_objectName; }
00101
00102 #ifdef OW_WIN32
00103 #pragma warning (push)
00104 #pragma warning (disable: 4251)
00105 #endif
00106
00107 CIMObjectPath m_objectName;
00108 CIMName m_role;
00109 CIMName m_resultRole;
00110 Array<entry> m_entries;
00111 Int32 m_offset;
00112
00113 #ifdef OW_WIN32
00114 #pragma warning (pop)
00115 #endif
00116
00117 };
00118 OW_HDB_API std::ostream& operator << (std::ostream& ostrm, const AssocDbEntry& arg);
00119 typedef Array<AssocDbEntry> AssocDbEntryArray;
00120 OW_HDB_API bool operator==(const AssocDbEntry::entry& lhs, const AssocDbEntry::entry& rhs);
00122 class AssocDb;
00124 typedef ResultHandlerIFC<AssocDbEntry::entry> AssocDbEntryResultHandlerIFC;
00125 class OW_HDB_API AssocDbHandle
00126 {
00127 private:
00128 struct AssocDbHandleData : public IntrusiveCountableBase
00129 {
00130 AssocDbHandleData();
00131 AssocDbHandleData(const AssocDbHandleData& arg);
00132 AssocDbHandleData(AssocDb* pdb, const File& file);
00133 ~AssocDbHandleData();
00134 AssocDbHandleData& operator= (const AssocDbHandleData& arg);
00135 AssocDb* m_pdb;
00136 File m_file;
00137 };
00138 typedef IntrusiveReference<AssocDbHandleData> AssocDbHandleDataRef;
00139
00140 public:
00141 AssocDbHandle() : m_pdata(NULL) {}
00142 AssocDbHandle(const AssocDbHandle& arg) : m_pdata(arg.m_pdata) {}
00143 AssocDbHandle& operator= (const AssocDbHandle& arg)
00144 {
00145 m_pdata = arg.m_pdata;
00146 return *this;
00147 }
00152 bool hasAssocEntries(const String& ns, const CIMObjectPath& instanceName);
00157
00158 void addEntry(const CIMObjectPath& objectName,
00159 const CIMName& assocClassName, const CIMName& resultClass,
00160 const CIMName& role, const CIMName& resultRole,
00161 const CIMObjectPath& associatedObject,
00162 const CIMObjectPath& assocClassPath);
00170 void addEntries(const String& ns, const CIMInstance& assocInstance);
00171 void addEntries(const String& ns, const CIMClass& assocClass);
00176
00177 void deleteEntry(const CIMObjectPath& objectName,
00178 const CIMName& assocClassName, const CIMName& resultClass,
00179 const CIMName& role, const CIMName& resultRole,
00180 const CIMObjectPath& associatedObject,
00181 const CIMObjectPath& assocClassPath);
00186
00194 void deleteEntries(const String& ns, const CIMInstance& assocInstance);
00195 void deleteEntries(const String& ns, const CIMClass& assocClass);
00203
00213 void getAllEntries(const CIMObjectPath& objectName,
00214 const SortedVectorSet<CIMName>* passocClasses,
00215 const SortedVectorSet<CIMName>* presultClasses,
00216 const CIMName& role,
00217 const CIMName& resultRole,
00218 AssocDbEntryResultHandlerIFC& result);
00219 File getFile() const { return m_pdata->m_file; }
00220
00221 typedef AssocDbHandleDataRef AssocDbHandle::*safe_bool;
00222 operator safe_bool () const
00223 { return m_pdata ? &AssocDbHandle::m_pdata : 0; }
00224 bool operator!() const
00225 { return !m_pdata; }
00226 private:
00227
00228 void addOrDeleteEntries(const String& ns, const CIMInstance& assocInstance, bool add);
00229 void addOrDeleteEntries(const String& ns, const CIMClass& assocClass, bool add);
00230
00231 #ifdef OW_WIN32
00232 #pragma warning (push)
00233 #pragma warning (disable: 4251)
00234 #endif
00235
00236 AssocDbHandle(AssocDb* pdb, const File& file) :
00237 m_pdata(new AssocDbHandleData(pdb, file)) {}
00238 AssocDbHandleDataRef m_pdata;
00239 friend class AssocDb;
00240
00241 #ifdef OW_WIN32
00242 #pragma warning (pop)
00243 #endif
00244
00245 };
00246
00247
00248
00249 struct OW_HDB_API AssocDbRecHeader
00250 {
00251 AssocDbRecHeader() { memset(this, 0, sizeof(*this)); }
00252 UInt32 chkSum;
00253 Int32 nextFree;
00254 UInt32 blkSize;
00255 UInt32 flags;
00256 size_t dataSize;
00257 };
00258 #define OW_ASSOCSIGNATURE "OWASSOCIATORFI2"
00259 #define OW_ASSOCSIGLEN 16
00260
00261
00262 struct OW_HDB_API AssocDbHeader
00263 {
00264 char signature[OW_ASSOCSIGLEN];
00265 Int32 firstFree;
00266 UInt32 version;
00267 };
00268
00269 class OW_HDB_API AssocDb
00270 {
00271 public:
00272 AssocDb();
00273 ~AssocDb();
00279 void open(const String& fileName);
00280 void init(const ServiceEnvironmentIFCRef& env);
00284 void close();
00291 AssocDbHandle getHandle();
00292
00293 typedef bool AssocDb::*safe_bool;
00297 operator safe_bool () const
00298 { return m_opened ? &AssocDb::m_opened : 0; }
00299 bool operator!() const
00300 { return !m_opened; }
00304 int getHandleCount() const { return m_hdlCount; }
00308 String getFileName() const { return m_fileName; }
00309 private:
00310 AssocDbEntry findEntry(const String& objectKey,
00311 AssocDbHandle& hdl);
00312 AssocDbEntry nextEntry(AssocDbHandle& hdl);
00313 void deleteEntry(const AssocDbEntry& entry, AssocDbHandle& hdl);
00314 void deleteEntry(const CIMObjectPath& objectName,
00315 const CIMName& assocClassName, const CIMName& resultClass,
00316 const CIMName& role, const CIMName& resultRole,
00317 const CIMObjectPath& associatedObject,
00318 const CIMObjectPath& assocClassPath, AssocDbHandle& hdl);
00319 void addEntry(const AssocDbEntry& entry, AssocDbHandle& hdl);
00320 void addEntry(const CIMObjectPath& objectName,
00321 const CIMName& assocClassName, const CIMName& resultClass,
00322 const CIMName& role, const CIMName& resultRole,
00323 const CIMObjectPath& associatedObject,
00324 const CIMObjectPath& assocClassPath, AssocDbHandle& hdl);
00325 void decHandleCount();
00326 MutexLock getDbLock() { return MutexLock(m_guard); }
00327 AssocDbEntry readEntry(Int32 offset, AssocDbHandle& hdl);
00328 void addToFreeList(Int32 offset, AssocDbHandle& hdl);
00329 AssocDbRecHeader getNewBlock(Int32& offset, UInt32 blkSize,
00330 AssocDbHandle& hdl);
00331 bool createFile();
00332 void checkFile();
00333
00334 #ifdef OW_WIN32
00335 #pragma warning (push)
00336 #pragma warning (disable: 4251)
00337 #endif
00338
00339 AssocDbHeader m_hdrBlock;
00340 IndexRef m_pIndex;
00341 String m_fileName;
00342 int m_hdlCount;
00343 bool m_opened;
00344 Mutex m_guard;
00345 ServiceEnvironmentIFCRef m_env;
00346 friend class AssocDbHandle;
00347 friend struct AssocDbHandle::AssocDbHandleData;
00348
00349 #ifdef OW_WIN32
00350 #pragma warning (pop)
00351 #endif
00352
00353 };
00354
00355 }
00356
00357 #endif