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.

450 lines
12 KiB

  1. /*++
  2. Copyright (C) 1998-1999 Microsoft Corporation
  3. Module Name:
  4. tracprop.cpp
  5. Abstract:
  6. Implementation of the advanced trace buffer property page.
  7. --*/
  8. #include "stdafx.h"
  9. #include <pdh.h> // for MIN_TIME_VALUE, MAX_TIME_VALUE
  10. #include "smcfgmsg.h"
  11. #include "smlogs.h"
  12. #include "smtraceq.h"
  13. #include "tracprop.h"
  14. #ifdef _DEBUG
  15. #define new DEBUG_NEW
  16. #undef THIS_FILE
  17. static char THIS_FILE[] = __FILE__;
  18. #endif
  19. static ULONG
  20. s_aulHelpIds[] =
  21. {
  22. IDC_TRACE_BUF_FLUSH_CHECK, IDH_TRACE_BUF_FLUSH_CHECK,
  23. IDC_TRACE_BUFFER_SIZE_EDIT, IDH_TRACE_BUFFER_SIZE_EDIT,
  24. IDC_TRACE_BUFFER_SIZE_SPIN, IDH_TRACE_BUFFER_SIZE_EDIT,
  25. IDC_TRACE_MIN_BUF_EDIT, IDH_TRACE_MIN_BUF_EDIT,
  26. IDC_TRACE_MIN_BUF_SPIN, IDH_TRACE_MIN_BUF_EDIT,
  27. IDC_TRACE_MAX_BUF_EDIT, IDH_TRACE_MAX_BUF_EDIT,
  28. IDC_TRACE_MAX_BUF_SPIN, IDH_TRACE_MAX_BUF_EDIT,
  29. IDC_TRACE_FLUSH_INT_EDIT, IDH_TRACE_FLUSH_INT_EDIT,
  30. IDC_TRACE_FLUSH_INT_SPIN, IDH_TRACE_FLUSH_INT_EDIT,
  31. 0,0
  32. };
  33. /////////////////////////////////////////////////////////////////////////////
  34. // CTraceProperty property page
  35. IMPLEMENT_DYNCREATE(CTraceProperty, CSmPropertyPage)
  36. CTraceProperty::CTraceProperty(MMC_COOKIE lCookie, LONG_PTR hConsole)
  37. : CSmPropertyPage ( CTraceProperty::IDD, hConsole )
  38. {
  39. // save pointers from arg list
  40. m_pTraceLogQuery = reinterpret_cast <CSmTraceLogQuery *>(lCookie);
  41. // EnableAutomation();
  42. //{{AFX_DATA_INIT(CTraceProperty)
  43. m_dwBufferSize = 0;
  44. m_dwFlushInterval = 0;
  45. m_dwMaxBufCount = 0;
  46. m_dwMinBufCount = 0;
  47. m_bEnableBufferFlush = FALSE;
  48. //}}AFX_DATA_INIT
  49. }
  50. CTraceProperty::CTraceProperty() : CSmPropertyPage(CTraceProperty::IDD)
  51. {
  52. ASSERT (FALSE); // only the constructor w/args should be called
  53. EnableAutomation();
  54. // //{{AFX_DATA_INIT(CTraceProperty)
  55. m_dwBufferSize = 0;
  56. m_dwFlushInterval = 0;
  57. m_dwMaxBufCount = 0;
  58. m_dwMinBufCount = 0;
  59. m_bEnableBufferFlush = FALSE;
  60. // //}}AFX_DATA_INIT
  61. }
  62. CTraceProperty::~CTraceProperty()
  63. {
  64. }
  65. void CTraceProperty::OnFinalRelease()
  66. {
  67. // When the last reference for an automation object is released
  68. // OnFinalRelease is called. The base class will automatically
  69. // deletes the object. Add additional cleanup required for your
  70. // object before calling the base class.
  71. CPropertyPage::OnFinalRelease();
  72. }
  73. void CTraceProperty::DoDataExchange(CDataExchange* pDX)
  74. {
  75. CString strTemp;
  76. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  77. CPropertyPage::DoDataExchange(pDX);
  78. //{{AFX_DATA_MAP(CTraceProperty)
  79. ValidateTextEdit(pDX, IDC_TRACE_BUFFER_SIZE_EDIT, 4, & m_dwBufferSize, eMinBufSize, eMaxBufSize);
  80. ValidateTextEdit(pDX, IDC_TRACE_FLUSH_INT_EDIT, 3, & m_dwFlushInterval, eMinFlushInt, eMaxFlushInt);
  81. ValidateTextEdit(pDX, IDC_TRACE_MAX_BUF_EDIT, 3, & m_dwMaxBufCount, eMinBufCount, eMaxBufCount);
  82. ValidateTextEdit(pDX, IDC_TRACE_MIN_BUF_EDIT, 3, & m_dwMinBufCount, eMinBufCount, eMaxBufCount);
  83. DDX_Check(pDX, IDC_TRACE_BUF_FLUSH_CHECK, m_bEnableBufferFlush);
  84. //}}AFX_DATA_MAP
  85. }
  86. BEGIN_MESSAGE_MAP(CTraceProperty, CSmPropertyPage)
  87. //{{AFX_MSG_MAP(CTraceProperty)
  88. ON_WM_DESTROY()
  89. ON_BN_CLICKED(IDC_TRACE_BUF_FLUSH_CHECK, OnTraceBufFlushCheck)
  90. ON_EN_CHANGE(IDC_TRACE_BUFFER_SIZE_EDIT, OnChangeTraceBufferSizeEdit)
  91. ON_EN_KILLFOCUS(IDC_TRACE_BUFFER_SIZE_EDIT, OnKillfocusTraceBufferSizeEdit)
  92. ON_NOTIFY(UDN_DELTAPOS, IDC_TRACE_BUFFER_SIZE_SPIN, OnDeltaposTraceBufferSizeSpin)
  93. ON_EN_CHANGE(IDC_TRACE_FLUSH_INT_EDIT, OnChangeTraceFlushIntEdit)
  94. ON_EN_KILLFOCUS(IDC_TRACE_FLUSH_INT_EDIT, OnKillfocusTraceFlushIntEdit)
  95. ON_NOTIFY(UDN_DELTAPOS, IDC_TRACE_FLUSH_INT_SPIN, OnDeltaposTraceFlushIntSpin)
  96. ON_EN_CHANGE(IDC_TRACE_MAX_BUF_EDIT, OnChangeTraceMaxBufEdit)
  97. ON_EN_KILLFOCUS(IDC_TRACE_MAX_BUF_EDIT, OnKillfocusTraceMaxBufEdit)
  98. ON_NOTIFY(UDN_DELTAPOS, IDC_TRACE_MAX_BUF_SPIN, OnDeltaposTraceMaxBufSpin)
  99. ON_EN_CHANGE(IDC_TRACE_MIN_BUF_EDIT, OnChangeTraceMinBufEdit)
  100. ON_EN_KILLFOCUS(IDC_TRACE_MIN_BUF_EDIT, OnKillfocusTraceMinBufEdit)
  101. ON_NOTIFY(UDN_DELTAPOS, IDC_TRACE_MIN_BUF_SPIN, OnDeltaposTraceMinBufSpin)
  102. //}}AFX_MSG_MAP
  103. END_MESSAGE_MAP()
  104. BEGIN_DISPATCH_MAP(CTraceProperty, CSmPropertyPage)
  105. //{{AFX_DISPATCH_MAP(CTraceProperty)
  106. // NOTE - the ClassWizard will add and remove mapping macros here.
  107. //}}AFX_DISPATCH_MAP
  108. END_DISPATCH_MAP()
  109. // Note: we add support for IID_ITraceProperty to support typesafe binding
  110. // from VBA. This IID must match the GUID that is attached to the
  111. // dispinterface in the .ODL file.
  112. // {65154EAF-BDBE-11D1-BF99-00C04F94A83A}
  113. static const IID IID_ITraceProperty =
  114. { 0x65154eaf, 0xbdbe, 0x11d1, { 0xbf, 0x99, 0x0, 0xc0, 0x4f, 0x94, 0xa8, 0x3a } };
  115. BEGIN_INTERFACE_MAP(CTraceProperty, CSmPropertyPage)
  116. INTERFACE_PART(CTraceProperty, IID_ITraceProperty, Dispatch)
  117. END_INTERFACE_MAP()
  118. BOOL
  119. CTraceProperty::SetFlushIntervalMode()
  120. {
  121. BOOL bShow;
  122. bShow = ((CButton *)(GetDlgItem(IDC_TRACE_BUF_FLUSH_CHECK)))->GetCheck();
  123. GetDlgItem(IDC_TRACE_FLUSH_INT_EDIT)->EnableWindow(bShow);
  124. GetDlgItem(IDC_TRACE_FLUSH_INT_SPIN)->EnableWindow(bShow);
  125. GetDlgItem(IDC_TRACE_INTERVAL_SECONDS_CAPTION)->EnableWindow(bShow);
  126. return TRUE;
  127. }
  128. BOOL
  129. CTraceProperty::IsValidLocalData ()
  130. {
  131. BOOL bIsValid = TRUE;
  132. if (bIsValid)
  133. {
  134. bIsValid = ValidateDWordInterval(IDC_TRACE_BUFFER_SIZE_EDIT,
  135. m_pTraceLogQuery->GetLogName(),
  136. (long) m_dwBufferSize,
  137. eMinBufSize,
  138. eMaxBufSize);
  139. }
  140. if (bIsValid)
  141. {
  142. bIsValid = ValidateDWordInterval(IDC_TRACE_FLUSH_INT_EDIT,
  143. m_pTraceLogQuery->GetLogName(),
  144. (long) m_dwFlushInterval,
  145. eMinFlushInt,
  146. eMaxFlushInt);
  147. }
  148. if (bIsValid)
  149. {
  150. bIsValid = ValidateDWordInterval(IDC_TRACE_MIN_BUF_EDIT,
  151. m_pTraceLogQuery->GetLogName(),
  152. (long) m_dwMinBufCount,
  153. eMinBufCount,
  154. eMaxBufCount);
  155. }
  156. if (bIsValid)
  157. {
  158. bIsValid = ValidateDWordInterval(IDC_TRACE_MAX_BUF_EDIT,
  159. m_pTraceLogQuery->GetLogName(),
  160. (long) m_dwMaxBufCount,
  161. eMinBufCount,
  162. eMaxBufCount);
  163. }
  164. // Extra data validation
  165. if (bIsValid && m_dwMaxBufCount < m_dwMinBufCount) {
  166. CString csMessage;
  167. csMessage.LoadString ( IDS_TRACE_MAX_BUFF );
  168. MessageBox ( csMessage, m_pTraceLogQuery->GetLogName(), MB_OK | MB_ICONERROR);
  169. GetDlgItem (IDC_TRACE_MAX_BUF_EDIT)->SetFocus();
  170. bIsValid = FALSE;
  171. }
  172. return bIsValid;
  173. }
  174. BOOL
  175. CTraceProperty::SaveDataToModel ( )
  176. {
  177. SLQ_TRACE_LOG_INFO stlInfo;
  178. BOOL bContinue = TRUE;
  179. ResourceStateManager rsm;
  180. // Write the data to the query.
  181. if ( bContinue ) {
  182. memset (&stlInfo, 0, sizeof(stlInfo));
  183. stlInfo.dwBufferSize = m_dwBufferSize;
  184. stlInfo.dwMinimumBuffers = m_dwMinBufCount;
  185. stlInfo.dwMaximumBuffers = m_dwMaxBufCount;
  186. stlInfo.dwBufferFlushInterval = m_dwFlushInterval;
  187. if ( m_bEnableBufferFlush )
  188. stlInfo.dwBufferFlags |= SLQ_TLI_ENABLE_BUFFER_FLUSH;
  189. m_pTraceLogQuery->SetTraceLogInfo ( &stlInfo );
  190. // Save property page shared data.
  191. m_pTraceLogQuery->UpdatePropPageSharedData();
  192. bContinue = UpdateService ( m_pTraceLogQuery, TRUE );
  193. }
  194. if ( bContinue ) {
  195. SetModifiedPage ( FALSE );
  196. }
  197. return bContinue;
  198. }
  199. /////////////////////////////////////////////////////////////////////////////
  200. // CTraceProperty message handlers
  201. BOOL
  202. CTraceProperty::OnSetActive()
  203. {
  204. BOOL bReturn;
  205. bReturn = CSmPropertyPage::OnSetActive();
  206. if (bReturn) {
  207. m_pTraceLogQuery->GetPropPageSharedData ( &m_SharedData );
  208. }
  209. return bReturn;
  210. }
  211. BOOL
  212. CTraceProperty::OnKillActive()
  213. {
  214. BOOL bContinue = TRUE;
  215. bContinue = CPropertyPage::OnKillActive();
  216. if ( bContinue ) {
  217. bContinue = IsValidData(m_pTraceLogQuery, VALIDATE_FOCUS );
  218. }
  219. // The trace advanced page does not modify shared data, so no reason to update it.
  220. if ( bContinue ) {
  221. SetIsActive ( FALSE );
  222. }
  223. return bContinue;
  224. }
  225. void
  226. CTraceProperty::OnCancel()
  227. {
  228. m_pTraceLogQuery->SyncPropPageSharedData(); // Clear the memory shared between property pages.
  229. }
  230. BOOL
  231. CTraceProperty::OnApply()
  232. {
  233. BOOL bContinue = TRUE;
  234. bContinue = UpdateData(TRUE);
  235. if ( bContinue ) {
  236. bContinue = IsValidData( m_pTraceLogQuery, VALIDATE_APPLY );
  237. }
  238. if ( bContinue ) {
  239. bContinue = SaveDataToModel();
  240. }
  241. if ( bContinue ) {
  242. bContinue = Apply( m_pTraceLogQuery );
  243. }
  244. if ( bContinue )
  245. bContinue = CPropertyPage::OnApply();
  246. return bContinue;
  247. }
  248. BOOL CTraceProperty::OnInitDialog()
  249. {
  250. SLQ_TRACE_LOG_INFO tlInfo;
  251. ResourceStateManager rsm;
  252. memset(&tlInfo, 0, sizeof(tlInfo));
  253. m_pTraceLogQuery->GetTraceLogInfo (&tlInfo);
  254. m_dwBufferSize = tlInfo.dwBufferSize;
  255. m_dwFlushInterval = tlInfo.dwBufferFlushInterval;
  256. m_dwMaxBufCount = tlInfo.dwMaximumBuffers;
  257. m_dwMinBufCount = tlInfo.dwMinimumBuffers;
  258. m_bEnableBufferFlush = (BOOL)((tlInfo.dwBufferFlags & SLQ_TLI_ENABLE_BUFFER_FLUSH) != 0);
  259. CSmPropertyPage::OnInitDialog();
  260. SetHelpIds ( (DWORD*)&s_aulHelpIds );
  261. SetFlushIntervalMode();
  262. return TRUE; // return TRUE unless you set the focus to a control
  263. // EXCEPTION: OCX Property Pages should return FALSE
  264. }
  265. void CTraceProperty::OnTraceBufFlushCheck()
  266. {
  267. UpdateData( TRUE);
  268. SetFlushIntervalMode();
  269. SetModifiedPage(TRUE);
  270. }
  271. void CTraceProperty::OnChangeTraceBufferSizeEdit()
  272. {
  273. DWORD dwOldValue;
  274. dwOldValue = m_dwBufferSize;
  275. UpdateData ( TRUE );
  276. if (dwOldValue != m_dwBufferSize) {
  277. SetModifiedPage(TRUE);
  278. }
  279. }
  280. void CTraceProperty::OnKillfocusTraceBufferSizeEdit()
  281. {
  282. DWORD dwOldValue;
  283. dwOldValue = m_dwBufferSize;
  284. UpdateData ( TRUE );
  285. if (dwOldValue != m_dwBufferSize) {
  286. SetModifiedPage(TRUE);
  287. }
  288. }
  289. void CTraceProperty::OnDeltaposTraceBufferSizeSpin(NMHDR* pNMHDR, LRESULT* pResult)
  290. {
  291. OnDeltaposSpin(pNMHDR, pResult, & m_dwBufferSize, eMinBufSize, eMaxBufSize);
  292. }
  293. void CTraceProperty::OnChangeTraceFlushIntEdit()
  294. {
  295. DWORD dwOldValue;
  296. dwOldValue = m_dwFlushInterval;
  297. UpdateData ( TRUE );
  298. if (dwOldValue != m_dwFlushInterval) {
  299. SetModifiedPage(TRUE);
  300. }
  301. }
  302. void CTraceProperty::OnKillfocusTraceFlushIntEdit()
  303. {
  304. DWORD dwOldValue;
  305. dwOldValue = m_dwFlushInterval;
  306. UpdateData ( TRUE );
  307. if (dwOldValue != m_dwFlushInterval) {
  308. SetModifiedPage(TRUE);
  309. }
  310. }
  311. void CTraceProperty::OnDeltaposTraceFlushIntSpin(NMHDR* pNMHDR, LRESULT* pResult)
  312. {
  313. OnDeltaposSpin(pNMHDR, pResult, & m_dwFlushInterval, eMinFlushInt, eMaxFlushInt);
  314. }
  315. void CTraceProperty::OnChangeTraceMaxBufEdit()
  316. {
  317. DWORD dwOldValue;
  318. dwOldValue = m_dwMaxBufCount;
  319. UpdateData ( TRUE );
  320. if (dwOldValue != m_dwMaxBufCount) {
  321. SetModifiedPage(TRUE);
  322. }
  323. }
  324. void CTraceProperty::OnKillfocusTraceMaxBufEdit()
  325. {
  326. DWORD dwOldValue;
  327. dwOldValue = m_dwMaxBufCount;
  328. UpdateData ( TRUE );
  329. if (dwOldValue != m_dwMaxBufCount) {
  330. SetModifiedPage(TRUE);
  331. }
  332. }
  333. void CTraceProperty::OnDeltaposTraceMaxBufSpin(NMHDR* pNMHDR, LRESULT* pResult)
  334. {
  335. OnDeltaposSpin(pNMHDR, pResult, & m_dwMaxBufCount, eMinBufCount, eMaxBufCount);
  336. }
  337. void CTraceProperty::OnChangeTraceMinBufEdit()
  338. {
  339. DWORD dwOldValue;
  340. dwOldValue = m_dwMinBufCount;
  341. UpdateData ( TRUE );
  342. if (dwOldValue != m_dwMinBufCount) {
  343. SetModifiedPage(TRUE);
  344. }
  345. }
  346. void CTraceProperty::OnKillfocusTraceMinBufEdit()
  347. {
  348. DWORD dwOldValue;
  349. dwOldValue = m_dwMinBufCount;
  350. UpdateData ( TRUE );
  351. if (dwOldValue != m_dwMinBufCount) {
  352. SetModifiedPage(TRUE);
  353. }
  354. }
  355. void CTraceProperty::OnDeltaposTraceMinBufSpin(NMHDR* pNMHDR, LRESULT* pResult)
  356. {
  357. OnDeltaposSpin(pNMHDR, pResult, & m_dwMinBufCount, eMinBufCount, eMaxBufCount);
  358. }
  359. void CTraceProperty::PostNcDestroy()
  360. {
  361. // delete this;
  362. CPropertyPage::PostNcDestroy();
  363. }