Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

196 lines
5.8 KiB

  1. //depot/private/wmi_branch2/admin/wmi/wbem/winmgmt/xfiles/filecach.h#8 - edit change 28793 (text)
  2. /*++
  3. Copyright (C) 2000-2001 Microsoft Corporation
  4. --*/
  5. #ifndef __WMI_A51_FILECACHE_H_
  6. #define __WMI_A51_FILECACHE_H_
  7. #include <set>
  8. #include <string>
  9. extern bool g_bShuttingDown;
  10. #include "pagemgr.h"
  11. #include "a51tools.h"
  12. #include "objheap.h"
  13. #include "index.h"
  14. class CFileCache
  15. {
  16. protected:
  17. long m_lRef;
  18. BOOL m_bInit;
  19. CPageSource m_TransactionManager;
  20. CObjectHeap m_ObjectHeap;
  21. DWORD m_dwBaseNameLen;
  22. WCHAR m_wszBaseName[MAX_PATH+1]; // be debugger friendly, live it last
  23. public:
  24. protected:
  25. public:
  26. CFileCache();
  27. ~CFileCache();
  28. private:
  29. void Clear(DWORD dwShutDownFlags)
  30. {
  31. m_ObjectHeap.Uninitialize(dwShutDownFlags);
  32. m_TransactionManager.Shutdown(dwShutDownFlags);
  33. }
  34. public:
  35. long Flush()
  36. {
  37. if (!m_bInit) return ERROR_SERVER_SHUTDOWN_IN_PROGRESS;
  38. return m_TransactionManager.Checkpoint();
  39. }
  40. long RollbackCheckpoint()
  41. {
  42. if (!m_bInit) return ERROR_SERVER_SHUTDOWN_IN_PROGRESS;
  43. return m_TransactionManager.CheckpointRollback();
  44. }
  45. long RollbackCheckpointIfNeeded()
  46. {
  47. if (!m_bInit) return ERROR_SERVER_SHUTDOWN_IN_PROGRESS;
  48. if (m_TransactionManager.GetStatus())
  49. return m_TransactionManager.CheckpointRollback();
  50. else
  51. return 0;
  52. }
  53. long Initialize(LPCWSTR wszBaseName);
  54. long Uninitialize(DWORD dwShutDownFlags);
  55. private:
  56. long InnerInitialize(LPCWSTR wszBaseName);
  57. long RepositoryExists(LPCWSTR wszBaseName);
  58. public:
  59. //Write 1 or 2 indexes pointing to the object in the object store
  60. long WriteObject(LPCWSTR wszFileName1, LPCWSTR wszFileName2, DWORD dwLen, BYTE* pBuffer)
  61. {
  62. if (!m_bInit) return ERROR_SERVER_SHUTDOWN_IN_PROGRESS;
  63. if (g_bShuttingDown) return ERROR_SERVER_SHUTDOWN_IN_PROGRESS;
  64. return m_ObjectHeap.WriteObject(wszFileName1, wszFileName2, dwLen, pBuffer);
  65. }
  66. //Writes a link and no object
  67. long WriteLink(LPCWSTR wszLinkName)
  68. {
  69. if (!m_bInit) return ERROR_SERVER_SHUTDOWN_IN_PROGRESS;
  70. if (g_bShuttingDown) return ERROR_SERVER_SHUTDOWN_IN_PROGRESS;
  71. return m_ObjectHeap.WriteLink(wszLinkName);
  72. }
  73. //Retrieve a buffer based on the index
  74. HRESULT ReadObject(LPCWSTR wszFileName, DWORD* pdwLen, BYTE** ppBuffer, bool bMustBeThere = false)
  75. {
  76. if (!m_bInit) return ERROR_SERVER_SHUTDOWN_IN_PROGRESS;
  77. if (g_bShuttingDown) return ERROR_SERVER_SHUTDOWN_IN_PROGRESS;
  78. return m_ObjectHeap.ReadObject(wszFileName, pdwLen, ppBuffer);
  79. }
  80. //Deletion of an object deletes the link also
  81. long DeleteObject(LPCWSTR wszFileName)
  82. {
  83. if (!m_bInit) return ERROR_SERVER_SHUTDOWN_IN_PROGRESS;
  84. if (g_bShuttingDown) return ERROR_SERVER_SHUTDOWN_IN_PROGRESS;
  85. return m_ObjectHeap.DeleteObject(wszFileName);
  86. }
  87. //Deletion of a link does not touch the object heap
  88. long DeleteLink(LPCWSTR wszLinkName)
  89. {
  90. if (!m_bInit) return ERROR_SERVER_SHUTDOWN_IN_PROGRESS;
  91. if (g_bShuttingDown) return ERROR_SERVER_SHUTDOWN_IN_PROGRESS;
  92. return m_ObjectHeap.DeleteLink(wszLinkName);
  93. }
  94. long BeginTransaction()
  95. {
  96. if (!m_bInit) return ERROR_SERVER_SHUTDOWN_IN_PROGRESS;
  97. if (g_bShuttingDown) return ERROR_SERVER_SHUTDOWN_IN_PROGRESS;
  98. return m_TransactionManager.BeginTrans();
  99. }
  100. long CommitTransaction()
  101. {
  102. if (!m_bInit) return ERROR_SERVER_SHUTDOWN_IN_PROGRESS;
  103. return m_TransactionManager.CommitTrans();
  104. }
  105. long AbortTransaction()
  106. {
  107. if (!m_bInit) return ERROR_SERVER_SHUTDOWN_IN_PROGRESS;
  108. long lRes = m_TransactionManager.RollbackTrans();
  109. if(lRes != ERROR_SUCCESS) return lRes;
  110. m_ObjectHeap.InvalidateCache();
  111. return ERROR_SUCCESS;
  112. }
  113. long AddRef() {return InterlockedIncrement(&m_lRef);}
  114. long Release() {long lRet = InterlockedDecrement(&m_lRef); if (!lRet) delete this;return lRet;}
  115. //Object enumeration methods that allow us to enumerate a set of objects and the
  116. //result is the heap object itself rather than just the path
  117. long ObjectEnumerationBegin(const wchar_t *wszSearchPrefix, void **ppHandle)
  118. {
  119. if (!m_bInit) return ERROR_SERVER_SHUTDOWN_IN_PROGRESS;
  120. if (g_bShuttingDown) return ERROR_SERVER_SHUTDOWN_IN_PROGRESS;
  121. return m_ObjectHeap.ObjectEnumerationBegin(wszSearchPrefix, ppHandle);
  122. }
  123. long ObjectEnumerationEnd(void *pHandle)
  124. {
  125. if (!m_bInit)return ERROR_SERVER_SHUTDOWN_IN_PROGRESS;
  126. if (g_bShuttingDown) return ERROR_SERVER_SHUTDOWN_IN_PROGRESS;
  127. return m_ObjectHeap.ObjectEnumerationEnd(pHandle);
  128. }
  129. long ObjectEnumerationNext(void *pHandle, CFileName &wszFileName, BYTE **ppBlob, DWORD *pdwSize)
  130. {
  131. if (!m_bInit) return ERROR_SERVER_SHUTDOWN_IN_PROGRESS;
  132. if (g_bShuttingDown) return ERROR_SERVER_SHUTDOWN_IN_PROGRESS;
  133. return m_ObjectHeap.ObjectEnumerationNext(pHandle, wszFileName, ppBlob, pdwSize);
  134. }
  135. long ObjectEnumerationFree(void *pHandle, BYTE *pBlob)
  136. {
  137. if (!m_bInit) return ERROR_SERVER_SHUTDOWN_IN_PROGRESS;
  138. return m_ObjectHeap.ObjectEnumerationFree(pHandle, pBlob);
  139. }
  140. //Index enumeration methods for iterating through the index
  141. long IndexEnumerationBegin(const wchar_t *wszSearchPrefix, void **ppHandle)
  142. {
  143. if (!m_bInit) return ERROR_SERVER_SHUTDOWN_IN_PROGRESS;
  144. if (g_bShuttingDown) return ERROR_SERVER_SHUTDOWN_IN_PROGRESS;
  145. return m_ObjectHeap.IndexEnumerationBegin(wszSearchPrefix, ppHandle);
  146. }
  147. long IndexEnumerationEnd(void *pHandle)
  148. {
  149. if (!m_bInit) return ERROR_SERVER_SHUTDOWN_IN_PROGRESS;
  150. if (g_bShuttingDown) return ERROR_SERVER_SHUTDOWN_IN_PROGRESS;
  151. return m_ObjectHeap.IndexEnumerationEnd(pHandle);
  152. }
  153. long IndexEnumerationNext(void *pHandle, CFileName &wszFileName)
  154. {
  155. if (!m_bInit) return ERROR_SERVER_SHUTDOWN_IN_PROGRESS;
  156. if (g_bShuttingDown) return ERROR_SERVER_SHUTDOWN_IN_PROGRESS;
  157. return m_ObjectHeap.IndexEnumerationNext(pHandle, wszFileName);
  158. }
  159. long EmptyCaches()
  160. {
  161. if (!m_bInit) return ERROR_SERVER_SHUTDOWN_IN_PROGRESS;
  162. long lRes = m_TransactionManager.EmptyCaches();
  163. if (lRes == 0)
  164. lRes = m_ObjectHeap.FlushCaches();
  165. return lRes;
  166. }
  167. };
  168. #endif