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.

3772 lines
103 KiB

  1. // emshellView.cpp : implementation of the CEmshellView class
  2. //
  3. #include "stdafx.h"
  4. #include "emshell.h"
  5. #include "ConnectionDlg.h"
  6. #include "comdef.h"
  7. #include "AutomaticSessDlg.h"
  8. #include "RemoteSessDlg.h"
  9. #include "PropPageGeneral.h"
  10. #include "PropPageDumpFiles.h"
  11. #include "PropPageLogFiles.h"
  12. #include "PropPageGenLogDump.h"
  13. #include "ReadLogsDlg.h"
  14. #include "EmOptions.h"
  15. #include "MSInfoDlg.h"
  16. #include "emshellDoc.h"
  17. #include "emshellView.h"
  18. #include "afxdlgs.h"
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24. #define ISTREAM_BUFFER_SIZE 0X10000
  25. extern const TCHAR* gtcNone;
  26. const TCHAR* gtcEmChm = _T("\\em.chm");
  27. /////////////////////////////////////////////////////////////////////////////
  28. // CEmshellView
  29. IMPLEMENT_DYNCREATE(CEmshellView, CFormView)
  30. BEGIN_MESSAGE_MAP(CEmshellView, CFormView)
  31. //{{AFX_MSG_MAP(CEmshellView)
  32. ON_WM_SIZE()
  33. ON_WM_DESTROY()
  34. ON_WM_TIMER()
  35. ON_UPDATE_COMMAND_UI(ID_VIEW_REFRESH, OnUpdateViewRefresh)
  36. ON_COMMAND(ID_REFRESH, OnViewRefresh)
  37. ON_UPDATE_COMMAND_UI(ID_PROCESSPOPUP_STOPSESSION, OnUpdateProcesspopupStopDebugSession)
  38. ON_COMMAND(ID_PROCESSPOPUP_STOPSESSION, OnProcesspopupStopDebugSession)
  39. ON_COMMAND(ID_PROCESSPOPUP_GENERATEMINIDUMP, OnProcesspopupGenerateminidump)
  40. ON_UPDATE_COMMAND_UI(ID_PROCESSPOPUP_GENERATEMINIDUMP, OnUpdateProcesspopupGenerateminidump)
  41. ON_COMMAND(ID_PROCESSPOPUP_GENERATEUSERDUMP, OnProcesspopupGenerateuserdump)
  42. ON_UPDATE_COMMAND_UI(ID_PROCESSPOPUP_GENERATEUSERDUMP, OnUpdateProcesspopupGenerateuserdump)
  43. ON_COMMAND(ID_PROCESSPOPUP_AUTOMATICSESSION, OnProcesspopupAutomaticsession)
  44. ON_UPDATE_COMMAND_UI(ID_PROCESSPOPUP_AUTOMATICSESSION, OnUpdateProcesspopupAutomaticsession)
  45. ON_UPDATE_COMMAND_UI(ID_PROCESSPOPUP_PROPERTIES, OnUpdateProcesspopupProperties)
  46. ON_COMMAND(ID_PROCESSPOPUP_PROPERTIES, OnProcesspopupProperties)
  47. ON_UPDATE_COMMAND_UI(ID_PROCESSPOPUP_MANUALSESSION, OnUpdateProcesspopupManualsession)
  48. ON_COMMAND(ID_PROCESSPOPUP_MANUALSESSION, OnProcesspopupManualsession)
  49. ON_COMMAND(ID_PROCESSPOPUP_REFRESH, OnProcesspopupRefresh)
  50. ON_UPDATE_COMMAND_UI(ID_PROCESSPOPUP_REFRESH, OnUpdateProcesspopupRefresh)
  51. ON_COMMAND(ID_VIEW_SERVICESANDAPPLICATIONS, OnViewServicesandapplications)
  52. ON_UPDATE_COMMAND_UI(ID_VIEW_SERVICESANDAPPLICATIONS, OnUpdateViewServicesandapplications)
  53. ON_COMMAND(ID_VIEW_LOGFILES, OnViewLogfiles)
  54. ON_UPDATE_COMMAND_UI(ID_VIEW_LOGFILES, OnUpdateViewLogfiles)
  55. ON_COMMAND(ID_VIEW_DUMPFILES, OnViewDumpfiles)
  56. ON_UPDATE_COMMAND_UI(ID_VIEW_DUMPFILES, OnUpdateViewDumpfiles)
  57. ON_UPDATE_COMMAND_UI(ID_LOGPOPUP_OPEN, OnUpdateLogpopupOpen)
  58. ON_COMMAND(ID_LOGPOPUP_OPEN, OnLogpopupOpen)
  59. ON_UPDATE_COMMAND_UI(ID_LOGPOPUP_PROPERTIES, OnUpdateLogpopupProperties)
  60. ON_COMMAND(ID_LOGPOPUP_PROPERTIES, OnLogpopupProperties)
  61. ON_COMMAND(ID_VIEW_APPLICATIONS, OnViewApplications)
  62. ON_UPDATE_COMMAND_UI(ID_VIEW_APPLICATIONS, OnUpdateViewApplications)
  63. ON_COMMAND(ID_VIEW_COMPLETEDSESSIONS, OnViewCompletedsessions)
  64. ON_UPDATE_COMMAND_UI(ID_VIEW_COMPLETEDSESSIONS, OnUpdateViewCompletedsessions)
  65. ON_COMMAND(ID_VIEW_SERVICES, OnViewServices)
  66. ON_UPDATE_COMMAND_UI(ID_VIEW_SERVICES, OnUpdateViewServices)
  67. ON_COMMAND(ID_PROCESSPOPUP_DELETESESSION, OnProcesspopupDeleteSession)
  68. ON_UPDATE_COMMAND_UI(ID_PROCESSPOPUP_DELETESESSION, OnUpdateProcesspopupDeleteSession)
  69. ON_COMMAND(IDM_TOOLS_OPTOINS, OnToolsOptions)
  70. ON_UPDATE_COMMAND_UI(IDM_TOOLS_OPTOINS, OnUpdateToolsOptoins)
  71. ON_COMMAND(ID_PROCESSPOPUP_CANCELSESSION, OnProcesspopupCancelDebugSession)
  72. ON_UPDATE_COMMAND_UI(ID_PROCESSPOPUP_CANCELSESSION, OnUpdateProcesspopupCancelDebugSession)
  73. ON_COMMAND(ID_LOGPOPUP_DELETE, OnLogpopupDelete)
  74. ON_UPDATE_COMMAND_UI(ID_LOGPOPUP_DELETE, OnUpdateLogpopupDelete)
  75. ON_COMMAND(ID_ACTION_GENERATENFOFILE, OnActionGenerateMSInfoFile)
  76. ON_UPDATE_COMMAND_UI(ID_ACTION_GENERATENFOFILE, OnUpdateActionGenerateMSInfoFile)
  77. ON_COMMAND(ID_VIEW_MSINFOFILES, OnViewMSInfoFiles)
  78. ON_UPDATE_COMMAND_UI(ID_VIEW_MSINFOFILES, OnUpdateViewMSInfoFiles)
  79. ON_COMMAND(ID_LOGPOPUP_EXPORT, OnLogpopupExport)
  80. ON_UPDATE_COMMAND_UI(ID_LOGPOPUP_EXPORT, OnUpdateLogpopupExport)
  81. ON_COMMAND(ID_VIEW_REFRESH, OnViewRefresh)
  82. ON_COMMAND(ID_HELP_CONTENTS, OnHelpContents)
  83. //}}AFX_MSG_MAP
  84. // Standard printing commands
  85. ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
  86. ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
  87. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
  88. END_MESSAGE_MAP()
  89. /////////////////////////////////////////////////////////////////////////////
  90. // CEmshellView construction/destruction
  91. CEmshellView::CEmshellView()
  92. : CFormView(CEmshellView::IDD),
  93. m_mainListControl(this)
  94. {
  95. //{{AFX_DATA_INIT(CEmshellView)
  96. // NOTE: the ClassWizard will add member initialization here
  97. //}}AFX_DATA_INIT
  98. memset ( &m_lastSelectedEmObj, 0, sizeof ( EmObject ) );
  99. }
  100. CEmshellView::~CEmshellView()
  101. {
  102. }
  103. void CEmshellView::DoDataExchange(CDataExchange* pDX)
  104. {
  105. CFormView::DoDataExchange(pDX);
  106. //{{AFX_DATA_MAP(CEmshellView)
  107. DDX_Control(pDX, IDC_LST_MAINLISTCTRL, m_mainListControl);
  108. //}}AFX_DATA_MAP
  109. }
  110. BOOL CEmshellView::PreCreateWindow(CREATESTRUCT& cs)
  111. {
  112. // TODO: Modify the Window class or styles here by modifying
  113. // the CREATESTRUCT cs
  114. return CFormView::PreCreateWindow(cs);
  115. }
  116. void CEmshellView::OnInitialUpdate()
  117. {
  118. CFormView::OnInitialUpdate();
  119. SetShellState(SHELLVIEW_ALL);
  120. GetParentFrame()->RecalcLayout();
  121. ResizeParentToFit();
  122. }
  123. /////////////////////////////////////////////////////////////////////////////
  124. // CEmshellView diagnostics
  125. #ifdef _DEBUG
  126. void CEmshellView::AssertValid() const
  127. {
  128. CFormView::AssertValid();
  129. }
  130. void CEmshellView::Dump(CDumpContext& dc) const
  131. {
  132. CFormView::Dump(dc);
  133. }
  134. CEmshellDoc* CEmshellView::GetDocument() // non-debug version is inline
  135. {
  136. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CEmshellDoc)));
  137. return (CEmshellDoc*)m_pDocument;
  138. }
  139. #endif //_DEBUG
  140. /////////////////////////////////////////////////////////////////////////////
  141. // CEmshellView message handlers
  142. BSTR
  143. CopyBSTR
  144. (
  145. LPBYTE pb,
  146. ULONG cb
  147. )
  148. {
  149. return ::SysAllocStringByteLen ((LPCSTR)pb, cb);
  150. }
  151. void CEmshellView::OnSize(UINT nType, int cx, int cy)
  152. {
  153. CFormView::OnSize(nType, cx, cy);
  154. if (m_mainListControl.GetSafeHwnd()) {
  155. UINT delta = 0;
  156. // m_mainListControl.ResizeColumnsWithRatio();
  157. m_mainListControl.MoveWindow(delta, delta, cx - (delta*2), cy- (delta*2));
  158. }
  159. SetScrollSizes(MM_TEXT, CSize(cx, cy));
  160. }
  161. PEmObject GetEmObj(BSTR bstrEmObj)
  162. {
  163. //Do a simple cast from a BSTR to an EmObject
  164. return ((PEmObject)bstrEmObj);
  165. }
  166. HRESULT CEmshellView::DisplayLogData(PEmObject pEmObject)
  167. {
  168. _ASSERTE(pEmObject != NULL);
  169. HRESULT hr = E_FAIL;
  170. CString strFileSize;
  171. CString strStartDate;
  172. LONG lRow = 0L;
  173. int nImage = 0;
  174. int nImageOffset = 0;
  175. do
  176. {
  177. if( pEmObject == NULL ){
  178. hr = E_INVALIDARG;
  179. break;
  180. }
  181. strFileSize.Format(_T("%d"), pEmObject->dwBucket1);
  182. lRow = m_mainListControl.SetItemText(-1, 0, pEmObject->szName);
  183. if(lRow == -1L){
  184. hr = E_FAIL;
  185. break;
  186. }
  187. //Set the itemData
  188. m_mainListControl.SetItemData(lRow, (ULONG_PTR) pEmObject);
  189. //Get the correct offset into the bitmap for the current status
  190. nImageOffset = GetImageOffsetFromStatus((EmSessionStatus)pEmObject->nStatus);
  191. //Call SetItem() with the index and image to show based on the state of pEmObject
  192. m_mainListControl.SetItem(lRow, 0, LVIF_IMAGE, NULL, nImageOffset, 0, 0, 0);
  193. lRow = m_mainListControl.SetItemText(lRow, 1, strFileSize);
  194. if(lRow == -1L){
  195. hr = E_FAIL;
  196. break;
  197. }
  198. //
  199. // a-mando
  200. //
  201. if( pEmObject->dateStart ) {
  202. COleDateTime oleDtTm( pEmObject->dateStart );
  203. strStartDate = oleDtTm.Format(_T("%c"));
  204. lRow = m_mainListControl.SetItemText(lRow, 2, strStartDate);
  205. if(lRow == -1L){
  206. hr = E_FAIL;
  207. break;
  208. }
  209. }
  210. // a-mando
  211. hr = S_OK;
  212. }
  213. while( false );
  214. return hr;
  215. }
  216. HRESULT CEmshellView::DisplayMSInfoData(PEmObject pEmObject)
  217. {
  218. return DisplayDumpData(pEmObject);
  219. }
  220. HRESULT CEmshellView::DisplayDumpData(PEmObject pEmObject)
  221. {
  222. _ASSERTE(pEmObject != NULL);
  223. HRESULT hr = E_FAIL;
  224. CString strFileSize;
  225. CString strStartDate;
  226. LONG lRow = 0L;
  227. int nImage = 0;
  228. int nImageOffset = 0;
  229. do
  230. {
  231. if( pEmObject == NULL ){
  232. hr = E_INVALIDARG;
  233. break;
  234. }
  235. strFileSize.Format(_T("%d"), pEmObject->dwBucket1);
  236. lRow = m_mainListControl.SetItemText(-1, 0, pEmObject->szName);
  237. if(lRow == -1L){
  238. hr = E_FAIL;
  239. break;
  240. }
  241. //Set the itemData
  242. m_mainListControl.SetItemData(lRow, (ULONG_PTR) pEmObject);
  243. //Get the correct offset into the bitmap for the current status
  244. nImageOffset = GetImageOffsetFromStatus((EmSessionStatus)pEmObject->nStatus);
  245. //Call SetItem() with the index and image to show based on the state of pEmObject
  246. m_mainListControl.SetItem(lRow, 0, LVIF_IMAGE, NULL, nImageOffset, 0, 0, 0);
  247. lRow = m_mainListControl.SetItemText(lRow, 1, strFileSize);
  248. if(lRow == -1L){
  249. hr = E_FAIL;
  250. break;
  251. }
  252. //
  253. // a-mando
  254. //
  255. if( pEmObject->dateStart ) {
  256. COleDateTime oleDtTm( pEmObject->dateStart );
  257. strStartDate = oleDtTm.Format(_T("%c"));
  258. lRow = m_mainListControl.SetItemText(lRow, 2, strStartDate);
  259. if(lRow == -1L){
  260. hr = E_FAIL;
  261. break;
  262. }
  263. }
  264. // a-mando
  265. hr = S_OK;
  266. }
  267. while( false );
  268. return hr;
  269. }
  270. HRESULT CEmshellView::DisplayServiceData(PEmObject pEmObject)
  271. {
  272. _ASSERTE(pEmObject != NULL);
  273. HRESULT hr = E_FAIL;
  274. TCHAR szPid[20] = {0};
  275. LONG lRow = 0L;
  276. int nImage = 0;
  277. CString csPROCStatus;
  278. int nImageOffset = 0;
  279. do
  280. {
  281. if( pEmObject == NULL ){
  282. hr = E_INVALIDARG;
  283. break;
  284. }
  285. _ltot(pEmObject->nId, szPid, 10);
  286. lRow = m_mainListControl.SetItemText(-1, 0, pEmObject->szName);
  287. if(lRow == -1L){
  288. hr = E_FAIL;
  289. break;
  290. }
  291. //Set the itemData
  292. m_mainListControl.SetItemData(lRow, (ULONG_PTR) pEmObject);
  293. //Get the correct offset into the bitmap for the current status
  294. nImageOffset = GetImageOffsetFromStatus((EmSessionStatus)pEmObject->nStatus);
  295. //Call SetItem() with the index and image to show based on the state of pEmObject
  296. m_mainListControl.SetItem(lRow, 0, LVIF_IMAGE, NULL, nImageOffset, 0, 0, 0);
  297. lRow = m_mainListControl.SetItemText(lRow, 1, pEmObject->szSecName);
  298. if(lRow == -1L){
  299. hr = E_FAIL;
  300. break;
  301. }
  302. lRow = m_mainListControl.SetItemText(lRow, 2, pEmObject->szBucket1);
  303. if(lRow == -1L){
  304. hr = E_FAIL;
  305. break;
  306. }
  307. lRow = m_mainListControl.SetItemText(lRow, 3, szPid);
  308. if(lRow == -1L){
  309. hr = E_FAIL;
  310. break;
  311. }
  312. //
  313. // a-mando
  314. //
  315. if( pEmObject->dateStart != 0L ) {
  316. COleDateTime oleDtTm(pEmObject->dateStart);
  317. CString strStartDate = oleDtTm.Format(_T("%c"));
  318. lRow = m_mainListControl.SetItemText(lRow, 4, strStartDate );
  319. if(lRow == -1L){
  320. hr = E_FAIL;
  321. break;
  322. }
  323. }
  324. if( pEmObject->dateEnd != 0L ) {
  325. COleDateTime oleDtTm(pEmObject->dateEnd);
  326. CString strEndDate = oleDtTm.Format(_T("%c"));
  327. lRow = m_mainListControl.SetItemText(lRow, 5, strEndDate );
  328. if(lRow == -1L){
  329. hr = E_FAIL;
  330. break;
  331. }
  332. }
  333. // a-mando
  334. ((CEmshellApp*)AfxGetApp())->GetStatusString(pEmObject->nStatus, csPROCStatus);
  335. lRow = m_mainListControl.SetItemText(lRow, 6, csPROCStatus);
  336. if(lRow == -1L){
  337. hr = E_FAIL;
  338. break;
  339. }
  340. hr = S_OK;
  341. }
  342. while( false );
  343. return hr;
  344. }
  345. HRESULT CEmshellView::DisplayProcessData(PEmObject pEmObject)
  346. {
  347. _ASSERTE(pEmObject != NULL);
  348. HRESULT hr = E_FAIL;
  349. TCHAR szPid[20] = {0};
  350. LONG lRow = 0L;
  351. int nImage = 0;
  352. CString csPROCStatus;
  353. int nImageOffset = 0;
  354. do
  355. {
  356. if( pEmObject == NULL ){
  357. hr = E_INVALIDARG;
  358. break;
  359. }
  360. _ltot(pEmObject->nId, szPid, 10);
  361. lRow = m_mainListControl.SetItemText(-1, 0, pEmObject->szName);
  362. if(lRow == -1L){
  363. hr = E_FAIL;
  364. break;
  365. }
  366. //Set the itemData
  367. m_mainListControl.SetItemData(lRow, (ULONG_PTR) pEmObject);
  368. //Get the correct offset into the bitmap for the current status
  369. nImageOffset = GetImageOffsetFromStatus((EmSessionStatus)pEmObject->nStatus);
  370. //Call SetItem() with the index and image to show based on the state of pEmObject
  371. m_mainListControl.SetItem(lRow, 0, LVIF_IMAGE, NULL, nImageOffset, 0, 0, 0);
  372. lRow = m_mainListControl.SetItemText(lRow, 1, szPid);
  373. if(lRow == -1L){
  374. hr = E_FAIL;
  375. break;
  376. }
  377. //
  378. // a-mando
  379. //
  380. if( pEmObject->dateStart != 0L ) {
  381. COleDateTime oleDtTm(pEmObject->dateStart);
  382. CString strStartDate = oleDtTm.Format(_T("%c"));
  383. lRow = m_mainListControl.SetItemText(lRow, 2, strStartDate );
  384. if(lRow == -1L){
  385. hr = E_FAIL;
  386. break;
  387. }
  388. }
  389. if( pEmObject->dateEnd != 0L ) {
  390. COleDateTime oleDtTm(pEmObject->dateEnd);
  391. CString strEndDate = oleDtTm.Format(_T("%c"));
  392. lRow = m_mainListControl.SetItemText(lRow, 3, strEndDate );
  393. if(lRow == -1L){
  394. hr = E_FAIL;
  395. break;
  396. }
  397. }
  398. // a-mando
  399. ((CEmshellApp*)AfxGetApp())->GetStatusString(pEmObject->nStatus, csPROCStatus);
  400. lRow = m_mainListControl.SetItemText(lRow, 4, csPROCStatus);
  401. if(lRow == -1L){
  402. hr = E_FAIL;
  403. break;
  404. }
  405. hr = S_OK;
  406. }
  407. while( false );
  408. return hr;
  409. }
  410. HRESULT CEmshellView::DisplayStoppedSessionData(PEmObject pEmObject)
  411. {
  412. _ASSERTE(pEmObject != NULL);
  413. return DisplayServiceData(pEmObject);
  414. }
  415. void CEmshellView::OnDestroy()
  416. {
  417. CFormView::OnDestroy();
  418. //If we have sessions still open, there is a big problem
  419. ASSERT(m_SessionTable.GetSize() == 0);
  420. // m_ShellImageList.DeleteImageList();
  421. }
  422. CPtrArray* CEmshellView::GetSessionTable()
  423. {
  424. return &m_SessionTable;
  425. }
  426. void CEmshellView::ClearSessionTable()
  427. {
  428. //Iterate through the collection removing all the elements and calling release on all the
  429. //session pointers. Also, call StopDebugSession CloseActiveSession and RemoveActiveSession
  430. //on all the active sessions
  431. IEmDebugSession* dsValue = NULL;
  432. INT_PTR nUpperBound = 0;
  433. PActiveSession pActiveSession = NULL;
  434. HRESULT hr = S_OK;
  435. do {
  436. //Get the size of the array, start at the end, and remove each element
  437. nUpperBound = m_SessionTable.GetUpperBound();
  438. if( nUpperBound == -1 ) break;
  439. for ( ; nUpperBound >= 0; nUpperBound-- ) {
  440. pActiveSession = ( PActiveSession ) m_SessionTable.GetAt( nUpperBound );
  441. if ( pActiveSession == NULL ) {
  442. hr = E_FAIL;
  443. break;
  444. }
  445. /* memcpy((void*)&emObject.guidstream, (void*)&pActiveSession->guid, sizeof( GUID ));
  446. //Call StopDebug on this active session if we're the master.
  447. if (pActiveSession->bMaster) {
  448. hr = pActiveSession->pIDebugSession->StopDebug();
  449. //So what are we supposed to do if it fails? We should still remove it from the active
  450. //session table.
  451. }
  452. //Create bstr's for the journey ahead, and break if we can't
  453. bstrEmObj = CopyBSTR ( (LPBYTE)&emObject, sizeof( EmObject ) );
  454. if( bstrEmObj == NULL ){
  455. hr = E_OUTOFMEMORY;
  456. break;
  457. }
  458. //Call CloseSession on the pEmObject
  459. hr = GetDocument()->GetEmManager()->CloseSession(bstrEmObj);
  460. if (FAILED(hr)) {
  461. CString strErrorMsg;
  462. strErrorMsg.LoadString(IDS_ERROR_FAILEDCLOSESESSION);
  463. ((CEmshellApp*)AfxGetApp())->DisplayErrMsgFromString(strErrorMsg);
  464. //We've handled the error, so set hr back to S_OK for the next time round
  465. hr = S_OK;
  466. }
  467. */
  468. //Delete the pActiveSession. This will release the interface too
  469. DeAllocActiveSession( pActiveSession );
  470. //Remove the item from the array
  471. m_SessionTable.RemoveAt( nUpperBound );
  472. }
  473. } while ( FALSE );
  474. if ( FAILED( hr ) ) {
  475. ((CEmshellApp*)AfxGetApp())->DisplayErrMsgFromHR( hr );
  476. }
  477. }
  478. HRESULT CEmshellView::StartManualDebugSession(EmObject* pEmObject)
  479. {
  480. IEmDebugSession* pIEmDebugSession = NULL;
  481. HRESULT hr = E_FAIL;
  482. BOOL bRetVal = FALSE;
  483. CString strMessage;
  484. INT_PTR nResult = 0;
  485. BSTR bstrPath = NULL;
  486. BSTR bstrEmObj = NULL;
  487. BSTR bstrECXEmObject = NULL;
  488. _variant_t varUsername;
  489. _variant_t varPort;
  490. _variant_t varPassword;
  491. _variant_t varAltSymPath;
  492. EmObject EmObjectFilter;
  493. PEmObject pEmObjectTmp = NULL;
  494. _variant_t var; //This will create and initialize the var variant
  495. LONG lParam = 0;
  496. do {
  497. //Create bstr's for the journey ahead, and break if we can't
  498. bstrEmObj = CopyBSTR ( (LPBYTE)pEmObject, sizeof( EmObject ) );
  499. if( bstrEmObj == NULL ){
  500. hr = E_OUTOFMEMORY;
  501. break;
  502. }
  503. memcpy(&EmObjectFilter, pEmObject, sizeof( EmObject ) );
  504. EmObjectFilter.type = EMOBJ_CMDSET;
  505. bstrECXEmObject = CopyBSTR ( (LPBYTE)&EmObjectFilter, sizeof( EmObject ) );
  506. //Start a debug session with OpenSession()
  507. hr = GetDocument()->GetEmManager()->OpenSession(bstrEmObj, &pIEmDebugSession);
  508. if ( hr == S_OK ) {
  509. //Get the EnumObjects for the ECX list control so we can pass it to the dlg
  510. hr = GetDocument()->GetEmManager()->EnumObjectsEx(bstrECXEmObject, &var);
  511. if ( FAILED(hr) ) break;
  512. PSessionSettings pSessionSettings = &((CEmshellApp*)AfxGetApp())->m_SessionSettings;
  513. //Create the Automatic Session Dialog
  514. CRemoteSessDlg dlg(pSessionSettings, &var);
  515. nResult = dlg.DoModal();
  516. if ( nResult == IDOK ) {
  517. //Check if the user wanted to save the settings, if so, call UpdateSessionDlgData(FALSE)
  518. if ( dlg.m_bRememberSettings ) {
  519. ((CEmshellApp*)AfxGetApp())->UpdateSessionData( TRUE );
  520. }
  521. if ( !dlg.m_strSelectedCommandSet.IsEmpty() && dlg.m_strSelectedCommandSet != gtcNone) {
  522. bstrPath = dlg.m_strSelectedCommandSet.AllocSysString();
  523. if( bstrPath == NULL ){
  524. hr = E_OUTOFMEMORY;
  525. break;
  526. }
  527. } else {
  528. bstrPath = ::SysAllocString( _T("") );
  529. }
  530. varUsername = pSessionSettings->strUsername.AllocSysString();
  531. varPassword = pSessionSettings->strPassword.AllocSysString();
  532. varPort.ChangeType(VT_I4);
  533. varPort.lVal = _ttoi(pSessionSettings->strPort);
  534. varAltSymPath = pSessionSettings->strAltSymbolPath.AllocSysString();
  535. //Init the var to nothing
  536. var.Clear();
  537. //Time to call DebugEx(), get ready for the ride!
  538. hr = pIEmDebugSession->DebugEx(bstrEmObj,
  539. SessType_Manual,
  540. bstrPath,
  541. lParam,
  542. varUsername,
  543. varPassword,
  544. varPort,
  545. var,
  546. varAltSymPath);
  547. //We don't need the bstr's, release them.
  548. SysFreeString ( bstrPath );
  549. if ( FAILED(hr) ) break;
  550. //Convert the bstrEmObj to an PEmObject and memcopy it into the itemdata's PEmObject
  551. pEmObjectTmp = GetEmObj(bstrEmObj);
  552. if( pEmObject == NULL ){
  553. hr = E_FAIL;
  554. break;
  555. }
  556. memcpy(pEmObject, pEmObjectTmp, sizeof( EmObject ) );
  557. AddActiveSession(pEmObject, pIEmDebugSession, TRUE);
  558. /* TCHAR szClientConnectString[_MAX_PATH] = {0};
  559. //Start the local cdb session
  560. GetClientConnectString(szClientConnectString, _MAX_PATH, pEmObject, varPort.lVal);
  561. hr = StartCDBClient(szClientConnectString);
  562. if ( FAILED(hr) ) break;
  563. */
  564. }
  565. else {
  566. //release the debugsession pointer, the user decided to cancel
  567. if ( pIEmDebugSession != NULL )
  568. //If we got here, we shouldn't have created an active session, so just release the
  569. //debug interface
  570. SAFE_RELEASEIX(pIEmDebugSession);
  571. }
  572. }
  573. else if ( hr == S_FALSE ) {
  574. //We were not able to open a master session, ask the user if they
  575. //would like to be the owner if this is an orphan
  576. if ( pEmObject->nStatus & STAT_ORPHAN ) {
  577. if ( CommenceOrphanCustodyBattle( pIEmDebugSession ) ) {
  578. //Get the status of the EmObject
  579. hr = pIEmDebugSession->GetStatus( bstrEmObj );
  580. if ( FAILED( hr ) ) break;
  581. //Convert the bstrEmObj to an PEmObject and memcopy it into the itemdata's PEmObject
  582. pEmObjectTmp = GetEmObj(bstrEmObj);
  583. if (pEmObjectTmp == NULL) break;
  584. memcpy(pEmObject, pEmObjectTmp, sizeof( EmObject ) );
  585. AddActiveSession(pEmObject, pIEmDebugSession, TRUE);
  586. break;
  587. }
  588. }
  589. //We were not able to open a master session, ask the user if they
  590. //would like to spectate
  591. strMessage.LoadString( IDS_DEBUG_ERROR );
  592. if ( ( (CEmshellApp*) AfxGetApp() )->DisplayErrMsgFromString( strMessage, MB_YESNO ) == IDYES ) {
  593. //Convert the bstrEmObj to an PEmObject and memcopy it into the itemdata's PEmObject
  594. pEmObjectTmp = GetEmObj(bstrEmObj);
  595. if (pEmObjectTmp == NULL) break;
  596. memcpy(pEmObject, pEmObjectTmp, sizeof( EmObject ) );
  597. AddActiveSession(pEmObject, pIEmDebugSession, FALSE);
  598. break;
  599. }
  600. else {
  601. //Release the debug interface, we never created an activesession.
  602. SAFE_RELEASEIX(pIEmDebugSession);
  603. }
  604. }
  605. } while (FALSE);
  606. if (FAILED(hr)) {
  607. if ( pIEmDebugSession != NULL )
  608. //If we got here, we shouldn't have created an active session, so just release the
  609. //debug interface
  610. SAFE_RELEASEIX(pIEmDebugSession);
  611. ((CEmshellApp*)AfxGetApp())->DisplayErrMsgFromHR(hr);
  612. }
  613. SysFreeString ( bstrPath );
  614. SysFreeString ( bstrEmObj );
  615. SysFreeString ( bstrECXEmObject );
  616. //Update the status of the EmObjects ListElement to reflect it's new status
  617. UpdateListElement(pEmObject);
  618. return hr;
  619. }
  620. HRESULT CEmshellView::StartAutomaticDebugSession(PEmObject pEmObject)
  621. {
  622. IEmDebugSession* pIEmDebugSession = NULL;
  623. HRESULT hr = E_FAIL;
  624. BOOL bRetVal = FALSE;
  625. CString strMessage;
  626. INT_PTR nResult = 0;
  627. BSTR bstrPath = NULL;
  628. BSTR bstrEmObj = NULL;
  629. BSTR bstrECXEmObject = NULL;
  630. _variant_t varAdminName;
  631. _variant_t varAltSymPath;
  632. PEmObject pEmObjectTmp = NULL;
  633. EmObject EmObjectFilter;
  634. _variant_t var; //This will create and initialize the var variant
  635. LONG lParam = 0;
  636. do {
  637. //Create bstr's for the journey ahead, and break if we can't
  638. bstrEmObj = CopyBSTR ( (LPBYTE)pEmObject, sizeof( EmObject ) );
  639. memcpy(&EmObjectFilter, pEmObject, sizeof( EmObject ) );
  640. EmObjectFilter.type = EMOBJ_CMDSET;
  641. bstrECXEmObject = CopyBSTR ( (LPBYTE)&EmObjectFilter, sizeof( EmObject ) );
  642. if( bstrEmObj == NULL ){
  643. hr = E_OUTOFMEMORY;
  644. break;
  645. }
  646. //Start a debug session with OpenSession()
  647. hr = GetDocument()->GetEmManager()->OpenSession(bstrEmObj, &pIEmDebugSession);
  648. if ( hr == S_OK ) {
  649. //Get the EnumObjects for the ECX list control so we can pass it to the dlg
  650. hr = GetDocument()->GetEmManager()->EnumObjectsEx(bstrECXEmObject, &var);
  651. if ( FAILED(hr) ) break;
  652. PSessionSettings pSessionSettings = &((CEmshellApp*)AfxGetApp())->m_SessionSettings;
  653. //Create the Automatic Session Dialog
  654. CAutomaticSessDlg dlg(pSessionSettings, &var, (EmObjectType)pEmObject->type);
  655. nResult = dlg.DoModal();
  656. if ( nResult == IDOK ) {
  657. //Check if the user wanted to save the settings, if so, call UpdateRegistry()
  658. if ( dlg.m_bRememberSettings ) {
  659. ((CEmshellApp*)AfxGetApp())->UpdateSessionData( TRUE );
  660. }
  661. bstrPath = dlg.m_strSelectedCommandSet.AllocSysString();
  662. if( bstrPath == NULL ){
  663. hr = E_OUTOFMEMORY;
  664. break;
  665. }
  666. varAdminName = pSessionSettings->strAdminName.AllocSysString();
  667. varAltSymPath = pSessionSettings->strAltSymbolPath.AllocSysString();
  668. //Init the var to nothing
  669. var.Clear();
  670. if ( dlg.m_bRecursiveMode ) lParam = lParam | RECURSIVE_MODE;
  671. if ( dlg.m_bMiniDump ) lParam = lParam | PRODUCE_MINI_DUMP;
  672. if ( dlg.m_bUserDump ) lParam = lParam | PRODUCE_USER_DUMP;
  673. //Set the cursor to a wait cursor
  674. CWaitCursor wait;
  675. //Time to call DebugEx(), get ready for the ride!
  676. hr = pIEmDebugSession->DebugEx(bstrEmObj,
  677. SessType_Automatic,
  678. bstrPath,
  679. lParam,
  680. var,
  681. var,
  682. var,
  683. varAdminName,
  684. varAltSymPath);
  685. //We don't need the bstr's, release them.
  686. SysFreeString ( bstrPath );
  687. if ( FAILED(hr) ) break;
  688. //Convert the bstrEmObj to an PEmObject and memcopy it into the itemdata's PEmObject
  689. pEmObjectTmp = GetEmObj(bstrEmObj);
  690. if( pEmObject == NULL ){
  691. hr = E_FAIL;
  692. break;
  693. }
  694. memcpy(pEmObject, pEmObjectTmp, sizeof( EmObject ) );
  695. AddActiveSession(pEmObject, pIEmDebugSession, TRUE);
  696. }
  697. else {
  698. //release the debugsession pointer, the user decided to cancel
  699. if ( pIEmDebugSession != NULL )
  700. //If we got here, we shouldn't have created an active session, so just release the
  701. //debug interface
  702. SAFE_RELEASEIX(pIEmDebugSession);
  703. }
  704. }
  705. else if ( hr == S_FALSE ) {
  706. //We were not able to open a master session, ask the user if they
  707. //would like to be the owner if this is an orphan
  708. if ( pEmObject->nStatus & STAT_ORPHAN ) {
  709. if ( CommenceOrphanCustodyBattle( pIEmDebugSession ) ) {
  710. //Get the status of the EmObject
  711. hr = pIEmDebugSession->GetStatus( bstrEmObj );
  712. if ( FAILED( hr ) ) break;
  713. //Convert the bstrEmObj to an PEmObject and memcopy it into the itemdata's PEmObject
  714. pEmObjectTmp = GetEmObj(bstrEmObj);
  715. if (pEmObjectTmp == NULL) break;
  716. memcpy(pEmObject, pEmObjectTmp, sizeof( EmObject ) );
  717. AddActiveSession(pEmObject, pIEmDebugSession, TRUE);
  718. break;
  719. }
  720. }
  721. //We were not able to open a master session, ask the user if they
  722. //would like to spectate
  723. strMessage.LoadString( IDS_DEBUG_ERROR );
  724. if (((CEmshellApp*)AfxGetApp())->DisplayErrMsgFromString(strMessage, MB_YESNO) == IDYES) {
  725. //Convert the bstrEmObj to an PEmObject and memcopy it into the itemdata's PEmObject
  726. pEmObjectTmp = GetEmObj(bstrEmObj);
  727. if (pEmObjectTmp == NULL) break;
  728. memcpy(pEmObject, pEmObjectTmp, sizeof( EmObject ) );
  729. AddActiveSession(pEmObject, pIEmDebugSession, FALSE);
  730. break;
  731. }
  732. else {
  733. //Release the debug interface, we never created an activesession.
  734. SAFE_RELEASEIX(pIEmDebugSession);
  735. }
  736. }
  737. } while (FALSE);
  738. if (FAILED(hr)) {
  739. if ( pIEmDebugSession != NULL )
  740. //If we got here, we shouldn't have created an active session, so just release the
  741. //debug interface
  742. SAFE_RELEASEIX(pIEmDebugSession);
  743. ((CEmshellApp*)AfxGetApp())->DisplayErrMsgFromHR(hr);
  744. }
  745. SysFreeString ( bstrPath );
  746. SysFreeString ( bstrEmObj );
  747. SysFreeString ( bstrECXEmObject );
  748. //Update the status of the EmObjects ListElement to reflect it's new status
  749. UpdateListElement(pEmObject);
  750. return hr;
  751. }
  752. void CEmshellView::DeAllocActiveSession(PActiveSession pActiveSession)
  753. {
  754. //Release the DebugSession
  755. SAFE_RELEASEIX(pActiveSession->pIDebugSession);
  756. if (pActiveSession != NULL)
  757. delete pActiveSession;
  758. else ((CEmshellApp*)AfxGetApp())->DisplayErrMsgFromHR(E_FAIL);
  759. }
  760. PActiveSession CEmshellView::AllocActiveSession(PEmObject pEmObject, IEmDebugSession* pIDebugSession)
  761. {
  762. HRESULT hr = E_FAIL;
  763. PActiveSession pActiveSession = NULL;
  764. do {
  765. //Allocate an ActiveSession object, initialize it, and return it
  766. pActiveSession = new ActiveSession;
  767. if (pActiveSession == NULL) {
  768. hr = E_OUTOFMEMORY;
  769. break;
  770. }
  771. //Initialize the members
  772. pActiveSession->pEmObject = pEmObject;
  773. pActiveSession->pIDebugSession = pIDebugSession;
  774. pActiveSession->bMaster = FALSE;
  775. memcpy((void*)&pActiveSession->guid, (void*)pEmObject->guidstream, sizeof( GUID ));
  776. hr = S_OK;
  777. } while (FALSE);
  778. if (FAILED(hr)) {
  779. ((CEmshellApp*)AfxGetApp())->DisplayErrMsgFromHR(hr);
  780. }
  781. return pActiveSession;
  782. }
  783. void CEmshellView::OnTimer(UINT nIDEvent)
  784. {
  785. INT_PTR nUpperBound = 0;
  786. PActiveSession pActiveSession = NULL;
  787. HRESULT hr = S_OK;
  788. PEmObject pEmObject = NULL;
  789. BSTR bstrEmObj = NULL;
  790. PEmObject pEmObjectTmp = NULL;
  791. if ( m_SessionTable.GetSize() > 0 ) {
  792. //Step through all the elements in the session table updating the status if it has a valid pEmObject
  793. for ( nUpperBound = m_SessionTable.GetUpperBound(); nUpperBound >= 0; nUpperBound-- ) {
  794. pActiveSession = ( PActiveSession ) m_SessionTable.GetAt( nUpperBound );
  795. if ( pActiveSession == NULL ) {
  796. hr = E_FAIL;
  797. break;
  798. }
  799. pEmObject = pActiveSession->pEmObject;
  800. //If we don't have an EmObject to refresh, we don't need to handle this one.
  801. if( pEmObject == NULL ) {
  802. continue;
  803. }
  804. //Create bstr's for the journey ahead, and break if we can't
  805. bstrEmObj = CopyBSTR ( ( LPBYTE )pEmObject, sizeof( EmObject ) );
  806. if( bstrEmObj == NULL ){
  807. hr = E_OUTOFMEMORY;
  808. break;
  809. }
  810. hr = pActiveSession->pIDebugSession->GetStatus( bstrEmObj );
  811. //If we failed to get the status on this session, don't stop, just continue to the next session
  812. if (FAILED( hr )) {
  813. hr = S_OK;
  814. continue;
  815. }
  816. //Convert the bstrEmObj to an PEmObject and memcopy it into the itemdata's PEmObject
  817. pEmObjectTmp = GetEmObj( bstrEmObj );
  818. if ( pEmObjectTmp == NULL ) {
  819. hr = E_FAIL;
  820. break;
  821. }
  822. SysFreeString( bstrEmObj );
  823. memcpy( pEmObject, pEmObjectTmp, sizeof( EmObject ) );
  824. //Update the ListCtl with the new info
  825. UpdateListElement( pEmObject );
  826. }
  827. }
  828. if ( FAILED( hr ) ) {
  829. ((CEmshellApp*)AfxGetApp())->DisplayErrMsgFromHR( hr );
  830. }
  831. SysFreeString ( bstrEmObj );
  832. CFormView::OnTimer( nIDEvent );
  833. }
  834. HRESULT CEmshellView::RemoveActiveSession( PEmObject pEmObject )
  835. {
  836. INT_PTR nUpperBound = 0;
  837. PActiveSession pActiveSession = NULL;
  838. //Search the session table looking for pEmObject->guidstream, if found close it
  839. //We don't call FindActiveSession() because we don't get the position of the element,
  840. //so do our own search...again :/
  841. for ( nUpperBound = m_SessionTable.GetUpperBound(); nUpperBound >= 0; nUpperBound-- ) {
  842. pActiveSession = ( PActiveSession ) m_SessionTable.GetAt( nUpperBound );
  843. if ( pActiveSession == NULL ) {
  844. break;
  845. }
  846. if( memcmp( ( void * ) &pActiveSession->guid, ( void * ) pEmObject->guidstream, sizeof( GUID ) ) == 0 ) {
  847. //Delete the pActiveSession. This will release the interface
  848. DeAllocActiveSession( pActiveSession );
  849. //Remove the item from the array
  850. m_SessionTable.RemoveAt( nUpperBound );
  851. //We have found the element, stop the search
  852. break;
  853. }
  854. }
  855. return S_OK;
  856. }
  857. HRESULT CEmshellView::DeleteDebugSession( PEmObject pEmObject )
  858. {
  859. HRESULT hr = E_FAIL;
  860. BSTR bstrEmObj = NULL;
  861. do {
  862. //Set the cursor to a wait cursor
  863. CWaitCursor wait;
  864. //Create bstr's for the journey ahead, and break if we can't
  865. bstrEmObj = CopyBSTR ( (LPBYTE)pEmObject, sizeof( EmObject ) );
  866. if( bstrEmObj == NULL ){
  867. hr = E_OUTOFMEMORY;
  868. break;
  869. }
  870. //Close the active session
  871. hr = GetDocument()->GetEmManager()->DeleteSession( bstrEmObj );
  872. if ( FAILED( hr ) ) {
  873. break;
  874. }
  875. } while ( FALSE );
  876. if ( FAILED( hr ) ) {
  877. ((CEmshellApp*)AfxGetApp())->DisplayErrMsgFromHR( hr );
  878. }
  879. SysFreeString ( bstrEmObj );
  880. return hr;
  881. }
  882. void CEmshellView::CancelDebugSession( PEmObject pEmObject )
  883. {
  884. PActiveSession pActiveSession = NULL;
  885. HRESULT hr = S_OK;
  886. BSTR bstrEmObj = NULL;
  887. PEmObject pEmObjectTmp = NULL;
  888. IEmDebugSession* pTempDebugSession = NULL;
  889. do {
  890. pActiveSession = FindActiveSession( pEmObject );
  891. if ( pActiveSession == NULL ) {
  892. //Create bstr's for the journey ahead, and break if we can't
  893. bstrEmObj = CopyBSTR ( ( LPBYTE ) pEmObject, sizeof( EmObject ) );
  894. if( bstrEmObj == NULL ) {
  895. hr = E_OUTOFMEMORY;
  896. break;
  897. }
  898. //We don't have a session open, so open a temporary session
  899. hr = GetDocument()->GetEmManager()->OpenSession( bstrEmObj, &pTempDebugSession );
  900. //If we can't get an S_OK, then it's not an orphan, just release the interface.
  901. if ( FAILED( hr ) ) {
  902. if ( pTempDebugSession ) {
  903. //Release the pTempDebugSession pointer
  904. SAFE_RELEASEIX( pTempDebugSession );
  905. }
  906. break;
  907. }
  908. //If it's an orphan, ask the user if they want to take control, and if so, add it to our session table
  909. if ( CommenceOrphanCustodyBattle( pTempDebugSession ) ) {
  910. pActiveSession = AddActiveSession( pEmObject, pTempDebugSession, TRUE );
  911. if ( !pActiveSession ) {
  912. if ( pTempDebugSession ) {
  913. //Release the pTempDebugSession pointer
  914. SAFE_RELEASEIX( pTempDebugSession );
  915. }
  916. break;
  917. }
  918. }
  919. else {
  920. if ( pTempDebugSession ) {
  921. //Release the pTempDebugSession pointer
  922. SAFE_RELEASEIX( pTempDebugSession );
  923. }
  924. break;
  925. }
  926. }
  927. else if ( !pActiveSession->bMaster ) {
  928. //We're not the master, so try to become one
  929. hr = pActiveSession->pIDebugSession->AdoptOrphan();
  930. if ( SUCCEEDED( hr ) ) {
  931. //We're now the master, so update the bMaster flag and continue
  932. pActiveSession->bMaster = TRUE;
  933. }
  934. else {
  935. //We couldn't get ownership of the session, abort with a message.
  936. break;
  937. }
  938. }
  939. //Set the cursor to a wait cursor
  940. CWaitCursor wait;
  941. //Stop the debug session
  942. hr = pActiveSession->pIDebugSession->CancelDebug( TRUE );
  943. if ( FAILED( hr ) ) {
  944. break;
  945. }
  946. //Create bstr's for the journey ahead, and break if we can't
  947. bstrEmObj = CopyBSTR ( ( LPBYTE ) pEmObject, sizeof( EmObject ) );
  948. if( bstrEmObj == NULL ) {
  949. hr = E_OUTOFMEMORY;
  950. break;
  951. }
  952. //Get the status of the EmObject
  953. hr = pActiveSession->pIDebugSession->GetStatus( bstrEmObj );
  954. if ( FAILED( hr ) ) break;
  955. //Convert the bstrEmObj to an PEmObject and memcopy it into the itemdata's PEmObject
  956. pEmObjectTmp = GetEmObj(bstrEmObj);
  957. if (pEmObjectTmp == NULL) {
  958. hr = E_FAIL;
  959. break;
  960. }
  961. SysFreeString( bstrEmObj );
  962. //Remove the session from the active session table
  963. RemoveActiveSession( pEmObject );
  964. //Update the ListCtl with the new info. The status should read Debug Completed or some such
  965. memcpy(pEmObject, pEmObjectTmp, sizeof( EmObject ) );
  966. UpdateListElement( pEmObject );
  967. } while( FALSE );
  968. if ( FAILED( hr ) ) {
  969. ((CEmshellApp*)AfxGetApp())->DisplayErrMsgFromHR( hr );
  970. }
  971. SysFreeString ( bstrEmObj );
  972. }
  973. BOOL CEmshellView::CommenceOrphanCustodyBattle( IEmDebugSession* pIEmDebugSession )
  974. {
  975. HRESULT hr;
  976. CString strMessage;
  977. BOOL bRetVal = FALSE;
  978. strMessage.LoadString( IDS_ORPHANCUSTODYCONFIRM );
  979. //Ask the user if they want custody of the orphan
  980. if (((CEmshellApp*)AfxGetApp())->DisplayErrMsgFromString( strMessage, MB_YESNO ) == IDYES) {
  981. //Take control and exit
  982. hr = pIEmDebugSession->AdoptOrphan();
  983. if ( SUCCEEDED( hr ) ) {
  984. bRetVal = TRUE;
  985. }
  986. else {
  987. ((CEmshellApp*)AfxGetApp())->DisplayErrMsgFromHR( hr );
  988. }
  989. }
  990. return bRetVal;
  991. }
  992. void CEmshellView::StopDebugSession( PEmObject pEmObject )
  993. {
  994. PActiveSession pActiveSession = NULL;
  995. HRESULT hr = S_OK;
  996. BSTR bstrEmObj = NULL;
  997. PEmObject pEmObjectTmp = NULL;
  998. IEmDebugSession* pTempDebugSession = NULL;
  999. do {
  1000. pActiveSession = FindActiveSession( pEmObject );
  1001. if ( pActiveSession == NULL ) {
  1002. //Create bstr's for the journey ahead, and break if we can't
  1003. bstrEmObj = CopyBSTR ( ( LPBYTE ) pEmObject, sizeof( EmObject ) );
  1004. if( bstrEmObj == NULL ) {
  1005. hr = E_OUTOFMEMORY;
  1006. break;
  1007. }
  1008. //We don't have a session open, so open a temporary session
  1009. hr = GetDocument()->GetEmManager()->OpenSession( bstrEmObj, &pTempDebugSession );
  1010. //Convert the bstrEmObj to an PEmObject and memcopy it into the itemdata's PEmObject
  1011. pEmObjectTmp = GetEmObj(bstrEmObj);
  1012. if (pEmObjectTmp == NULL) {
  1013. hr = E_FAIL;
  1014. break;
  1015. }
  1016. SysFreeString( bstrEmObj );
  1017. //If we can't get an S_OK, then it's not an orphan, just release the interface.
  1018. if ( FAILED( hr ) ) {
  1019. if ( pTempDebugSession ) {
  1020. //Release the pTempDebugSession pointer
  1021. SAFE_RELEASEIX( pTempDebugSession );
  1022. }
  1023. break;
  1024. }
  1025. //If it's an orphan, ask the user if they want to take control, and if successfull,
  1026. //add it to our session table
  1027. if ( pEmObject->nStatus & STAT_ORPHAN && CommenceOrphanCustodyBattle( pTempDebugSession ) ) {
  1028. pActiveSession = AddActiveSession( pEmObject, pTempDebugSession, TRUE );
  1029. if ( !pActiveSession ) {
  1030. if ( pTempDebugSession ) {
  1031. //Release the pTempDebugSession pointer
  1032. SAFE_RELEASEIX( pTempDebugSession );
  1033. break;
  1034. }
  1035. }
  1036. }
  1037. else {
  1038. if ( pTempDebugSession ) {
  1039. //Release the pTempDebugSession pointer
  1040. SAFE_RELEASEIX( pTempDebugSession );
  1041. }
  1042. break;
  1043. }
  1044. }
  1045. else if ( !pActiveSession->bMaster ) {
  1046. //We're not the master, so try to become one
  1047. hr = pActiveSession->pIDebugSession->AdoptOrphan();
  1048. if ( SUCCEEDED( hr ) ) {
  1049. //We're now the master, so update the bMaster flag and continue
  1050. pActiveSession->bMaster = TRUE;
  1051. }
  1052. else {
  1053. //We couldn't get ownership of the session, just remove the session from the active session table.
  1054. //Remove the session from the active session table
  1055. RemoveActiveSession( pEmObject );
  1056. hr = S_OK;
  1057. break;
  1058. }
  1059. }
  1060. //Set the cursor to a wait cursor
  1061. CWaitCursor wait;
  1062. //Stop the debug session
  1063. hr = pActiveSession->pIDebugSession->StopDebug( TRUE );
  1064. if ( FAILED( hr ) ) {
  1065. break;
  1066. }
  1067. //Create bstr's for the journey ahead, and break if we can't
  1068. bstrEmObj = CopyBSTR ( ( LPBYTE ) pEmObject, sizeof( EmObject ) );
  1069. if( bstrEmObj == NULL ) {
  1070. hr = E_OUTOFMEMORY;
  1071. break;
  1072. }
  1073. //Get the status of the EmObject
  1074. hr = pActiveSession->pIDebugSession->GetStatus( bstrEmObj );
  1075. if ( FAILED( hr ) ) break;
  1076. //Convert the bstrEmObj to an PEmObject and memcopy it into the itemdata's PEmObject
  1077. pEmObjectTmp = GetEmObj(bstrEmObj);
  1078. if (pEmObjectTmp == NULL) {
  1079. hr = E_FAIL;
  1080. break;
  1081. }
  1082. SysFreeString( bstrEmObj );
  1083. //Remove the session from the active session table
  1084. // RemoveActiveSession( pEmObject );
  1085. //Update the ListCtl with the new info. The status should read Debug Completed or some such
  1086. memcpy(pEmObject, pEmObjectTmp, sizeof( EmObject ) );
  1087. UpdateListElement( pEmObject );
  1088. } while( FALSE );
  1089. if ( FAILED( hr ) ) {
  1090. ((CEmshellApp*)AfxGetApp())->DisplayErrMsgFromHR( hr );
  1091. }
  1092. SysFreeString ( bstrEmObj );
  1093. }
  1094. PActiveSession CEmshellView::AddActiveSession(PEmObject pEmObject, IEmDebugSession* pIEmDebugSession, BOOL bMaster)
  1095. {
  1096. PActiveSession pActiveSession = NULL;
  1097. do {
  1098. pActiveSession = AllocActiveSession(pEmObject, pIEmDebugSession);
  1099. if (pActiveSession == NULL) break;
  1100. //Initialize the bMaster flag of the active session object
  1101. pActiveSession->bMaster = bMaster;
  1102. //Set the session type
  1103. pActiveSession->nSessionType = (SessionType) pEmObject->type2;
  1104. //Set the object type
  1105. pActiveSession->emObjType = (EmObjectType) pEmObject->type;
  1106. //Add the pDebugSession to the session table if we succeeded in opening a debug session
  1107. m_SessionTable.Add((void*&)pActiveSession);
  1108. } while ( FALSE );
  1109. return pActiveSession;
  1110. }
  1111. void CEmshellView::UpdateListElement(PEmObject pEmObject)
  1112. {
  1113. switch (m_enumShellViewState) {
  1114. case SHELLVIEW_ALL:
  1115. RefreshAllViewElement(pEmObject);
  1116. break;
  1117. case SHELLVIEW_APPLICATIONS:
  1118. RefreshProcessViewElement(pEmObject);
  1119. break;
  1120. case SHELLVIEW_SERVICES:
  1121. RefreshServiceViewElement(pEmObject);
  1122. break;
  1123. case SHELLVIEW_COMPLETEDSESSIONS:
  1124. RefreshCompletedSessionViewElement(pEmObject);
  1125. break;
  1126. case SHELLVIEW_LOGFILES:
  1127. RefreshLogViewElement(pEmObject);
  1128. break;
  1129. case SHELLVIEW_DUMPFILES:
  1130. RefreshDumpViewElement(pEmObject);
  1131. break;
  1132. case SHELLVIEW_NONE:
  1133. default:
  1134. break;
  1135. }
  1136. }
  1137. void CEmshellView::RefreshProcessViewElement(PEmObject pEmObject)
  1138. {
  1139. CString strTempString = _T("");
  1140. int nImageOffset = 0;
  1141. //Given an PEmObject, find the element in the ListCtl, update it's image
  1142. //and call UpdateData on the ListControl
  1143. PEmObject pListEmObject = NULL;
  1144. //Step through every item in the list control searching for pEmObject
  1145. int nCount = m_mainListControl.GetItemCount();
  1146. for (int i = 0;i < nCount; i++) {
  1147. pListEmObject = (PEmObject)m_mainListControl.GetItemData(i);
  1148. if (pListEmObject == NULL) break;
  1149. if (memcmp((void *)pListEmObject->guidstream, (void *)pEmObject->guidstream, sizeof( GUID ) ) == 0) {
  1150. //Get the correct offset into the bitmap for the current status
  1151. nImageOffset = GetImageOffsetFromStatus((EmSessionStatus)pEmObject->nStatus);
  1152. //We have found the item, update its image based on its state
  1153. m_mainListControl.SetItem(i, 0, LVIF_IMAGE, NULL, nImageOffset, 0, 0, 0);
  1154. //Image Name
  1155. strTempString.Format(_T("%s"), pListEmObject->szName);
  1156. m_mainListControl.SetItemText(i, 0, strTempString);
  1157. //PID
  1158. strTempString.Format(_T("%d"), pListEmObject->nId);
  1159. m_mainListControl.SetItemText(i, 1, strTempString);
  1160. //
  1161. // a-mando
  1162. //
  1163. // Start Date
  1164. if( pEmObject->dateStart != 0L ) {
  1165. COleDateTime oleDtTm(pListEmObject->dateStart);
  1166. CString strStartDate = oleDtTm.Format(_T("%c"));
  1167. m_mainListControl.SetItemText(i, 2, strStartDate );
  1168. }
  1169. // End Date
  1170. if( pEmObject->dateEnd != 0L ) {
  1171. COleDateTime oleDtTm(pListEmObject->dateEnd);
  1172. CString strEndDate = oleDtTm.Format(_T("%c"));
  1173. m_mainListControl.SetItemText(i, 3, strEndDate );
  1174. }
  1175. // a-mando
  1176. //Status
  1177. ((CEmshellApp*)AfxGetApp())->GetStatusString(pListEmObject->nStatus, strTempString);
  1178. m_mainListControl.SetItemText(i, 4, strTempString);
  1179. m_mainListControl.Update(i);
  1180. //We have found the element, stop the search
  1181. break;
  1182. }
  1183. }
  1184. }
  1185. void CEmshellView::RefreshServiceViewElement(PEmObject pEmObject)
  1186. {
  1187. CString strTempString = _T("");
  1188. int nImageOffset = 0;
  1189. //Given an PEmObject, find the element in the ListCtl, update it's image
  1190. //and call UpdateData on the ListControl
  1191. PEmObject pListEmObject = NULL;
  1192. //Step through every item in the list control searching for pEmObject
  1193. int nCount = m_mainListControl.GetItemCount();
  1194. for (int i = 0;i < nCount; i++) {
  1195. pListEmObject = (PEmObject)m_mainListControl.GetItemData(i);
  1196. if (pListEmObject == NULL) break;
  1197. if (memcmp((void *)pListEmObject->guidstream, (void *)pEmObject->guidstream, sizeof( GUID ) ) == 0) {
  1198. //Get the correct offset into the bitmap for the current status
  1199. nImageOffset = GetImageOffsetFromStatus((EmSessionStatus)pEmObject->nStatus);
  1200. //We have found the item, update its image based on its state
  1201. m_mainListControl.SetItem(i, 0, LVIF_IMAGE, NULL, nImageOffset, 0, 0, 0);
  1202. //Image Name
  1203. strTempString.Format(_T("%s"), pListEmObject->szName);
  1204. m_mainListControl.SetItemText(i, 0, strTempString);
  1205. //Short Name
  1206. strTempString.Format(_T("%s"), pListEmObject->szSecName);
  1207. m_mainListControl.SetItemText(i, 1, strTempString);
  1208. //Description Name
  1209. strTempString.Format(_T("%s"), pListEmObject->szBucket1);
  1210. m_mainListControl.SetItemText(i, 2, strTempString);
  1211. //PID
  1212. strTempString.Format(_T("%d"), pListEmObject->nId);
  1213. m_mainListControl.SetItemText(i, 3, strTempString);
  1214. //
  1215. // a-mando
  1216. //
  1217. if( pEmObject->dateStart != 0L ) {
  1218. COleDateTime oleDtTm(pListEmObject->dateStart);
  1219. CString strStartDate = oleDtTm.Format(_T("%c"));
  1220. m_mainListControl.SetItemText(i, 4, strStartDate );
  1221. }
  1222. if( pEmObject->dateEnd != 0L ) {
  1223. COleDateTime oleDtTm(pListEmObject->dateEnd);
  1224. CString strEndDate = oleDtTm.Format(_T("%c"));
  1225. m_mainListControl.SetItemText(i, 5, strEndDate );
  1226. }
  1227. // a-mando
  1228. //Status
  1229. ((CEmshellApp*)AfxGetApp())->GetStatusString(pListEmObject->nStatus, strTempString);
  1230. m_mainListControl.SetItemText(i, 6, strTempString);
  1231. m_mainListControl.Update(i);
  1232. //We have found the element, stop the search
  1233. break;
  1234. }
  1235. }
  1236. }
  1237. void CEmshellView::RefreshCompletedSessionViewElement(PEmObject pEmObject)
  1238. {
  1239. RefreshServiceViewElement(pEmObject);
  1240. }
  1241. void CEmshellView::RefreshAllViewElement(PEmObject pEmObject)
  1242. {
  1243. RefreshServiceViewElement(pEmObject);
  1244. }
  1245. void CEmshellView::RefreshLogViewElement(PEmObject pEmObject)
  1246. {
  1247. CString strTempString = _T("");
  1248. int nImageOffset = 0;
  1249. int nImage = 0;
  1250. //Given an PEmObject, find the element in the ListCtl, update it's image
  1251. //and call UpdateData on the ListControl
  1252. PEmObject pListEmObject = NULL;
  1253. //Step through every item in the list control searching for pEmObject
  1254. int nCount = m_mainListControl.GetItemCount();
  1255. for (int i = 0;i < nCount; i++) {
  1256. pListEmObject = (PEmObject)m_mainListControl.GetItemData(i);
  1257. if (pListEmObject == NULL) break;
  1258. if (memcmp((void *)pListEmObject->guidstream, (void *)pEmObject->guidstream, sizeof( GUID ) ) == 0) {
  1259. //Get the correct offset into the bitmap for the current status
  1260. nImageOffset = GetImageOffsetFromStatus((EmSessionStatus)pEmObject->nStatus);
  1261. //We have found the item, update its image based on its state
  1262. m_mainListControl.SetItem(i, 0, LVIF_IMAGE, NULL, nImageOffset, 0, 0, 0);
  1263. //Image Name
  1264. strTempString.Format(_T("%d bytes"), pListEmObject->szName);
  1265. m_mainListControl.SetItemText(i, 0, strTempString);
  1266. //File Size
  1267. strTempString.Format(_T("%d"), pListEmObject->dwBucket1);
  1268. m_mainListControl.SetItemText(i, 1, strTempString);
  1269. m_mainListControl.Update(i);
  1270. //We have found the element, stop the search
  1271. break;
  1272. }
  1273. }
  1274. }
  1275. void CEmshellView::RefreshDumpViewElement(PEmObject pEmObject)
  1276. {
  1277. RefreshLogViewElement(pEmObject);
  1278. }
  1279. void CEmshellView::ReSynchApplications()
  1280. {
  1281. //iterate through all the sessions and find the corrisponding GUID in the ListCtrl
  1282. //Clear the list control
  1283. PEmObject pEmObject = NULL;
  1284. INT_PTR nUpperBound = 0;
  1285. PActiveSession pActiveSession = NULL;
  1286. HRESULT hr = S_OK;
  1287. BOOL bFound = FALSE;
  1288. do {
  1289. nUpperBound = m_SessionTable.GetUpperBound();
  1290. if (nUpperBound == -1) break;
  1291. //Get the GUID and look it up in the session table
  1292. //If found, map the pEmObject to the session, else remove it.
  1293. for (; nUpperBound >= 0; nUpperBound--) {
  1294. pActiveSession = (PActiveSession) m_SessionTable.GetAt(nUpperBound);
  1295. if (pActiveSession == NULL) {
  1296. hr = E_FAIL;
  1297. break;
  1298. }
  1299. //If the pActiveSession is not process, continue
  1300. if ( pActiveSession->emObjType != EMOBJ_PROCESS ) continue;
  1301. //Step through every item in the list control
  1302. int nCount = m_mainListControl.GetItemCount();
  1303. for (int i = 0;i < nCount; i++) {
  1304. pEmObject = (PEmObject)m_mainListControl.GetItemData(i);
  1305. if (pEmObject == NULL) {
  1306. hr = E_FAIL;
  1307. break;
  1308. }
  1309. if(memcmp((void *)&pActiveSession->guid, (void *)pEmObject->guidstream, sizeof( GUID ) ) == 0) {
  1310. //Assign the pEmObject to the pActiveSession
  1311. pActiveSession->pEmObject = pEmObject;
  1312. //We have found the element, stop the search
  1313. bFound = TRUE;
  1314. break;
  1315. }
  1316. }
  1317. if (!bFound) {
  1318. //We have a session table element that does not map to a list element
  1319. //Notify the error of the anomoly and remove it from the session table
  1320. CString strMessage;
  1321. strMessage.LoadString(IDS_SESSIONLISTANOMOLY);
  1322. ((CEmshellApp*)AfxGetApp())->DisplayErrMsgFromString(strMessage);
  1323. //Delete the pActiveSession. This will release the interface too
  1324. DeAllocActiveSession(pActiveSession);
  1325. //Remove the item from the session table
  1326. m_SessionTable.RemoveAt(nUpperBound);
  1327. break;
  1328. }
  1329. }
  1330. } while (FALSE);
  1331. if (FAILED(hr)) {
  1332. ((CEmshellApp*)AfxGetApp())->DisplayErrMsgFromHR(hr);
  1333. }
  1334. }
  1335. void CEmshellView::ReSynchServices()
  1336. {
  1337. //iterate through all the sessions and find the corrisponding GUID in the ListCtrl
  1338. //Clear the list control
  1339. PEmObject pEmObject = NULL;
  1340. INT_PTR nUpperBound = 0;
  1341. PActiveSession pActiveSession = NULL;
  1342. HRESULT hr = S_OK;
  1343. BOOL bFound = FALSE;
  1344. do {
  1345. nUpperBound = m_SessionTable.GetUpperBound();
  1346. if (nUpperBound == -1) break;
  1347. //Get the GUID and look it up in the session table
  1348. //If found, map the pEmObject to the session, else remove it.
  1349. for (; nUpperBound >= 0; nUpperBound--) {
  1350. pActiveSession = (PActiveSession) m_SessionTable.GetAt(nUpperBound);
  1351. if (pActiveSession == NULL) {
  1352. hr = E_FAIL;
  1353. break;
  1354. }
  1355. //If the pActiveSession is not service, continue
  1356. if ( pActiveSession->emObjType != EMOBJ_SERVICE ) continue;
  1357. //Step through every item in the list control
  1358. int nCount = m_mainListControl.GetItemCount();
  1359. for (int i = 0;i < nCount; i++) {
  1360. pEmObject = (PEmObject)m_mainListControl.GetItemData(i);
  1361. if (pEmObject == NULL) {
  1362. hr = E_FAIL;
  1363. break;
  1364. }
  1365. if(memcmp((void *)&pActiveSession->guid, (void *)pEmObject->guidstream, sizeof( GUID ) ) == 0) {
  1366. //Assign the pEmObject to the pActiveSession
  1367. pActiveSession->pEmObject = pEmObject;
  1368. //We have found the element, stop the search
  1369. bFound = TRUE;
  1370. break;
  1371. }
  1372. }
  1373. if (!bFound) {
  1374. //We have a session table element that does not map to a list element
  1375. //Notify the error of the anomoly and remove it from the session table
  1376. CString strMessage;
  1377. strMessage.LoadString(IDS_SESSIONLISTANOMOLY);
  1378. ((CEmshellApp*)AfxGetApp())->DisplayErrMsgFromString(strMessage);
  1379. //Delete the pActiveSession. This will release the interface too
  1380. DeAllocActiveSession(pActiveSession);
  1381. //Remove the item from the session table
  1382. m_SessionTable.RemoveAt(nUpperBound);
  1383. break;
  1384. }
  1385. }
  1386. } while (FALSE);
  1387. if (FAILED(hr)) {
  1388. ((CEmshellApp*)AfxGetApp())->DisplayErrMsgFromHR(hr);
  1389. }
  1390. }
  1391. void CEmshellView::ReSynchStoppedSessions()
  1392. {
  1393. //iterate through all the sessions and find the corrisponding GUID in the ListCtrl
  1394. //Clear the list control
  1395. PEmObject pEmObject = NULL;
  1396. INT_PTR nUpperBound = 0;
  1397. PActiveSession pActiveSession = NULL;
  1398. HRESULT hr = S_OK;
  1399. BOOL bFound = FALSE;
  1400. do {
  1401. nUpperBound = m_SessionTable.GetUpperBound();
  1402. if (nUpperBound == -1) break;
  1403. //Get the GUID and look it up in the session table
  1404. //If found, map the pEmObject to the session, else remove it.
  1405. for (; nUpperBound >= 0; nUpperBound--) {
  1406. pActiveSession = (PActiveSession) m_SessionTable.GetAt(nUpperBound);
  1407. if (pActiveSession == NULL) {
  1408. hr = E_FAIL;
  1409. break;
  1410. }
  1411. //Step through every item in the list control
  1412. int nCount = m_mainListControl.GetItemCount();
  1413. for (int i = 0;i < nCount; i++) {
  1414. pEmObject = (PEmObject)m_mainListControl.GetItemData(i);
  1415. if (pEmObject == NULL) {
  1416. hr = E_FAIL;
  1417. break;
  1418. }
  1419. if(memcmp((void *)&pActiveSession->guid, (void *)pEmObject->guidstream, sizeof( GUID ) ) == 0) {
  1420. //Assign the pEmObject to the pActiveSession
  1421. pActiveSession->pEmObject = pEmObject;
  1422. //We have found the element, stop the search
  1423. bFound = TRUE;
  1424. break;
  1425. }
  1426. }
  1427. }
  1428. } while (FALSE);
  1429. if (FAILED(hr)) {
  1430. ((CEmshellApp*)AfxGetApp())->DisplayErrMsgFromHR(hr);
  1431. }
  1432. }
  1433. void CEmshellView::GenerateDump(PEmObject pEmObject, BOOL bMiniDump)
  1434. {
  1435. INT_PTR nUpperBound = 0;
  1436. PActiveSession pActiveSession = NULL;
  1437. HRESULT hr = E_FAIL;
  1438. BSTR bstrEmObj = NULL;
  1439. IEmDebugSession* pTempDebugSession = NULL;
  1440. BOOL bTempSession = FALSE;
  1441. PEmObject pEmObjectTmp = NULL;
  1442. //Set the cursor to a wait cursor
  1443. CWaitCursor wait;
  1444. do {
  1445. //Find the element in the session table
  1446. pActiveSession = FindActiveSession( pEmObject );
  1447. //Create bstr's for the journey ahead, and break if we can't
  1448. bstrEmObj = CopyBSTR ( (LPBYTE)pEmObject, sizeof( EmObject ) );
  1449. if( bstrEmObj == NULL ){
  1450. hr = E_OUTOFMEMORY;
  1451. break;
  1452. }
  1453. if (pActiveSession == NULL) {
  1454. //Get a temporary IDebugSession*
  1455. hr = GetDocument()->GetEmManager()->OpenSession(bstrEmObj, &pTempDebugSession);
  1456. if (FAILED(hr)) break;
  1457. bTempSession = TRUE;
  1458. }
  1459. else {
  1460. //Generate the dumpfile
  1461. pTempDebugSession = pActiveSession->pIDebugSession;
  1462. if ( pTempDebugSession == NULL ) break;
  1463. }
  1464. //Generate the dumpfile
  1465. hr = pTempDebugSession->GenerateDumpFile(bMiniDump);
  1466. if (FAILED(hr)) break;
  1467. hr = pTempDebugSession->GetStatus(bstrEmObj);
  1468. if (FAILED(hr)) break;
  1469. //Convert the bstrEmObj to an PEmObject and memcopy it into the itemdata's PEmObject
  1470. pEmObjectTmp = GetEmObj(bstrEmObj);
  1471. if (pEmObjectTmp == NULL) break;
  1472. SysFreeString( bstrEmObj );
  1473. memcpy(pEmObject, pEmObjectTmp, sizeof( EmObject ) );
  1474. //Update the ListCtl with the new info
  1475. UpdateListElement(pEmObject);
  1476. } while (FALSE);
  1477. if (FAILED(hr)) {
  1478. ((CEmshellApp*)AfxGetApp())->DisplayErrMsgFromHR(hr);
  1479. }
  1480. SysFreeString( bstrEmObj );
  1481. if ( bTempSession && pTempDebugSession ) {
  1482. //Release the pTempDebugSession pointer
  1483. SAFE_RELEASEIX( pTempDebugSession );
  1484. }
  1485. }
  1486. void CEmshellView::OnViewRefresh()
  1487. {
  1488. RefreshListCtl();
  1489. }
  1490. void CEmshellView::RefreshListCtl()
  1491. {
  1492. //refresh the list control based on it's contents
  1493. if ( GetDocument()->GetConnectedToServerState() ) {
  1494. //Refresh everything. Rebuild the list.
  1495. ListCtrlClear();
  1496. //Pass in the current view
  1497. ListCtrlPopulate(m_enumShellViewState);
  1498. m_mainListControl.RefreshList();
  1499. }
  1500. }
  1501. //******** Right click popup menu item updateUI handlers ***********//
  1502. //*********************************************************//
  1503. void CEmshellView::OnUpdateProcesspopupStopDebugSession( CCmdUI* pCmdUI )
  1504. {
  1505. PEmObject pEmObject = NULL;
  1506. BOOL bEnable = FALSE;
  1507. PActiveSession pActiveSession = NULL;
  1508. do {
  1509. if ( !GetDocument()->GetConnectedToServerState() ) break;
  1510. if ( m_enumShellViewState != SHELLVIEW_ALL &&
  1511. m_enumShellViewState != SHELLVIEW_APPLICATIONS &&
  1512. m_enumShellViewState != SHELLVIEW_SERVICES &&
  1513. m_enumShellViewState != SHELLVIEW_COMPLETEDSESSIONS ) break;
  1514. // Update the state of this button based on the state of the currently selected item
  1515. //Get the currently selected emObject
  1516. pEmObject = GetSelectedEmObject();
  1517. if ( pEmObject == NULL ) break;
  1518. pActiveSession = FindActiveSession( pEmObject );
  1519. //Determine if the status of pActiveSession and enable this appropriately
  1520. if ( pEmObject->nStatus & STAT_SESS_DEBUG_IN_PROGRESS &&
  1521. ( pEmObject->nStatus & STAT_ORPHAN || pActiveSession ) )
  1522. bEnable = TRUE;
  1523. }while ( FALSE );
  1524. pCmdUI->Enable( bEnable);
  1525. }
  1526. void CEmshellView::OnUpdateProcesspopupCancelDebugSession( CCmdUI* pCmdUI )
  1527. {
  1528. PEmObject pEmObject = NULL;
  1529. BOOL bEnable = FALSE;
  1530. PActiveSession pActiveSession = NULL;
  1531. do {
  1532. if ( !GetDocument()->GetConnectedToServerState() ) break;
  1533. if ( m_enumShellViewState != SHELLVIEW_ALL &&
  1534. m_enumShellViewState != SHELLVIEW_APPLICATIONS &&
  1535. m_enumShellViewState != SHELLVIEW_SERVICES &&
  1536. m_enumShellViewState != SHELLVIEW_COMPLETEDSESSIONS ) break;
  1537. // Update the state of this button based on the state of the currently selected item
  1538. //Get the currently selected emObject
  1539. pEmObject = GetSelectedEmObject();
  1540. if ( pEmObject == NULL ) break;
  1541. pActiveSession = FindActiveSession( pEmObject );
  1542. //Determine if the status of pActiveSession and enable this apprpriately
  1543. if ( pEmObject->nStatus & STAT_SESS_DEBUG_IN_PROGRESS &&
  1544. ( pEmObject->nStatus & STAT_ORPHAN || ( pActiveSession && pActiveSession->bMaster ) ) )
  1545. bEnable = TRUE;
  1546. }while (FALSE);
  1547. pCmdUI->Enable( bEnable);
  1548. }
  1549. void CEmshellView::OnUpdateViewRefresh(CCmdUI* pCmdUI)
  1550. {
  1551. //We get this call everytime the menu is about to be shown
  1552. pCmdUI->Enable ( GetDocument()->GetConnectedToServerState() );
  1553. }
  1554. void CEmshellView::OnUpdateProcesspopupGenerateminidump(CCmdUI* pCmdUI)
  1555. {
  1556. PEmObject pEmObject = NULL;
  1557. BOOL bEnable = FALSE;
  1558. do {
  1559. if ( !GetDocument()->GetConnectedToServerState() ) break;
  1560. if ( m_enumShellViewState != SHELLVIEW_ALL &&
  1561. m_enumShellViewState != SHELLVIEW_APPLICATIONS &&
  1562. m_enumShellViewState != SHELLVIEW_SERVICES &&
  1563. m_enumShellViewState != SHELLVIEW_COMPLETEDSESSIONS ) break;
  1564. // Update the state of this button based on the state of the currently selected item
  1565. // If we are the master, then we can stop this session
  1566. //Get the currently selected emObject
  1567. pEmObject = GetSelectedEmObject();
  1568. if ( pEmObject == NULL ) break;
  1569. if ( !( pEmObject->nStatus & STAT_NOTRUNNING ) &&
  1570. !( pEmObject->nStatus & STAT_SESS_STOPPED ) &&
  1571. ( pEmObject->type & EMOBJ_PROCESS ||
  1572. pEmObject->type & EMOBJ_SERVICE ) ) {
  1573. bEnable = TRUE;
  1574. }
  1575. }while (FALSE);
  1576. pCmdUI->Enable( bEnable);
  1577. }
  1578. void CEmshellView::OnUpdateProcesspopupGenerateuserdump(CCmdUI* pCmdUI)
  1579. {
  1580. PEmObject pEmObject = NULL;
  1581. BOOL bEnable = FALSE;
  1582. do {
  1583. if ( !GetDocument()->GetConnectedToServerState() ) break;
  1584. if ( m_enumShellViewState != SHELLVIEW_ALL &&
  1585. m_enumShellViewState != SHELLVIEW_APPLICATIONS &&
  1586. m_enumShellViewState != SHELLVIEW_SERVICES &&
  1587. m_enumShellViewState != SHELLVIEW_COMPLETEDSESSIONS ) break;
  1588. // Update the state of this button based on the state of the currently selected item
  1589. // If we are the master, then we can stop this session
  1590. //Get the currently selected emObject
  1591. pEmObject = GetSelectedEmObject();
  1592. if ( pEmObject == NULL ) break;
  1593. if ( !( pEmObject->nStatus & STAT_NOTRUNNING ) &&
  1594. !( pEmObject->nStatus & STAT_SESS_STOPPED ) &&
  1595. ( pEmObject->type & EMOBJ_PROCESS ||
  1596. pEmObject->type & EMOBJ_SERVICE ) ) {
  1597. bEnable = TRUE;
  1598. }
  1599. }while (FALSE);
  1600. pCmdUI->Enable( bEnable);
  1601. }
  1602. void CEmshellView::OnUpdateProcesspopupAutomaticsession(CCmdUI* pCmdUI)
  1603. {
  1604. PEmObject pEmObject = NULL;
  1605. BOOL bEnable = FALSE;
  1606. PActiveSession pActiveSession = NULL;
  1607. // Allow if this isn't being debugged
  1608. do {
  1609. if ( !GetDocument()->GetConnectedToServerState() ) break;
  1610. if ( m_enumShellViewState != SHELLVIEW_ALL &&
  1611. m_enumShellViewState != SHELLVIEW_APPLICATIONS &&
  1612. m_enumShellViewState != SHELLVIEW_SERVICES &&
  1613. m_enumShellViewState != SHELLVIEW_COMPLETEDSESSIONS ) break;
  1614. // Update the state of this button based on the state of the currently selected item
  1615. //Get the currently selected emObject
  1616. pEmObject = GetSelectedEmObject();
  1617. if ( pEmObject == NULL ) break;
  1618. //Find the element in the session table
  1619. pActiveSession = FindActiveSession( pEmObject );
  1620. //Determine the status of pActiveSession and enable this apprpriately
  1621. if ( !pActiveSession && (pEmObject->nStatus & STAT_SESS_NOT_STARTED) ||
  1622. ( pEmObject->type2 == SessType_Automatic && pEmObject->nStatus & STAT_ORPHAN ) ) {
  1623. bEnable = TRUE;
  1624. }
  1625. }while (FALSE);
  1626. pCmdUI->Enable( bEnable);
  1627. }
  1628. void CEmshellView::OnUpdateProcesspopupManualsession(CCmdUI* pCmdUI)
  1629. {
  1630. PEmObject pEmObject = NULL;
  1631. BOOL bEnable = FALSE;
  1632. PActiveSession pActiveSession = NULL;
  1633. // Allow if this isn't being debugged
  1634. do {
  1635. if ( !GetDocument()->GetConnectedToServerState() ) break;
  1636. if ( m_enumShellViewState != SHELLVIEW_ALL &&
  1637. m_enumShellViewState != SHELLVIEW_APPLICATIONS &&
  1638. m_enumShellViewState != SHELLVIEW_SERVICES &&
  1639. m_enumShellViewState != SHELLVIEW_COMPLETEDSESSIONS ) break;
  1640. // Update the state of this button based on the state of the currently selected item
  1641. // If we are the master, then we can stop this session
  1642. //Get the currently selected emObject
  1643. pEmObject = GetSelectedEmObject();
  1644. if ( pEmObject == NULL ) break;
  1645. //Find the element in the session table
  1646. pActiveSession = FindActiveSession( pEmObject );
  1647. //Determine if the status of pActiveSession and enable this apprpriately
  1648. // if ( pEmObject->nStatus & STAT_SESS_NOT_STARTED ) {
  1649. if ( !pActiveSession && (pEmObject->nStatus & STAT_SESS_NOT_STARTED) ||
  1650. ( pEmObject->type2 == SessType_Manual && pEmObject->nStatus & STAT_ORPHAN ) ) {
  1651. bEnable = TRUE;
  1652. }
  1653. }while (FALSE);
  1654. pCmdUI->Enable( bEnable);
  1655. }
  1656. void CEmshellView::OnUpdateProcesspopupProperties(CCmdUI* pCmdUI)
  1657. {
  1658. BOOL bEnable = FALSE;
  1659. do {
  1660. if ( !GetDocument()->GetConnectedToServerState() ) break;
  1661. if ( GetSelectedEmObject() == NULL ) break;
  1662. bEnable = TRUE;
  1663. } while ( FALSE );
  1664. // Always allow properties
  1665. pCmdUI->Enable( bEnable );
  1666. }
  1667. void CEmshellView::OnUpdateProcesspopupRefresh(CCmdUI* pCmdUI)
  1668. {
  1669. // Only allow refresh if the current item is in our session table
  1670. PEmObject pEmObject = NULL;
  1671. BOOL bEnable = FALSE;
  1672. do {
  1673. if ( !GetDocument()->GetConnectedToServerState() ) break;
  1674. if ( m_enumShellViewState != SHELLVIEW_ALL &&
  1675. m_enumShellViewState != SHELLVIEW_APPLICATIONS &&
  1676. m_enumShellViewState != SHELLVIEW_SERVICES &&
  1677. m_enumShellViewState != SHELLVIEW_COMPLETEDSESSIONS ) break;
  1678. // Update the state of this button based on the state of the currently selected item
  1679. // If we are the master, then we can stop this session
  1680. //Get the currently selected emObject
  1681. pEmObject = GetSelectedEmObject();
  1682. if ( pEmObject == NULL ) break;
  1683. bEnable = TRUE;
  1684. }while (FALSE);
  1685. pCmdUI->Enable( bEnable);
  1686. }
  1687. //******** Right click popup menu item handlers ***********//
  1688. //*********************************************************//
  1689. void CEmshellView::OnProcesspopupStopDebugSession()
  1690. {
  1691. //Stop the session for the current item selected
  1692. PEmObject pEmObject = NULL;
  1693. HRESULT hr = E_FAIL;
  1694. do {
  1695. pEmObject = GetSelectedEmObject();
  1696. if ( pEmObject == NULL ) break;
  1697. //Stop and remove the session
  1698. StopDebugSession( pEmObject );
  1699. hr = S_OK;
  1700. } while ( FALSE );
  1701. if ( FAILED( hr ) ) {
  1702. ((CEmshellApp*)AfxGetApp())->DisplayErrMsgFromHR( hr );
  1703. }
  1704. }
  1705. void CEmshellView::OnProcesspopupGenerateminidump()
  1706. {
  1707. PEmObject pEmObject = NULL;
  1708. HRESULT hr = E_FAIL;
  1709. do {
  1710. pEmObject = GetSelectedEmObject();
  1711. if (pEmObject == NULL) break;
  1712. //Generate the MiniDump file
  1713. GenerateDump(pEmObject, TRUE);
  1714. hr = S_OK;
  1715. } while (FALSE);
  1716. if (FAILED(hr)) {
  1717. ((CEmshellApp*)AfxGetApp())->DisplayErrMsgFromHR(hr);
  1718. }
  1719. }
  1720. void CEmshellView::OnProcesspopupGenerateuserdump()
  1721. {
  1722. PEmObject pEmObject = NULL;
  1723. HRESULT hr = E_FAIL;
  1724. do {
  1725. pEmObject = GetSelectedEmObject();
  1726. if (pEmObject == NULL) break;
  1727. //Generate the UserDump file
  1728. GenerateDump(pEmObject, FALSE);
  1729. hr = S_OK;
  1730. } while(FALSE);
  1731. if (FAILED(hr)) {
  1732. ((CEmshellApp*)AfxGetApp())->DisplayErrMsgFromHR(hr);
  1733. }
  1734. }
  1735. void CEmshellView::OnProcesspopupAutomaticsession()
  1736. {
  1737. PEmObject pEmObject = NULL;
  1738. HRESULT hr = E_FAIL;
  1739. do {
  1740. pEmObject = GetSelectedEmObject();
  1741. if ( pEmObject == NULL ) break;
  1742. //Start the automatic session
  1743. hr = StartAutomaticDebugSession(pEmObject);
  1744. } while (FALSE);
  1745. }
  1746. void CEmshellView::OnProcesspopupManualsession()
  1747. {
  1748. // Start a manual session with the server
  1749. PEmObject pEmObject = NULL;
  1750. HRESULT hr = E_FAIL;
  1751. do {
  1752. pEmObject = GetSelectedEmObject();
  1753. if (pEmObject == NULL) break;
  1754. //Start the manual session
  1755. hr = StartManualDebugSession(pEmObject);
  1756. } while (FALSE);
  1757. if (FAILED(hr)) {
  1758. ((CEmshellApp*)AfxGetApp())->DisplayErrMsgFromHR(hr);
  1759. }
  1760. }
  1761. void CEmshellView::OnProcesspopupProperties()
  1762. {
  1763. PEmObject pEmObject = NULL;
  1764. IEmDebugSession* pIDebugSession = NULL;
  1765. do {
  1766. pEmObject = GetSelectedEmObject();
  1767. if ( pEmObject == NULL ) break;
  1768. if ( pEmObject ) {
  1769. //Get the current view state from the shell
  1770. switch ( GetViewState() ) {
  1771. case SHELLVIEW_LOGFILES:
  1772. case SHELLVIEW_DUMPFILES:
  1773. case SHELLVIEW_MSINFOFILES:
  1774. ShowProperties( pEmObject );
  1775. break;
  1776. default:
  1777. DoModalPropertySheet( pEmObject );
  1778. }
  1779. }
  1780. } while (FALSE);
  1781. }
  1782. void CEmshellView::OnProcesspopupRefresh()
  1783. {
  1784. // Refresh the currently selected item
  1785. // Get the currently selected EmObject
  1786. PEmObject pEmObject = NULL;
  1787. HRESULT hr = E_FAIL;
  1788. PActiveSession pActiveSession = NULL;
  1789. BSTR bstrEmObj = NULL;
  1790. PEmObject pEmObjectTmp = NULL;
  1791. IEmDebugSession* pTempDebugSession = NULL;
  1792. BOOL bTempSession = FALSE;
  1793. do {
  1794. pEmObject = GetSelectedEmObject();
  1795. if (pEmObject == NULL) break;
  1796. //Find the element in the session table
  1797. pActiveSession = FindActiveSession( pEmObject );
  1798. //Create bstr's for the journey ahead, and break if we can't
  1799. bstrEmObj = CopyBSTR ( (LPBYTE)pEmObject, sizeof( EmObject ) );
  1800. if( bstrEmObj == NULL ){
  1801. hr = E_OUTOFMEMORY;
  1802. break;
  1803. }
  1804. if ( pActiveSession == NULL ) {
  1805. hr = GetDocument()->GetEmManager()->OpenSession(bstrEmObj, &pTempDebugSession);
  1806. if (FAILED(hr)) break;
  1807. bTempSession = TRUE;
  1808. hr = pTempDebugSession->GetStatus(bstrEmObj);
  1809. if (FAILED(hr)) break;
  1810. }
  1811. else {
  1812. hr = pActiveSession->pIDebugSession->GetStatus(bstrEmObj);
  1813. if (FAILED(hr)) break;
  1814. }
  1815. //Convert the bstrEmObj to an PEmObject and memcopy it into the itemdata's PEmObject
  1816. pEmObjectTmp = GetEmObj(bstrEmObj);
  1817. if (pEmObjectTmp == NULL) break;
  1818. SysFreeString( bstrEmObj );
  1819. memcpy(pEmObject, pEmObjectTmp, sizeof( EmObject ) );
  1820. //Update the element
  1821. UpdateListElement(pEmObject);
  1822. hr = S_OK;
  1823. } while (FALSE);
  1824. if (FAILED(hr)) {
  1825. ((CEmshellApp*)AfxGetApp())->DisplayErrMsgFromHR(hr);
  1826. }
  1827. SysFreeString ( bstrEmObj );
  1828. if ( pTempDebugSession ) {
  1829. //Release the pTempDebugSession pointer
  1830. SAFE_RELEASEIX( pTempDebugSession );
  1831. }
  1832. }
  1833. PEmObject CEmshellView::GetSelectedEmObject()
  1834. {
  1835. PEmObject pEmObject = NULL;
  1836. int nIndex = -1;
  1837. do {
  1838. nIndex = GetSelectedItemIndex();
  1839. if (nIndex == -1) break;
  1840. pEmObject = (PEmObject) m_mainListControl.GetItemData(nIndex);
  1841. } while (FALSE);
  1842. return pEmObject;
  1843. }
  1844. int CEmshellView::GetSelectedItemIndex()
  1845. {
  1846. POSITION pos = 0;
  1847. int nIndex = -1;
  1848. do {
  1849. pos = m_mainListControl.GetFirstSelectedItemPosition();
  1850. if(pos == NULL) break;
  1851. //Get the nIndex for the currently selected item
  1852. nIndex = m_mainListControl.GetNextSelectedItem(pos);
  1853. } while (FALSE);
  1854. return nIndex;
  1855. }
  1856. PActiveSession CEmshellView::FindActiveSession(PEmObject pEmObject)
  1857. {
  1858. //iterate through all the sessions and find the corrisponding pEmObject
  1859. INT_PTR nUpperBound = 0;
  1860. PActiveSession pActiveSession = NULL;
  1861. BOOL bFound = FALSE;
  1862. PActiveSession pRetVal = NULL;
  1863. do {
  1864. nUpperBound = m_SessionTable.GetUpperBound();
  1865. if ( nUpperBound == -1 ) break;
  1866. if ( pEmObject == NULL ) break;
  1867. //look up the pEmObject in the session table
  1868. //If found, map the pEmObject to the session, else remove it.
  1869. for (; nUpperBound >= 0; nUpperBound--) {
  1870. pActiveSession = (PActiveSession) m_SessionTable.GetAt(nUpperBound);
  1871. if ( pActiveSession == NULL ) break;
  1872. if( memcmp( ( void * ) &pActiveSession->guid, ( void * ) pEmObject->guidstream, sizeof( GUID ) ) == 0 ) {
  1873. pRetVal = pActiveSession;
  1874. }
  1875. }
  1876. } while ( FALSE );
  1877. return pRetVal;
  1878. }
  1879. int CEmshellView::GetImageOffsetFromStatus(EmSessionStatus em)
  1880. {
  1881. int retVal = 0;
  1882. //Use a switch/case statement to determine the correct offset into the bitmap
  1883. switch (em) {
  1884. case STAT_SESS_NONE_STAT_NONE:
  1885. retVal = 0;
  1886. break;
  1887. case STAT_SESS_NOT_STARTED_NOTRUNNING:
  1888. retVal = 1;
  1889. break;
  1890. case STAT_SESS_NOT_STARTED_RUNNING:
  1891. retVal = 2;
  1892. break;
  1893. case STAT_SESS_NOT_STARTED_FILECREATED_SUCCESSFULLY:
  1894. retVal = 3;
  1895. break;
  1896. case STAT_SESS_NOT_STARTED_FILECREATION_FAILED:
  1897. retVal = 4;
  1898. break;
  1899. case STAT_SESS_DEBUG_IN_PROGRESS_NONE:
  1900. retVal = 5;
  1901. break;
  1902. case STAT_SESS_DEBUG_IN_PROGRESS_FILECREATED_SUCESSFULLY:
  1903. retVal = 6;
  1904. break;
  1905. case STAT_SESS_DEBUG_IN_PROGRESS_FILECREATION_FAILED:
  1906. retVal = 7;
  1907. break;
  1908. case STAT_SESS_DEBUG_IN_PROGRESS_ORPHAN_NONE:
  1909. retVal = 8;
  1910. break;
  1911. case STAT_SESS_DEBUG_IN_PROGRESS_ORPHAN_FILECREATED_SUCESSFULLY:
  1912. retVal = 9;
  1913. break;
  1914. case STAT_SESS_DEBUG_IN_PROGRESS_ORPHAN_FILECREATION_FAILED:
  1915. retVal = 10;
  1916. break;
  1917. case STAT_SESS_STOPPED_SUCCESS:
  1918. retVal = 11;
  1919. break;
  1920. case STAT_SESS_STOPPED_FAILED:
  1921. retVal = 12;
  1922. break;
  1923. case STAT_SESS_STOPPED_ORPHAN_SUCCESS:
  1924. retVal = 13;
  1925. break;
  1926. case STAT_SESS_STOPPED_ORPHAN_FAILED:
  1927. retVal = 14;
  1928. break;
  1929. case STAT_SESS_STOPPED_DEBUGGEE_KILLED:
  1930. retVal = 15;
  1931. break;
  1932. case STAT_SESS_STOPPED_DEBUGGEE_EXITED:
  1933. retVal = 16;
  1934. break;
  1935. case STAT_SESS_STOPPED_EXCEPTION_OCCURED:
  1936. retVal = 17;
  1937. break;
  1938. case STAT_SESS_STOPPED_ORPHAN_DEBUGGEE_KILLED:
  1939. retVal = 18;
  1940. break;
  1941. case STAT_SESS_STOPPED_ORPHAN_DEBUGGEE_EXITED:
  1942. retVal = 19;
  1943. break;
  1944. case STAT_SESS_STOPPED_ORPHAN_EXCEPTION_OCCURED:
  1945. retVal = 20;
  1946. break;
  1947. case STAT_SESS_STOPPED_ACCESSVIOLATION_OCCURED:
  1948. retVal = 21;
  1949. break;
  1950. case STAT_SESS_STOPPED_ORPHAN_ACCESSVIOLATION_OCCURED:
  1951. retVal = 22;
  1952. break;
  1953. }
  1954. return retVal;
  1955. }
  1956. void CEmshellView::InitializeAllView()
  1957. {
  1958. InitializeServiceView();
  1959. }
  1960. void CEmshellView::InitializeCompletedSessionsView()
  1961. {
  1962. InitializeServiceView();
  1963. }
  1964. void CEmshellView::InitializeProcessView()
  1965. {
  1966. //This gets called only when the user is first starting the app or when
  1967. //the user is changing views.
  1968. //Reset the list control
  1969. m_mainListControl.ResetListCtrl();
  1970. //Load the string resources for the CListCtrl columns
  1971. CString strImageName, strPID, strStatus, strStartDate, strEndDate;
  1972. strImageName.LoadString(IDS_LC_IMAGENAME);
  1973. strPID.LoadString(IDS_LC_PID);
  1974. strStatus.LoadString(IDS_LC_STATUS);
  1975. strStartDate.LoadString(IDS_LC_STARTDATE);
  1976. strEndDate.LoadString(IDS_LC_ENDDATE);
  1977. //Unload the last image resources, if there are any
  1978. m_ShellImageList.DeleteImageList();
  1979. //Load the image resources for the CListCtrl items
  1980. m_ShellImageList.Create(IDB_STATUS_BITMAP, 16, 1, CLR_NONE);
  1981. m_mainListControl.SetImageList(&m_ShellImageList, LVSIL_SMALL);
  1982. //Add the columns to the list control
  1983. m_mainListControl.BeginSetColumn(5);
  1984. m_mainListControl.AddColumn(strImageName);
  1985. m_mainListControl.AddColumn(strPID, VT_I4);
  1986. m_mainListControl.AddColumn(strStartDate);
  1987. m_mainListControl.AddColumn(strEndDate);
  1988. m_mainListControl.AddColumn(strStatus);
  1989. m_mainListControl.EndSetColumn();
  1990. m_mainListControl.ResizeColumnsFitScreen();
  1991. m_mainListControl.SetExtendedStyle(LVS_EX_FULLROWSELECT);
  1992. }
  1993. void CEmshellView::InitializeServiceView()
  1994. {
  1995. //This gets called only when the user is first starting the app or when
  1996. //the user is changing views.
  1997. //Reset the list control
  1998. m_mainListControl.ResetListCtrl();
  1999. //Load the string resources for the CListCtrl columns
  2000. CString strImageName, strPID, strStatus, strShortName, strDescription,
  2001. strStartDate, strEndDate;
  2002. strImageName.LoadString(IDS_LC_IMAGENAME);
  2003. strPID.LoadString(IDS_LC_PID);
  2004. strStatus.LoadString(IDS_LC_STATUS);
  2005. strShortName.LoadString(IDS_LC_SHORTNAME);
  2006. strDescription.LoadString(IDS_LC_DESCRIPTION);
  2007. strStartDate.LoadString(IDS_LC_STARTDATE);
  2008. strEndDate.LoadString(IDS_LC_ENDDATE);
  2009. //Unload the last image resources, if there are any
  2010. m_ShellImageList.DeleteImageList();
  2011. //Load the image resources for the CListCtrl items
  2012. m_ShellImageList.Create(IDB_STATUS_BITMAP, 16, 1, CLR_NONE);
  2013. m_mainListControl.SetImageList(&m_ShellImageList, LVSIL_SMALL);
  2014. //Add the columns to the list control
  2015. m_mainListControl.BeginSetColumn(7);
  2016. m_mainListControl.AddColumn(strImageName);
  2017. m_mainListControl.AddColumn(strShortName);
  2018. m_mainListControl.AddColumn(strDescription);
  2019. m_mainListControl.AddColumn(strPID, VT_I4);
  2020. m_mainListControl.AddColumn(strStartDate);
  2021. m_mainListControl.AddColumn(strEndDate);
  2022. m_mainListControl.AddColumn(strStatus);
  2023. m_mainListControl.EndSetColumn();
  2024. m_mainListControl.ResizeColumnsFitScreen();
  2025. m_mainListControl.SetExtendedStyle(LVS_EX_FULLROWSELECT);
  2026. }
  2027. void CEmshellView::InitializeLogView()
  2028. {
  2029. //Reset the list control
  2030. m_mainListControl.ResetListCtrl();
  2031. //Load the string resources for the CListCtrl columns
  2032. CString strFileName, strSize, strTime; //, strProc;
  2033. strFileName.LoadString(IDS_LC_FILENAME);
  2034. strSize.LoadString(IDS_LC_FILESIZE);
  2035. strTime.LoadString(IDS_LC_FILETIME);
  2036. // strProc.LoadString(IDS_LC_FILEPROCESS);
  2037. //Unload the last image resources, if there are any
  2038. m_ShellImageList.DeleteImageList();
  2039. //Load the image resources for the CListCtrl items
  2040. m_ShellImageList.Create(IDB_STATUS_BITMAP, 16, 1, CLR_NONE);
  2041. m_mainListControl.SetImageList(&m_ShellImageList, LVSIL_SMALL);
  2042. //Add the columns to the list control
  2043. m_mainListControl.BeginSetColumn(3);
  2044. m_mainListControl.AddColumn(strFileName);
  2045. m_mainListControl.AddColumn(strSize, VT_I4);
  2046. m_mainListControl.AddColumn(strTime);
  2047. // m_mainListControl.AddColumn(strProc);
  2048. m_mainListControl.EndSetColumn();
  2049. m_mainListControl.ResizeColumnsFitScreen();
  2050. m_mainListControl.SetExtendedStyle(LVS_EX_FULLROWSELECT);
  2051. }
  2052. void CEmshellView::InitializeDumpView()
  2053. {
  2054. InitializeLogView();
  2055. }
  2056. void CEmshellView::PopulateProcessType()
  2057. {
  2058. _variant_t var; //This will create and initialize the var variant
  2059. HRESULT hr = E_FAIL;
  2060. LONG lLBound = 0;
  2061. LONG lUBound = 0;
  2062. BSTR bstrEmObj = NULL;
  2063. BSTR bstrEmObjectFilter = NULL;
  2064. PEmObject pCurrentObj = NULL;
  2065. EmObject EmObjectFilter;
  2066. memset(&EmObjectFilter, 0, sizeof( EmObject ));
  2067. do {
  2068. EmObjectFilter.type = EMOBJ_PROCESS;
  2069. bstrEmObjectFilter = CopyBSTR ( (LPBYTE)&EmObjectFilter, sizeof( EmObject ) );
  2070. //Populate the list control based on the EmObjectType
  2071. //Enumerate all the objects and stick them in the variant
  2072. //hr = GetDocument()->GetEmManager()->EnumObjectsEx(bstrEmObjectFilter, &var);
  2073. hr = GetDocument()->GetEmManager()->EnumObjects(EMOBJ_PROCESS, &var );
  2074. if(FAILED(hr)) break;
  2075. //Get the lower and upper bounds of the variant array
  2076. hr = SafeArrayGetLBound(var.parray, 1, &lLBound);
  2077. if(FAILED(hr)) break;
  2078. hr = SafeArrayGetUBound(var.parray, 1, &lUBound);
  2079. if(FAILED(hr)) break;
  2080. //There are elements at both the lower bound and upper bound, so include them
  2081. for(; lLBound <= lUBound; lLBound++)
  2082. {
  2083. //Get a BSTR object from the safe array
  2084. hr = SafeArrayGetElement(var.parray, &lLBound, &bstrEmObj);
  2085. if (FAILED(hr)) break;
  2086. //Create a local copy of the EmObject (there aren't any pointers in
  2087. //EmObject structure, so don't worry about doing a deep copy
  2088. pCurrentObj = ((CEmshellApp*)AfxGetApp())->AllocEmObject();
  2089. if ( pCurrentObj != NULL ) {
  2090. *pCurrentObj = *GetEmObj( bstrEmObj );
  2091. }
  2092. SysFreeString( bstrEmObj );
  2093. //Unallocate the EmObject if it has an hr of E_FAIL
  2094. if (FAILED(pCurrentObj->hr)) {
  2095. ((CEmshellApp*)AfxGetApp())->DeAllocEmObject( pCurrentObj );
  2096. continue;
  2097. }
  2098. if ( !( (CEmshellApp*)AfxGetApp() )->CanDisplayProcess( pCurrentObj->szName ) ){
  2099. ((CEmshellApp*)AfxGetApp())->DeAllocEmObject( pCurrentObj );
  2100. continue;
  2101. }
  2102. //Depending on the current view, use the correct DisplayData routine
  2103. if ( m_enumShellViewState == SHELLVIEW_APPLICATIONS ) {
  2104. //Convert the BSTR object to an EmObject and pass it to DisplayData
  2105. DisplayProcessData( pCurrentObj );
  2106. } else {
  2107. DisplayServiceData( pCurrentObj );
  2108. }
  2109. }
  2110. } while (FALSE);
  2111. SafeArrayDestroyData(var.parray);
  2112. SysFreeString ( bstrEmObjectFilter );
  2113. SysFreeString ( bstrEmObj );
  2114. if (FAILED(hr)) {
  2115. ((CEmshellApp*)AfxGetApp())->DisplayErrMsgFromHR(hr);
  2116. }
  2117. }
  2118. void CEmshellView::PopulateServiceType()
  2119. {
  2120. _variant_t var; //This will create and initialize the var variant
  2121. HRESULT hr = E_FAIL;
  2122. LONG lLBound = 0;
  2123. LONG lUBound = 0;
  2124. BSTR bstrEmObj = NULL;
  2125. BSTR bstrEmObjectFilter = NULL;
  2126. PEmObject pCurrentObj = NULL;
  2127. EmObject EmObjectFilter;
  2128. memset(&EmObjectFilter, 0, sizeof( EmObject ));
  2129. do {
  2130. EmObjectFilter.type = EMOBJ_SERVICE;
  2131. bstrEmObjectFilter = CopyBSTR ( (LPBYTE)&EmObjectFilter, sizeof( EmObject ) );
  2132. //Populate the list control based on the EmObjectType
  2133. //Enumerate all the objects and stick them in the variant
  2134. //hr = GetDocument()->GetEmManager()->EnumObjectsEx(bstrEmObjectFilter, &var);
  2135. hr = GetDocument()->GetEmManager()->EnumObjects(EMOBJ_SERVICE, &var );
  2136. if(FAILED(hr)) break;
  2137. //Get the lower and upper bounds of the variant array
  2138. hr = SafeArrayGetLBound(var.parray, 1, &lLBound);
  2139. if(FAILED(hr)) break;
  2140. hr = SafeArrayGetUBound(var.parray, 1, &lUBound);
  2141. if(FAILED(hr)) break;
  2142. //There are elements at both the lower bound and upper bound, so include them
  2143. for(; lLBound <= lUBound; lLBound++)
  2144. {
  2145. //Get a BSTR object from the safe array
  2146. hr = SafeArrayGetElement(var.parray, &lLBound, &bstrEmObj);
  2147. if (FAILED(hr)) break;
  2148. //Create a local copy of the EmObject (there aren't any pointers in
  2149. //EmObject structure, so don't worry about doing a deep copy
  2150. pCurrentObj = ((CEmshellApp*)AfxGetApp())->AllocEmObject();
  2151. if (pCurrentObj == NULL) {
  2152. hr = E_FAIL;
  2153. break;
  2154. }
  2155. *pCurrentObj = *GetEmObj( bstrEmObj );
  2156. SysFreeString( bstrEmObj );
  2157. //Unallocate the EmObject if it has an hr of E_FAIL
  2158. if ( (_tcscmp(pCurrentObj->szName, _T("")) == 0) && FAILED(pCurrentObj->hr)) {
  2159. ((CEmshellApp*)AfxGetApp())->DeAllocEmObject( pCurrentObj );
  2160. continue;
  2161. }
  2162. if ( !( (CEmshellApp*)AfxGetApp() )->CanDisplayService( pCurrentObj->szName, pCurrentObj->szSecName ) ){
  2163. ((CEmshellApp*)AfxGetApp())->DeAllocEmObject( pCurrentObj );
  2164. continue;
  2165. }
  2166. //Convert the BSTR object to an EmObject and pass it to DisplayData
  2167. DisplayServiceData( pCurrentObj );
  2168. }
  2169. } while (FALSE);
  2170. SafeArrayDestroyData(var.parray);
  2171. SysFreeString ( bstrEmObjectFilter );
  2172. SysFreeString ( bstrEmObj );
  2173. if (FAILED(hr)) {
  2174. ((CEmshellApp*)AfxGetApp())->DisplayErrMsgFromHR(hr);
  2175. }
  2176. }
  2177. void CEmshellView::PopulateDumpType()
  2178. {
  2179. _variant_t var; //This will create and initialize the var variant
  2180. HRESULT hr = E_FAIL;
  2181. LONG lLBound = 0;
  2182. LONG lUBound = 0;
  2183. BSTR bstrEmObj = NULL;
  2184. BSTR bstrEmObjectFilter = NULL;
  2185. EmObject *pCurrentObj = NULL;
  2186. EmObject EmObjectFilter;
  2187. memset(&EmObjectFilter, 0, sizeof( EmObject ) );
  2188. do {
  2189. EmObjectFilter.type = EMOBJ_MINIDUMP;
  2190. bstrEmObjectFilter = CopyBSTR ( (LPBYTE)&EmObjectFilter, sizeof( EmObject ) );
  2191. //Populate the list control based on the EmObjectType
  2192. //Enumerate all the objects and stick them in the variant
  2193. hr = GetDocument()->GetEmManager()->EnumObjectsEx(bstrEmObjectFilter, &var);
  2194. if(FAILED(hr)) break;
  2195. //Get the lower and upper bounds of the variant array
  2196. hr = SafeArrayGetLBound(var.parray, 1, &lLBound);
  2197. if(FAILED(hr)) break;
  2198. hr = SafeArrayGetUBound(var.parray, 1, &lUBound);
  2199. if(FAILED(hr)) break;
  2200. //There are elements at both the lower bound and upper bound, so include them
  2201. for(; lLBound <= lUBound; lLBound++)
  2202. {
  2203. //Get a BSTR object from the safe array
  2204. hr = SafeArrayGetElement(var.parray, &lLBound, &bstrEmObj);
  2205. if (FAILED(hr)) break;
  2206. //Create a local copy of the EmObject (there aren't any pointers in
  2207. //EmObject structure, so don't worry about doing a deep copy
  2208. pCurrentObj = ((CEmshellApp*)AfxGetApp())->AllocEmObject();
  2209. if (pCurrentObj != NULL) {
  2210. *pCurrentObj = *GetEmObj( bstrEmObj );
  2211. }
  2212. SysFreeString( bstrEmObj );
  2213. //Unallocate the EmObject if it has an hr of E_FAIL
  2214. if (FAILED(pCurrentObj->hr)) {
  2215. ((CEmshellApp*)AfxGetApp())->DeAllocEmObject( pCurrentObj );
  2216. continue;
  2217. }
  2218. //Convert the BSTR object to an EmObject and pass it to DisplayData
  2219. DisplayDumpData( pCurrentObj );
  2220. }
  2221. } while (FALSE);
  2222. SafeArrayDestroyData(var.parray);
  2223. SysFreeString ( bstrEmObjectFilter );
  2224. SysFreeString ( bstrEmObj );
  2225. if (FAILED(hr)) {
  2226. ((CEmshellApp*)AfxGetApp())->DisplayErrMsgFromHR(hr);
  2227. }
  2228. }
  2229. void CEmshellView::PopulateCompletedSessionsType()
  2230. {
  2231. _variant_t var; //This will create and initialize the var variant
  2232. HRESULT hr = E_FAIL;
  2233. LONG lLBound = 0;
  2234. LONG lUBound = 0;
  2235. BSTR bstrEmObj = NULL;
  2236. BSTR bstrEmObjectFilter = NULL;
  2237. EmObject *pCurrentObj = NULL;
  2238. EmObject EmObjectFilter;
  2239. memset(&EmObjectFilter, 0, sizeof( EmObject ) );
  2240. do {
  2241. EmObjectFilter.type = EMOBJ_PROCESS;
  2242. EmObjectFilter.nStatus = STAT_SESS_STOPPED; // only the HIWORD is the filter.
  2243. bstrEmObjectFilter = CopyBSTR ( (LPBYTE)&EmObjectFilter, sizeof( EmObject ) );
  2244. //Populate the list control based on the EmObjectType
  2245. //Enumerate all the objects and stick them in the variant
  2246. hr = GetDocument()->GetEmManager()->EnumObjectsEx(bstrEmObjectFilter, &var);
  2247. if(hr != S_OK) break;
  2248. //Get the lower and upper bounds of the variant array
  2249. hr = SafeArrayGetLBound(var.parray, 1, &lLBound);
  2250. if(FAILED(hr)) break;
  2251. hr = SafeArrayGetUBound(var.parray, 1, &lUBound);
  2252. if(FAILED(hr)) break;
  2253. //There are elements at both the lower bound and upper bound, so include them
  2254. for(; lLBound <= lUBound; lLBound++)
  2255. {
  2256. //Get a BSTR object from the safe array
  2257. hr = SafeArrayGetElement(var.parray, &lLBound, &bstrEmObj);
  2258. if (FAILED(hr)) break;
  2259. //Create a local copy of the EmObject (there aren't any pointers in
  2260. //EmObject structure, so don't worry about doing a deep copy
  2261. pCurrentObj = ((CEmshellApp*)AfxGetApp())->AllocEmObject();
  2262. if (pCurrentObj != NULL) {
  2263. *pCurrentObj = *GetEmObj( bstrEmObj );
  2264. }
  2265. SysFreeString( bstrEmObj );
  2266. //Unallocate the EmObject if it has an hr of E_FAIL
  2267. if (FAILED(pCurrentObj->hr)) {
  2268. ((CEmshellApp*)AfxGetApp())->DeAllocEmObject( pCurrentObj );
  2269. continue;
  2270. }
  2271. //Convert the BSTR object to an EmObject and pass it to DisplayData
  2272. DisplayStoppedSessionData( pCurrentObj );
  2273. }
  2274. } while (FALSE);
  2275. SafeArrayDestroyData(var.parray);
  2276. SysFreeString ( bstrEmObjectFilter );
  2277. SysFreeString ( bstrEmObj );
  2278. if (FAILED(hr)) {
  2279. ((CEmshellApp*)AfxGetApp())->DisplayErrMsgFromHR(hr);
  2280. }
  2281. }
  2282. void CEmshellView::PopulateLogType()
  2283. {
  2284. _variant_t var; //This will create and initialize the var variant
  2285. HRESULT hr = E_FAIL;
  2286. LONG lLBound = 0;
  2287. LONG lUBound = 0;
  2288. BSTR bstrEmObj = NULL;
  2289. BSTR bstrEmObjectFilter = NULL;
  2290. EmObject *pCurrentObj = NULL;
  2291. EmObject EmObjectFilter;
  2292. memset(&EmObjectFilter, 0, sizeof( EmObject ) );
  2293. do {
  2294. EmObjectFilter.type = EMOBJ_LOGFILE;
  2295. bstrEmObjectFilter = CopyBSTR ( (LPBYTE)&EmObjectFilter, sizeof( EmObject ) );
  2296. //Populate the list control based on the EmObjectType
  2297. //Enumerate all the objects and stick them in the variant
  2298. hr = GetDocument()->GetEmManager()->EnumObjectsEx(bstrEmObjectFilter, &var);
  2299. if(FAILED(hr)) break;
  2300. //Get the lower and upper bounds of the variant array
  2301. hr = SafeArrayGetLBound(var.parray, 1, &lLBound);
  2302. if(FAILED(hr)) break;
  2303. hr = SafeArrayGetUBound(var.parray, 1, &lUBound);
  2304. if(FAILED(hr)) break;
  2305. //There are elements at both the lower bound and upper bound, so include them
  2306. for(; lLBound <= lUBound; lLBound++)
  2307. {
  2308. //Get a BSTR object from the safe array
  2309. hr = SafeArrayGetElement(var.parray, &lLBound, &bstrEmObj);
  2310. if (FAILED(hr)) break;
  2311. //Create a local copy of the EmObject (there aren't any pointers in
  2312. //EmObject structure, so don't worry about doing a deep copy
  2313. pCurrentObj = ((CEmshellApp*)AfxGetApp())->AllocEmObject();
  2314. if (pCurrentObj != NULL) {
  2315. *pCurrentObj = *GetEmObj( bstrEmObj );
  2316. }
  2317. SysFreeString( bstrEmObj );
  2318. //Unallocate the EmObject if it has an hr of E_FAIL
  2319. if (FAILED(pCurrentObj->hr)) {
  2320. ((CEmshellApp*)AfxGetApp())->DeAllocEmObject( pCurrentObj );
  2321. continue;
  2322. }
  2323. //Convert the BSTR object to an EmObject and pass it to DisplayData
  2324. DisplayLogData( pCurrentObj );
  2325. }
  2326. } while (FALSE);
  2327. SafeArrayDestroyData(var.parray);
  2328. SysFreeString ( bstrEmObjectFilter );
  2329. SysFreeString ( bstrEmObj );
  2330. if (FAILED(hr)) {
  2331. ((CEmshellApp*)AfxGetApp())->DisplayErrMsgFromHR(hr);
  2332. }
  2333. }
  2334. void CEmshellView::StoreOffSelectedEmObject()
  2335. {
  2336. PEmObject pEmObject = NULL;
  2337. //Get the currently selected emObject
  2338. pEmObject = GetSelectedEmObject();
  2339. if ( pEmObject != NULL ) {
  2340. //store off it's name
  2341. m_lastSelectedEmObj = *pEmObject;
  2342. }
  2343. else {
  2344. memset ( &m_lastSelectedEmObj, 0, sizeof ( EmObject ) );
  2345. }
  2346. }
  2347. void CEmshellView::SetShellState(EMShellViewState eState)
  2348. {
  2349. StoreOffSelectedEmObject();
  2350. //Clear the current view
  2351. ListCtrlClear();
  2352. //Set the view style to the appropriate enum view state
  2353. m_enumShellViewState = eState;
  2354. //Initialize the new view state
  2355. ListCtrlInitialize(m_enumShellViewState);
  2356. }
  2357. void CEmshellView::ListCtrlInitialize(EMShellViewState eShellViewState)
  2358. {
  2359. switch (eShellViewState) {
  2360. case SHELLVIEW_ALL:
  2361. InitializeAllView();
  2362. break;
  2363. case SHELLVIEW_APPLICATIONS:
  2364. InitializeProcessView();
  2365. break;
  2366. case SHELLVIEW_COMPLETEDSESSIONS:
  2367. InitializeCompletedSessionsView();
  2368. break;
  2369. case SHELLVIEW_SERVICES:
  2370. InitializeServiceView();
  2371. break;
  2372. case SHELLVIEW_LOGFILES:
  2373. InitializeLogView();
  2374. break;
  2375. case SHELLVIEW_DUMPFILES:
  2376. InitializeDumpView();
  2377. break;
  2378. case SHELLVIEW_MSINFOFILES:
  2379. InitializeMSInfoView();
  2380. break;
  2381. case SHELLVIEW_NONE:
  2382. break;
  2383. }
  2384. }
  2385. void CEmshellView::SelectItemBySZNAME(TCHAR* pszName, int nId)
  2386. {
  2387. //Search through the list selecting the item whose itemdata.szname matches pszName
  2388. //Given a pszName, find the element in the ListCtl
  2389. PEmObject pListEmObject = NULL;
  2390. BOOL bFound = FALSE;
  2391. int nFirstMatch = -1;
  2392. //Step through every item in the list control searching for pEmObject
  2393. int nCount = m_mainListControl.GetItemCount();
  2394. for (int i = 0;i < nCount; i++) {
  2395. pListEmObject = (PEmObject) m_mainListControl.GetItemData(i);
  2396. if (pListEmObject == NULL) break;
  2397. if (wcscmp(pListEmObject->szName, pszName) == 0 ) {
  2398. if (nFirstMatch == -1 )
  2399. nFirstMatch = i;
  2400. if (pListEmObject->nId == nId) {
  2401. m_mainListControl.SelectItem(i);
  2402. bFound = TRUE;
  2403. //We have found the element, stop the search
  2404. break;
  2405. }
  2406. }
  2407. }
  2408. //If the we didn't find a perfect match, select the first near match
  2409. //And if we didn't find any, select the first item in the list
  2410. if ( !bFound ) {
  2411. if (nFirstMatch == -1) {
  2412. m_mainListControl.SelectItem(0);
  2413. }
  2414. else {
  2415. m_mainListControl.SelectItem(nFirstMatch);
  2416. }
  2417. }
  2418. }
  2419. void CEmshellView::ListCtrlPopulate(EMShellViewState eShellViewState)
  2420. {
  2421. DWORD dwPollSessionsFreq = 30L; // default is 30 secs
  2422. ((CEmshellApp*)AfxGetApp())->GetEmShellRegOptions( TRUE, &dwPollSessionsFreq );
  2423. switch (eShellViewState) {
  2424. case SHELLVIEW_ALL:
  2425. PopulateProcessType();
  2426. PopulateServiceType();
  2427. ReSynchServices();
  2428. ReSynchApplications();
  2429. SetTimer( 1, dwPollSessionsFreq*1000, 0);
  2430. break;
  2431. case SHELLVIEW_APPLICATIONS:
  2432. PopulateProcessType();
  2433. ReSynchApplications();
  2434. SetTimer( 1, dwPollSessionsFreq*1000, 0);
  2435. break;
  2436. case SHELLVIEW_SERVICES:
  2437. PopulateServiceType();
  2438. ReSynchServices();
  2439. SetTimer( 1, dwPollSessionsFreq*1000, 0);
  2440. break;
  2441. case SHELLVIEW_COMPLETEDSESSIONS:
  2442. PopulateCompletedSessionsType();
  2443. ReSynchStoppedSessions();
  2444. break;
  2445. case SHELLVIEW_LOGFILES:
  2446. PopulateLogType();
  2447. break;
  2448. case SHELLVIEW_DUMPFILES:
  2449. PopulateDumpType();
  2450. break;
  2451. case SHELLVIEW_MSINFOFILES:
  2452. PopulateMSInfoType();
  2453. break;
  2454. case SHELLVIEW_NONE:
  2455. break;
  2456. }
  2457. //Select the last selected item
  2458. //Try to select the last emobject name selected. If not, select the first item in the view.
  2459. SelectItemBySZNAME( m_lastSelectedEmObj.szName, m_lastSelectedEmObj.nId );
  2460. }
  2461. /*void CEmshellView::CloseAllSessions()
  2462. {
  2463. }
  2464. */
  2465. void CEmshellView::ListCtrlClear()
  2466. {
  2467. INT_PTR nUpperBound = 0;
  2468. PActiveSession pActiveSession = NULL;
  2469. HRESULT hr = E_FAIL;
  2470. PEmObject pEmObject = NULL;
  2471. INT_PTR nCount = m_mainListControl.GetItemCount();
  2472. //We need to make sure the timer doesn't get through when the list is empty
  2473. //Destroy the timer first
  2474. KillTimer(1);
  2475. //Step through every item in the list control and delete the pEmObjects
  2476. //and the item.
  2477. for (int i = 0;i < nCount; i++) {
  2478. pEmObject = (PEmObject)m_mainListControl.GetItemData(i);
  2479. //Cast dwData to a EmObject and call delete on it
  2480. ((CEmshellApp*)AfxGetApp())->DeAllocEmObject(pEmObject);
  2481. }
  2482. //Remove all the items from the list control
  2483. i = m_mainListControl.DeleteAllItems();
  2484. ASSERT(m_mainListControl.GetItemCount() == 0);
  2485. //Set all the pEmObjects to NULL
  2486. for (nUpperBound = m_SessionTable.GetUpperBound(); nUpperBound >= 0; nUpperBound--) {
  2487. pActiveSession = (PActiveSession) m_SessionTable.GetAt(nUpperBound);
  2488. ASSERT(pActiveSession != NULL);
  2489. pActiveSession->pEmObject = NULL;
  2490. }
  2491. }
  2492. void CEmshellView::OnViewServicesandapplications()
  2493. {
  2494. if ( m_enumShellViewState == SHELLVIEW_ALL ) return;
  2495. SetShellState(SHELLVIEW_ALL);
  2496. ListCtrlPopulate(SHELLVIEW_ALL);
  2497. }
  2498. void CEmshellView::OnUpdateViewServicesandapplications(CCmdUI* pCmdUI)
  2499. {
  2500. BOOL bEnable = FALSE;
  2501. BOOL bChecked = FALSE;
  2502. if ( GetDocument()->GetConnectedToServerState() == TRUE ) {
  2503. bEnable = TRUE;
  2504. if ( m_enumShellViewState == SHELLVIEW_ALL ) {
  2505. bChecked = TRUE;
  2506. }
  2507. }
  2508. pCmdUI->Enable ( bEnable );
  2509. pCmdUI->SetCheck( bChecked );
  2510. }
  2511. void CEmshellView::OnViewLogfiles()
  2512. {
  2513. if ( m_enumShellViewState == SHELLVIEW_LOGFILES ) return;
  2514. SetShellState(SHELLVIEW_LOGFILES);
  2515. ListCtrlPopulate(SHELLVIEW_LOGFILES);
  2516. }
  2517. void CEmshellView::OnUpdateViewLogfiles(CCmdUI* pCmdUI)
  2518. {
  2519. BOOL bEnable = FALSE;
  2520. BOOL bChecked = FALSE;
  2521. if ( GetDocument()->GetConnectedToServerState() == TRUE ) {
  2522. bEnable = TRUE;
  2523. if ( m_enumShellViewState == SHELLVIEW_LOGFILES )
  2524. bChecked = TRUE;
  2525. }
  2526. pCmdUI->Enable ( bEnable );
  2527. pCmdUI->SetCheck( bChecked );
  2528. }
  2529. void CEmshellView::OnViewDumpfiles()
  2530. {
  2531. if ( m_enumShellViewState == SHELLVIEW_DUMPFILES ) return;
  2532. SetShellState(SHELLVIEW_DUMPFILES);
  2533. ListCtrlPopulate(SHELLVIEW_DUMPFILES);
  2534. }
  2535. void CEmshellView::OnUpdateViewDumpfiles(CCmdUI* pCmdUI)
  2536. {
  2537. BOOL bEnable = FALSE;
  2538. BOOL bChecked = FALSE;
  2539. if ( GetDocument()->GetConnectedToServerState() == TRUE ) {
  2540. bEnable = TRUE;
  2541. if ( m_enumShellViewState == SHELLVIEW_DUMPFILES )
  2542. bChecked = TRUE;
  2543. }
  2544. pCmdUI->Enable ( bEnable );
  2545. pCmdUI->SetCheck( bChecked );
  2546. }
  2547. void CEmshellView::OnUpdateLogpopupOpen(CCmdUI* pCmdUI)
  2548. {
  2549. BOOL bEnable = FALSE;
  2550. //TODO: Enable the button when display a log file is supported
  2551. pCmdUI->Enable ( m_enumShellViewState == SHELLVIEW_LOGFILES );
  2552. }
  2553. void CEmshellView::OnLogpopupOpen()
  2554. {
  2555. // TODO: Add your command handler code here
  2556. PEmObject pEmObject = NULL;
  2557. pEmObject = GetSelectedEmObject();
  2558. if ( pEmObject == NULL ) return;
  2559. CReadLogsDlg ReadLogDlg(pEmObject, GetDocument()->GetEmManager());
  2560. ReadLogDlg.DoModal();
  2561. }
  2562. void CEmshellView::OnUpdateLogpopupProperties(CCmdUI* pCmdUI)
  2563. {
  2564. BOOL bEnable = FALSE;
  2565. //TODO: Enable the button when properties of a log file is supported
  2566. pCmdUI->Enable ( TRUE );
  2567. }
  2568. void CEmshellView::OnLogpopupProperties()
  2569. {
  2570. // TODO: Add your command handler code here
  2571. PEmObject pEmObject = GetSelectedEmObject();
  2572. if ( pEmObject ) {
  2573. ShowProperties( pEmObject );
  2574. }
  2575. }
  2576. void CEmshellView::ShowProperties( PEmObject pEmObject )
  2577. {
  2578. CPropertySheet propsheet;
  2579. CPropPageGenLogDump genLogDumpPropPage;
  2580. genLogDumpPropPage.m_pEmObj = pEmObject;
  2581. genLogDumpPropPage.m_pParentPropSheet = &propsheet;
  2582. propsheet.AddPage(&genLogDumpPropPage);
  2583. propsheet.SetTitle( pEmObject->szName, PSH_PROPTITLE );
  2584. propsheet.DoModal();
  2585. if( genLogDumpPropPage.m_bDeleteFile ) {
  2586. OnLogpopupDelete();
  2587. }
  2588. }
  2589. EMShellViewState CEmshellView::GetViewState()
  2590. {
  2591. return m_enumShellViewState;
  2592. }
  2593. HRESULT CEmshellView::StartCDBClient(IN LPTSTR lpszConnectString)
  2594. {
  2595. STARTUPINFO sp;
  2596. PROCESS_INFORMATION pi;
  2597. ZeroMemory(&sp, sizeof( sp ) );
  2598. ZeroMemory(&pi, sizeof( pi ) );
  2599. BOOL bCdbCreated = CreateProcess(// This has to be obtained from the registry...
  2600. _T("C:\\Debuggers\\cdb.exe"),
  2601. lpszConnectString,
  2602. NULL,
  2603. NULL,
  2604. FALSE,
  2605. CREATE_NEW_PROCESS_GROUP | CREATE_NEW_CONSOLE,
  2606. NULL,
  2607. NULL,
  2608. &sp,
  2609. &pi
  2610. );
  2611. //
  2612. // Wait till CDB does some initializations..
  2613. // Don't know how long to wait.. have to figure out a way..
  2614. //
  2615. Sleep(2000);
  2616. if(bCdbCreated == FALSE){
  2617. return HRESULT_FROM_WIN32(GetLastError());
  2618. }
  2619. return S_OK;
  2620. }
  2621. HRESULT CEmshellView::GetClientConnectString(IN OUT LPTSTR pszConnectString, IN DWORD dwBuffSize, PEmObject pEmSessObj, int nPort)
  2622. {
  2623. _ASSERTE(pszConnectString != NULL);
  2624. _ASSERTE(dwBuffSize > 0L);
  2625. HRESULT hr = E_FAIL;
  2626. DWORD dwBuff = MAX_COMPUTERNAME_LENGTH;
  2627. do
  2628. {
  2629. if( pszConnectString == NULL ||
  2630. dwBuffSize <= 0L ) break;
  2631. if( nPort != 0 ){
  2632. _stprintf(pszConnectString, _T(" -remote tcp:server=%s,port=%d"), GetDocument()->GetServerName(), nPort);
  2633. }
  2634. else {
  2635. _stprintf(pszConnectString, _T(" -remote npipe:server=%s,pipe=EM_%d"), GetDocument()->GetServerName(), pEmSessObj->nId);
  2636. }
  2637. hr = S_OK;
  2638. }
  2639. while( false );
  2640. return hr;
  2641. }
  2642. void CEmshellView::DoModalPropertySheet(PEmObject pEmObject)
  2643. {
  2644. CPropertySheet propsheet;
  2645. CPropPageGeneral generalPropPage;
  2646. CPropPageLogFiles logFilesPropPage;
  2647. CPropPageDumpFiles dumpFilesPropPage;
  2648. BOOL bInActiveSessionTable = FALSE;
  2649. generalPropPage.m_pEmObject = pEmObject;
  2650. logFilesPropPage.m_pEmObject = pEmObject;
  2651. logFilesPropPage.m_pIEmManager = GetDocument()->GetEmManager();
  2652. dumpFilesPropPage.m_pEmObject = pEmObject;
  2653. dumpFilesPropPage.m_pIEmManager = GetDocument()->GetEmManager();
  2654. propsheet.AddPage(&generalPropPage);
  2655. propsheet.AddPage(&logFilesPropPage);
  2656. propsheet.AddPage(&dumpFilesPropPage);
  2657. //
  2658. // a-mando
  2659. //
  2660. propsheet.SetTitle( pEmObject->szName, PSH_PROPTITLE );
  2661. propsheet.DoModal();
  2662. }
  2663. void CEmshellView::OnViewApplications()
  2664. {
  2665. if ( m_enumShellViewState == SHELLVIEW_APPLICATIONS ) return;
  2666. SetShellState(SHELLVIEW_APPLICATIONS);
  2667. ListCtrlPopulate(SHELLVIEW_APPLICATIONS);
  2668. }
  2669. void CEmshellView::OnUpdateViewApplications(CCmdUI* pCmdUI)
  2670. {
  2671. BOOL bEnable = FALSE;
  2672. BOOL bChecked = FALSE;
  2673. if ( GetDocument()->GetConnectedToServerState() == TRUE ) {
  2674. bEnable = TRUE;
  2675. if ( m_enumShellViewState == SHELLVIEW_APPLICATIONS )
  2676. bChecked = TRUE;
  2677. }
  2678. pCmdUI->Enable ( bEnable );
  2679. pCmdUI->SetCheck( bChecked );
  2680. }
  2681. void CEmshellView::OnViewCompletedsessions()
  2682. {
  2683. if ( m_enumShellViewState == SHELLVIEW_COMPLETEDSESSIONS ) return;
  2684. SetShellState(SHELLVIEW_COMPLETEDSESSIONS);
  2685. ListCtrlPopulate(SHELLVIEW_COMPLETEDSESSIONS);
  2686. }
  2687. void CEmshellView::OnUpdateViewCompletedsessions(CCmdUI* pCmdUI)
  2688. {
  2689. BOOL bEnable = FALSE;
  2690. BOOL bChecked = FALSE;
  2691. if ( GetDocument()->GetConnectedToServerState() == TRUE ) {
  2692. bEnable = TRUE;
  2693. if ( m_enumShellViewState == SHELLVIEW_COMPLETEDSESSIONS )
  2694. bChecked = TRUE;
  2695. }
  2696. pCmdUI->Enable ( bEnable );
  2697. pCmdUI->SetCheck( bChecked );
  2698. }
  2699. void CEmshellView::OnViewServices()
  2700. {
  2701. if ( m_enumShellViewState == SHELLVIEW_SERVICES ) return;
  2702. SetShellState(SHELLVIEW_SERVICES);
  2703. ListCtrlPopulate(SHELLVIEW_SERVICES);
  2704. }
  2705. void CEmshellView::OnUpdateViewServices(CCmdUI* pCmdUI)
  2706. {
  2707. BOOL bEnable = FALSE;
  2708. BOOL bChecked = FALSE;
  2709. if ( GetDocument()->GetConnectedToServerState() == TRUE ) {
  2710. bEnable = TRUE;
  2711. if ( m_enumShellViewState == SHELLVIEW_SERVICES )
  2712. bChecked = TRUE;
  2713. }
  2714. pCmdUI->Enable ( bEnable );
  2715. pCmdUI->SetCheck( bChecked );
  2716. }
  2717. void CEmshellView::OnProcesspopupDeleteSession()
  2718. {
  2719. //Delete the session for the current item selected
  2720. PEmObject pEmObject = NULL;
  2721. HRESULT hr = E_FAIL;
  2722. int nIndex = -1;
  2723. PActiveSession pActiveSession = NULL;
  2724. IEmDebugSession* pTempDebugSession = NULL;
  2725. BSTR bstrEmObj = NULL;
  2726. do {
  2727. nIndex = GetSelectedItemIndex();
  2728. if ( nIndex == -1 ) break;
  2729. pEmObject = ( PEmObject ) m_mainListControl.GetItemData( nIndex );
  2730. if ( pEmObject == NULL ) break;
  2731. //Find the element in the session table
  2732. pActiveSession = FindActiveSession( pEmObject );
  2733. if ( pActiveSession == NULL ) {
  2734. //Create bstr's for the journey ahead, and break if we can't
  2735. bstrEmObj = CopyBSTR ( (LPBYTE)pEmObject, sizeof( EmObject ) );
  2736. if( bstrEmObj == NULL ){
  2737. hr = E_OUTOFMEMORY;
  2738. break;
  2739. }
  2740. //We don't have a session open, so open a temporary session
  2741. hr = GetDocument()->GetEmManager()->OpenSession( bstrEmObj, &pTempDebugSession );
  2742. if (FAILED(hr)) break;
  2743. SysFreeString( bstrEmObj );
  2744. if ( hr == S_OK ) {
  2745. //We are the master now... Delete the debug session
  2746. hr = DeleteDebugSession( pEmObject );
  2747. if ( FAILED( hr ) ) break;
  2748. }
  2749. else if ( hr == S_FALSE ) {
  2750. //Adopt the orphan if the user wants
  2751. if ( CommenceOrphanCustodyBattle( pTempDebugSession ) ) {
  2752. hr = DeleteDebugSession( pEmObject );
  2753. if ( FAILED( hr ) ) break;
  2754. } else break;
  2755. }
  2756. else if ( hr == E_FAIL ) {
  2757. //Notify the user that the process currently belongs to someone else
  2758. break;
  2759. }
  2760. }
  2761. else {
  2762. //Close and remove the currently selected session
  2763. hr = DeleteDebugSession( pEmObject );
  2764. if ( FAILED( hr ) ) break;
  2765. hr = RemoveActiveSession( pEmObject );
  2766. if ( FAILED( hr ) ) break;
  2767. }
  2768. //Cast dwData to a EmObject and call delete on it
  2769. ((CEmshellApp*)AfxGetApp())->DeAllocEmObject(pEmObject);
  2770. //Remove the item from the list control
  2771. m_mainListControl.DeleteItem( nIndex );
  2772. } while ( FALSE );
  2773. if ( FAILED( hr ) ) {
  2774. ((CEmshellApp*)AfxGetApp())->DisplayErrMsgFromHR( hr );
  2775. }
  2776. if ( pTempDebugSession ) {
  2777. //Release the pTempDebugSession pointer
  2778. SAFE_RELEASEIX( pTempDebugSession );
  2779. }
  2780. SysFreeString ( bstrEmObj );
  2781. }
  2782. void CEmshellView::OnUpdateProcesspopupDeleteSession( CCmdUI* pCmdUI )
  2783. {
  2784. PEmObject pEmObject = NULL;
  2785. PActiveSession pActiveSession = NULL;
  2786. BOOL bEnable = FALSE;
  2787. do {
  2788. if ( !GetDocument()->GetConnectedToServerState() ) break;
  2789. // Update the state of this button based on the state of the currently selected item
  2790. //Get the currently selected emObject
  2791. pEmObject = GetSelectedEmObject();
  2792. if ( pEmObject == NULL ) break;
  2793. pActiveSession = FindActiveSession( pEmObject );
  2794. //Determine if the status of pActiveSession and enable this apprpriately
  2795. //If it's status is stopped && (it's an orphan || it's in our session table)
  2796. if ( pEmObject->nStatus & STAT_SESS_STOPPED &&
  2797. ( pEmObject->nStatus & STAT_ORPHAN || pActiveSession ) ) {
  2798. bEnable = TRUE;
  2799. }
  2800. }while ( FALSE );
  2801. pCmdUI->Enable( bEnable );
  2802. }
  2803. void CEmshellView::OnToolsOptions()
  2804. {
  2805. // TODO: Add your command handler code here
  2806. CEmOptions EmOpts;
  2807. DWORD dwPollSessionsFreq = 30L; // default
  2808. if( EmOpts.DoModal() == IDOK ) {
  2809. ((CEmshellApp*)AfxGetApp())->GetEmShellRegOptions( FALSE, &dwPollSessionsFreq );
  2810. KillTimer( 1 );
  2811. SetTimer( 1, dwPollSessionsFreq*1000, 0);
  2812. }
  2813. }
  2814. void CEmshellView::OnUpdateToolsOptoins(CCmdUI* pCmdUI)
  2815. {
  2816. // TODO: Add your command update UI handler code here
  2817. }
  2818. void CEmshellView::OnProcesspopupCancelDebugSession()
  2819. {
  2820. //Stop the session for the current item selected
  2821. PEmObject pEmObject = NULL;
  2822. HRESULT hr = E_FAIL;
  2823. do {
  2824. pEmObject = GetSelectedEmObject();
  2825. if ( pEmObject == NULL ) break;
  2826. //Stop and remove the session
  2827. CancelDebugSession( pEmObject );
  2828. hr = S_OK;
  2829. } while ( FALSE );
  2830. if ( FAILED( hr ) ) {
  2831. ((CEmshellApp*)AfxGetApp())->DisplayErrMsgFromHR( hr );
  2832. }
  2833. }
  2834. //
  2835. // a-mando
  2836. //
  2837. void CEmshellView::OnLogpopupDelete()
  2838. {
  2839. //Stop the session for the current item selected
  2840. PEmObject pEmObject = NULL;
  2841. HRESULT hr = E_FAIL;
  2842. BSTR bstrEmObj = NULL;
  2843. UINT nIndex = -1;
  2844. do {
  2845. nIndex = GetSelectedItemIndex();
  2846. if ( nIndex == -1 ) break;
  2847. pEmObject = GetSelectedEmObject();
  2848. if ( pEmObject == NULL ) break;
  2849. bstrEmObj = CopyBSTR ( (LPBYTE)pEmObject, sizeof( EmObject ) );
  2850. if( bstrEmObj == NULL ){
  2851. hr = E_OUTOFMEMORY;
  2852. break;
  2853. }
  2854. hr = GetDocument()->GetEmManager()->DeleteFile( bstrEmObj );
  2855. if( FAILED(hr) ) break;
  2856. //Remove the item from the list control
  2857. m_mainListControl.DeleteItem( nIndex );
  2858. if( !m_mainListControl.SelectItem( nIndex ) ) {
  2859. m_mainListControl.SelectItem( nIndex-1 );
  2860. }
  2861. } while ( FALSE );
  2862. if ( FAILED( hr ) ) {
  2863. ((CEmshellApp*)AfxGetApp())->DisplayErrMsgFromHR( hr );
  2864. }
  2865. }
  2866. void CEmshellView::OnUpdateLogpopupDelete(CCmdUI* pCmdUI)
  2867. {
  2868. // TODO: Add your command update UI handler code here
  2869. }
  2870. // a-mando
  2871. void CEmshellView::OnActionGenerateMSInfoFile()
  2872. {
  2873. // TODO: Add your command handler code here
  2874. CMSInfoDlg DlgMsInfo;
  2875. BSTR bstrCategories = NULL;
  2876. HRESULT hr = S_OK;
  2877. CWaitCursor wait;
  2878. // we won't show this dialog if the user doesn't want it.
  2879. if( !((CEmshellApp*)AfxGetApp())->m_dwShowMSInfoDlg || DlgMsInfo.DoModal() == IDOK ) {
  2880. ((CEmshellApp*)AfxGetApp())->m_dwShowMSInfoDlg = !DlgMsInfo.m_bDlgNoShow;
  2881. bstrCategories = DlgMsInfo.m_csCategories.AllocSysString();
  2882. hr = GetDocument()->GetEmManager()->MakeNFO( NULL, NULL, bstrCategories );
  2883. }
  2884. SysFreeString( bstrCategories );
  2885. if ( FAILED( hr ) ) {
  2886. ((CEmshellApp*)AfxGetApp())->DisplayErrMsgFromHR( hr );
  2887. }
  2888. }
  2889. void CEmshellView::OnUpdateActionGenerateMSInfoFile(CCmdUI* pCmdUI)
  2890. {
  2891. // TODO: Add your command update UI handler code here
  2892. pCmdUI->Enable( GetDocument()->GetConnectedToServerState() );
  2893. }
  2894. void CEmshellView::OnViewMSInfoFiles()
  2895. {
  2896. if ( m_enumShellViewState == SHELLVIEW_MSINFOFILES ) return;
  2897. SetShellState(SHELLVIEW_MSINFOFILES);
  2898. ListCtrlPopulate(SHELLVIEW_MSINFOFILES);
  2899. }
  2900. void CEmshellView::OnUpdateViewMSInfoFiles(CCmdUI* pCmdUI)
  2901. {
  2902. BOOL bEnable = FALSE;
  2903. BOOL bChecked = FALSE;
  2904. if ( GetDocument()->GetConnectedToServerState() == TRUE ) {
  2905. bEnable = TRUE;
  2906. if ( m_enumShellViewState == SHELLVIEW_MSINFOFILES )
  2907. bChecked = TRUE;
  2908. }
  2909. pCmdUI->Enable ( bEnable );
  2910. pCmdUI->SetCheck( bChecked );
  2911. }
  2912. void CEmshellView::PopulateMSInfoType()
  2913. {
  2914. _variant_t var; //This will create and initialize the var variant
  2915. HRESULT hr = E_FAIL;
  2916. LONG lLBound = 0;
  2917. LONG lUBound = 0;
  2918. BSTR bstrEmObj = NULL;
  2919. BSTR bstrEmObjectFilter = NULL;
  2920. EmObject *pCurrentObj = NULL;
  2921. EmObject EmObjectFilter;
  2922. memset(&EmObjectFilter, 0, sizeof( EmObject ) );
  2923. do {
  2924. EmObjectFilter.type = EMOBJ_MSINFO;
  2925. bstrEmObjectFilter = CopyBSTR ( (LPBYTE)&EmObjectFilter, sizeof( EmObject ) );
  2926. //Populate the list control based on the EmObjectType
  2927. //Enumerate all the objects and stick them in the variant
  2928. hr = GetDocument()->GetEmManager()->EnumObjectsEx(bstrEmObjectFilter, &var);
  2929. if(FAILED(hr)) break;
  2930. //Get the lower and upper bounds of the variant array
  2931. hr = SafeArrayGetLBound(var.parray, 1, &lLBound);
  2932. if(FAILED(hr)) break;
  2933. hr = SafeArrayGetUBound(var.parray, 1, &lUBound);
  2934. if(FAILED(hr)) break;
  2935. //There are elements at both the lower bound and upper bound, so include them
  2936. for(; lLBound <= lUBound; lLBound++)
  2937. {
  2938. //Get a BSTR object from the safe array
  2939. hr = SafeArrayGetElement(var.parray, &lLBound, &bstrEmObj);
  2940. if (FAILED(hr)) break;
  2941. //Create a local copy of the EmObject (there aren't any pointers in
  2942. //EmObject structure, so don't worry about doing a deep copy
  2943. pCurrentObj = ((CEmshellApp*)AfxGetApp())->AllocEmObject();
  2944. if (pCurrentObj != NULL) {
  2945. *pCurrentObj = *GetEmObj( bstrEmObj );
  2946. }
  2947. SysFreeString( bstrEmObj );
  2948. //Unallocate the EmObject if it has an hr of E_FAIL
  2949. if (FAILED(pCurrentObj->hr)) {
  2950. ((CEmshellApp*)AfxGetApp())->DeAllocEmObject( pCurrentObj );
  2951. continue;
  2952. }
  2953. //Convert the BSTR object to an EmObject and pass it to DisplayData
  2954. DisplayMSInfoData( pCurrentObj );
  2955. }
  2956. } while (FALSE);
  2957. SafeArrayDestroyData(var.parray);
  2958. SysFreeString ( bstrEmObjectFilter );
  2959. SysFreeString( bstrEmObj );
  2960. if (FAILED(hr)) {
  2961. ((CEmshellApp*)AfxGetApp())->DisplayErrMsgFromHR(hr);
  2962. }
  2963. }
  2964. void CEmshellView::InitializeMSInfoView()
  2965. {
  2966. InitializeLogView();
  2967. }
  2968. void CEmshellView::OnLogpopupExport()
  2969. {
  2970. PEmObject pEmObject = NULL;
  2971. CString strDirPath;
  2972. do {
  2973. pEmObject = GetSelectedEmObject();
  2974. if ( pEmObject == NULL ) break;
  2975. //Get the path
  2976. if ( ( (CEmshellApp*) AfxGetApp() )->AskForPath( strDirPath ) ) {
  2977. //Export the file
  2978. ((CEmshellApp*)AfxGetApp())->ExportLog( pEmObject, strDirPath, GetDocument()->GetEmManager() );
  2979. }
  2980. } while ( FALSE );
  2981. }
  2982. void CEmshellView::OnUpdateLogpopupExport(CCmdUI* pCmdUI)
  2983. {
  2984. // TODO: Add your command update UI handler code here
  2985. }
  2986. void CEmshellView::OnHelpContents()
  2987. {
  2988. // TODO: Add your command handler code here
  2989. HWND hwnd = HtmlHelp( ::GetDesktopWindow(), ((CEmshellApp*)AfxGetApp())->m_strApplicationPath + gtcEmChm, HH_DISPLAY_TOPIC, NULL );
  2990. }