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.

236 lines
5.4 KiB

  1. // Copyright (c) 1997-2001 Microsoft Corporation, All Rights Reserved
  2. /*--------------------------------------------------
  3. Filename: timer.hpp
  4. Author: B.Rajeev
  5. Purpose: Provides declarations for the Timer class.
  6. --------------------------------------------------*/
  7. #ifndef __TIMER__
  8. #define __TIMER__
  9. #define ILLEGAL_TIMER_EVENT_ID 0
  10. #define RETRY_TIMEOUT_FACTOR 10
  11. typedef UINT_PTR TimerEventId;
  12. #include <snmpevt.h>
  13. #include <snmpthrd.h>
  14. #include "forward.h"
  15. #include "common.h"
  16. #include "message.h"
  17. typedef CMap< TimerEventId, TimerEventId, Timer *, Timer * > TimerMapping;
  18. typedef CList< WaitingMessage * , WaitingMessage * > WaitingMessageContainer;
  19. class SnmpClThreadObject : public SnmpThreadObject
  20. {
  21. private:
  22. protected:
  23. public:
  24. SnmpClThreadObject () ;
  25. void Initialise () ;
  26. void Uninitialise () ;
  27. } ;
  28. class SnmpClTrapThreadObject : public SnmpThreadObject
  29. {
  30. private:
  31. protected:
  32. public:
  33. SnmpClTrapThreadObject () ;
  34. void Initialise () ;
  35. void Uninitialise () ;
  36. } ;
  37. /*--------------------------------------------------
  38. Overview
  39. --------
  40. Timer: Provides methods for setting and cancelling timer
  41. events. When the timer is informed of a timer event, it determines
  42. the corresponding waiting message and notifies it.
  43. note - the timer has static data structures which enable it
  44. to identify the timer instance corresponding to a timer event id.
  45. therefore, each timer event must not only be registered as a
  46. <timer_event_id, waiting_message *> pair within a timer instance, but
  47. also as a <timer_event_id, timer *> pair in the static CMap. The CriticalSection
  48. is needed to serialize access to the CMap
  49. --------------------------------------------------*/
  50. class Timer
  51. {
  52. // counter to generate timer_event_id
  53. static TimerEventId next_timer_event_id;
  54. // v1 session: for obtaining the event handler
  55. SnmpImpSession *session;
  56. // map for (event_id, waiting_message) association and
  57. // unique event_id generation
  58. static TimerMapping timer_mapping;
  59. WaitingMessageContainer waiting_message_mapping;
  60. static BOOL CreateCriticalSection();
  61. static void DestroyCriticalSection();
  62. public:
  63. Timer(SnmpImpSession &session);
  64. // generates and returns a new event id
  65. // associates the pair (event_id, waiting_message)
  66. // creates the timer event
  67. void SetMessageTimerEvent (WaitingMessage &waiting_message);
  68. TimerEventId SetTimerEvent(UINT timeout_value);
  69. // Removes the association (event_id, waiting_message)
  70. void CancelMessageTimer(WaitingMessage &waiting_message,TimerEventId event_id);
  71. // Kills the registered timer event
  72. void CancelTimer(TimerEventId event_id);
  73. // used to create the static CriticalSection
  74. static BOOL InitializeStaticComponents();
  75. // used to destroy the static CriticalSection
  76. static void DestroyStaticComponents();
  77. // it determines the corresponding Timer and calls
  78. // its TimerEventNotification with the appropriate parameters
  79. static void CALLBACK HandleGlobalEvent(HWND hWnd ,UINT message,
  80. UINT_PTR idEvent, DWORD dwTime);
  81. // informs the timer instance of the event. the instance
  82. // must pass the event to the corresponding waiting message
  83. void TimerEventNotification(TimerEventId event_id);
  84. virtual ~Timer(void);
  85. static SnmpClThreadObject *g_timerThread ;
  86. static UINT g_SnmpWmTimer ;
  87. // the CriticalSection serializes accesses to the static timer_mapping
  88. static CriticalSection timer_CriticalSection;
  89. };
  90. class SnmpTimerObject
  91. {
  92. private:
  93. HWND hWnd ;
  94. UINT_PTR timerId ;
  95. TIMERPROC lpTimerFunc ;
  96. protected:
  97. public:
  98. SnmpTimerObject (
  99. HWND hWnd ,
  100. UINT_PTR timerId ,
  101. UINT elapsedTime ,
  102. TIMERPROC lpTimerFunc
  103. ) ;
  104. ~SnmpTimerObject () ;
  105. UINT_PTR GetTimerId () { return timerId ; }
  106. HWND GetHWnd () { return hWnd ; }
  107. TIMERPROC GetTimerFunc () { return lpTimerFunc ; }
  108. static Window *window ;
  109. static CMap <UINT_PTR,UINT_PTR,SnmpTimerObject *,SnmpTimerObject *> timerMap ;
  110. static void TimerNotification ( HWND hWnd , UINT timerId ) ;
  111. } ;
  112. class SnmpTimerEventObject : public SnmpTaskObject
  113. {
  114. private:
  115. protected:
  116. SnmpTimerEventObject () {}
  117. public:
  118. virtual ~SnmpTimerEventObject () {} ;
  119. } ;
  120. class SnmpSetTimerObject : public SnmpTimerEventObject
  121. {
  122. private:
  123. UINT_PTR timerId ;
  124. HWND hWnd ;
  125. UINT elapsedTime ;
  126. TIMERPROC lpTimerFunc ;
  127. protected:
  128. public:
  129. SnmpSetTimerObject (
  130. HWND hWnd, // handle of window for timer messages
  131. UINT_PTR nIDEvent, // timer identifier
  132. UINT uElapse, // time-out value
  133. TIMERPROC lpTimerFunc // address of timer procedure
  134. ) ;
  135. ~SnmpSetTimerObject () ;
  136. UINT_PTR GetTimerId () { return timerId ; }
  137. void Process () ;
  138. } ;
  139. class SnmpKillTimerObject : public SnmpTimerEventObject
  140. {
  141. private:
  142. BOOL status ;
  143. HWND hWnd ;
  144. UINT_PTR timerId ;
  145. protected:
  146. public:
  147. SnmpKillTimerObject (
  148. HWND hWnd , // handle of window that installed timer
  149. UINT_PTR uIDEvent // timer identifier
  150. ) ;
  151. ~SnmpKillTimerObject () {} ;
  152. void Process () ;
  153. BOOL GetStatus () { return status ; }
  154. } ;
  155. UINT_PTR SnmpSetTimer (
  156. HWND hWnd, // handle of window for timer messages
  157. UINT_PTR nIDEvent, // timer identifier
  158. UINT uElapse, // time-out value,
  159. TIMERPROC lpTimerFunc // address of timer procedure
  160. ) ;
  161. BOOL SnmpKillTimer (
  162. HWND hWnd, // handle of window that installed timer
  163. UINT_PTR uIDEvent // timer identifier
  164. ) ;
  165. #endif // __TIMER__