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.

451 lines
13 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. ASSERT ( m_pTraceLogQuery->CastToTraceLogQuery() );
  42. m_pQuery = dynamic_cast <CSmLogQuery*>(m_pTraceLogQuery);
  43. // EnableAutomation();
  44. //{{AFX_DATA_INIT(CTraceProperty)
  45. m_dwBufferSize = 0;
  46. m_dwFlushInterval = 0;
  47. m_dwMaxBufCount = 0;
  48. m_dwMinBufCount = 0;
  49. m_bEnableBufferFlush = FALSE;
  50. //}}AFX_DATA_INIT
  51. }
  52. CTraceProperty::CTraceProperty() : CSmPropertyPage(CTraceProperty::IDD)
  53. {
  54. ASSERT (FALSE); // only the constructor w/args should be called
  55. EnableAutomation();
  56. // //{{AFX_DATA_INIT(CTraceProperty)
  57. m_dwBufferSize = 0;
  58. m_dwFlushInterval = 0;
  59. m_dwMaxBufCount = 0;
  60. m_dwMinBufCount = 0;
  61. m_bEnableBufferFlush = FALSE;
  62. // //}}AFX_DATA_INIT
  63. }
  64. CTraceProperty::~CTraceProperty()
  65. {
  66. }
  67. void CTraceProperty::OnFinalRelease()
  68. {
  69. // When the last reference for an automation object is released
  70. // OnFinalRelease is called. The base class will automatically
  71. // deletes the object. Add additional cleanup required for your
  72. // object before calling the base class.
  73. CPropertyPage::OnFinalRelease();
  74. }
  75. void CTraceProperty::DoDataExchange(CDataExchange* pDX)
  76. {
  77. CString strTemp;
  78. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  79. CPropertyPage::DoDataExchange(pDX);
  80. //{{AFX_DATA_MAP(CTraceProperty)
  81. ValidateTextEdit(pDX, IDC_TRACE_BUFFER_SIZE_EDIT, 4, & m_dwBufferSize, eMinBufSize, eMaxBufSize);
  82. ValidateTextEdit(pDX, IDC_TRACE_FLUSH_INT_EDIT, 3, & m_dwFlushInterval, eMinFlushInt, eMaxFlushInt);
  83. ValidateTextEdit(pDX, IDC_TRACE_MAX_BUF_EDIT, 3, & m_dwMaxBufCount, eMinBufCount, eMaxBufCount);
  84. ValidateTextEdit(pDX, IDC_TRACE_MIN_BUF_EDIT, 3, & m_dwMinBufCount, eMinBufCount, eMaxBufCount);
  85. DDX_Check(pDX, IDC_TRACE_BUF_FLUSH_CHECK, m_bEnableBufferFlush);
  86. //}}AFX_DATA_MAP
  87. }
  88. BEGIN_MESSAGE_MAP(CTraceProperty, CSmPropertyPage)
  89. //{{AFX_MSG_MAP(CTraceProperty)
  90. ON_WM_DESTROY()
  91. ON_BN_CLICKED(IDC_TRACE_BUF_FLUSH_CHECK, OnTraceBufFlushCheck)
  92. ON_EN_CHANGE(IDC_TRACE_BUFFER_SIZE_EDIT, OnChangeTraceBufferSizeEdit)
  93. ON_EN_KILLFOCUS(IDC_TRACE_BUFFER_SIZE_EDIT, OnKillfocusTraceBufferSizeEdit)
  94. ON_NOTIFY(UDN_DELTAPOS, IDC_TRACE_BUFFER_SIZE_SPIN, OnDeltaposTraceBufferSizeSpin)
  95. ON_EN_CHANGE(IDC_TRACE_FLUSH_INT_EDIT, OnChangeTraceFlushIntEdit)
  96. ON_EN_KILLFOCUS(IDC_TRACE_FLUSH_INT_EDIT, OnKillfocusTraceFlushIntEdit)
  97. ON_NOTIFY(UDN_DELTAPOS, IDC_TRACE_FLUSH_INT_SPIN, OnDeltaposTraceFlushIntSpin)
  98. ON_EN_CHANGE(IDC_TRACE_MAX_BUF_EDIT, OnChangeTraceMaxBufEdit)
  99. ON_EN_KILLFOCUS(IDC_TRACE_MAX_BUF_EDIT, OnKillfocusTraceMaxBufEdit)
  100. ON_NOTIFY(UDN_DELTAPOS, IDC_TRACE_MAX_BUF_SPIN, OnDeltaposTraceMaxBufSpin)
  101. ON_EN_CHANGE(IDC_TRACE_MIN_BUF_EDIT, OnChangeTraceMinBufEdit)
  102. ON_EN_KILLFOCUS(IDC_TRACE_MIN_BUF_EDIT, OnKillfocusTraceMinBufEdit)
  103. ON_NOTIFY(UDN_DELTAPOS, IDC_TRACE_MIN_BUF_SPIN, OnDeltaposTraceMinBufSpin)
  104. //}}AFX_MSG_MAP
  105. END_MESSAGE_MAP()
  106. BEGIN_DISPATCH_MAP(CTraceProperty, CSmPropertyPage)
  107. //{{AFX_DISPATCH_MAP(CTraceProperty)
  108. // NOTE - the ClassWizard will add and remove mapping macros here.
  109. //}}AFX_DISPATCH_MAP
  110. END_DISPATCH_MAP()
  111. // Note: we add support for IID_ITraceProperty to support typesafe binding
  112. // from VBA. This IID must match the GUID that is attached to the
  113. // dispinterface in the .ODL file.
  114. // {65154EAF-BDBE-11D1-BF99-00C04F94A83A}
  115. static const IID IID_ITraceProperty =
  116. { 0x65154eaf, 0xbdbe, 0x11d1, { 0xbf, 0x99, 0x0, 0xc0, 0x4f, 0x94, 0xa8, 0x3a } };
  117. BEGIN_INTERFACE_MAP(CTraceProperty, CSmPropertyPage)
  118. INTERFACE_PART(CTraceProperty, IID_ITraceProperty, Dispatch)
  119. END_INTERFACE_MAP()
  120. BOOL
  121. CTraceProperty::SetFlushIntervalMode()
  122. {
  123. BOOL bShow;
  124. bShow = ((CButton *)(GetDlgItem(IDC_TRACE_BUF_FLUSH_CHECK)))->GetCheck();
  125. GetDlgItem(IDC_TRACE_FLUSH_INT_EDIT)->EnableWindow(bShow);
  126. GetDlgItem(IDC_TRACE_FLUSH_INT_SPIN)->EnableWindow(bShow);
  127. GetDlgItem(IDC_TRACE_INTERVAL_SECONDS_CAPTION)->EnableWindow(bShow);
  128. return TRUE;
  129. }
  130. BOOL
  131. CTraceProperty::IsValidLocalData ()
  132. {
  133. BOOL bIsValid = TRUE;
  134. if (bIsValid)
  135. {
  136. bIsValid = ValidateDWordInterval(IDC_TRACE_BUFFER_SIZE_EDIT,
  137. m_pTraceLogQuery->GetLogName(),
  138. (long) m_dwBufferSize,
  139. eMinBufSize,
  140. eMaxBufSize);
  141. }
  142. if (bIsValid && m_bEnableBufferFlush)
  143. {
  144. bIsValid = ValidateDWordInterval(IDC_TRACE_FLUSH_INT_EDIT,
  145. m_pTraceLogQuery->GetLogName(),
  146. (long) m_dwFlushInterval,
  147. eMinFlushInt,
  148. eMaxFlushInt);
  149. }
  150. if (bIsValid)
  151. {
  152. bIsValid = ValidateDWordInterval(IDC_TRACE_MIN_BUF_EDIT,
  153. m_pTraceLogQuery->GetLogName(),
  154. (long) m_dwMinBufCount,
  155. eMinBufCount,
  156. eMaxBufCount);
  157. }
  158. if (bIsValid)
  159. {
  160. bIsValid = ValidateDWordInterval(IDC_TRACE_MAX_BUF_EDIT,
  161. m_pTraceLogQuery->GetLogName(),
  162. (long) m_dwMaxBufCount,
  163. eMinBufCount,
  164. eMaxBufCount);
  165. }
  166. // Extra data validation
  167. if (bIsValid && m_dwMaxBufCount < m_dwMinBufCount) {
  168. CString csMessage;
  169. csMessage.LoadString ( IDS_TRACE_MAX_BUFF );
  170. MessageBox ( csMessage, m_pTraceLogQuery->GetLogName(), MB_OK | MB_ICONERROR);
  171. SetFocusAnyPage ( IDC_TRACE_MAX_BUF_EDIT );
  172. bIsValid = FALSE;
  173. }
  174. return bIsValid;
  175. }
  176. BOOL
  177. CTraceProperty::SaveDataToModel ( )
  178. {
  179. SLQ_TRACE_LOG_INFO stlInfo;
  180. BOOL bContinue = TRUE;
  181. ResourceStateManager rsm;
  182. // Write the data to the query.
  183. if ( bContinue ) {
  184. memset (&stlInfo, 0, sizeof(stlInfo));
  185. stlInfo.dwBufferSize = m_dwBufferSize;
  186. stlInfo.dwMinimumBuffers = m_dwMinBufCount;
  187. stlInfo.dwMaximumBuffers = m_dwMaxBufCount;
  188. stlInfo.dwBufferFlushInterval = m_dwFlushInterval;
  189. if ( m_bEnableBufferFlush )
  190. stlInfo.dwBufferFlags |= SLQ_TLI_ENABLE_BUFFER_FLUSH;
  191. m_pTraceLogQuery->SetTraceLogInfo ( &stlInfo );
  192. if ( bContinue ) {
  193. // ApplyRunAs must be called before UpdateService
  194. bContinue = ApplyRunAs( m_pTraceLogQuery );
  195. }
  196. // Save property page shared data.
  197. m_pTraceLogQuery->UpdatePropPageSharedData();
  198. bContinue = UpdateService ( m_pTraceLogQuery, TRUE );
  199. }
  200. return bContinue;
  201. }
  202. /////////////////////////////////////////////////////////////////////////////
  203. // CTraceProperty message handlers
  204. BOOL
  205. CTraceProperty::OnSetActive()
  206. {
  207. BOOL bReturn;
  208. bReturn = CSmPropertyPage::OnSetActive();
  209. if (bReturn) {
  210. m_pTraceLogQuery->GetPropPageSharedData ( &m_SharedData );
  211. }
  212. return bReturn;
  213. }
  214. BOOL
  215. CTraceProperty::OnKillActive()
  216. {
  217. BOOL bContinue = TRUE;
  218. bContinue = CPropertyPage::OnKillActive();
  219. if ( bContinue ) {
  220. bContinue = IsValidData(m_pTraceLogQuery, VALIDATE_FOCUS );
  221. }
  222. // The trace advanced page does not modify shared data, so no reason to update it.
  223. if ( bContinue ) {
  224. SetIsActive ( FALSE );
  225. }
  226. return bContinue;
  227. }
  228. void
  229. CTraceProperty::OnCancel()
  230. {
  231. m_pTraceLogQuery->SyncPropPageSharedData(); // Clear the memory shared between property pages.
  232. }
  233. BOOL
  234. CTraceProperty::OnApply()
  235. {
  236. BOOL bContinue = TRUE;
  237. bContinue = UpdateData(TRUE);
  238. if ( bContinue ) {
  239. bContinue = IsValidData( m_pTraceLogQuery, VALIDATE_APPLY );
  240. }
  241. if ( bContinue ) {
  242. bContinue = SaveDataToModel();
  243. }
  244. if ( bContinue )
  245. bContinue = CSmPropertyPage::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. }