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.

175 lines
4.2 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: npd.h
  8. //
  9. //--------------------------------------------------------------------------
  10. #ifndef NPD_H
  11. #define NPD_H
  12. #ifndef COMDBG_H
  13. #include <comdbg.h>
  14. #endif
  15. // {118B559C-6D8C-11d0-B503-00C04FD9080A}
  16. extern const GUID IID_PersistData;
  17. #if _MSC_VER < 1100
  18. class PersistData : public IUnknown, public CComObjectRoot
  19. #else
  20. class __declspec(uuid("118B559C-6D8C-11d0-B503-00C04FD9080A")) PersistData :
  21. public IUnknown, public CComObjectRoot
  22. #endif
  23. {
  24. public:
  25. BEGIN_COM_MAP(PersistData)
  26. COM_INTERFACE_ENTRY(PersistData)
  27. END_COM_MAP()
  28. DECLARE_NOT_AGGREGATABLE(PersistData)
  29. HRESULT Initialize(IStorage* pRoot, BOOL bSameAsLoad)
  30. {
  31. m_spRoot = pRoot;
  32. ASSERT(m_spRoot != NULL);
  33. if (m_spRoot == NULL)
  34. return E_INVALIDARG;
  35. m_bSameAsLoad = bSameAsLoad;
  36. if (bSameAsLoad)
  37. return Open();
  38. return Create();
  39. }
  40. HRESULT Create(IStorage* pRoot)
  41. {
  42. m_spRoot = pRoot;
  43. ASSERT(m_spRoot != NULL);
  44. if (m_spRoot == NULL)
  45. return E_INVALIDARG;
  46. m_bSameAsLoad = TRUE;
  47. return Create();
  48. }
  49. HRESULT Open(IStorage* pRoot)
  50. {
  51. m_spRoot = pRoot;
  52. ASSERT(m_spRoot != NULL);
  53. if (m_spRoot == NULL)
  54. return E_INVALIDARG;
  55. m_bSameAsLoad = TRUE;
  56. return Open();
  57. }
  58. IStorage* GetRoot()
  59. {
  60. return m_spRoot;
  61. }
  62. BOOL SameAsLoad()
  63. {
  64. return m_bSameAsLoad;
  65. }
  66. void SetSameAsLoad(BOOL bSame = TRUE)
  67. {
  68. m_bSameAsLoad = bSame;
  69. }
  70. void ClearSameAsLoad()
  71. {
  72. m_bSameAsLoad = FALSE;
  73. }
  74. IStream* GetTreeStream()
  75. {
  76. return m_spTreeStream;
  77. }
  78. IStorage* GetNodeStorage()
  79. {
  80. return m_spNodeStorage;
  81. }
  82. protected:
  83. explicit PersistData()
  84. : m_bSameAsLoad(TRUE)
  85. {
  86. }
  87. virtual ~PersistData()
  88. {
  89. }
  90. private:
  91. IStoragePtr m_spRoot;
  92. BOOL m_bSameAsLoad;
  93. IStreamPtr m_spTreeStream;
  94. IStoragePtr m_spNodeStorage;
  95. explicit PersistData(const PersistData&);
  96. // No copy.
  97. PersistData& operator=(const PersistData&);
  98. // No copy.
  99. HRESULT Create()
  100. {
  101. ASSERT(m_bSameAsLoad || (!m_bSameAsLoad && m_spRoot != NULL));
  102. if (!m_bSameAsLoad && m_spRoot == NULL)
  103. return E_INVALIDARG;
  104. // Create the stream for the tree
  105. HRESULT hr = CreateDebugStream(m_spRoot, L"tree",
  106. STGM_CREATE | STGM_SHARE_EXCLUSIVE | STGM_READWRITE, L"\\tree",
  107. &m_spTreeStream);
  108. ASSERT(SUCCEEDED(hr) && m_spTreeStream != NULL);
  109. if (FAILED(hr))
  110. return hr;
  111. // Create the storage for the nodes
  112. hr = CreateDebugStorage(m_spRoot, L"nodes",
  113. STGM_CREATE | STGM_SHARE_EXCLUSIVE | STGM_READWRITE, L"\\nodes",
  114. &m_spNodeStorage);
  115. ASSERT(SUCCEEDED(hr) && m_spNodeStorage != NULL);
  116. if (FAILED(hr))
  117. return hr;
  118. return S_OK;
  119. }
  120. HRESULT Open()
  121. {
  122. ASSERT(m_bSameAsLoad || (!m_bSameAsLoad && m_spRoot != NULL));
  123. if (!m_bSameAsLoad && m_spRoot == NULL)
  124. return E_INVALIDARG;
  125. // Open the stream for the trees persistent data.
  126. HRESULT hr = OpenDebugStream(m_spRoot, L"tree",
  127. STGM_SHARE_EXCLUSIVE | STGM_READWRITE, L"\\tree", &m_spTreeStream);
  128. ASSERT(SUCCEEDED(hr) && m_spTreeStream != NULL);
  129. if (FAILED(hr))
  130. return hr;
  131. // Open the storage for the nodes
  132. hr = OpenDebugStorage(m_spRoot, L"nodes",
  133. STGM_SHARE_EXCLUSIVE | STGM_READWRITE, L"\\nodes",
  134. &m_spNodeStorage);
  135. ASSERT(SUCCEEDED(hr) && m_spNodeStorage != NULL);
  136. if (FAILED(hr))
  137. return hr;
  138. return S_OK;
  139. }
  140. }; // class PersistData
  141. DEFINE_COM_SMARTPTR(PersistData); // PersistDataPtr
  142. #endif // NPD_H