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.

213 lines
5.1 KiB

  1. /*++
  2. Copyright (C) 2000-2001 Microsoft Corporation
  3. --*/
  4. #ifndef __CREPOSIT__H_
  5. #define __CREPOSIT__H_
  6. #include <windows.h>
  7. #include <wbemidl.h>
  8. #include <unk.h>
  9. #include <wbemcomn.h>
  10. #include <sync.h>
  11. #include <reposit.h>
  12. #include <wmiutils.h>
  13. #include <filecach.h>
  14. #include <hiecache.h>
  15. #include <corex.h>
  16. #include "a51fib.h"
  17. #include "lock.h"
  18. extern CLock g_readWriteLock;
  19. extern bool g_bShuttingDown;
  20. /* ===================================================================================
  21. * A51_REP_FS_VERSION
  22. *
  23. * 1 - Original A51 file-based repository
  24. * 2 - All Objects stored in single file (Whistler Beta 1)
  25. * 3 - BTree added
  26. * 4 - System Class optimisation - put all system classes in __SYSTEMCLASS namespace
  27. * 5 - Change to system classes in __SYSTEMCLASS namespace - need to propagate change
  28. * to all namespaces as there may be instances of these classes.
  29. * 6 - XFiles: New page based heap. Transacted page manager sitting under new heap and
  30. * BTree. Instance indexing improved so instance queries are faster
  31. * ===================================================================================
  32. */
  33. #define A51_REP_FS_VERSION 6
  34. #define A51_CLASSDEF_FILE_PREFIX L"CD_"
  35. #define A51_CLASSRELATION_DIR_PREFIX L"CR_"
  36. #define A51_CHILDCLASS_FILE_PREFIX L"C_"
  37. #define A51_KEYROOTINST_DIR_PREFIX L"KI_"
  38. #define A51_INSTDEF_FILE_PREFIX L"I_"
  39. #define A51_CLASSINST_DIR_PREFIX L"CI_"
  40. #define A51_INSTLINK_FILE_PREFIX L"IL_"
  41. #define A51_INSTREF_DIR_PREFIX L"IR_"
  42. #define A51_REF_FILE_PREFIX L"R_"
  43. #define A51_SCOPE_DIR_PREFIX L"SC_"
  44. #define A51_SYSTEMCLASS_NS L"__SYSTEMCLASS"
  45. class CGlobals;
  46. extern CGlobals g_Glob;
  47. class CNamespaceHandle;
  48. extern CNamespaceHandle * g_pSystemClassNamespace;
  49. /*
  50. DWORD g_dwOldRepositoryVersion = 0;
  51. DWORD g_dwCurrentRepositoryVersion = 0;
  52. DWORD g_ShutDownFlags = 0;
  53. */
  54. class CForestCache;
  55. class CGlobals
  56. {
  57. private:
  58. BOOL m_bInit;
  59. CRITICAL_SECTION m_cs;
  60. _IWmiCoreServices* m_pCoreServices;
  61. CForestCache m_ForestCache;
  62. CFileCache m_FileCache;
  63. long m_lRootDirLen;
  64. WCHAR m_wszRootDir[MAX_PATH]; // keep this last: be debugger friendly
  65. public:
  66. CGlobals():m_bInit(FALSE)
  67. {
  68. InitializeCriticalSection(&m_cs);
  69. };
  70. ~CGlobals()
  71. {
  72. DeleteCriticalSection(&m_cs);
  73. };
  74. HRESULT Initialize();
  75. HRESULT Deinitialize();
  76. _IWmiCoreServices * GetCoreSvcs();
  77. CForestCache * GetForestCache();
  78. CFileCache * GetFileCache();
  79. WCHAR * GetRootDir() {return (WCHAR *)m_wszRootDir;}
  80. long GetRootDirLen() {return m_lRootDirLen;};
  81. void SetRootDirLen(long Len) { m_lRootDirLen = Len;};
  82. BOOL IsInit(){ return m_bInit; };
  83. };
  84. HRESULT DoAutoDatabaseRestore();
  85. class CNamespaceHandle;
  86. class CRepository : public CUnkBase<IWmiDbController, &IID_IWmiDbController>
  87. {
  88. private:
  89. CFlexArray m_aSystemClasses; //Used for part of the upgrade process.
  90. static DWORD m_ShutDownFlags;
  91. static HANDLE m_hShutdownEvent;
  92. static HANDLE m_hFlusherThread;
  93. static LONG m_ulReadCount;
  94. static LONG m_ulWriteCount;
  95. static HANDLE m_hWriteEvent;
  96. static HANDLE m_hReadEvent;
  97. static int m_threadState;
  98. static CCritSec m_cs;
  99. static LONG m_threadCount;
  100. enum { ThreadStateDead, ThreadStateIdle, ThreadStateFlush, ThreadStateOperationPending};
  101. protected:
  102. HRESULT Initialize();
  103. HRESULT UpgradeRepositoryFormat();
  104. HRESULT GetRepositoryDirectory();
  105. HRESULT InitializeGlobalVariables();
  106. HRESULT InitializeRepositoryVersions();
  107. static DWORD WINAPI _FlusherThread(void *);
  108. public:
  109. HRESULT STDMETHODCALLTYPE Logon(
  110. WMIDB_LOGON_TEMPLATE *pLogonParms,
  111. DWORD dwFlags,
  112. DWORD dwRequestedHandleType,
  113. IWmiDbSession **ppSession,
  114. IWmiDbHandle **ppRootNamespace
  115. );
  116. HRESULT STDMETHODCALLTYPE GetLogonTemplate(
  117. LCID lLocale,
  118. DWORD dwFlags,
  119. WMIDB_LOGON_TEMPLATE **ppLogonTemplate
  120. );
  121. HRESULT STDMETHODCALLTYPE FreeLogonTemplate(
  122. WMIDB_LOGON_TEMPLATE **ppTemplate
  123. );
  124. HRESULT STDMETHODCALLTYPE Shutdown(
  125. DWORD dwFlags
  126. );
  127. HRESULT STDMETHODCALLTYPE SetCallTimeout(
  128. DWORD dwMaxTimeout
  129. );
  130. HRESULT STDMETHODCALLTYPE SetCacheValue(
  131. DWORD dwMaxBytes
  132. );
  133. HRESULT STDMETHODCALLTYPE FlushCache(
  134. DWORD dwFlags
  135. );
  136. HRESULT STDMETHODCALLTYPE GetStatistics(
  137. DWORD dwParameter,
  138. DWORD *pdwValue
  139. );
  140. HRESULT STDMETHODCALLTYPE Backup(
  141. LPCWSTR wszBackupFile,
  142. long lFlags
  143. );
  144. HRESULT STDMETHODCALLTYPE Restore(
  145. LPCWSTR wszBackupFile,
  146. long lFlags
  147. );
  148. HRESULT STDMETHODCALLTYPE LockRepository();
  149. HRESULT STDMETHODCALLTYPE UnlockRepository();
  150. HRESULT STDMETHODCALLTYPE GetRepositoryVersions(DWORD *pdwOldVersion, DWORD *pdwCurrentVersion);
  151. static HRESULT ReadOperationNotification();
  152. static HRESULT WriteOperationNotification();
  153. static HRESULT RecoverCheckpoint();
  154. public:
  155. CRepository(CLifeControl* pControl) : TUnkBase(pControl)
  156. {
  157. }
  158. ~CRepository()
  159. {
  160. }
  161. HRESULT GetNamespaceHandle(LPCWSTR wszNamespaceName,
  162. CNamespaceHandle** ppHandle);
  163. };
  164. #endif /*__CREPOSIT__H_*/