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.

372 lines
11 KiB

  1. //
  2. // Driver Verifier UI
  3. // Copyright (c) Microsoft Corporation, 1999
  4. //
  5. //
  6. // module: CntPage.cxx
  7. // author: DMihai
  8. // created: 01/04/98
  9. //
  10. // Description:
  11. //
  12. // Global Counters PropertyPage.
  13. #include "stdafx.h"
  14. #include "drvvctrl.hxx"
  15. #include "CntPage.hxx"
  16. #include "DrvCSht.hxx"
  17. #ifdef _DEBUG
  18. #define new DEBUG_NEW
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22. // timer ID
  23. #define REFRESH_TIMER_ID 0x4321
  24. // manual, high, normal, low speed
  25. #define REFRESH_SPEED_VARS 4
  26. // timer intervals in millisec for manual, high, normal, low speed
  27. static UINT uTimerIntervals[ REFRESH_SPEED_VARS ] =
  28. {
  29. 0, // Manual
  30. 1000, // High Speed
  31. 5000, // Normal Speed
  32. 10000 // Low Speed
  33. };
  34. //
  35. // help IDs
  36. //
  37. static DWORD MyHelpIds[] =
  38. {
  39. IDC_COUNT_RAISEIRQL_EDIT, IDH_DV_CountersTab_other_irql,
  40. IDC_COUNT_ACQSPINL_EDIT, IDH_DV_CountersTab_other_spinlocks,
  41. IDC_COUNT_SYNCREX_EDIT, IDH_DV_CountersTab_other_sync,
  42. IDC_COUNT_TRIMS_EDIT, IDH_DV_CountersTab_other_trims,
  43. IDC_COUNT_ALLOC_ATTEMPT_EDIT, IDH_DV_CountersTab_allocations_attempt,
  44. IDC_COUNT_ALLOC_SUCC_EDIT, IDH_DV_CountersTab_allocations_succeed,
  45. IDC_COUNT_ALLOCSUCC_SPECPOOL_EDIT, IDH_DV_CountersTab_allocations_succeed_pool,
  46. IDC_COUNT_ALLOC_NOTAG_EDIT, IDH_DV_CountersTab_allocations_wotag,
  47. IDC_COUNT_ALLOC_FAILED_EDIT, IDH_DV_CountersTab_allocations_failed,
  48. IDC_COUNT_ALLOC_FAILEDDEL_EDIT, IDH_DV_CountersTab_other_faults,
  49. IDC_COUNT_REFRESH_BUTTON, IDH_DV_common_refresh_nowbutton,
  50. IDC_COUNT_MANUAL_RADIO, IDH_DV_common_refresh_manual,
  51. IDC_COUNT_HSPEED_RADIO, IDH_DV_common_refresh_high,
  52. IDC_COUNT_NORM_RADIO, IDH_DV_common_refresh_normal,
  53. IDC_COUNT_LOW_RADIO, IDH_DV_common_refresh_low,
  54. 0, 0
  55. };
  56. /////////////////////////////////////////////////////////////////////
  57. static void GetStringFromULONG( CString &strValue, ULONG uValue )
  58. {
  59. LPTSTR lptstrValue = strValue.GetBuffer( 64 );
  60. if( lptstrValue != NULL )
  61. {
  62. _stprintf( lptstrValue, _T( "%lu" ), uValue );
  63. strValue.ReleaseBuffer();
  64. }
  65. else
  66. {
  67. ASSERT( FALSE );
  68. strValue.Empty();
  69. }
  70. }
  71. /////////////////////////////////////////////////////////////////////
  72. // CCountersPage property page
  73. IMPLEMENT_DYNCREATE(CCountersPage, CPropertyPage)
  74. CCountersPage::CCountersPage()
  75. : CPropertyPage(CCountersPage::IDD)
  76. {
  77. //{{AFX_DATA_INIT(CCountersPage)
  78. m_strAcqSpinlEdit = _T("");
  79. m_strAllocAttemptEdit = _T("");
  80. m_strAllocFailed = _T("");
  81. m_strAllocFailedDelEdit = _T("");
  82. m_strAllocNoTagEdit = _T("");
  83. m_strAllocSucc = _T("");
  84. m_strAllocSuccSpecPool = _T("");
  85. m_strRaiseIrqLevelEdit = _T("");
  86. m_strSyncrExEdit = _T("");
  87. m_strTrimsEdit = _T("");
  88. m_nUpdateIntervalIndex = 2;
  89. //}}AFX_DATA_INIT
  90. m_uTimerHandler = 0;
  91. }
  92. void CCountersPage::DoDataExchange(CDataExchange* pDX)
  93. {
  94. if( ! pDX->m_bSaveAndValidate )
  95. {
  96. // query the kernel
  97. if( KrnGetSystemVerifierState( &m_KrnVerifState ) &&
  98. m_KrnVerifState.DriverCount > 0 )
  99. {
  100. // RaiseIrqls
  101. GetStringFromULONG( m_strRaiseIrqLevelEdit,
  102. m_KrnVerifState.RaiseIrqls );
  103. // AcquireSpinLocks
  104. GetStringFromULONG( m_strAcqSpinlEdit,
  105. m_KrnVerifState.AcquireSpinLocks );
  106. // SynchronizeExecutions
  107. GetStringFromULONG( m_strSyncrExEdit,
  108. m_KrnVerifState.SynchronizeExecutions );
  109. // AllocationsAttempted
  110. GetStringFromULONG( m_strAllocAttemptEdit,
  111. m_KrnVerifState.AllocationsAttempted );
  112. // AllocationsSucceeded
  113. GetStringFromULONG( m_strAllocSucc,
  114. m_KrnVerifState.AllocationsSucceeded );
  115. // AllocationsSucceededSpecialPool
  116. GetStringFromULONG( m_strAllocSuccSpecPool,
  117. m_KrnVerifState.AllocationsSucceededSpecialPool );
  118. // AllocationsWithNoTag
  119. GetStringFromULONG( m_strAllocNoTagEdit,
  120. m_KrnVerifState.AllocationsWithNoTag );
  121. // Trims
  122. GetStringFromULONG( m_strTrimsEdit,
  123. m_KrnVerifState.Trims );
  124. // AllocationsFailed
  125. GetStringFromULONG( m_strAllocFailed,
  126. m_KrnVerifState.AllocationsFailed );
  127. // AllocationsFailedDeliberately
  128. GetStringFromULONG( m_strAllocFailedDelEdit,
  129. m_KrnVerifState.AllocationsFailedDeliberately );
  130. }
  131. else
  132. {
  133. // RaiseIrqls
  134. VERIFY( m_strRaiseIrqLevelEdit.LoadString( IDS_ZERO ) );
  135. // AcquireSpinLocks
  136. VERIFY( m_strAcqSpinlEdit.LoadString( IDS_ZERO ) );
  137. // SynchronizeExecutions
  138. VERIFY( m_strSyncrExEdit.LoadString( IDS_ZERO ) );
  139. // AllocationsAttempted
  140. VERIFY( m_strAllocAttemptEdit.LoadString( IDS_ZERO ) );
  141. // AllocationsSucceeded
  142. VERIFY( m_strAllocSucc.LoadString( IDS_ZERO ) );
  143. // AllocationsSucceededSpecialPool
  144. VERIFY( m_strAllocSuccSpecPool.LoadString( IDS_ZERO ) );
  145. // AllocationsWithNoTag
  146. VERIFY( m_strAllocNoTagEdit.LoadString( IDS_ZERO ) );
  147. // Trims
  148. VERIFY( m_strTrimsEdit.LoadString( IDS_ZERO ) );
  149. // AllocationsFailed
  150. VERIFY( m_strAllocFailed.LoadString( IDS_ZERO ) );
  151. // AllocationsFailedDeliberately
  152. VERIFY( m_strAllocFailedDelEdit.LoadString( IDS_ZERO ) );
  153. }
  154. }
  155. CPropertyPage::DoDataExchange(pDX);
  156. //{{AFX_DATA_MAP(CCountersPage)
  157. DDX_Text(pDX, IDC_COUNT_ACQSPINL_EDIT, m_strAcqSpinlEdit);
  158. DDX_Text(pDX, IDC_COUNT_ALLOC_ATTEMPT_EDIT, m_strAllocAttemptEdit);
  159. DDX_Text(pDX, IDC_COUNT_ALLOC_FAILED_EDIT, m_strAllocFailed);
  160. DDX_Text(pDX, IDC_COUNT_ALLOC_FAILEDDEL_EDIT, m_strAllocFailedDelEdit);
  161. DDX_Text(pDX, IDC_COUNT_ALLOC_NOTAG_EDIT, m_strAllocNoTagEdit);
  162. DDX_Text(pDX, IDC_COUNT_ALLOC_SUCC_EDIT, m_strAllocSucc);
  163. DDX_Text(pDX, IDC_COUNT_ALLOCSUCC_SPECPOOL_EDIT, m_strAllocSuccSpecPool);
  164. DDX_Text(pDX, IDC_COUNT_RAISEIRQL_EDIT, m_strRaiseIrqLevelEdit);
  165. DDX_Text(pDX, IDC_COUNT_SYNCREX_EDIT, m_strSyncrExEdit);
  166. DDX_Text(pDX, IDC_COUNT_TRIMS_EDIT, m_strTrimsEdit);
  167. DDX_Radio(pDX, IDC_COUNT_MANUAL_RADIO, m_nUpdateIntervalIndex);
  168. //}}AFX_DATA_MAP
  169. }
  170. BEGIN_MESSAGE_MAP(CCountersPage, CPropertyPage)
  171. //{{AFX_MSG_MAP(CCountersPage)
  172. ON_BN_CLICKED(IDC_COUNT_REFRESH_BUTTON, OnCountRefreshButton)
  173. ON_WM_TIMER()
  174. ON_BN_CLICKED(IDC_COUNT_HSPEED_RADIO, OnCountHspeedRadio)
  175. ON_BN_CLICKED(IDC_COUNT_LOW_RADIO, OnCountLowRadio)
  176. ON_BN_CLICKED(IDC_COUNT_MANUAL_RADIO, OnCountManualRadio)
  177. ON_BN_CLICKED(IDC_COUNT_NORM_RADIO, OnCountNormRadio)
  178. ON_MESSAGE( WM_HELP, OnHelp )
  179. ON_MESSAGE( WM_CONTEXTMENU, OnContextMenu )
  180. //}}AFX_MSG_MAP
  181. END_MESSAGE_MAP()
  182. /////////////////////////////////////////////////////////////////////
  183. void CCountersPage::OnRefreshTimerChanged()
  184. {
  185. UINT uTimerElapse = 0;
  186. // kill the pending timer
  187. if( m_uTimerHandler != 0 )
  188. {
  189. VERIFY( KillTimer( REFRESH_TIMER_ID ) );
  190. }
  191. // sanity check
  192. if( m_nUpdateIntervalIndex < 0 ||
  193. m_nUpdateIntervalIndex >= REFRESH_SPEED_VARS )
  194. {
  195. m_nUpdateIntervalIndex = 0;
  196. CheckRadioButton( IDC_COUNT_MANUAL_RADIO, IDC_COUNT_LOW_RADIO,
  197. IDC_COUNT_MANUAL_RADIO );
  198. }
  199. // new timer interval
  200. uTimerElapse = uTimerIntervals[ m_nUpdateIntervalIndex ];
  201. if( uTimerElapse > 0 )
  202. {
  203. VERIFY( m_uTimerHandler = SetTimer( REFRESH_TIMER_ID,
  204. uTimerElapse, NULL ) );
  205. }
  206. }
  207. /////////////////////////////////////////////////////////////////////
  208. // CCountersPage message handlers
  209. BOOL CCountersPage::OnInitDialog()
  210. {
  211. CPropertyPage::OnInitDialog();
  212. OnRefreshTimerChanged();
  213. return TRUE; // return TRUE unless you set the focus to a control
  214. // EXCEPTION: OCX Property Pages should return FALSE
  215. }
  216. /////////////////////////////////////////////////////////////////////
  217. void CCountersPage::OnCountRefreshButton()
  218. {
  219. UpdateData( FALSE );
  220. }
  221. /////////////////////////////////////////////////////////////////////
  222. void CCountersPage::OnTimer(UINT nIDEvent)
  223. {
  224. if( nIDEvent == REFRESH_TIMER_ID )
  225. {
  226. CDrvChkSheet *pParentSheet = (CDrvChkSheet *)GetParent();
  227. if( pParentSheet != NULL )
  228. {
  229. ASSERT_VALID( pParentSheet );
  230. if( pParentSheet->GetActivePage() == this )
  231. {
  232. // refresh the displayed data
  233. OnCountRefreshButton();
  234. }
  235. }
  236. }
  237. CPropertyPage::OnTimer(nIDEvent);
  238. }
  239. /////////////////////////////////////////////////////////////////////
  240. BOOL CCountersPage::OnQueryCancel()
  241. {
  242. // give parent PropertySheet a chance to refuse the Cancel if needed
  243. CDrvChkSheet *pParentSheet = (CDrvChkSheet *)GetParent();
  244. if( pParentSheet != NULL )
  245. {
  246. ASSERT_VALID( pParentSheet );
  247. if( ! pParentSheet->OnQueryCancel() )
  248. {
  249. return FALSE;
  250. }
  251. }
  252. return CPropertyPage::OnQueryCancel();
  253. }
  254. /////////////////////////////////////////////////////////////////////
  255. BOOL CCountersPage::OnApply()
  256. {
  257. // refuse to apply
  258. // (we don't use the standard PropertSheet buttons; Apply, OK)
  259. return FALSE;
  260. }
  261. /////////////////////////////////////////////////////////////////////
  262. void CCountersPage::OnCountManualRadio()
  263. {
  264. // switch to manual refresh
  265. m_nUpdateIntervalIndex = 0;
  266. OnRefreshTimerChanged();
  267. }
  268. void CCountersPage::OnCountHspeedRadio()
  269. {
  270. // switch to high speed refresh
  271. m_nUpdateIntervalIndex = 1;
  272. OnRefreshTimerChanged();
  273. }
  274. void CCountersPage::OnCountNormRadio()
  275. {
  276. // switch to normal speed refresh
  277. m_nUpdateIntervalIndex = 2;
  278. OnRefreshTimerChanged();
  279. }
  280. void CCountersPage::OnCountLowRadio()
  281. {
  282. // switch to low speed refresh
  283. m_nUpdateIntervalIndex = 3;
  284. OnRefreshTimerChanged();
  285. }
  286. /////////////////////////////////////////////////////////////
  287. LONG CCountersPage::OnHelp( WPARAM wParam, LPARAM lParam )
  288. {
  289. LONG lResult = 0;
  290. LPHELPINFO lpHelpInfo = (LPHELPINFO)lParam;
  291. ::WinHelp(
  292. (HWND) lpHelpInfo->hItemHandle,
  293. VERIFIER_HELP_FILE,
  294. HELP_WM_HELP,
  295. (DWORD_PTR) MyHelpIds );
  296. return lResult;
  297. }
  298. /////////////////////////////////////////////////////////////
  299. LONG CCountersPage::OnContextMenu( WPARAM wParam, LPARAM lParam )
  300. {
  301. LONG lResult = 0;
  302. ::WinHelp(
  303. (HWND) wParam,
  304. VERIFIER_HELP_FILE,
  305. HELP_CONTEXTMENU,
  306. (DWORD_PTR) MyHelpIds );
  307. return lResult;
  308. }