Leaked source code of windows server 2003
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.

194 lines
6.1 KiB

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