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.

316 lines
9.6 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2000 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // CBaseClusterAction.h
  7. //
  8. // Description:
  9. // Header file for CBaseClusterAction class.
  10. //
  11. // The CBaseClusterAction class is the base class for the other
  12. // base cluster action classes. The base cluster actions are forming a
  13. // cluster, joining a cluster, upgrade support and cleanup.
  14. //
  15. // For each base cluster action, there is a class derived from this
  16. // class that performs the desired action. This class encapsulates
  17. // what is common to these actions.
  18. //
  19. // Implementation Files:
  20. // CBaseClusterAction.cpp
  21. //
  22. // Maintained By:
  23. // Vij Vasu (Vvasu) 03-MAR-2000
  24. //
  25. //////////////////////////////////////////////////////////////////////////////
  26. // Make sure that this file is included only once per compile path.
  27. #pragma once
  28. //////////////////////////////////////////////////////////////////////////
  29. // Include Files
  30. //////////////////////////////////////////////////////////////////////////
  31. // For MAX_PATH
  32. #include <windows.h>
  33. // For the CAction base class
  34. #include "CAction.h"
  35. // For the CActionList base class
  36. #include "CActionList.h"
  37. // For a few common definitions
  38. #include "CommonDefs.h"
  39. // For HINF, SetupCloseInfFile, etc.
  40. #include <setupapi.h>
  41. // For the CStr class.
  42. #include "CStr.h"
  43. //////////////////////////////////////////////////////////////////////////
  44. // Forward declarations.
  45. //////////////////////////////////////////////////////////////////////////
  46. class CBCAInterface;
  47. //////////////////////////////////////////////////////////////////////////////
  48. //++
  49. //
  50. // class CBaseClusterAction
  51. //
  52. // Description:
  53. // The CBaseClusterAction class is the base class for the other
  54. // base cluster action classes. The base cluster actions are forming a
  55. // cluster, joining a cluster, upgrade support and cleanup.
  56. //
  57. // For each base cluster action, there is a class derived from this
  58. // class that performs the desired action. This class encapsulates
  59. // what is common to these actions.
  60. //
  61. // An object of this class is intended for one time use only. That is,
  62. // after an object has been committed, it cannot be re-committed.
  63. //
  64. // This class is intended to be used as a base class only. Therefore,
  65. // its constructors and destructors are protected
  66. //
  67. //--
  68. //////////////////////////////////////////////////////////////////////////////
  69. class CBaseClusterAction : public CAction
  70. {
  71. public:
  72. //////////////////////////////////////////////////////////////////////////
  73. // Public constructors and destructors
  74. //////////////////////////////////////////////////////////////////////////
  75. // Default destructor.
  76. virtual ~CBaseClusterAction() throw();
  77. //////////////////////////////////////////////////////////////////////////
  78. // Public methods
  79. //////////////////////////////////////////////////////////////////////////
  80. //
  81. // Base class method.
  82. // Commit this action. This method has to be durable and consistent. It shoud
  83. // try as far as possible to be atomic.
  84. //
  85. void Commit();
  86. //
  87. // Base class method.
  88. // Rollback this action. Be careful about throwing exceptions from this method
  89. // as a stack unwind might be in progress when this method is called.
  90. //
  91. void Rollback();
  92. //////////////////////////////////////////////////////////////////////////
  93. // Public accessors
  94. //////////////////////////////////////////////////////////////////////////
  95. // Get the type of this action.
  96. EBaseConfigAction
  97. EbcaGetAction() const throw()
  98. {
  99. return m_ebcaAction;
  100. }
  101. // Get the cluster installation directory.
  102. const CStr &
  103. RStrGetClusterInstallDirectory() const throw()
  104. {
  105. return m_strClusterInstallDir;
  106. }
  107. // Get the localquorum directory.
  108. const CStr &
  109. RStrGetLocalQuorumDirectory() const throw()
  110. {
  111. return m_strLocalQuorumDir;
  112. }
  113. // Get the handle to the main INF file.
  114. HINF
  115. HGetMainInfFileHandle() const throw()
  116. {
  117. return m_sihMainInfFile;
  118. }
  119. // Get the name of the main INF file.
  120. const CStr &
  121. RStrGetMainInfFileName() const throw()
  122. {
  123. return m_strMainInfFileName;
  124. }
  125. // Get the handle to the SC Manager.
  126. SC_HANDLE
  127. HGetSCMHandle() const throw()
  128. {
  129. return m_sscmhSCMHandle;
  130. }
  131. // Get the interface pointer.
  132. CBCAInterface *
  133. PBcaiGetInterfacePointer() const throw()
  134. {
  135. return m_pbcaiInterface;
  136. }
  137. //////////////////////////////////////////////////////////////////////////
  138. // Public member functions
  139. //////////////////////////////////////////////////////////////////////////
  140. // Returns the number of progress messages that this action will send.
  141. UINT
  142. UiGetMaxProgressTicks() const throw()
  143. {
  144. //
  145. // The maximum progress ticks for this object comprises of:
  146. // - m_alActionList.UiGetMaxProgressTicks() => The progress ticks of
  147. // the contained action objects.
  148. return m_alActionList.UiGetMaxProgressTicks();
  149. }
  150. protected:
  151. //////////////////////////////////////////////////////////////////////////
  152. // Protected constructors and destructors
  153. //////////////////////////////////////////////////////////////////////////
  154. //
  155. // Default constructor.
  156. // Reads the location of the cluster binaries from the registry,
  157. // opens the INF file, etc.
  158. //
  159. CBaseClusterAction( CBCAInterface * pbcaiInterfaceIn );
  160. //////////////////////////////////////////////////////////////////////////
  161. // Protected accessors
  162. //////////////////////////////////////////////////////////////////////////
  163. // Set the type of action being performed by this object.
  164. void
  165. SetAction( EBaseConfigAction ebcaAction )
  166. {
  167. m_ebcaAction = ebcaAction;
  168. }
  169. // Allow derived classes to modify this action list.
  170. CActionList &
  171. RalGetActionList() throw()
  172. {
  173. return m_alActionList;
  174. }
  175. // Associate a particular directory with an id in the main INF file.
  176. void
  177. SetDirectoryId( const WCHAR * pcszDirectoryNameIn, UINT uiIdIn );
  178. private:
  179. //////////////////////////////////////////////////////////////////////////
  180. // Private types
  181. //////////////////////////////////////////////////////////////////////////
  182. // Class used to automatically release a semaphore.
  183. class CSemaphoreHandleTrait
  184. {
  185. public:
  186. //////////////////////////////////////////////////////////////////////////
  187. // Public types
  188. //////////////////////////////////////////////////////////////////////////
  189. typedef HANDLE ResourceType;
  190. //////////////////////////////////////////////////////////////////////////
  191. // Public methods
  192. //////////////////////////////////////////////////////////////////////////
  193. // A routine used to close a handle.
  194. static void CloseRoutine( ResourceType hResourceIn )
  195. {
  196. ReleaseSemaphore( hResourceIn, 1, NULL );
  197. } //*** CloseRoutine()
  198. // Get the null value for this type.
  199. static ResourceType HGetNullValue()
  200. {
  201. return NULL;
  202. } //*** HGetNullValue()
  203. }; //*** class CSemaphoreHandleTrait
  204. // A class that automatically releases a signalled semaphore.
  205. typedef CSmartResource< CSemaphoreHandleTrait > SmartSemaphoreLock;
  206. // The base class for this class.
  207. typedef CAction BaseClass;
  208. // A smart INF file handle.
  209. typedef CSmartResource<
  210. CHandleTrait<
  211. HINF
  212. , VOID
  213. , SetupCloseInfFile
  214. , INVALID_HANDLE_VALUE
  215. >
  216. >
  217. SmartInfHandle;
  218. // Smart semaphore type
  219. typedef CSmartResource< CHandleTrait< HANDLE, BOOL, CloseHandle > > SmartSemaphoreHandle;
  220. //////////////////////////////////////////////////////////////////////////
  221. // Private member functions
  222. //////////////////////////////////////////////////////////////////////////
  223. // Copy constructor
  224. CBaseClusterAction( const CBaseClusterAction & );
  225. // Assignment operator
  226. const CBaseClusterAction & operator =( const CBaseClusterAction & );
  227. //////////////////////////////////////////////////////////////////////////
  228. // Private data
  229. //////////////////////////////////////////////////////////////////////////
  230. // Pointer to the interface class.
  231. CBCAInterface * m_pbcaiInterface;
  232. // Action to be performed.
  233. EBaseConfigAction m_ebcaAction;
  234. // The list of actions to be performed by this action.
  235. CActionList m_alActionList;
  236. // The installation directory of the cluster binaries.
  237. CStr m_strClusterInstallDir;
  238. // The directory used to store the localquorum files.
  239. CStr m_strLocalQuorumDir;
  240. // Name of the main INF file.
  241. CStr m_strMainInfFileName;
  242. // A handle to the main INF file.
  243. SmartInfHandle m_sihMainInfFile;
  244. // A semaphore used to ensure that only one configuration is in progress.
  245. SmartSemaphoreHandle m_sshConfigSemaphoreHandle;
  246. // A smart handle to the Service Control Manager.
  247. SmartSCMHandle m_sscmhSCMHandle;
  248. }; //*** class CBaseClusterAction