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.

192 lines
5.6 KiB

  1. /**********************************************************************/
  2. /** Microsoft Passport **/
  3. /** Copyright(c) Microsoft Corporation, 1999 - 2001 **/
  4. /**********************************************************************/
  5. /*
  6. ppnotificationthread.h
  7. implement the methods runing a separte thread watching for registry
  8. changes, and timer for CCD refresh
  9. FILE HISTORY:
  10. */
  11. #ifndef __PPNOTIFICATIONTHREAD_H
  12. #define __PPNOTIFICATIONTHREAD_H
  13. #include <windows.h>
  14. #include <winbase.h>
  15. #include <atlbase.h>
  16. #include <msxml.h>
  17. #include "tstring"
  18. #include <vector>
  19. using namespace std;
  20. #include "PassportThread.hpp"
  21. #include "PassportLock.hpp"
  22. #include "PassportEvent.hpp"
  23. #include "PassportLockedInteger.hpp"
  24. #include "nexus.h"
  25. //� Notification types used in structure below
  26. #define NOTIF_CONFIG 1
  27. #define NOTIF_CCD 2
  28. //////////////////////////////////////////////////////////////////////////
  29. //
  30. // NOTIFICATION_CLIENT -- notification client
  31. //
  32. //
  33. typedef struct
  34. {
  35. DWORD dwNotificationType;
  36. union
  37. {
  38. IConfigurationUpdate* piConfigUpdate;
  39. ICCDUpdate* piCCDUpdate;
  40. } NotificationInterface;
  41. tstring strCCDName; //� Will be empty for config notif types
  42. HANDLE hClientHandle;
  43. }
  44. NOTIFICATION_CLIENT;
  45. typedef vector<NOTIFICATION_CLIENT> CLIENT_LIST;
  46. //////////////////////////////////////////////////////////////////////////
  47. //
  48. // CCD_INFO -- CCD timer element
  49. //
  50. //
  51. class CCD_INFO
  52. {
  53. public:
  54. tstring strCCDName;
  55. tstring strCCDURL;
  56. tstring strCCDLocalFile;
  57. DWORD dwCCDRefreshInterval;
  58. DWORD dwDefaultRefreshInterval;
  59. HANDLE hCCDTimer;
  60. CCD_INFO()
  61. {
  62. strCCDName = TEXT("");
  63. strCCDURL = TEXT("");
  64. strCCDLocalFile = TEXT("");
  65. dwCCDRefreshInterval = 0;
  66. dwDefaultRefreshInterval= 0;
  67. hCCDTimer = CreateWaitableTimer(NULL, TRUE, NULL);
  68. };
  69. CCD_INFO(const CCD_INFO& ci)
  70. {
  71. strCCDName = ci.strCCDName;
  72. strCCDURL = ci.strCCDURL;
  73. strCCDLocalFile = ci.strCCDLocalFile;
  74. dwCCDRefreshInterval = ci.dwCCDRefreshInterval;
  75. dwDefaultRefreshInterval= ci.dwDefaultRefreshInterval;
  76. HANDLE hProcess = GetCurrentProcess();
  77. DuplicateHandle(hProcess,
  78. ci.hCCDTimer,
  79. hProcess,
  80. &hCCDTimer, 0, FALSE, DUPLICATE_SAME_ACCESS);
  81. };
  82. ~CCD_INFO()
  83. {
  84. CloseHandle(hCCDTimer);
  85. }
  86. const CCD_INFO&
  87. operator = (const CCD_INFO& ci)
  88. {
  89. strCCDName = ci.strCCDName;
  90. strCCDURL = ci.strCCDURL;
  91. strCCDLocalFile = ci.strCCDLocalFile;
  92. dwCCDRefreshInterval = ci.dwCCDRefreshInterval;
  93. dwDefaultRefreshInterval= ci.dwDefaultRefreshInterval;
  94. CloseHandle(hCCDTimer);
  95. HANDLE hProcess = GetCurrentProcess();
  96. DuplicateHandle(hProcess,
  97. ci.hCCDTimer,
  98. hProcess,
  99. &hCCDTimer, 0, FALSE, DUPLICATE_SAME_ACCESS);
  100. return ci;
  101. }
  102. BOOL SetTimer(DWORD dwOneTimeRefreshInterval = 0xFFFFFFFF)
  103. {
  104. // Reset the timer.
  105. LARGE_INTEGER liDueTime;
  106. DWORD dwError;
  107. DWORD dwRefreshInterval = (dwOneTimeRefreshInterval != 0xFFFFFFFF ?
  108. dwOneTimeRefreshInterval :
  109. (dwCCDRefreshInterval != 0xFFFFFFFF ?
  110. dwCCDRefreshInterval :
  111. dwDefaultRefreshInterval
  112. )
  113. );
  114. liDueTime.QuadPart = -((LONGLONG)(dwRefreshInterval) * 10000000);
  115. if(!SetWaitableTimer(hCCDTimer, &liDueTime, 0, NULL, NULL, FALSE))
  116. {
  117. dwError = GetLastError();
  118. return FALSE;
  119. }
  120. return TRUE;
  121. }
  122. };
  123. typedef vector<CCD_INFO> CCD_INFO_LIST;
  124. //////////////////////////////////////////////////////////////////////////
  125. //
  126. // PpNotificationThread -- notification thread
  127. //
  128. //
  129. class PpNotificationThread : public PassportThread, public IConfigurationUpdate
  130. {
  131. public:
  132. PpNotificationThread();
  133. ~PpNotificationThread();
  134. HRESULT AddCCDClient(tstring& strCCDName, ICCDUpdate* piUpdate, HANDLE* phClientHandle);
  135. HRESULT AddLocalConfigClient(IConfigurationUpdate* piUpdate, HANDLE* phClientHandle);
  136. HRESULT RemoveClient(HANDLE hClientHandle);
  137. HRESULT GetCCD(tstring& strCCDName, IXMLDocument** ppiStream, BOOL bForceFetch = TRUE);
  138. void run(void);
  139. void LocalConfigurationUpdated(void);
  140. void stop(void);
  141. bool start(void);
  142. private:
  143. static PassportLockedInteger m_NextHandle;
  144. // Private methods.
  145. BOOL GetCCDInfo(tstring& strCCDName, CCD_INFO& ccdInfo);
  146. BOOL ReadCCDInfo(tstring& strCCDName, DWORD dwDefaultRefreshInterval, CRegKey& CCDRegKey);
  147. // Private data
  148. CLIENT_LIST m_ClientList;
  149. PassportLock m_ClientListLock;
  150. CCD_INFO_LIST m_aciCCDInfoList;
  151. PassportLock m_CCDInfoLock;
  152. PassportEvent m_StartupThread;
  153. PassportEvent m_ShutdownThread;
  154. PassportEvent m_ShutdownAck;
  155. };
  156. #endif // __PPNOTIFICATIONTHREAD_H