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.

158 lines
3.9 KiB

  1. #include "precomp.h"
  2. #include "fsdiag.h"
  3. DEBUG_FILEZONE(ZONE_T120_GCCNC);
  4. /*
  5. * alarm.cpp
  6. *
  7. * Copyright (c) 1995 by Databeam Corporation, Lexington, KY
  8. *
  9. * Abstract:
  10. * This is the implementation file for the Alarm class. Objects of this
  11. * class are used when the creator wishes to make sure that a certain
  12. * activity doesn't exceed a certain amount of time.
  13. *
  14. * By convention, an Alarm object is created with the time limitation
  15. * passed in as the only parameter to the constructor. The creator can
  16. * then periodically ask the Alarm object if it has expired. This hides
  17. * all time maintenance code from the creator.
  18. *
  19. * Note that the Alarm class is PASSIVE, meaning that it will not call
  20. * back into its creator when the specified time is exceeded. This
  21. * capability could be added at a future data. if desirable. Right now,
  22. * the creator MUST call into an Alarm object to ask it if it has expired.
  23. *
  24. * Private Data:
  25. * Duration
  26. * This refers to the original duration of the alarm. It is kept
  27. * around to allow the creator to reset the alarm without having to
  28. * respecify the duration.
  29. * Expiration_Time
  30. * This is the time (in clock ticks) upon which the alarm will expire.
  31. * Whenever the alarm is asked if it has expired, it checks the current
  32. * system clock against this value.
  33. * Expired
  34. * This is a boolean flag that indicates whether or not the alarm has
  35. * already expired. This prevents the object from repeatedly checking
  36. * the system clock if the timer has already expired.
  37. *
  38. * Caveats:
  39. * None
  40. *
  41. * Author:
  42. * James P. Galvin, Jr.
  43. *
  44. * Revision History:
  45. * 09JAN95 jpg Original
  46. */
  47. #include "alarm.h"
  48. /*
  49. * Alarm ()
  50. *
  51. * Public
  52. *
  53. * Function Description
  54. * This is the constructor for the Alarm class. It calls Set to initialize
  55. * all instance variables, and calculate the first expiration time value
  56. * based on the specified duration.
  57. */
  58. CAlarm::CAlarm(UINT nDuration)
  59. {
  60. Set(nDuration);
  61. }
  62. /*
  63. * ~Alarm ()
  64. *
  65. * Public
  66. *
  67. * Function Description
  68. * This is the destructor for the Alarm class. It currently does nothing.
  69. */
  70. /*
  71. * void Set ()
  72. *
  73. * Public
  74. *
  75. * Function Description
  76. * This function initializes the alarm duration instance variable and
  77. * calls Reset to ready the alarm for use.
  78. */
  79. void CAlarm::Set(UINT nDuration)
  80. {
  81. m_nDuration = nDuration;
  82. /*
  83. * Call Reset to initialize remaining instance variables and ready the
  84. * alarm for use.
  85. */
  86. Reset();
  87. }
  88. /*
  89. * void Reset ()
  90. *
  91. * Public
  92. *
  93. * Function Description
  94. * This function calculate an expiration time value based on the specified
  95. * duration and marks the alarm as unexpired.
  96. */
  97. void CAlarm::Reset(void)
  98. {
  99. /*
  100. * Determine the expiration time by adding the alarm duration to the
  101. * current time.
  102. */
  103. m_nStartTime = (UINT) ::GetTickCount();
  104. m_fExpired = FALSE;
  105. }
  106. /*
  107. * void Expire ()
  108. *
  109. * Public
  110. *
  111. * Function Description
  112. * This function can be used to expire an alarm prematurely. This might
  113. * be useful if the alarm is used to determine whether or not to perform
  114. * an action, and the caller decides to inhibit the action for reasons
  115. * other than time.
  116. */
  117. /*
  118. * BOOL IsExpired ()
  119. *
  120. * Public
  121. *
  122. * Function Description
  123. * This function is used to check an alarm to see if it has expired.
  124. */
  125. BOOL CAlarm::IsExpired(void)
  126. {
  127. /*
  128. * See if the alarm has already expired before checking it again.
  129. */
  130. // LONCHANC: The alarm object is totally bogus. We check for expiration
  131. // only when we are sending a PDU out. However, when it expires, it is
  132. // possible that there is no PDU to send. In this case, no one will know
  133. // this alarm is expired. This means some actions will not be taken in time.
  134. // Now, make it always expired because it did not work at all before and
  135. // most of time it returned "expired."
  136. #if 1
  137. m_fExpired = TRUE;
  138. #else
  139. if (! m_fExpired)
  140. {
  141. if (m_nStartTime + m_nDuration <= (UINT) ::GetTickCount())
  142. {
  143. m_fExpired = TRUE;
  144. }
  145. }
  146. #endif
  147. return m_fExpired;
  148. }