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.

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