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.

238 lines
6.4 KiB

  1. /*++
  2. Copyright (C) 1999-2001 Microsoft Corporation
  3. Module Name:
  4. RESYNC2.H
  5. Abstract:
  6. Declares the various idle task
  7. History:
  8. --*/
  9. #ifndef _RESYNC2_H_
  10. #define _RESYNC2_H_
  11. #include <wmistr.h>
  12. #include <wmium.h>
  13. #include <sync.h>
  14. #define MAX_LOOP 0x100000
  15. #define LOAD_CTR_EVENT_NAME _T("WMI_SysEvent_LodCtr")
  16. #define UNLOAD_CTR_EVENT_NAME _T("WMI_SysEvent_UnLodCtr")
  17. #define REVERSE_DREDGE_EVENT_NAME_SET _T("WMI_RevAdap_Set")
  18. #define REVERSE_DREDGE_EVENT_NAME_ACK _T("WMI_RevAdap_ACK")
  19. //
  20. // these names containd the Idle word just because of a misunderstanding,
  21. // but we don't have idle task, just pending task at most
  22. //
  23. #define PENDING_TASK_START _T("WMI_ProcessIdleTasksStart")
  24. #define PENDING_TASK_COMPLETE _T("WMI_ProcessIdleTasksComplete")
  25. #define SIG_WDMEVENTS_BUSY ((DWORD)'EMDW')
  26. #define SIG_WDMEVENTS_FREE ((DWORD)'emdw')
  27. class CWDMListener
  28. {
  29. enum {
  30. Type_Added,
  31. Type_Removed
  32. };
  33. public:
  34. CWDMListener();
  35. ~CWDMListener();
  36. DWORD OpenAdd();
  37. DWORD CloseAdd();
  38. DWORD OpenRemove();
  39. DWORD CloseRemove();
  40. DWORD Register();
  41. VOID Unregister();
  42. static VOID NTAPI EvtCallBackAdd(VOID * pContext,BOOLEAN bTimerFired);
  43. static VOID NTAPI EvtCallBackRem(VOID * pContext,BOOLEAN bTimerFired);
  44. static VOID WINAPI WmiCallBack(PWNODE_HEADER Wnode, UINT_PTR NotificationContext);
  45. VOID EvtCallThis(BOOLEAN bTimerFired,int Type);
  46. private:
  47. DWORD m_dwSignature;
  48. WMIHANDLE m_hEventAdd;
  49. WMIHANDLE m_hEventRem;
  50. HANDLE m_hWaitAdd;
  51. HANDLE m_hWaitRem;
  52. BOOL m_UnInited;
  53. CCritSec m_cs;
  54. GUID m_GuidAdd;// = GUID_MOF_RESOURCE_ADDED_NOTIFICATION ;
  55. GUID m_GuidRem;// = GUID_MOF_RESOURCE_REMOVED_NOTIFICATION ;
  56. };
  57. #define SIG_COUNTEEVENTS_BUSY ((DWORD)'ETNC')
  58. #define SIG_COUNTEEVENTS_FREE ((DWORD)'etnc')
  59. class CCounterEvts
  60. {
  61. enum {
  62. Type_Load,
  63. Type_Unload
  64. };
  65. public:
  66. CCounterEvts();
  67. ~CCounterEvts();
  68. DWORD Init();
  69. VOID UnInit();
  70. DWORD Register();
  71. DWORD Unregister();
  72. static VOID NTAPI EvtCallBackLoad(VOID * pContext,BOOLEAN bTimerFired);
  73. static VOID NTAPI EvtCallBackUnload(VOID * pContext,BOOLEAN bTimerFired);
  74. static VOID NTAPI EvtCallBackPendingTask(VOID * pContext,BOOLEAN bTimerFired);
  75. VOID CallBack(BOOLEAN bTimerFired,int Type);
  76. VOID CallBackPending(BOOLEAN bTimerFired);
  77. BOOL IsInited(){return !m_Uninited; };
  78. HANDLE GetTaskCompleteEvent(){ return m_hPendingTasksComplete; };
  79. private:
  80. DWORD m_dwSignature;
  81. HANDLE m_hTerminateEvt;
  82. HANDLE m_LoadCtrEvent;
  83. HANDLE m_UnloadCtrEvent;
  84. HANDLE m_WaitLoadCtr;
  85. HANDLE m_WaitUnloadCtr;
  86. BOOL m_Uninited;
  87. HANDLE m_hWmiReverseAdapSetLodCtr;
  88. HANDLE m_hWmiReverseAdapLodCtrDone;
  89. HANDLE m_hWaitPendingTasksStart;
  90. HANDLE m_hPendingTasksStart;
  91. HANDLE m_hPendingTasksComplete;
  92. };
  93. DWORD ResyncPerf(DWORD dwReason);
  94. #define MAX_PROCESS_WAIT (10*60*1000)
  95. #define MAX_PROCESS_NUM (2)
  96. #define RESYNC_FULL_THROTTLE 0
  97. #define RESYNC_DELTA_THROTTLE 1
  98. #define RESYNC_RADAPD_THROTTLE 2
  99. #define RESYNC_FULL_RADAPD_THROTTLE 3
  100. #define RESYNC_DELTA_RADAPD_THROTTLE 4
  101. #define RESYNC_FULL_RADAPD_NOTHROTTLE 5
  102. #define RESYNC_TYPE_INITIAL 0
  103. #define RESYNC_TYPE_LODCTR 1
  104. #define RESYNC_TYPE_WDMEVENT 2
  105. #define RESYNC_TYPE_CLASSCREATION 2 // intentionally duplicated
  106. #define RESYNC_TYPE_PENDING_TASKS 3
  107. #define RESYNC_TYPE_MAX 4
  108. #define SIG_RESYNC_PERF ((DWORD)'YSER')
  109. class CMonitorEvents;
  110. //
  111. // the gate-ing is implemented with the ResyncPerfTask::bFree
  112. // The GetAvailable() will set the bFree to FALSE,
  113. // and any task completion will set that to TRUE.
  114. // A task can be completed:
  115. // immediatly in the Timer-Phase
  116. // this happens if the task has been disabled by ProcessIdleTasks
  117. // this happens if the ProcessIdleTasks command
  118. // will be re-processed when OutStandingProcess == 0
  119. // A task can be completed in the Event-Call back phase
  120. // when a process naturally exits or terminate process is invoked.
  121. // when there is an error in the machinery that creates the process
  122. //
  123. //
  124. class ResyncPerfTask{
  125. public:
  126. DWORD dwSig;
  127. BOOL bFree; // set under CritSec
  128. DWORD Type; // set by GetAvailable
  129. DWORD CmdType; // set by GetAvailable or the TimerCallback
  130. HANDLE hTimer; // set by the
  131. DWORD dwTimeDue; // set by GetAvailable
  132. CMonitorEvents * pMonitor; // set by the constructor
  133. HANDLE hProcess; // set by the DeltaDredge
  134. HANDLE hWaitHandle; //
  135. BOOL Enabled; // this is to disable an already scheduled stask
  136. };
  137. //
  138. //
  139. // MonitorEvents
  140. // This class monitors the Load-Unlodctr events
  141. // schedules the ResyncPerf
  142. // and monitors for WDM events in a Service-friendly way
  143. //
  144. ///////////////////////////////////////////////////////////////
  145. class CMonitorEvents
  146. {
  147. public:
  148. CMonitorEvents();
  149. ~CMonitorEvents();
  150. BOOL Init();
  151. BOOL Uninit();
  152. DWORD Register(); // called in the running/continue
  153. DWORD Unregister(BOOL bIsSystemShutDown); // called in the pause/stop
  154. VOID Lock(){ EnterCriticalSection(&m_cs); };
  155. VOID Unlock(){ LeaveCriticalSection(&m_cs); };
  156. VOID RegRead();
  157. ResyncPerfTask * GetAvailable(DWORD dwReason);
  158. DWORD GetFullTime(){ return m_dwTimeToFull; };
  159. FILETIME & GetTimeStamp(){ return m_FileTime; };
  160. static VOID NTAPI TimerCallBack(VOID * pContext,BOOLEAN bTimerFired);
  161. static VOID NTAPI EventCallBack(VOID * pContext,BOOLEAN bTimerFired);
  162. BOOL IsRegistred(){ return m_bRegistred; };
  163. HANDLE GetTaskCompleteEvent(){ return m_CntsEvts.GetTaskCompleteEvent(); };
  164. static BOOL WINAPI MonitorCtrlHandler( DWORD dwCtrlType );
  165. static BOOL CreateProcess_(TCHAR * pCmdLine,
  166. CMonitorEvents * pMonitor,
  167. ResyncPerfTask * pPerf);
  168. // public to avoid accessors
  169. LONG m_OutStandingProcesses ;
  170. BOOL m_bFullReverseNeeded;
  171. private:
  172. BOOL m_bRegistred;
  173. DWORD m_dwSig;
  174. BOOL m_bInit;
  175. CRITICAL_SECTION m_cs;
  176. CCounterEvts m_CntsEvts;
  177. CWDMListener m_WDMListener;
  178. ResyncPerfTask m_ResyncTasks[RESYNC_TYPE_MAX];
  179. DWORD m_dwADAPDelaySec;
  180. DWORD m_dwLodCtrDelaySec;
  181. DWORD m_dwTimeToFull;
  182. DWORD m_dwTimeToKillAdap;
  183. FILETIME m_FileTime;
  184. };
  185. #endif /**/