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.

304 lines
7.7 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corp., 1991 **/
  4. /**********************************************************************/
  5. /*
  6. blttm.hxx
  7. BLT timer multiplexer object header file.
  8. FILE HISTORY:
  9. terryk 29-May-91 Created
  10. terryk 18-Jul-91 Code review changes.
  11. Attend: terryk jonn ericch
  12. rustanl 10-Sep-91 Large changes, introducing new timer hierarchy
  13. beng 04-Oct-1991 Relocated type TIMER_ID to bltglob
  14. KeithMo 23-Oct-1991 Added forward references.
  15. */
  16. #ifndef _BLTTM_HXX_
  17. #define _BLTTM_HXX_
  18. #include "slist.hxx"
  19. //
  20. // Forward references.
  21. //
  22. DLL_CLASS BLT_MASTER_TIMER;
  23. DLL_CLASS TIMER_BASE;
  24. DLL_CLASS TIMER_WINDOW;
  25. DLL_CLASS WINDOW_TIMER;
  26. DLL_CLASS PROC_TIMER;
  27. DLL_CLASS TIMER_CALLOUT;
  28. DLL_CLASS TIMER;
  29. DECL_SLIST_OF( TIMER_BASE, DLL_BASED );
  30. /**********************************************************\
  31. NAME: BLT_MASTER_TIMER
  32. SYNOPSIS: Master timer. It consists of a set of function to
  33. control the list of timer.
  34. INTERFACE: Init() - initialize the master timer
  35. Term() - terminate the master timer
  36. ResetIterator() - reset the link list to the first timer
  37. NextTimer() - return the next timer in the link list.
  38. RemoveTimer() - remove the given timer from the link list
  39. Insert() - insert the given timer to the link list
  40. by using insertion method.
  41. ClearMasterHotkey() - clears hotkey (if any) associated
  42. with invisible master timer window
  43. and returns vkey code (NULL if none).
  44. PARENT: BASE
  45. USES: SLIST, ITER, TIMER_BASE
  46. CAVEATS: In order to use the package, the programmer should called
  47. BLT_MASTER_TIMER's Init function. He/she should also called
  48. the Term function at the end of the application.
  49. HISTORY:
  50. terryk 1-Jun-91 Created
  51. terryk 18-Jul-91 Change the name of the functions
  52. to ResetIterator and NextTimer
  53. rustanl 09-Sep-1991 Changed Init return code and made
  54. use of it
  55. jonn 05-Jul-95 ClearMasterHotkey
  56. \**********************************************************/
  57. DLL_CLASS BLT_MASTER_TIMER: public BASE
  58. {
  59. private:
  60. SLIST_OF( TIMER_BASE ) _slTimer; // singly linked list of timers
  61. ITER_SL_OF( TIMER_BASE ) _iterTimer; // iterator for the timer list
  62. UINT_PTR _wTimerId; // the system timer id
  63. TIMER_WINDOW * _pclwinTimerApp; // pointer to window which receives
  64. // OnTimer calls, triggering the
  65. // master timer
  66. static BLT_MASTER_TIMER * _pBltMasterTimer; // pointer to THE master timer;
  67. // initialized in Init.
  68. public:
  69. static APIERR Init(); // initialize the master timer
  70. static VOID Term(); // destroy the master timer
  71. BLT_MASTER_TIMER();
  72. ~BLT_MASTER_TIMER();
  73. VOID ResetIterator();
  74. TIMER_BASE * NextTimer();
  75. APIERR InsertTimer( TIMER_BASE * pTimer );
  76. VOID RemoveTimer( TIMER_BASE * pTimer );
  77. static APIERR QueryMasterTimer( BLT_MASTER_TIMER * * ppmastertimer );
  78. static ULONG ClearMasterTimerHotkey();
  79. };
  80. /**********************************************************\
  81. NAME: TIMER_BASE
  82. SYNOPSIS: This object will multiplex the window's system timer.
  83. INTERFACE: TIMER_BASE() - constructor
  84. ~TIMER_BASE() - destructor
  85. Enable() - Enable or disable the timer
  86. IsEnabled() - Returns whether the timer is enabled
  87. PARENT: BASE
  88. USE: BLT_MASTER_TIMER
  89. CAVEATS: The programmer should call BLT_MASTER_TIMER initialize
  90. first. The programmer should also call BLT_MASTER_TIMER's
  91. Term at the end of the program to terminate the master timer.
  92. HISTORY:
  93. terryk 1-Jun-91 Created
  94. terryk 18-Jul-91 Change the member variables to private
  95. rustanl 06-Sep-91 Changed name to TIMER_BASE, and created
  96. new timer class WINDOW_TIMER and PROC_TIMER.
  97. \**********************************************************/
  98. DLL_CLASS TIMER_BASE: public BASE
  99. {
  100. friend class BLT_MASTER_TIMER;
  101. friend class TIMER_WINDOW;
  102. private:
  103. BOOL _fEnabled; // Whether or not the timer is enabled
  104. ULONG _msInterval; // interval at which the timer will activate
  105. ULONG _ulNextTimerDue; // tick count at which next timer is due
  106. BOOL _fBeingServed; // is timer being served
  107. TIMER_ID _tid; // timer ID
  108. VOID SetNewTimeDue(); // sets _ulNextTimerDue to new value
  109. protected:
  110. virtual VOID DispatchTimer();
  111. public:
  112. TIMER_BASE( ULONG msInterval,
  113. BOOL fEnabled = TRUE );
  114. ~TIMER_BASE();
  115. VOID Enable( BOOL fEnable ); // Enables or disables the timer
  116. BOOL IsEnabled() const
  117. { return ( _fEnabled ); }
  118. VOID TriggerNow(); // Forces a timer.
  119. TIMER_ID QueryID() const
  120. { return _tid; }
  121. };
  122. /*************************************************************************
  123. NAME: WINDOW_TIMER
  124. SYNOPSIS: Timer which calls out to a window
  125. INTERFACE: WINDOW_TIMER() - Constructor
  126. PARENT: TIMER_BASE
  127. HISTORY:
  128. rustanl 06-Sep-1991 Created from previous BLT_TIMER class
  129. **************************************************************************/
  130. DLL_CLASS WINDOW_TIMER : public TIMER_BASE
  131. {
  132. private:
  133. HWND _hwnd; // window handle
  134. BOOL _fPostMsg; // TRUE to post msg; FALSE to send msg
  135. protected:
  136. virtual VOID DispatchTimer();
  137. public:
  138. WINDOW_TIMER( HWND hwnd,
  139. ULONG msInterval,
  140. BOOL fEnabled = TRUE,
  141. BOOL fPostMsg = FALSE );
  142. };
  143. /*************************************************************************
  144. NAME: PROC_TIMER
  145. SYNOPSIS: Timer which calls out to a TimerProc
  146. INTERFACE: PROC_TIMER() - Constructor
  147. PARENT: TIMER_BASE
  148. HISTORY:
  149. rustanl 06-Sep-1991 Created from previous BLT_TIMER class
  150. beng 17-Oct-1991 Win32 conversion
  151. **************************************************************************/
  152. DLL_CLASS PROC_TIMER : public TIMER_BASE
  153. {
  154. private:
  155. HWND _hwnd;
  156. MFARPROC _lpTimerFunc; // callback function
  157. protected:
  158. virtual VOID DispatchTimer();
  159. public:
  160. PROC_TIMER( HWND hwnd,
  161. MFARPROC lpTimerFunc,
  162. ULONG msInterval,
  163. BOOL fEnabled = TRUE );
  164. };
  165. /*************************************************************************
  166. NAME: TIMER_CALLOUT
  167. SYNOPSIS: Outlet for timer fires
  168. INTERFACE: TIMER_CALLOUT() - Constructor
  169. PARENT: BASE
  170. NOTES: CODEWORK. The DISPATCHER::OnTimer method should be
  171. renamed something like OnWindowTimer, so as to
  172. disambiguate it from this method. Perhaps this method
  173. could also get a better name.
  174. Note, don't confuse the OnTimerNotification method with
  175. the DISPATCHER::OnTimer method.
  176. HISTORY:
  177. rustanl 05-Sep-1991 Created
  178. **************************************************************************/
  179. DLL_CLASS TIMER_CALLOUT : public BASE
  180. {
  181. friend class TIMER;
  182. protected:
  183. virtual VOID OnTimerNotification( TIMER_ID tid );
  184. public:
  185. TIMER_CALLOUT() {}
  186. };
  187. /*************************************************************************
  188. NAME: TIMER
  189. SYNOPSIS: Timer which calls out to a TIMER_CALLOUT object
  190. INTERFACE: TIMER() - Constructor
  191. PARENT: TIMER_BASE
  192. HISTORY:
  193. rustanl 06-Sep-1991 Created
  194. **************************************************************************/
  195. DLL_CLASS TIMER : public TIMER_BASE
  196. {
  197. private:
  198. TIMER_CALLOUT * _ptimercallout;
  199. protected:
  200. virtual VOID DispatchTimer();
  201. public:
  202. TIMER( TIMER_CALLOUT * ptimercallout,
  203. ULONG msInterval,
  204. BOOL fEnabled = TRUE );
  205. };
  206. #endif // _BLTTM_HXX_