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.

325 lines
11 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2000-2001 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // CStatusReport.h
  7. //
  8. // Description:
  9. // Header file for CStatusReport class.
  10. //
  11. // CStatusReport is a class the provides the functionality sending a
  12. // status report.
  13. //
  14. // Implementation File:
  15. // CStatusReport.cpp
  16. //
  17. // Maintained By:
  18. // David Potter (DavidP) 30-MAR-2001
  19. // Vij Vasu (Vvasu) 05-JUN-2000
  20. //
  21. //////////////////////////////////////////////////////////////////////////////
  22. // Make sure that this file is included only once per compile path.
  23. #pragma once
  24. //////////////////////////////////////////////////////////////////////////////
  25. // Include files
  26. //////////////////////////////////////////////////////////////////////////////
  27. // A few common declarations
  28. #include "CommonDefs.h"
  29. // For the exceptions thrown by this class.
  30. #include "Exceptions.h"
  31. // For the CBCAInterface class
  32. #include "CBCAInterface.h"
  33. //////////////////////////////////////////////////////////////////////////////
  34. //++
  35. //
  36. // class CStatusReport
  37. //
  38. // Description:
  39. // CStatusReport is a class the provides the functionality sending a
  40. // status report. Each status report can have a number of steps. For
  41. // example, the task of creating the cluster service could have 4 steps,
  42. //
  43. // The user interface is so designed that if the first step of a report is
  44. // sent, the last one has to be sent as well, even if an error occurs after
  45. // sending the first one. This class queues the last status report for
  46. // sending in case and exception occurs and the last report has not been
  47. // sent yet.
  48. //
  49. // It is not possible to send the last, outstanding status report from the
  50. // destructor of this class since the error code contained in the exception
  51. // that is causing this object to be destroyed is not known. So, this last
  52. // status report is queued with the CBCAInterface object which will send this
  53. // report once the exception has been caught.
  54. //
  55. //--
  56. //////////////////////////////////////////////////////////////////////////////
  57. class CStatusReport
  58. {
  59. public:
  60. //////////////////////////////////////////////////////////////////////////
  61. // Constructors and destructors
  62. //////////////////////////////////////////////////////////////////////////
  63. // Constructor.
  64. CStatusReport(
  65. CBCAInterface * pbcaiInterfaceIn
  66. , const CLSID & clsidTaskMajorIn
  67. , const CLSID & clsidTaskMinorIn
  68. , ULONG ulMinIn
  69. , ULONG ulMaxIn
  70. , UINT idsDescriptionStringIdIn
  71. )
  72. : m_pbcaiInterface( pbcaiInterfaceIn )
  73. , m_clsidTaskMajor( clsidTaskMajorIn )
  74. , m_clsidTaskMinor( clsidTaskMinorIn )
  75. , m_ulMin( ulMinIn )
  76. , m_ulMax( ulMaxIn )
  77. , m_ulNext( ulMinIn )
  78. , m_idsDescriptionStringId( idsDescriptionStringIdIn )
  79. , m_idsReferenceStringId( 0 )
  80. , m_fLastStepSent( false )
  81. {
  82. TraceFunc( "" );
  83. // Validate the parameters.
  84. if ( ( pbcaiInterfaceIn == NULL )
  85. || ( ulMinIn > ulMaxIn )
  86. )
  87. {
  88. THR( E_INVALIDARG );
  89. THROW_ASSERT( E_INVALIDARG, "The parameters for this status report are invalid." );
  90. } // if: the parameters are invalid
  91. TraceFuncExit();
  92. } //*** CStatusReport::CStatusReport
  93. // Constructor.
  94. CStatusReport(
  95. CBCAInterface * pbcaiInterfaceIn
  96. , const CLSID & clsidTaskMajorIn
  97. , const CLSID & clsidTaskMinorIn
  98. , ULONG ulMinIn
  99. , ULONG ulMaxIn
  100. , UINT idsDescriptionStringIdIn
  101. , UINT idsReferenceStringIdIn
  102. )
  103. : m_pbcaiInterface( pbcaiInterfaceIn )
  104. , m_clsidTaskMajor( clsidTaskMajorIn )
  105. , m_clsidTaskMinor( clsidTaskMinorIn )
  106. , m_ulMin( ulMinIn )
  107. , m_ulMax( ulMaxIn )
  108. , m_ulNext( ulMinIn )
  109. , m_idsDescriptionStringId( idsDescriptionStringIdIn )
  110. , m_idsReferenceStringId( idsReferenceStringIdIn )
  111. , m_fLastStepSent( false )
  112. {
  113. TraceFunc( "" );
  114. // Validate the parameters.
  115. if ( ( pbcaiInterfaceIn == NULL )
  116. || ( ulMinIn > ulMaxIn )
  117. )
  118. {
  119. THR( E_INVALIDARG );
  120. THROW_ASSERT( E_INVALIDARG, "The parameters for this status report are invalid." );
  121. } // if: the parameters are invalid
  122. TraceFuncExit();
  123. } //*** CStatusReport::CStatusReport
  124. // Default destructor.
  125. ~CStatusReport( void )
  126. {
  127. TraceFunc( "" );
  128. // If the last step has not been sent, queue it for sending. This is most probably because
  129. // an exception has occurred (if no exception has occurred and the last step has not been
  130. // sent, then it is a programming error).
  131. if ( ! m_fLastStepSent )
  132. {
  133. // The last step has not been sent.
  134. // Don't throw exceptions from destructor. An unwind may already be in progress.
  135. try
  136. {
  137. // Queue the last step for sending. The CBCAInterface object will fill in the
  138. // error code from the current exception and send this report.
  139. m_pbcaiInterface->QueueStatusReportCompletion(
  140. m_clsidTaskMajor
  141. , m_clsidTaskMinor
  142. , m_ulMin
  143. , m_ulMax
  144. , m_idsDescriptionStringId
  145. , m_idsReferenceStringId
  146. );
  147. }
  148. catch( ... )
  149. {
  150. // Catch all errors. Do not rethrow this exception - the app may be terminated due to
  151. // a collided unwind - so log the error.
  152. THR( E_UNEXPECTED );
  153. LogMsg( "[BC] Caught an exception while trying to send the last step of a status report during cleanup." );
  154. }
  155. }
  156. TraceFuncExit();
  157. } //*** CStatusReport::~CStatusReport
  158. //////////////////////////////////////////////////////////////////////////
  159. // Public methods
  160. //////////////////////////////////////////////////////////////////////////
  161. // Send the next step of this report.
  162. void SendNextStep( HRESULT hrStatusIn, UINT idsDescriptionStringIdIn = 0, UINT idsReferenceStringIdIn = 0 )
  163. {
  164. TraceFunc( "" );
  165. if ( m_fLastStepSent )
  166. {
  167. LogMsg( "[BC] The last step for this status report has already been sent! Throwing an exception." );
  168. THR( E_INVALIDARG );
  169. THROW_ASSERT( E_INVALIDARG, "The last step for this status report has already been sent." );
  170. } // if: the last step has already been sent
  171. else
  172. {
  173. if ( idsDescriptionStringIdIn == 0 )
  174. {
  175. idsDescriptionStringIdIn = m_idsDescriptionStringId;
  176. }
  177. if ( idsReferenceStringIdIn == 0 )
  178. {
  179. idsReferenceStringIdIn = m_idsReferenceStringId;
  180. }
  181. m_pbcaiInterface->SendStatusReport(
  182. m_clsidTaskMajor
  183. , m_clsidTaskMinor
  184. , m_ulMin
  185. , m_ulMax
  186. , m_ulNext
  187. , hrStatusIn
  188. , idsDescriptionStringIdIn
  189. , idsReferenceStringIdIn
  190. );
  191. ++m_ulNext;
  192. m_fLastStepSent = ( m_ulNext > m_ulMax );
  193. } // else: the last step has not been sent
  194. TraceFuncExit();
  195. } //*** CStatusReport::SendNextStep
  196. // Send the last step of this report, if it hasn't been sent already.
  197. void SendLastStep( HRESULT hrStatusIn, UINT idsDescriptionStringIdIn = 0, UINT idsReferenceStringIdIn = 0 )
  198. {
  199. TraceFunc( "" );
  200. if ( m_fLastStepSent )
  201. {
  202. LogMsg( "[BC] The last step for this status report has already been sent! Throwing an exception." );
  203. THR( E_INVALIDARG );
  204. THROW_ASSERT( E_INVALIDARG, "The last step for this status report has already been sent." );
  205. } // if: the last step has already been sent
  206. else
  207. {
  208. if ( idsDescriptionStringIdIn == 0 )
  209. {
  210. idsDescriptionStringIdIn = m_idsDescriptionStringId;
  211. }
  212. if ( idsReferenceStringIdIn == 0 )
  213. {
  214. idsReferenceStringIdIn = m_idsReferenceStringId;
  215. }
  216. m_pbcaiInterface->SendStatusReport(
  217. m_clsidTaskMajor
  218. , m_clsidTaskMinor
  219. , m_ulMin
  220. , m_ulMax
  221. , m_ulMax
  222. , hrStatusIn
  223. , idsDescriptionStringIdIn
  224. , idsReferenceStringIdIn
  225. );
  226. m_fLastStepSent = true;
  227. } // else: the last step has not been sent
  228. TraceFuncExit();
  229. } //*** CStatusReport::SendLastStep
  230. // Get the description string ID.
  231. UINT IdsGetDescriptionStringId( void )
  232. {
  233. return m_idsDescriptionStringId;
  234. }
  235. // Set the description string ID.
  236. void SetDescriptionStringId( UINT idsDescriptionStringIdIn )
  237. {
  238. m_idsDescriptionStringId = idsDescriptionStringIdIn;
  239. }
  240. // Get the reference string ID.
  241. UINT IdsGetReferenceStringId( void )
  242. {
  243. return m_idsReferenceStringId;
  244. }
  245. // Set the reference string ID.
  246. void SetReferenceStringId( UINT idsReferenceStringIdIn )
  247. {
  248. m_idsReferenceStringId = idsReferenceStringIdIn;
  249. }
  250. private:
  251. //////////////////////////////////////////////////////////////////////////
  252. // Private data
  253. //////////////////////////////////////////////////////////////////////////
  254. // Pointer to the interface class.
  255. CBCAInterface * m_pbcaiInterface;
  256. // The major and minor class id to be sent with this status report.
  257. CLSID m_clsidTaskMajor;
  258. CLSID m_clsidTaskMinor;
  259. // The range for this status report
  260. ULONG m_ulMin;
  261. ULONG m_ulMax;
  262. ULONG m_ulNext;
  263. // The string id of the description to be sent with this status report
  264. UINT m_idsDescriptionStringId;
  265. // The REF string id of the description to be sent with this status report
  266. UINT m_idsReferenceStringId;
  267. // Flag to indicate if the last step has been sent.
  268. bool m_fLastStepSent;
  269. }; //*** class CStatusReport