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.

595 lines
17 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. // Copyright (c) 2002 Microsoft Corporation. All rights reserved.
  3. // Copyright (c) 2002 OSR Open Systems Resources, Inc.
  4. //
  5. // ProviderSetupDlg.cpp : implementation file
  6. //////////////////////////////////////////////////////////////////////////////
  7. #include "stdafx.h"
  8. #include <tchar.h>
  9. #include <wmistr.h>
  10. #include <initguid.h>
  11. extern "C" {
  12. #include <evntrace.h>
  13. }
  14. #include <traceprt.h>
  15. #include "TraceView.h"
  16. #include "LogSession.h"
  17. #include "FormatSourceSelectDlg.h"
  18. #include "DisplayDlg.h"
  19. #include "ProviderControlGuidDlg.h"
  20. #include "LogDisplayOptionDlg.h"
  21. #include "LogSessionInformationDlg.h"
  22. #include "ProviderSetupDlg.h"
  23. #include "LogSessionPropSht.h"
  24. #include "ProviderFormatInfo.h"
  25. #include "Utils.h"
  26. // CProviderSetupDlg dialog
  27. IMPLEMENT_DYNAMIC(CProviderSetupDlg, CPropertyPage)
  28. CProviderSetupDlg::CProviderSetupDlg()
  29. : CPropertyPage(CProviderSetupDlg::IDD)
  30. {
  31. }
  32. CProviderSetupDlg::~CProviderSetupDlg()
  33. {
  34. }
  35. int CProviderSetupDlg::OnInitDialog()
  36. {
  37. BOOL retVal;
  38. CLogSessionPropSht *pSheet;
  39. CTraceSession *pTraceSession;
  40. CString str;
  41. retVal = CPropertyPage::OnInitDialog();
  42. //
  43. // Disable the remove button
  44. //
  45. GetDlgItem(IDC_REMOVE_PROVIDER_BUTTON)->EnableWindow(FALSE);
  46. m_providerListCtrl.InsertColumn(0,_T("Name"), LVCFMT_LEFT, 348); //80);
  47. pSheet = (CLogSessionPropSht *) GetParent();
  48. m_pLogSession = pSheet->m_pLogSession;
  49. if(m_pLogSession != NULL) {
  50. for(LONG ii = 0; ii < m_pLogSession->m_traceSessionArray.GetSize(); ii++) {
  51. pTraceSession = (CTraceSession *)m_pLogSession->m_traceSessionArray[ii];
  52. if(pTraceSession != NULL) {
  53. //
  54. // Put the provider on the display
  55. //
  56. m_providerListCtrl.InsertItem(ii,
  57. pTraceSession->m_controlGuidFriendlyName[0]);
  58. m_providerListCtrl.SetItemData(ii, (DWORD_PTR)pTraceSession);
  59. m_providerListCtrl.SetItemText(pTraceSession->m_traceSessionID,
  60. 1,
  61. pTraceSession->m_controlGuid[0]);
  62. }
  63. }
  64. }
  65. return retVal;
  66. }
  67. void CProviderSetupDlg::DoDataExchange(CDataExchange* pDX)
  68. {
  69. CPropertyPage::DoDataExchange(pDX);
  70. DDX_Control(pDX, IDC_CURRENT_PROVIDER_LIST, m_providerListCtrl);
  71. }
  72. BEGIN_MESSAGE_MAP(CProviderSetupDlg, CPropertyPage)
  73. ON_BN_CLICKED(IDC_ADD_PROVIDER_BUTTON, OnBnClickedAddProviderButton)
  74. ON_BN_CLICKED(IDC_REMOVE_PROVIDER_BUTTON, OnBnClickedRemoveProviderButton)
  75. ON_NOTIFY(NM_CLICK, IDC_CURRENT_PROVIDER_LIST, OnNMClickCurrentProviderList)
  76. ON_NOTIFY(NM_RCLICK, IDC_CURRENT_PROVIDER_LIST, OnNMRclickCurrentProviderList)
  77. END_MESSAGE_MAP()
  78. BOOL CProviderSetupDlg::OnSetActive()
  79. {
  80. CLogSessionPropSht *pSheet = (CLogSessionPropSht*) GetParent();
  81. CString dialogTxt;
  82. CString tempString;
  83. BOOL retVal;
  84. retVal = CPropertyPage::OnSetActive();
  85. //
  86. // Fix the title if in Wizard mode
  87. //
  88. if(pSheet->IsWizard()) {
  89. CTabCtrl* pTab = pSheet->GetTabControl();
  90. //
  91. //If its not the active page, just set the tab item
  92. //
  93. TC_ITEM ti;
  94. ti.mask = TCIF_TEXT;
  95. ti.pszText =_T("Create New Log Session");
  96. VERIFY(pTab->SetItem(0, &ti));
  97. }
  98. //
  99. // disable/enable buttons as appropriate
  100. //
  101. if(m_pLogSession->m_bTraceActive) {
  102. GetDlgItem(IDC_ADD_PROVIDER_BUTTON)->EnableWindow(FALSE);
  103. GetDlgItem(IDC_REMOVE_PROVIDER_BUTTON)->EnableWindow(FALSE);
  104. } else {
  105. GetDlgItem(IDC_ADD_PROVIDER_BUTTON)->EnableWindow(TRUE);
  106. }
  107. //
  108. // display the proper text for the group box
  109. //
  110. if(::IsWindow(pSheet->m_logSessionInformationDlg.m_hWnd)) {
  111. dialogTxt.Format(_T("Provider List For "));
  112. pSheet->m_logSessionInformationDlg.m_logSessionName.GetWindowText(tempString);
  113. dialogTxt += (LPCTSTR)tempString;
  114. GetDlgItem(IDC_PROVIDER_SETUP_STATIC)->SetWindowText(dialogTxt);
  115. }
  116. if(0 == m_pLogSession->m_traceSessionArray.GetSize()) {
  117. pSheet->SetWizardButtons(0);
  118. } else {
  119. pSheet->SetWizardButtons(PSWIZB_NEXT);
  120. }
  121. return retVal;
  122. }
  123. void CProviderSetupDlg::OnBnClickedAddProviderButton()
  124. {
  125. CString str;
  126. CTraceSession *pTraceSession = NULL;
  127. CFileFind fileFind;
  128. CString extension;
  129. CString traceDirectory;
  130. CString tmcPath;
  131. CString tmfPath;
  132. CString ctlPath;
  133. CString tempPath;
  134. CString providerName;
  135. CString tempDirectory;
  136. CTraceSession *pTrace;
  137. BOOL bNoID;
  138. LONG traceSessionID = 0;
  139. CLogSessionPropSht *pSheet;
  140. ULONG flags = 0;
  141. BOOL bProcess;
  142. BOOL bThread;
  143. BOOL bDisk;
  144. BOOL bNet;
  145. BOOL bFileIO;
  146. BOOL bPageFault;
  147. BOOL bHardFault;
  148. BOOL bImageLoad;
  149. BOOL bRegistry;
  150. //
  151. // Get the parent property sheet
  152. //
  153. pSheet = (CLogSessionPropSht *) GetParent();
  154. //
  155. // Get the trace session ID
  156. //
  157. do {
  158. bNoID = FALSE;
  159. for(LONG ii = 0; ii < m_pLogSession->m_traceSessionArray.GetSize(); ii++) {
  160. pTrace = (CTraceSession *)m_pLogSession->m_traceSessionArray[ii];
  161. if(pTrace == NULL) {
  162. continue;
  163. }
  164. if(traceSessionID == pTrace->m_traceSessionID) {
  165. bNoID = TRUE;
  166. traceSessionID++;
  167. }
  168. }
  169. } while(bNoID);
  170. //
  171. // Create the new trace session
  172. //
  173. pTraceSession = new CTraceSession(traceSessionID);
  174. if(NULL == pTraceSession) {
  175. AfxMessageBox(_T("Failed To Initialize Provider, Resource Allocation Failure"));
  176. return;
  177. }
  178. //
  179. // Promt the user for trace providers
  180. //
  181. CProviderControlGuidDlg *pDialog = new CProviderControlGuidDlg(this, pTraceSession);
  182. if(IDOK != pDialog->DoModal()) {
  183. delete pTraceSession;
  184. delete pDialog;
  185. return;
  186. }
  187. bProcess = pDialog->m_bProcess;
  188. bThread = pDialog->m_bThread;
  189. bDisk = pDialog->m_bDisk;
  190. bNet = pDialog->m_bNet;
  191. bFileIO = pDialog->m_bFileIO;
  192. bPageFault = pDialog->m_bPageFault;
  193. bHardFault = pDialog->m_bHardFault;
  194. bImageLoad = pDialog->m_bImageLoad;
  195. bRegistry = pDialog->m_bRegistry;
  196. delete pDialog;
  197. //
  198. // Handle PDB input
  199. //
  200. if(!pTraceSession->m_pdbFile.IsEmpty()) {
  201. if(!pTraceSession->ProcessPdb()) {
  202. delete pTraceSession;
  203. return;
  204. }
  205. //
  206. // We have a control GUID whether we can display info or
  207. // not we are good to start a trace, so add the session
  208. // to the list
  209. //
  210. m_pLogSession->m_traceSessionArray.Add(pTraceSession);
  211. if(pTraceSession->m_tmfFile.GetSize() == 0) {
  212. AfxMessageBox(_T("Failed To Get Format Information From PDB\nEvent Data Will Not Be Formatted"));
  213. }
  214. } else if(!pTraceSession->m_ctlFile.IsEmpty()) {
  215. //
  216. // Handle CTL file input here
  217. //
  218. FILE *ctlFile;
  219. TCHAR line[MAX_STR_LENGTH];
  220. LONG count;
  221. BOOL bFoundCtlFile = FALSE;
  222. ctlFile = _tfopen((LPTSTR)(LPCTSTR)pTraceSession->m_ctlFile,
  223. _T("r"));
  224. if (ctlFile == NULL) {
  225. str.Format(_T("Unable To Open Control GUID File %s"),
  226. pTraceSession->m_ctlFile);
  227. AfxMessageBox(str);
  228. delete pTraceSession;
  229. return;
  230. }
  231. while( _fgetts(line, MAX_STR_LENGTH, ctlFile) != NULL ) {
  232. if (_tcslen(line) < 36)
  233. continue;
  234. if(line[0] == ';' ||
  235. line[0] == '\0' ||
  236. line[0] == '#' ||
  237. line[0] == '/') {
  238. continue;
  239. }
  240. bFoundCtlFile = TRUE;
  241. str = line;
  242. pTraceSession->m_controlGuid.Add(str);
  243. //
  244. // add a control GUID friendly name
  245. //
  246. pTraceSession->m_controlGuidFriendlyName.Add(pTraceSession->m_ctlFile);
  247. }
  248. fclose(ctlFile);
  249. if(!bFoundCtlFile) {
  250. AfxMessageBox(_T("Unable To Obtain Control GUID"));
  251. delete pTraceSession;
  252. return;
  253. }
  254. //
  255. // We have a control GUID whether we can display info or
  256. // not we are good to start a trace, so add the session
  257. // to the list
  258. //
  259. m_pLogSession->m_traceSessionArray.Add(pTraceSession);
  260. //
  261. // Now get the TMF File(s)
  262. //
  263. GetTmfInfo(pTraceSession);
  264. } else if(pTraceSession->m_bKernelLogger) {
  265. //
  266. // The kernel logger was selected,
  267. // so we specify the logger name here
  268. // Set the session name in the property sheet
  269. //
  270. pSheet->m_displayName = KERNEL_LOGGER_NAME;
  271. if(bProcess) {
  272. flags |= EVENT_TRACE_FLAG_PROCESS;
  273. }
  274. if(bThread) {
  275. flags |= EVENT_TRACE_FLAG_THREAD;
  276. }
  277. if(bDisk) {
  278. flags |= EVENT_TRACE_FLAG_DISK_IO;
  279. }
  280. if(bNet) {
  281. flags |= EVENT_TRACE_FLAG_NETWORK_TCPIP;
  282. }
  283. if(bFileIO) {
  284. flags |= EVENT_TRACE_FLAG_DISK_FILE_IO;
  285. }
  286. if(bPageFault) {
  287. flags |= EVENT_TRACE_FLAG_MEMORY_PAGE_FAULTS;
  288. }
  289. if(bHardFault) {
  290. flags |= EVENT_TRACE_FLAG_MEMORY_HARD_FAULTS;
  291. }
  292. if(bImageLoad) {
  293. flags |= EVENT_TRACE_FLAG_IMAGE_LOAD;
  294. }
  295. if(bRegistry) {
  296. flags |= EVENT_TRACE_FLAG_REGISTRY;
  297. }
  298. //
  299. // Update the flags data
  300. //
  301. pSheet->m_logSessionValues[Flags].Format(_T("%d"), flags);
  302. //
  303. // We have a control GUID whether we can display info or
  304. // not we are good to start a trace, so add the session
  305. // to the list
  306. //
  307. m_pLogSession->m_traceSessionArray.Add(pTraceSession);
  308. //
  309. // Now get the system TMF File
  310. //
  311. //
  312. // Use the common controls file open dialog
  313. //
  314. CFileDialog fileDlg(TRUE,
  315. _T(".tmf"),
  316. _T("system.tmf"),
  317. OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST |
  318. OFN_HIDEREADONLY | OFN_EXPLORER |
  319. OFN_NOCHANGEDIR,
  320. _T("System TMF File (system.tmf)|system.tmf||"),
  321. this);
  322. //
  323. // Pop the dialog... Any error, just return
  324. //
  325. if( fileDlg.DoModal()!=IDOK ) {
  326. return;
  327. }
  328. //
  329. // Get the file name
  330. //
  331. if(!fileDlg.GetPathName().IsEmpty()) {
  332. //
  333. // Store the file name
  334. //
  335. //
  336. // Add it to the trace session
  337. //
  338. pTraceSession->m_tmfFile.Add(fileDlg.GetPathName());
  339. }
  340. //
  341. // add a control GUID friendly name
  342. //
  343. pTraceSession->m_controlGuidFriendlyName.Add(KERNEL_LOGGER_NAME);
  344. } else {
  345. //
  346. // Handle manually entered control GUID here
  347. //
  348. if((0 == pTraceSession->m_controlGuid.GetSize()) ||
  349. (pTraceSession->m_controlGuid[0].IsEmpty())) {
  350. AfxMessageBox(_T("Unable To Obtain Control GUID"));
  351. delete pTraceSession;
  352. return;
  353. }
  354. //
  355. // Add a control GUID to the provider list
  356. //
  357. pTraceSession->m_controlGuidFriendlyName.Add(pTraceSession->m_controlGuid[0]);
  358. //
  359. // We have a control GUID whether we can display info or
  360. // not we are good to start a trace, so add the session
  361. // to the list
  362. //
  363. m_pLogSession->m_traceSessionArray.Add(pTraceSession);
  364. //
  365. // Now get the TMF File(s)
  366. //
  367. GetTmfInfo(pTraceSession);
  368. }
  369. //
  370. // Put the provider on the display
  371. //
  372. m_providerListCtrl.InsertItem(pTraceSession->m_traceSessionID,
  373. pTraceSession->m_controlGuidFriendlyName[0]);
  374. m_providerListCtrl.SetItemData(pTraceSession->m_traceSessionID, (DWORD_PTR)pTraceSession);
  375. pSheet->SetWizardButtons(PSWIZB_NEXT);
  376. return;
  377. }
  378. BOOL CProviderSetupDlg::GetTmfInfo(CTraceSession *pTraceSession)
  379. {
  380. //
  381. // Now get the TMF file(s) or path as necessary
  382. //
  383. CFormatSourceSelectDlg *pDialog = new CFormatSourceSelectDlg(this, pTraceSession);
  384. if(NULL == pDialog) {
  385. return FALSE;
  386. }
  387. if(IDOK != pDialog->DoModal()) {
  388. delete pDialog;
  389. return FALSE;
  390. }
  391. delete pDialog;
  392. return TRUE;
  393. }
  394. void CProviderSetupDlg::OnBnClickedRemoveProviderButton()
  395. {
  396. CTraceSession *pTraceSession;
  397. POSITION pos;
  398. BOOL bFound = FALSE;
  399. CLogSessionPropSht *pSheet;
  400. int index;
  401. //
  402. // Get the parent property sheet
  403. //
  404. pSheet = (CLogSessionPropSht *) GetParent();
  405. pos = m_providerListCtrl.GetFirstSelectedItemPosition();
  406. if (pos == NULL) {
  407. return;
  408. }
  409. while (pos)
  410. {
  411. index = m_providerListCtrl.GetNextSelectedItem(pos);
  412. pTraceSession = (CTraceSession *)m_providerListCtrl.GetItemData(index);
  413. //
  414. // Pull the provider from the display
  415. //
  416. m_providerListCtrl.DeleteItem(index);
  417. if(pTraceSession != NULL) {
  418. for(LONG ii = 0; ii < m_pLogSession->m_traceSessionArray.GetSize(); ii++) {
  419. if(m_pLogSession->m_traceSessionArray[ii] == pTraceSession) {
  420. m_pLogSession->m_traceSessionArray.RemoveAt(ii);
  421. //
  422. // If the kernel logger is being removed, change the
  423. // log session name stored by the property sheet back
  424. // to what is stored in the CLogSession object
  425. //
  426. if(pTraceSession->m_bKernelLogger) {
  427. //
  428. // Set the session name in the property sheet
  429. //
  430. pSheet->m_displayName = pSheet->m_pLogSession->GetDisplayName();
  431. //
  432. // Set the flags back to the default as well
  433. //
  434. pSheet->m_logSessionValues[Flags] = (LPCTSTR)m_pLogSession->m_logSessionValues[Flags];
  435. }
  436. delete pTraceSession;
  437. break;
  438. }
  439. }
  440. }
  441. }
  442. //
  443. // Check for at least one provider
  444. //
  445. if(0 == m_pLogSession->m_traceSessionArray.GetSize()) {
  446. //
  447. // disable the remove button
  448. //
  449. GetDlgItem(IDC_REMOVE_PROVIDER_BUTTON)->EnableWindow(FALSE);
  450. //
  451. // Disable the next button if there are no providers
  452. //
  453. pSheet->SetWizardButtons(0);
  454. }
  455. }
  456. void CProviderSetupDlg::OnNMClickCurrentProviderList(NMHDR *pNMHDR, LRESULT *pResult)
  457. {
  458. POSITION pos;
  459. *pResult = 0;
  460. if(m_pLogSession->m_bTraceActive) {
  461. //
  462. // don't enable anything
  463. //
  464. return;
  465. }
  466. pos = m_providerListCtrl.GetFirstSelectedItemPosition();
  467. if(pos == NULL) {
  468. //
  469. // Disable the remove button
  470. //
  471. GetDlgItem(IDC_REMOVE_PROVIDER_BUTTON)->EnableWindow(FALSE);
  472. } else {
  473. //
  474. // Enable the remove button
  475. //
  476. GetDlgItem(IDC_REMOVE_PROVIDER_BUTTON)->EnableWindow(TRUE);
  477. }
  478. }
  479. void CProviderSetupDlg::OnNMRclickCurrentProviderList(NMHDR *pNMHDR, LRESULT *pResult)
  480. {
  481. POSITION pos;
  482. pos = m_providerListCtrl.GetFirstSelectedItemPosition();
  483. if (pos == NULL) {
  484. //
  485. // Disable the remove button
  486. //
  487. GetDlgItem(IDC_REMOVE_PROVIDER_BUTTON)->EnableWindow(FALSE);
  488. } else {
  489. //
  490. // Enable the remove button
  491. //
  492. GetDlgItem(IDC_REMOVE_PROVIDER_BUTTON)->EnableWindow(TRUE);
  493. }
  494. *pResult = 0;
  495. }