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.

443 lines
14 KiB

  1. /*
  2. Copyright (c) 1997-1999 Microsoft Corporation.
  3. File: Win32Clock.H
  4. Description:
  5. Alarm event provider - header file defines alarm provider class
  6. History:
  7. */
  8. #ifndef _WIN32CLOCKPROV_H_
  9. #define _WIN32CLOCKPROV_H_
  10. #include <objbase.h>
  11. #include <wbemprov.h>
  12. #include "tss.h"
  13. #include "datep.h"
  14. #include <unk.h>
  15. /*
  16. class Win32_CurrentTime
  17. {
  18. uint16 Year;
  19. uint32 Month;
  20. uint32 Day;
  21. uint32 DayOfWeek;
  22. uint32 WeekInMonth;
  23. uint32 Quarter;
  24. uint32 Hour;
  25. uint32 Minute;
  26. uint32 Second;
  27. };
  28. */
  29. #define WIN32LOCALTIMECLASS L"Win32_LocalTime"
  30. #define WIN32UTCTIMECLASS L"Win32_UTCTime"
  31. #define INSTMODEVCLASS L"__InstanceModificationEvent"
  32. template <class T> class CArray
  33. {
  34. int
  35. m_nElts;
  36. struct _Node { ULONG m_Key; T *m_pT; _Node *m_pNext; }
  37. *m_pHead;
  38. CRITICAL_SECTION
  39. m_hModificationLock;
  40. public:
  41. CArray(void)
  42. {
  43. m_pHead = NULL; m_nElts = 0;
  44. InitializeCriticalSection(&m_hModificationLock);
  45. }
  46. ~CArray(void)
  47. {
  48. DeleteCriticalSection(&m_hModificationLock);
  49. }
  50. void Lock(void)
  51. { EnterCriticalSection(&m_hModificationLock); }
  52. void UnLock(void)
  53. { LeaveCriticalSection(&m_hModificationLock); }
  54. void Insert(T *pT, ULONG Key)
  55. // **** to check for dup. keys, change this to sorted order
  56. {
  57. Lock();
  58. _Node
  59. *pNewNode = NULL;
  60. if(Key == -1) return;
  61. pNewNode = new _Node();
  62. if(NULL == pNewNode) return;
  63. pNewNode->m_pT = pT; pT->AddRef();
  64. pNewNode->m_Key = Key;
  65. pNewNode->m_pNext = m_pHead;
  66. m_pHead = pNewNode;
  67. m_nElts++;
  68. UnLock();
  69. }
  70. void Remove(T *pT)
  71. {
  72. Lock();
  73. _Node
  74. *pCurrent = m_pHead,
  75. *pPrev = NULL;
  76. // **** find element using pointer
  77. while((NULL != pCurrent) && (pCurrent->m_pT != pT))
  78. {
  79. pPrev = pCurrent;
  80. pCurrent = pCurrent->m_pNext;
  81. }
  82. // **** remove element, if found, from queue
  83. if(NULL != pCurrent)
  84. {
  85. if(NULL == pPrev)
  86. m_pHead = m_pHead->m_pNext;
  87. else
  88. pPrev->m_pNext = pCurrent->m_pNext;
  89. pCurrent->m_pT->Release();
  90. delete pCurrent;
  91. m_nElts--;
  92. }
  93. UnLock();
  94. }
  95. // **** find element by Index
  96. T* operator[] (ULONG Index)
  97. {
  98. _Node
  99. *pCurrent = m_pHead;
  100. // **** get element using array index
  101. if( Index >= m_nElts )
  102. return NULL;
  103. while((NULL != pCurrent) && (Index > 0)) // optimize?
  104. {
  105. pCurrent = pCurrent->m_pNext;
  106. Index--;
  107. }
  108. if(NULL != pCurrent)
  109. return pCurrent->m_pT;
  110. return NULL;
  111. }
  112. // **** get element by key
  113. T* operator() (ULONG Key, BOOL bLock = FALSE)
  114. {
  115. if(TRUE == bLock) Lock();
  116. _Node
  117. *pCurrent = m_pHead;
  118. // **** find element using Key
  119. while((pCurrent != NULL) && (pCurrent->m_Key != Key)) // optimize?
  120. pCurrent = pCurrent->m_pNext;
  121. if(NULL != pCurrent)
  122. return pCurrent->m_pT;
  123. else
  124. if(TRUE == bLock) UnLock();
  125. return NULL;
  126. }
  127. };
  128. class CWin32Clock
  129. :
  130. public IWbemEventProvider,
  131. public IWbemEventProviderQuerySink,
  132. public IWbemServices,
  133. public IWbemProviderInit
  134. {
  135. public:
  136. class CScheduledEvent : public CTimerInstruction
  137. {
  138. public:
  139. enum { TypeNONE = 0, TypeUTC, TypeLocal };
  140. ULONG
  141. m_Type,
  142. m_cRef, // reference count on this object
  143. m_dwId; // unique id assigned by WMI
  144. ULONGLONG
  145. m_stLastFiringTime; // the first, and possibly only, firing
  146. // time for the event generator
  147. CWin32Clock
  148. *m_pWin32Clock; // ptr back to clock obj containing
  149. // this CScheduledEvent object
  150. wchar_t
  151. *m_WQLStmt; // WQL stmt that defines behavior for
  152. // this CScheduledEvent object
  153. int
  154. m_nDatePatterns; // # of date pattern objects
  155. WQLDateTime
  156. m_WQLTime; // interprets WQL statement and
  157. // calculates next firing time
  158. // Local members
  159. CScheduledEvent();
  160. ~CScheduledEvent();
  161. HRESULT Init(CWin32Clock *pClock, wchar_t *WQLStmt, ULONG dwId);
  162. HRESULT ReInit(wchar_t *WQLStmt);
  163. void GetTime(SYSTEMTIME *CurrentTime) const;
  164. void GetFileTime(FILETIME *CurrentTime) const;
  165. // Inherited from CTimerInstruction
  166. void AddRef();
  167. void Release();
  168. int GetInstructionType();
  169. CWbemTime GetNextFiringTime(CWbemTime LastFiringTime,
  170. long* plFiringCount) const;
  171. CWbemTime GetFirstFiringTime() const;
  172. HRESULT Fire(long lNumTimes, CWbemTime NextFiringTime);
  173. };
  174. CLifeControl* m_pControl;
  175. CCritSec m_csWin32Clock;
  176. // **** WMI attributes for both Event and Instance providers
  177. CTimerGenerator m_Timer; // timer object to hold pending events
  178. ULONG m_cRef; // reference count on this object
  179. IWbemServices *m_pNs; // resource handle to wmi service daemon
  180. IWbemClassObject *m_pLocalTimeClassDef; // CIM class def for Win32_CurrentTime
  181. IWbemClassObject *m_pUTCTimeClassDef; // CIM class def for Win32_CurrentTime
  182. // **** WMI Event Provider specific attributes
  183. ULONGLONG m_MostRecentLocalFiringTime;
  184. ULONGLONG m_MostRecentUTCFiringTime;
  185. IWbemObjectSink *m_pSink; // sink object in which to place inst. objs
  186. IWbemClassObject *m_pInstModClassDef; // class def for __InstanceModificationEvent
  187. HANDLE m_ClockResetThread; // holds thread that adjusts firing times
  188. // when the clock is reset
  189. HWND m_hEventWindowHandle;
  190. CArray<CScheduledEvent> m_EventArray; // array of clock provider objects
  191. public:
  192. CWin32Clock(CLifeControl* pControl);
  193. ~CWin32Clock();
  194. // local members
  195. static DWORD AsyncEventThread(LPVOID pArg);
  196. static HRESULT SystemTimeToWin32_CurrentTime(IWbemClassObject *pClassDef, IWbemClassObject ** pNewInst, SYSTEMTIME *TheTime);
  197. HRESULT SendEvent(IWbemClassObject *pSystemTime);
  198. HRESULT ReAlignToCurrentTime(void);
  199. // IUnknown members
  200. STDMETHODIMP QueryInterface(REFIID, LPVOID *);
  201. STDMETHODIMP_(ULONG) AddRef(void);
  202. STDMETHODIMP_(ULONG) Release(void);
  203. // Inherited from IWbemEventProvider
  204. HRESULT STDMETHODCALLTYPE ProvideEvents(
  205. /* [in] */ IWbemObjectSink __RPC_FAR *pSink,
  206. /* [in] */ long lFlags);
  207. // Inherited from IWbemEventProviderQuerySink
  208. HRESULT STDMETHODCALLTYPE NewQuery(
  209. /* [in] */ unsigned long dwId,
  210. /* [in] */ wchar_t *wszQueryLanguage,
  211. /* [in] */ wchar_t *wszQuery);
  212. HRESULT STDMETHODCALLTYPE CancelQuery(
  213. /* [in] */ unsigned long dwId);
  214. // Inherited from IWbemProviderInit
  215. HRESULT STDMETHODCALLTYPE Initialize(
  216. /* [in] */ LPWSTR pszUser,
  217. /* [in] */ LONG lFlags,
  218. /* [in] */ LPWSTR pszNamespace,
  219. /* [in] */ LPWSTR pszLocale,
  220. /* [in] */ IWbemServices __RPC_FAR *pNamespace,
  221. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  222. /* [in] */ IWbemProviderInitSink __RPC_FAR *pInitSink);
  223. // Inherited from IWbemServices
  224. HRESULT STDMETHODCALLTYPE OpenNamespace(
  225. /* [in] */ const BSTR Namespace,
  226. /* [in] */ long lFlags,
  227. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  228. /* [unique][in][out] */ IWbemServices __RPC_FAR *__RPC_FAR *ppWorkingNamespace,
  229. /* [unique][in][out] */ IWbemCallResult __RPC_FAR *__RPC_FAR *ppResult) {return WBEM_E_NOT_SUPPORTED;};
  230. HRESULT STDMETHODCALLTYPE CancelAsyncCall(
  231. /* [in] */ IWbemObjectSink __RPC_FAR *pSink) {return WBEM_E_NOT_SUPPORTED;};
  232. HRESULT STDMETHODCALLTYPE QueryObjectSink(
  233. /* [in] */ long lFlags,
  234. /* [out] */ IWbemObjectSink __RPC_FAR *__RPC_FAR *ppResponseHandler) {return WBEM_E_NOT_SUPPORTED;};
  235. HRESULT STDMETHODCALLTYPE GetObject(
  236. /* [in] */ const BSTR ObjectPath,
  237. /* [in] */ long lFlags,
  238. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  239. /* [unique][in][out] */ IWbemClassObject __RPC_FAR *__RPC_FAR *ppObject,
  240. /* [unique][in][out] */ IWbemCallResult __RPC_FAR *__RPC_FAR *ppCallResult) {return WBEM_E_NOT_SUPPORTED;};
  241. HRESULT STDMETHODCALLTYPE GetObjectAsync(
  242. /* [in] */ const BSTR ObjectPath,
  243. /* [in] */ long lFlags,
  244. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  245. /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler);
  246. HRESULT STDMETHODCALLTYPE PutClass(
  247. /* [in] */ IWbemClassObject __RPC_FAR *pObject,
  248. /* [in] */ long lFlags,
  249. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  250. /* [unique][in][out] */ IWbemCallResult __RPC_FAR *__RPC_FAR *ppCallResult) {return WBEM_E_NOT_SUPPORTED;};
  251. HRESULT STDMETHODCALLTYPE PutClassAsync(
  252. /* [in] */ IWbemClassObject __RPC_FAR *pObject,
  253. /* [in] */ long lFlags,
  254. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  255. /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler) {return WBEM_E_NOT_SUPPORTED;};
  256. HRESULT STDMETHODCALLTYPE DeleteClass(
  257. /* [in] */ const BSTR Class,
  258. /* [in] */ long lFlags,
  259. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  260. /* [unique][in][out] */ IWbemCallResult __RPC_FAR *__RPC_FAR *ppCallResult) {return WBEM_E_NOT_SUPPORTED;};
  261. HRESULT STDMETHODCALLTYPE DeleteClassAsync(
  262. /* [in] */ const BSTR Class,
  263. /* [in] */ long lFlags,
  264. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  265. /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler) {return WBEM_E_NOT_SUPPORTED;};
  266. HRESULT STDMETHODCALLTYPE CreateClassEnum(
  267. /* [in] */ const BSTR Superclass,
  268. /* [in] */ long lFlags,
  269. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  270. /* [out] */ IEnumWbemClassObject __RPC_FAR *__RPC_FAR *ppEnum) {return WBEM_E_NOT_SUPPORTED;};
  271. HRESULT STDMETHODCALLTYPE CreateClassEnumAsync(
  272. /* [in] */ const BSTR Superclass,
  273. /* [in] */ long lFlags,
  274. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  275. /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler) {return WBEM_E_NOT_SUPPORTED;};
  276. HRESULT STDMETHODCALLTYPE PutInstance(
  277. /* [in] */ IWbemClassObject __RPC_FAR *pInst,
  278. /* [in] */ long lFlags,
  279. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  280. /* [unique][in][out] */ IWbemCallResult __RPC_FAR *__RPC_FAR *ppCallResult) {return WBEM_E_NOT_SUPPORTED;};
  281. HRESULT STDMETHODCALLTYPE PutInstanceAsync(
  282. /* [in] */ IWbemClassObject __RPC_FAR *pInst,
  283. /* [in] */ long lFlags,
  284. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  285. /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler) {return WBEM_E_NOT_SUPPORTED;};
  286. HRESULT STDMETHODCALLTYPE DeleteInstance(
  287. /* [in] */ const BSTR ObjectPath,
  288. /* [in] */ long lFlags,
  289. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  290. /* [unique][in][out] */ IWbemCallResult __RPC_FAR *__RPC_FAR *ppCallResult) {return WBEM_E_NOT_SUPPORTED;};
  291. HRESULT STDMETHODCALLTYPE DeleteInstanceAsync(
  292. /* [in] */ const BSTR ObjectPath,
  293. /* [in] */ long lFlags,
  294. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  295. /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler) {return WBEM_E_NOT_SUPPORTED;};
  296. HRESULT STDMETHODCALLTYPE CreateInstanceEnum(
  297. /* [in] */ const BSTR Class,
  298. /* [in] */ long lFlags,
  299. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  300. /* [out] */ IEnumWbemClassObject __RPC_FAR *__RPC_FAR *ppEnum) {return WBEM_E_NOT_SUPPORTED;};
  301. HRESULT STDMETHODCALLTYPE CreateInstanceEnumAsync(
  302. /* [in] */ const BSTR Class,
  303. /* [in] */ long lFlags,
  304. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  305. /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler);
  306. HRESULT STDMETHODCALLTYPE ExecQuery(
  307. /* [in] */ const BSTR QueryLanguage,
  308. /* [in] */ const BSTR Query,
  309. /* [in] */ long lFlags,
  310. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  311. /* [out] */ IEnumWbemClassObject __RPC_FAR *__RPC_FAR *ppEnum) {return WBEM_E_NOT_SUPPORTED;};
  312. HRESULT STDMETHODCALLTYPE ExecQueryAsync(
  313. /* [in] */ const BSTR QueryLanguage,
  314. /* [in] */ const BSTR Query,
  315. /* [in] */ long lFlags,
  316. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  317. /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler) {return WBEM_E_NOT_SUPPORTED;};
  318. HRESULT STDMETHODCALLTYPE ExecNotificationQuery(
  319. /* [in] */ const BSTR QueryLanguage,
  320. /* [in] */ const BSTR Query,
  321. /* [in] */ long lFlags,
  322. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  323. /* [out] */ IEnumWbemClassObject __RPC_FAR *__RPC_FAR *ppEnum) {return WBEM_E_NOT_SUPPORTED;};
  324. HRESULT STDMETHODCALLTYPE ExecNotificationQueryAsync(
  325. /* [in] */ const BSTR QueryLanguage,
  326. /* [in] */ const BSTR Query,
  327. /* [in] */ long lFlags,
  328. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  329. /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler) {return WBEM_E_NOT_SUPPORTED;};
  330. HRESULT STDMETHODCALLTYPE ExecMethod( const BSTR, const BSTR, long, IWbemContext*,
  331. IWbemClassObject*, IWbemClassObject**, IWbemCallResult**) {return WBEM_E_NOT_SUPPORTED;}
  332. HRESULT STDMETHODCALLTYPE ExecMethodAsync( const BSTR, const BSTR, long,
  333. IWbemContext*, IWbemClassObject*, IWbemObjectSink*) {return WBEM_E_NOT_SUPPORTED;}
  334. };
  335. #endif