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.

249 lines
7.9 KiB

  1. //*****************************************************************************
  2. //
  3. // WBEMTSS.H
  4. //
  5. // Copyright (c) 1996-1999, Microsoft Corporation, All rights reserved
  6. //
  7. // This file defines the classes used by the Timer Subsystem.
  8. //
  9. // Classes defined:
  10. //
  11. // RecurrenceInstruction Complex recurrence information.
  12. // TimerInstruction Single instruction for the timer
  13. //
  14. //
  15. //
  16. // 26-Nov-96 raymcc Draft
  17. // 28-Dec-96 a-richm Alpha PDK Release
  18. // 12-Apr-97 a-levn Extensive changes
  19. //
  20. //*****************************************************************************
  21. #ifndef _WBEMTSS_H_
  22. #define _WBEMTSS_H_
  23. #include <wbemidl.h>
  24. #include <wbemint.h>
  25. #include <stdio.h>
  26. #include "sync.h"
  27. #include "statsync.h"
  28. #include "CWbemTime.h"
  29. #include "parmdefs.h"
  30. #include "tss.h"
  31. #include "wstring.h"
  32. //*****************************************************************************
  33. //
  34. // class CTimerInstruction
  35. //
  36. // Generic timer instruction class. Has a name (m_wsTimerId) and knows
  37. // whether events that were missed due to the system being halted or dead
  38. // should be fired.
  39. //
  40. // Derived classes must be able to tell when their next firing time is.
  41. //
  42. //*****************************************************************************
  43. class CEss;
  44. class CWinMgmtTimerGenerator;
  45. class CWBEMTimerInstruction : public CTimerInstruction
  46. {
  47. protected:
  48. long m_lRefCount;
  49. CWinMgmtTimerGenerator* m_pGenerator;
  50. IWbemServices* m_pNamespace;
  51. WString m_wsNamespace;
  52. WString m_wsTimerId;
  53. BOOL m_bSkipIfPassed;
  54. BOOL m_bRemoved;
  55. public:
  56. CWBEMTimerInstruction();
  57. virtual ~CWBEMTimerInstruction();
  58. void AddRef()
  59. {InterlockedIncrement(&m_lRefCount);}
  60. void Release()
  61. {if(InterlockedDecrement(&m_lRefCount) == 0) delete this;}
  62. BOOL SkipIfPassed() const {return m_bSkipIfPassed;}
  63. void SetSkipIfPassed(BOOL bSkip) {m_bSkipIfPassed = bSkip;}
  64. INTERNAL LPCWSTR GetTimerId() {return m_wsTimerId;}
  65. INTERNAL LPCWSTR GetNamespace() {return m_wsNamespace;}
  66. void SetTimerId(LPCWSTR wszTimerId)
  67. {
  68. m_wsTimerId = wszTimerId;
  69. }
  70. public:
  71. static HRESULT CheckObject(IWbemClassObject* pObject);
  72. static HRESULT LoadFromWbemObject(LPCWSTR wszNamespace,
  73. ADDREF IWbemServices* pNamespace,
  74. CWinMgmtTimerGenerator* pGenerator,
  75. IN IWbemClassObject* pObject,
  76. OUT RELEASE_ME CWBEMTimerInstruction*& pInstruction);
  77. virtual CWbemTime GetNextFiringTime(CWbemTime LastFiringTime,
  78. OUT long* plFiringCount) const;
  79. virtual CWbemTime GetFirstFiringTime() const;
  80. virtual HRESULT Fire(long lNumTimes, CWbemTime NextFitingTime);
  81. virtual HRESULT MarkForRemoval();
  82. virtual int GetInstructionType() {return INSTTYPE_WBEM;}
  83. HRESULT StoreNextFiring(CWbemTime When);
  84. CWbemTime GetStartingFiringTime(CWbemTime OldTime) const;
  85. protected:
  86. CWbemTime SkipMissed(CWbemTime Firing, long* plMissedCount = NULL) const;
  87. virtual CWbemTime ComputeNextFiringTime(CWbemTime LastFiringTime) const = 0;
  88. virtual CWbemTime ComputeFirstFiringTime() const = 0;
  89. virtual HRESULT LoadFromWbemObject(IN IWbemClassObject* pObject) = 0;
  90. protected:
  91. static CStaticCritSec mstatic_cs;
  92. };
  93. //*****************************************************************************
  94. //
  95. // class CAbsoluteTimerInstruction
  96. //
  97. // A type of timer instruction which only fires once --- at the preset time.
  98. //
  99. //*****************************************************************************
  100. class CAbsoluteTimerInstruction : public CWBEMTimerInstruction
  101. {
  102. protected:
  103. CWbemTime m_When;
  104. public:
  105. CAbsoluteTimerInstruction() : CWBEMTimerInstruction(){}
  106. CWbemTime GetFiringTime() const{return m_When;}
  107. void SetFiringTime(CWbemTime When) {m_When = When;}
  108. public:
  109. CWbemTime ComputeNextFiringTime(CWbemTime LastFiringTime) const;
  110. CWbemTime ComputeFirstFiringTime() const;
  111. static HRESULT CheckObject(IWbemClassObject* pObject);
  112. HRESULT LoadFromWbemObject(IN IWbemClassObject* pObject);
  113. static INTERNAL LPCWSTR GetWbemClassName()
  114. {return L"__AbsoluteTimerInstruction";}
  115. virtual HRESULT Fire(long lNumTimes, CWbemTime NextFitingTime);
  116. };
  117. //*****************************************************************************
  118. //
  119. // class CIntervalTimerInstruction
  120. //
  121. // A type of timer instruction which fires every N milliseconds starting at
  122. // a given time.
  123. //
  124. //*****************************************************************************
  125. class CIntervalTimerInstruction : public CWBEMTimerInstruction
  126. {
  127. protected:
  128. CWbemTime m_Start; // not used
  129. CWbemInterval m_Interval;
  130. public:
  131. CIntervalTimerInstruction()
  132. : CWBEMTimerInstruction(), m_Start(), m_Interval()
  133. {}
  134. CWbemTime GetStart() const {return m_Start;}
  135. void SetStart(CWbemTime Start) {m_Start = Start;}
  136. CWbemInterval GetInterval() const {return m_Interval;}
  137. void SetInterval(CWbemInterval Interval) {m_Interval = Interval;}
  138. public:
  139. static HRESULT CheckObject(IWbemClassObject* pObject) {return S_OK;}
  140. CWbemTime ComputeNextFiringTime(CWbemTime LastFiringTime) const;
  141. CWbemTime ComputeFirstFiringTime() const;
  142. HRESULT LoadFromWbemObject(IN IWbemClassObject* pObject);
  143. static INTERNAL LPCWSTR GetWbemClassName()
  144. {return L"__IntervalTimerInstruction";}
  145. };
  146. //*****************************************************************************
  147. //
  148. // class CRecurringInstruction
  149. //
  150. // A more complex recurrence instruction. TBD
  151. //
  152. //*****************************************************************************
  153. class CRecurringTimerInstruction : public CWBEMTimerInstruction
  154. {
  155. // TBD
  156. public:
  157. CWbemTime ComputeNextFiringTime(CWbemTime LastFiringTime) const
  158. {return CWbemTime::GetInfinity();}
  159. CWbemTime ComputeFirstFiringTime() const
  160. {return CWbemTime::GetInfinity();}
  161. HRESULT LoadFromWbemObject(IN IWbemClassObject* pObject)
  162. {return E_UNEXPECTED;}
  163. static INTERNAL LPCWSTR GetWbemClassName()
  164. {return L"__RecurringTimerInstruction";}
  165. static HRESULT CheckObject(IWbemClassObject* pObject) {return S_OK;}
  166. };
  167. class CWinMgmtTimerGenerator : public CTimerGenerator
  168. {
  169. public:
  170. CWinMgmtTimerGenerator(CEss* pEss);
  171. HRESULT LoadTimerEventQueue(LPCWSTR wszNamespace,
  172. IWbemServices* pNamespace);
  173. HRESULT LoadTimerEventObject(LPCWSTR wszNamespace,
  174. IWbemServices* pNamespace,
  175. IWbemClassObject * pTimerInstruction,
  176. IWbemClassObject * pNextFiring = NULL);
  177. HRESULT LoadTimerEventObject(LPCWSTR wszNamespace,
  178. IWbemClassObject * pTimerInstruction);
  179. HRESULT CheckTimerInstruction(IWbemClassObject* pInst);
  180. HRESULT Remove(LPCWSTR wszNamespace, LPCWSTR wszId);
  181. HRESULT Remove(LPCWSTR wszNamespace);
  182. HRESULT FireInstruction(CWBEMTimerInstruction* pInst, long lNumFirings);
  183. virtual HRESULT Shutdown();
  184. HRESULT SaveAndRemove(LONG bIsSystemShutDown);
  185. void DumpStatistics(FILE* f, long lFlags);
  186. protected:
  187. class CIdTest : public CInstructionTest
  188. {
  189. protected:
  190. LPCWSTR m_wszId;
  191. LPCWSTR m_wszNamespace;
  192. public:
  193. CIdTest(LPCWSTR wszNamespace, LPCWSTR wszId)
  194. : m_wszId(wszId), m_wszNamespace(wszNamespace) {}
  195. BOOL operator()(CTimerInstruction* pInst);
  196. };
  197. class CNamespaceTest : public CInstructionTest
  198. {
  199. protected:
  200. LPCWSTR m_wszNamespace;
  201. public:
  202. CNamespaceTest(LPCWSTR wszNamespace)
  203. : m_wszNamespace(wszNamespace) {}
  204. BOOL operator()(CTimerInstruction* pInst);
  205. };
  206. protected:
  207. CEss* m_pEss;
  208. };
  209. #endif