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.

230 lines
5.6 KiB

  1. /*
  2. **++
  3. **
  4. ** Copyright (c) 2000-2001 Microsoft Corporation
  5. **
  6. **
  7. ** Module Name:
  8. **
  9. ** objects.h
  10. **
  11. **
  12. ** Abstract:
  13. **
  14. ** Test program to exercise backup and multilayer snapshots
  15. **
  16. ** Author:
  17. **
  18. ** Adi Oltean [aoltean] 02/22/2001
  19. **
  20. ** Revision History:
  21. **
  22. **--
  23. */
  24. #ifndef __ML_OBJECTS_H__
  25. #define __ML_OBJECTS_H__
  26. #if _MSC_VER > 1000
  27. #pragma once
  28. #endif
  29. ///////////////////////////////////////////////////////////////////////////////
  30. // Snapshot-related classes
  31. class CVssVolumeInfo;
  32. // Keeps the information that describes one snapshot
  33. class CVssSnapshotInfo
  34. {
  35. // Constructors& destructors
  36. private:
  37. CVssSnapshotInfo& operator = (const CVssSnapshotInfo&);
  38. CVssSnapshotInfo();
  39. CVssSnapshotInfo(const CVssSnapshotInfo&);
  40. public:
  41. CVssSnapshotInfo(
  42. IN bool bActive,
  43. IN LONG lContext,
  44. IN VSS_ID SnapshotSetId,
  45. IN VSS_PWSZ pwszDeviceName,
  46. IN VSS_PWSZ pwszVolumeName,
  47. IN CVssVolumeInfo* pVol
  48. ): m_pwszDeviceName(NULL), m_pwszVolumeName(NULL)
  49. {
  50. CVssFunctionTracer ft(VSSDBG_VSSTEST, L"CVssSnapshotInfo::CVssSnapshotInfo");
  51. try
  52. {
  53. m_bActive = bActive;
  54. m_lContext = lContext;
  55. m_SnapshotSetId = SnapshotSetId;
  56. m_pVol = pVol;
  57. ::VssSafeDuplicateStr(ft, m_pwszDeviceName, pwszDeviceName);
  58. ::VssSafeDuplicateStr(ft, m_pwszVolumeName, pwszVolumeName);
  59. }
  60. VSS_STANDARD_CATCH(ft)
  61. if (ft.HrFailed()) {
  62. ::VssFreeString(m_pwszDeviceName);
  63. ::VssFreeString(m_pwszVolumeName);
  64. }
  65. };
  66. ~CVssSnapshotInfo()
  67. {
  68. ::VssFreeString(m_pwszDeviceName);
  69. ::VssFreeString(m_pwszVolumeName);
  70. };
  71. BOOL m_bActive;
  72. LONG m_lContext;
  73. VSS_ID m_SnapshotSetId;
  74. VSS_PWSZ m_pwszDeviceName;
  75. VSS_PWSZ m_pwszVolumeName;
  76. CVssVolumeInfo* m_pVol;
  77. };
  78. // Keeps an internal map of snapshots from a snapshot set.
  79. // The key is the original volume name
  80. class CVssSnapshotSetInfo:
  81. public CVssSimpleMap< LPCWSTR, CVssSnapshotInfo* >
  82. {
  83. // Constructors& destructors
  84. private:
  85. CVssSnapshotSetInfo& operator = (const CVssSnapshotSetInfo&);
  86. CVssSnapshotSetInfo(const CVssSnapshotSetInfo&);
  87. CVssSnapshotSetInfo();
  88. public:
  89. CVssSnapshotSetInfo(
  90. IN VSS_ID SnapshotSetId
  91. ): m_SnapshotSetId(SnapshotSetId) {};
  92. ~CVssSnapshotSetInfo() {
  93. // Remove all elements
  94. for (int i = 0; i < GetSize(); i++) {
  95. CVssSnapshotInfo* pSnapInfo = GetValueAt(i);
  96. delete pSnapInfo;
  97. }
  98. // Remove all items
  99. RemoveAll();
  100. };
  101. // Attributes
  102. public:
  103. VSS_ID GetSnapshotSetID() const { return m_SnapshotSetId; };
  104. // Implementation
  105. private:
  106. VSS_ID m_SnapshotSetId;
  107. };
  108. // Keeps an internal map of snapshots from a snapshot set.
  109. // The key is the original volume name
  110. class CVssSnapshotSetCollection:
  111. public CVssSimpleMap< VSS_ID, CVssSnapshotSetInfo* >
  112. {
  113. // Constructors& destructors
  114. private:
  115. CVssSnapshotSetCollection& operator = (const CVssSnapshotSetCollection&);
  116. public:
  117. ~CVssSnapshotSetCollection() {
  118. // Remove all elements
  119. for (int i = 0; i < GetSize(); i++) {
  120. CVssSnapshotSetInfo* pSnapSetInfo = GetValueAt(i);
  121. delete pSnapSetInfo;
  122. }
  123. // Remove all items
  124. RemoveAll();
  125. }
  126. };
  127. ///////////////////////////////////////////////////////////////////////////////
  128. // Volume-related classes
  129. // Keeps the information that describes one volume
  130. class CVssVolumeInfo
  131. {
  132. // Constructors/ destructors
  133. private:
  134. CVssVolumeInfo();
  135. CVssVolumeInfo(const CVssVolumeInfo&);
  136. public:
  137. CVssVolumeInfo(
  138. IN VSS_PWSZ pwszVolumeName,
  139. IN VSS_PWSZ pwszVolumeDisplayName
  140. ): m_pwszVolumeName(NULL), m_pwszVolumeDisplayName(NULL)
  141. {
  142. CVssFunctionTracer ft(VSSDBG_VSSTEST, L"CVssVolumeInfo::CVssVolumeInfo");
  143. try
  144. {
  145. ::VssSafeDuplicateStr(ft, m_pwszVolumeName, pwszVolumeName);
  146. ::VssSafeDuplicateStr(ft, m_pwszVolumeDisplayName, pwszVolumeDisplayName);
  147. }
  148. VSS_STANDARD_CATCH(ft)
  149. if (ft.HrFailed()) {
  150. ::VssFreeString(m_pwszVolumeName);
  151. ::VssFreeString(m_pwszVolumeDisplayName);
  152. }
  153. };
  154. ~CVssVolumeInfo()
  155. {
  156. ::VssFreeString(m_pwszVolumeName);
  157. ::VssFreeString(m_pwszVolumeDisplayName);
  158. };
  159. // Attributes
  160. public:
  161. VSS_PWSZ GetVolumeName() const { return m_pwszVolumeName; };
  162. VSS_PWSZ GetVolumeDisplayName() const { return m_pwszVolumeDisplayName; };
  163. // Implementation
  164. private:
  165. VSS_PWSZ m_pwszVolumeName;
  166. VSS_PWSZ m_pwszVolumeDisplayName;
  167. };
  168. // Keeps an internal array of volume names
  169. // that does NOT remove the volume structures in the destructor
  170. class CVssVolumeMapNoRemove: public CVssSimpleMap<VSS_PWSZ, CVssVolumeInfo*>
  171. {
  172. };
  173. // Keeps an internal array of volume names
  174. // that REMOVES the volume structures in the destructor
  175. class CVssVolumeMap: public CVssSimpleMap<VSS_PWSZ, CVssVolumeInfo*>
  176. {
  177. public:
  178. ~CVssVolumeMap() {
  179. // Remove all volumes
  180. for (int i = 0; i < GetSize(); i++) {
  181. CVssVolumeInfo* pVolumeInfo = GetValueAt(i);
  182. delete pVolumeInfo;
  183. }
  184. // Remove all items
  185. RemoveAll();
  186. }
  187. };
  188. #endif // __ML_OBJECTS_H__