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.

200 lines
5.3 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1997.
  5. //
  6. // File: psavtrak.hxx
  7. //
  8. // Contents: A pure virtual class to indicate progress in a save content-index
  9. // operation. The save consists of two parts:
  10. //
  11. // 1. Merge Operation
  12. // 2. Copying the index data
  13. //
  14. // This class also permits communicating an aout
  15. // Classes: PSaveProgressTracker
  16. //
  17. // History: 3-18-97 srikants Created
  18. //
  19. //----------------------------------------------------------------------------
  20. #pragma once
  21. //+---------------------------------------------------------------------------
  22. //
  23. // Class: PSaveProgressTracker
  24. //
  25. // Purpose: A pure virtual class for indicating progress and communicating
  26. // abort of a long operation.
  27. //
  28. // History: 3-18-97 srikants Created
  29. //
  30. //----------------------------------------------------------------------------
  31. class PSaveProgressTracker
  32. {
  33. public:
  34. virtual void UpdateMergeProgress( ULONG ulNumerator, ULONG ulDenominator ) = 0;
  35. virtual void UpdateCopyProgress( ULONG ulNumerator, ULONG ulDenominator ) = 0;
  36. virtual void GetProgress( ULONG & ulNumerator, ULONG & ulDenominator ) = 0;
  37. virtual void SetAbort() = 0;
  38. virtual BOOL IsAbort() = 0;
  39. };
  40. //+---------------------------------------------------------------------------
  41. //
  42. // Class: CProgressTracker
  43. //
  44. // Purpose: An implementation of the PSaveProgressTracker using the
  45. // IProgressNotify interface.
  46. //
  47. // History: 3-20-97 srikants Created
  48. //
  49. //----------------------------------------------------------------------------
  50. class CProgressTracker : public PSaveProgressTracker
  51. {
  52. public:
  53. CProgressTracker()
  54. : _fAbort(FALSE),
  55. _fTracking(FALSE),
  56. _ulNumerator(0),
  57. _ulDenominator(1),
  58. _pfClientAbort(0),
  59. _pProgressNotify(0)
  60. {
  61. _evt.Set();
  62. }
  63. ~CProgressTracker()
  64. {
  65. Win4Assert( 0 == _pfClientAbort );
  66. Win4Assert( 0 == _pProgressNotify );
  67. Win4Assert( !_fTracking );
  68. }
  69. //
  70. // Assuming that it will be called from within an outer lock.
  71. //
  72. void LokStartTracking( IProgressNotify * pNotify = 0,
  73. BOOL const * pfClientAbort = 0 )
  74. {
  75. _pProgressNotify = pNotify;
  76. if ( 0 == pfClientAbort )
  77. _pfClientAbort = &_fAbort;
  78. else _pfClientAbort = pfClientAbort;
  79. _ulNumerator = 0;
  80. _ulDenominator = 1;
  81. _fAbort = FALSE;
  82. _fTracking = TRUE;
  83. _evt.Reset();
  84. }
  85. //
  86. // Assuming that it will be called from within an outer lock.
  87. //
  88. void LokStopTracking()
  89. {
  90. _pProgressNotify = 0;
  91. _pfClientAbort = 0;
  92. _fTracking = FALSE;
  93. _fAbort = FALSE;
  94. _evt.Set();
  95. }
  96. BOOL LokIsTracking() const
  97. {
  98. return _fTracking;
  99. }
  100. void WaitForCompletion()
  101. {
  102. _evt.Wait();
  103. }
  104. //
  105. // I have assumed that merge and copy are 50% each. If we see that
  106. // Merge is a much bigger portion, we have to adjust these numbers.
  107. //
  108. virtual void UpdateMergeProgress( ULONG ulNumerator, ULONG ulDenominator )
  109. {
  110. //
  111. // Assume that Merge is half the work.
  112. //
  113. _UpdateProgress( ulNumerator, ulDenominator * 2 );
  114. }
  115. virtual void UpdateCopyProgress( ULONG ulNumerator, ULONG ulDenominator )
  116. {
  117. //
  118. // Progress = num/(2*denom) + 1/2
  119. // = (num + denom)/2*denom
  120. _UpdateProgress( (ulNumerator+ulDenominator) , 2*ulDenominator );
  121. }
  122. virtual void GetProgress( ULONG & ulNumerator, ULONG & ulDenominator )
  123. {
  124. ulNumerator = _ulNumerator;
  125. ulDenominator = _ulDenominator;
  126. }
  127. virtual void SetAbort()
  128. {
  129. _fAbort = TRUE;
  130. }
  131. virtual BOOL IsAbort()
  132. {
  133. return _fAbort || (*_pfClientAbort);
  134. }
  135. private:
  136. BOOL _fAbort; // Abort controlled by us.
  137. BOOL _fTracking; // Is there an active tracking
  138. ULONG _ulNumerator;
  139. ULONG _ulDenominator;
  140. CEventSem _evt;
  141. BOOL const * _pfClientAbort; // Abort controlled by the client
  142. IProgressNotify * _pProgressNotify;
  143. void _UpdateProgress( ULONG ulNumerator, ULONG ulDenominator )
  144. {
  145. Win4Assert( _fTracking );
  146. Win4Assert( 0 != ulDenominator );
  147. _ulNumerator = ulNumerator;
  148. _ulDenominator = ulDenominator;
  149. ciDebugOut(( DEB_ERROR,
  150. "Save Progress = %d percent\n",
  151. (_ulNumerator*100)/_ulDenominator ));
  152. if ( _pProgressNotify )
  153. {
  154. _pProgressNotify->OnProgress(
  155. (DWORD) _ulNumerator,
  156. (DWORD) _ulDenominator,
  157. FALSE, // Not accurate
  158. FALSE // Ownership of Blocking Behavior
  159. );
  160. }
  161. }
  162. };