Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1320 lines
37 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. provider.cpp
  7. Filter node handler
  8. FILE HISTORY:
  9. */
  10. #include "stdafx.h"
  11. #include "server.h"
  12. #include "LogDataNode.h"
  13. #include "logdatapp.h"
  14. #include "SpdUtil.h"
  15. #define ELLIPSIS _T("...")
  16. /*---------------------------------------------------------------------------
  17. Class CLogDataHandler implementation
  18. ---------------------------------------------------------------------------*/
  19. /*---------------------------------------------------------------------------
  20. Constructor and destructor
  21. Description
  22. Author: NSun
  23. ---------------------------------------------------------------------------*/
  24. CLogDataHandler::CLogDataHandler(ITFSComponentData * pComponentData)
  25. : CIpsmHandler(pComponentData),
  26. m_pComponent(NULL)
  27. {
  28. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  29. }
  30. CLogDataHandler::~CLogDataHandler()
  31. {
  32. }
  33. /*!--------------------------------------------------------------------------
  34. CLogDataHandler::InitializeNode
  35. Initializes node specific data
  36. Author: NSun
  37. ---------------------------------------------------------------------------*/
  38. HRESULT
  39. CLogDataHandler::InitializeNode
  40. (
  41. ITFSNode * pNode
  42. )
  43. {
  44. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  45. CString strTemp;
  46. strTemp.LoadString(IDS_LOG_NODE);
  47. SetDisplayName(strTemp);
  48. // Make the node immediately visible
  49. pNode->SetVisibilityState(TFS_VIS_SHOW);
  50. pNode->SetData(TFS_DATA_COOKIE, (LPARAM) pNode);
  51. pNode->SetData(TFS_DATA_IMAGEINDEX, ICON_IDX_FOLDER_CLOSED);
  52. pNode->SetData(TFS_DATA_OPENIMAGEINDEX, ICON_IDX_FOLDER_OPEN);
  53. pNode->SetData(TFS_DATA_USER, (LPARAM) this);
  54. pNode->SetData(TFS_DATA_TYPE, IPFWMON_LOGDATA);
  55. pNode->SetData(TFS_DATA_SCOPE_LEAF_NODE, TRUE);
  56. SetColumnStringIDs(&aColumns[IPFWMON_LOGDATA][0]);
  57. SetColumnWidths(&aColumnWidths[IPFWMON_LOGDATA][0]);
  58. return hrOK;
  59. }
  60. /*---------------------------------------------------------------------------
  61. CLogDataHandler::GetImageIndex
  62. -
  63. Author: NSun
  64. ---------------------------------------------------------------------------*/
  65. int
  66. CLogDataHandler::GetImageIndex(BOOL bOpenImage)
  67. {
  68. int nIndex = -1;
  69. return nIndex;
  70. }
  71. /*---------------------------------------------------------------------------
  72. Overridden base handler functions
  73. ---------------------------------------------------------------------------*/
  74. /*---------------------------------------------------------------------------
  75. CLogDataHandler::OnAddMenuItems
  76. Adds context menu items for the SA scope pane node
  77. Author: NSun
  78. ---------------------------------------------------------------------------*/
  79. STDMETHODIMP
  80. CLogDataHandler::OnAddMenuItems
  81. (
  82. ITFSNode * pNode,
  83. LPCONTEXTMENUCALLBACK pContextMenuCallback,
  84. LPDATAOBJECT lpDataObject,
  85. DATA_OBJECT_TYPES type,
  86. DWORD dwType,
  87. long * pInsertionAllowed
  88. )
  89. {
  90. HRESULT hr = hrOK;
  91. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  92. if (type == CCT_SCOPE && (*pInsertionAllowed & CCM_INSERTIONALLOWED_TOP))
  93. {
  94. CString strBuffer;
  95. WZC_CONTEXT wzcContext = {0};
  96. DWORD dwMenu;
  97. strBuffer.Empty();
  98. m_spSpdInfo->GetComputerName(&strBuffer);
  99. WZCQueryContext(
  100. //strBuffer.IsEmpty()? NULL : (LPWSTR)(LPCWSTR)strBuffer,
  101. NULL,
  102. WZC_CONTEXT_CTL_LOG,
  103. &wzcContext,
  104. NULL);
  105. dwMenu = (wzcContext.dwFlags & WZC_CTXT_LOGGING_ON) ? IDS_MENU_DISABLE_LOGGING : IDS_MENU_ENABLE_LOGGING,
  106. strBuffer.LoadString(dwMenu);
  107. hr = LoadAndAddMenuItem(
  108. pContextMenuCallback,
  109. strBuffer,
  110. dwMenu,
  111. CCM_INSERTIONPOINTID_PRIMARY_TOP,
  112. 0);
  113. Assert(hrOK == hr);
  114. strBuffer.LoadString(IDS_MENU_FLUSH_LOGS);
  115. hr = LoadAndAddMenuItem(pContextMenuCallback,
  116. strBuffer,
  117. IDS_MENU_FLUSH_LOGS,
  118. CCM_INSERTIONPOINTID_PRIMARY_TOP,
  119. 0);
  120. Assert(hrOK == hr);
  121. }
  122. return hr;
  123. }
  124. /*!--------------------------------------------------------------------------
  125. CLogDataHandler::AddMenuItems
  126. Adds context menu items for virtual list box (result pane) items
  127. Author: NSun
  128. ---------------------------------------------------------------------------*/
  129. STDMETHODIMP
  130. CLogDataHandler::AddMenuItems
  131. (
  132. ITFSComponent * pComponent,
  133. MMC_COOKIE cookie,
  134. LPDATAOBJECT pDataObject,
  135. LPCONTEXTMENUCALLBACK pContextMenuCallback,
  136. long * pInsertionAllowed
  137. )
  138. {
  139. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  140. HRESULT hr = hrOK;
  141. CString strMenuItem;
  142. SPINTERNAL spInternal;
  143. LONG fFlags = 0;
  144. spInternal = ExtractInternalFormat(pDataObject);
  145. /* virtual listbox notifications come to the handler of the node that
  146. * is selected. check to see if this notification is for a virtual
  147. * listbox item or this SA node itself.
  148. */
  149. if (*pInsertionAllowed & CCM_INSERTIONALLOWED_VIEW)
  150. {
  151. //load and view menu items here
  152. }
  153. return hr;
  154. }
  155. /*!--------------------------------------------------------------------------
  156. CLogDataHandler::OnRefresh
  157. Default implementation for the refresh functionality
  158. Author: NSun
  159. ---------------------------------------------------------------------------*/
  160. HRESULT
  161. CLogDataHandler::OnRefresh(
  162. ITFSNode * pNode,
  163. LPDATAOBJECT pDataObject,
  164. DWORD dwType,
  165. LPARAM arg,
  166. LPARAM param
  167. )
  168. {
  169. HRESULT hr = S_OK;
  170. DWORD dwNew = 0;
  171. DWORD dwTotal = 0;
  172. int i = 0;
  173. SPIConsole spConsole;
  174. CORg(CHandler::OnRefresh(pNode, pDataObject, dwType, arg, param));
  175. //
  176. // Get new records if any
  177. //
  178. CORg(m_spSpdInfo->EnumLogData(&dwNew, &dwTotal));
  179. i = m_spSpdInfo->GetLogDataCount();
  180. //
  181. // Now notify the virtual listbox
  182. //
  183. CORg(m_spNodeMgr->GetConsole(&spConsole) );
  184. CORg(MaintainSelection());
  185. CORg(spConsole->UpdateAllViews(
  186. pDataObject,
  187. i,
  188. RESULT_PANE_SET_VIRTUAL_LB_SIZE));
  189. Error:
  190. return hr;
  191. }
  192. /*---------------------------------------------------------------------------
  193. CLogDataHandler::OnCommand
  194. Handles context menu commands for SA scope pane node
  195. Author: NSun
  196. ---------------------------------------------------------------------------*/
  197. STDMETHODIMP
  198. CLogDataHandler::OnCommand
  199. (
  200. ITFSNode * pNode,
  201. long nCommandId,
  202. DATA_OBJECT_TYPES type,
  203. LPDATAOBJECT pDataObject,
  204. DWORD dwType
  205. )
  206. {
  207. HRESULT hr = S_OK;
  208. int i = 0;
  209. CString strBuffer;
  210. WZC_CONTEXT wzcContext = {0};
  211. HANDLE hSessionContainer = NULL;
  212. SPIConsole spConsole;
  213. DWORD dwNew = 0;
  214. DWORD dwTotal = 0;
  215. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  216. //
  217. // Handle the scope context menu commands here
  218. //
  219. switch (nCommandId)
  220. {
  221. case IDS_MENU_ENABLE_LOGGING:
  222. case IDS_MENU_DISABLE_LOGGING:
  223. strBuffer.Empty();
  224. m_spSpdInfo->GetComputerName(&strBuffer);
  225. //
  226. // Disabling logging will not flush client side logs or reset the
  227. // session. User may query these records if desired.
  228. //
  229. if (IDS_MENU_ENABLE_LOGGING == nCommandId)
  230. {
  231. wzcContext.dwFlags = WZC_CTXT_LOGGING_ON;
  232. //
  233. // Enumerate from the beginning, flush all the old logs
  234. //
  235. m_spSpdInfo->StartFromFirstRecord(TRUE);
  236. CORg(m_spSpdInfo->FlushLogs());
  237. CORg(m_spSpdInfo->EnumLogData(&dwNew, &dwTotal));
  238. //
  239. // Now notify the virtual listbox
  240. //
  241. CORg(m_spNodeMgr->GetConsole(&spConsole) );
  242. CORg(MaintainSelection());
  243. CORg(spConsole->UpdateAllViews(
  244. pDataObject,
  245. dwTotal,
  246. RESULT_PANE_SET_VIRTUAL_LB_SIZE));
  247. }
  248. else
  249. wzcContext.dwFlags = 0;
  250. WZCSetContext(
  251. //strBuffer.IsEmpty()? NULL : (LPWSTR)(LPCWSTR)strBuffer,
  252. NULL,
  253. WZC_CONTEXT_CTL_LOG,
  254. &wzcContext,
  255. NULL);
  256. break;
  257. case IDS_MENU_FLUSH_LOGS:
  258. m_spSpdInfo->GetSession(&hSessionContainer);
  259. FlushWZCDbLog(hSessionContainer);
  260. CORg(m_spSpdInfo->FlushLogs());
  261. i = 0;
  262. // now notify the virtual listbox
  263. CORg ( m_spNodeMgr->GetConsole(&spConsole) );
  264. CORg ( spConsole->UpdateAllViews(
  265. pDataObject,
  266. i,
  267. RESULT_PANE_SET_VIRTUAL_LB_SIZE));
  268. break;
  269. default:
  270. break;
  271. }
  272. COM_PROTECT_ERROR_LABEL;
  273. return hr;
  274. }
  275. /*!--------------------------------------------------------------------------
  276. CLogDataHandler::Command
  277. Handles context menu commands for virtual listbox items
  278. Author: NSun
  279. ---------------------------------------------------------------------------*/
  280. STDMETHODIMP
  281. CLogDataHandler::Command
  282. (
  283. ITFSComponent * pComponent,
  284. MMC_COOKIE cookie,
  285. int nCommandID,
  286. LPDATAOBJECT pDataObject
  287. )
  288. {
  289. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  290. HRESULT hr = S_OK;
  291. /*
  292. SPITFSNode spNode;
  293. m_spResultNodeMgr->FindNode(cookie, &spNode);
  294. FILTER_TYPE NewFltrType = m_FltrType;
  295. // handle result context menu and view menus here
  296. switch (nCommandID)
  297. {
  298. case IDS_VIEW_ALL_FLTR:
  299. NewFltrType = FILTER_TYPE_ANY;
  300. break;
  301. case IDS_VIEW_TRANSPORT_FLTR:
  302. NewFltrType = FILTER_TYPE_TRANSPORT;
  303. break;
  304. case IDS_VIEW_TUNNEL_FLTR:
  305. NewFltrType = FILTER_TYPE_TUNNEL;
  306. break;
  307. default:
  308. break;
  309. }
  310. //Update the views if a different view is selected.
  311. if (NewFltrType != m_FltrType)
  312. {
  313. UpdateViewType(spNode, NewFltrType);
  314. }
  315. */
  316. return hr;
  317. }
  318. /*!--------------------------------------------------------------------------
  319. CLogDataHandler::HasPropertyPages
  320. Implementation of ITFSNodeHandler::HasPropertyPages
  321. NOTE: the root node handler has to over-ride this function to
  322. handle the snapin manager property page (wizard) case!!!
  323. Author: KennT
  324. ---------------------------------------------------------------------------*/
  325. STDMETHODIMP
  326. CLogDataHandler::HasPropertyPages
  327. (
  328. ITFSNode * pNode,
  329. LPDATAOBJECT pDataObject,
  330. DATA_OBJECT_TYPES type,
  331. DWORD dwType
  332. )
  333. {
  334. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  335. return hrFalse;
  336. }
  337. /*---------------------------------------------------------------------------
  338. CLogDataHandler::CreatePropertyPages
  339. Description
  340. Author: NSun
  341. ---------------------------------------------------------------------------*/
  342. STDMETHODIMP
  343. CLogDataHandler::CreatePropertyPages
  344. (
  345. ITFSNode * pNode,
  346. LPPROPERTYSHEETCALLBACK lpSA,
  347. LPDATAOBJECT pDataObject,
  348. LONG_PTR handle,
  349. DWORD dwType
  350. )
  351. {
  352. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  353. DWORD dwError;
  354. DWORD dwDynDnsFlags;
  355. //
  356. // Create the property page
  357. //
  358. SPIComponentData spComponentData;
  359. m_spNodeMgr->GetComponentData(&spComponentData);
  360. //CServerProperties * pServerProp = new CServerProperties(pNode, spComponentData, m_spTFSCompData, NULL);
  361. //
  362. // Object gets deleted when the page is destroyed
  363. //
  364. Assert(lpSA != NULL);
  365. //return pServerProp->CreateModelessSheet(lpSA, handle);
  366. return hrFalse;
  367. }
  368. /*---------------------------------------------------------------------------
  369. CLogDataHandler::OnPropertyChange
  370. Description
  371. Author: NSun
  372. ---------------------------------------------------------------------------*/
  373. HRESULT
  374. CLogDataHandler::OnPropertyChange
  375. (
  376. ITFSNode * pNode,
  377. LPDATAOBJECT pDataobject,
  378. DWORD dwType,
  379. LPARAM arg,
  380. LPARAM lParam
  381. )
  382. {
  383. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  384. //CServerProperties * pServerProp = reinterpret_cast<CServerProperties *>(lParam);
  385. LONG_PTR changeMask = 0;
  386. // tell the property page to do whatever now that we are back on the
  387. // main thread
  388. //pServerProp->OnPropertyChange(TRUE, &changeMask);
  389. //pServerProp->AcknowledgeNotify();
  390. if (changeMask)
  391. pNode->ChangeNode(changeMask);
  392. return hrOK;
  393. }
  394. /*---------------------------------------------------------------------------
  395. CLogDataHandler::OnExpand
  396. Handles enumeration of a scope item
  397. Author: NSun
  398. ---------------------------------------------------------------------------*/
  399. HRESULT
  400. CLogDataHandler::OnExpand
  401. (
  402. ITFSNode * pNode,
  403. LPDATAOBJECT pDataObject,
  404. DWORD dwType,
  405. LPARAM arg,
  406. LPARAM param
  407. )
  408. {
  409. HRESULT hr = hrOK;
  410. if (m_bExpanded)
  411. return hr;
  412. // do the default handling
  413. CORg (CIpsmHandler::OnExpand(pNode, pDataObject, dwType, arg, param));
  414. Error:
  415. return hr;
  416. }
  417. /*!--------------------------------------------------------------------------
  418. CLogDataHandler::OnResultSelect
  419. Handles the MMCN_SELECT notifcation
  420. Author: NSun
  421. ---------------------------------------------------------------------------*/
  422. HRESULT
  423. CLogDataHandler::OnResultSelect
  424. (
  425. ITFSComponent * pComponent,
  426. LPDATAOBJECT pDataObject,
  427. MMC_COOKIE cookie,
  428. LPARAM arg,
  429. LPARAM lParam
  430. )
  431. {
  432. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  433. HRESULT hr = hrOK;
  434. SPINTERNAL spInternal;
  435. SPIConsole spConsole;
  436. SPIConsoleVerb spConsoleVerb;
  437. SPITFSNode spNode;
  438. BOOL bStates[ARRAYLEN(g_ConsoleVerbs)];
  439. int i;
  440. LONG_PTR dwNodeType;
  441. BOOL fSelect = HIWORD(arg);
  442. SPIResultData spResultData;
  443. /* virtual listbox notifications come to the handler of the node that
  444. * is selected. check to see if this notification is for a virtual
  445. * listbox item or the active registrations node itself.
  446. */
  447. CORg (pComponent->GetConsoleVerb(&spConsoleVerb));
  448. m_verbDefault = MMC_VERB_OPEN;
  449. if (!fSelect)
  450. {
  451. return hr;
  452. }
  453. if (m_spSpdInfo)
  454. {
  455. DWORD dwInitInfo;
  456. dwInitInfo=m_spSpdInfo->GetInitInfo();
  457. if (!(dwInitInfo & MON_LOG_DATA))
  458. {
  459. CORg(m_spSpdInfo->EnumLogData(NULL, NULL));
  460. m_spSpdInfo->SetInitInfo(dwInitInfo | MON_LOG_DATA);
  461. }
  462. m_spSpdInfo->SetActiveInfo(MON_LOG_DATA);
  463. // Get the current count
  464. i = m_spSpdInfo->GetLogDataCount();
  465. // now notify the virtual listbox
  466. CORg ( m_spNodeMgr->GetConsole(&spConsole) );
  467. CORg ( spConsole->UpdateAllViews(pDataObject, i,
  468. RESULT_PANE_SET_VIRTUAL_LB_SIZE) );
  469. }
  470. // now update the verbs...
  471. spInternal = ExtractInternalFormat(pDataObject);
  472. Assert(spInternal);
  473. if (spInternal->HasVirtualIndex())
  474. {
  475. //we have a selected result item
  476. m_pComponent = pComponent;
  477. CORg(pComponent->GetResultData(&spResultData));
  478. CORg(GetSelectedItem(&m_nSelIndex, &m_SelLogData, spResultData));
  479. //TODO add to here if we want to have some result console verbs
  480. // we gotta do special stuff for the virtual index items
  481. dwNodeType = IPFWMON_LOGDATA_ITEM;
  482. for (i = 0; i < ARRAYLEN(g_ConsoleVerbs); bStates[i++] = FALSE);
  483. //enable the "properties" and "refresh" menu
  484. bStates[MMC_VERB_PROPERTIES & 0x000F] = TRUE;
  485. bStates[MMC_VERB_REFRESH & 0x000F] = TRUE;
  486. m_verbDefault = MMC_VERB_PROPERTIES;
  487. }
  488. else
  489. {
  490. // enable/disable delete depending if the node supports it
  491. CORg (m_spNodeMgr->FindNode(cookie, &spNode));
  492. dwNodeType = spNode->GetData(TFS_DATA_TYPE);
  493. for (i = 0; i < ARRAYLEN(g_ConsoleVerbs); bStates[i++] = TRUE);
  494. //hide "delete" and "properties" context menu
  495. bStates[MMC_VERB_PROPERTIES & 0x000F] = FALSE;
  496. bStates[MMC_VERB_DELETE & 0x000F] = FALSE;
  497. bStates[MMC_VERB_REFRESH & 0x000F] = TRUE;
  498. }
  499. EnableVerbs(spConsoleVerb, g_ConsoleVerbStates[dwNodeType], bStates);
  500. COM_PROTECT_ERROR_LABEL;
  501. return hr;
  502. }
  503. /*
  504. * CLogDataHandler::OnResultColumnClick
  505. * Description: Handles the MMCN_COLUMN_CLICK notification
  506. * Parameters:
  507. * Returns: S_OK - lets mmc know we handle notification
  508. * other error - indicates a failure to mmc
  509. */
  510. HRESULT CLogDataHandler::OnResultColumnClick(ITFSComponent *pComponent,
  511. LPARAM nColumn,
  512. BOOL bAscending)
  513. {
  514. DWORD dwColID = 0;
  515. HRESULT hr = S_OK;
  516. Assert(nColumn < DimensionOf[IPFWMON_LOGDATA]);
  517. dwColID = aColumns[IPFWMON_LOGDATA][nColumn];
  518. hr = m_spSpdInfo->SetSortOptions(dwColID, bAscending);
  519. return hr;
  520. }
  521. /*!--------------------------------------------------------------------------
  522. CLogDataHandler::OnDelete
  523. The base handler calls this when MMC sends a MMCN_DELETE for a
  524. scope pane item. We just call our delete command handler.
  525. Author: NSun
  526. ---------------------------------------------------------------------------*/
  527. HRESULT
  528. CLogDataHandler::OnDelete
  529. (
  530. ITFSNode * pNode,
  531. LPARAM arg,
  532. LPARAM lParam
  533. )
  534. {
  535. return S_FALSE;
  536. }
  537. /*!--------------------------------------------------------------------------
  538. CLogDataHandler::HasPropertyPages
  539. Handle the result notification
  540. Author: NSun
  541. ---------------------------------------------------------------------------*/
  542. STDMETHODIMP
  543. CLogDataHandler::HasPropertyPages(
  544. ITFSComponent *pComponent,
  545. MMC_COOKIE cookie,
  546. LPDATAOBJECT pDataObject
  547. )
  548. {
  549. HRESULT hr = S_OK;
  550. int nCount = 0;
  551. int nIndex = 0;
  552. CLogDataProperties *pLogDataProp = NULL;
  553. CLogDataGenProp *pGenProp = NULL;
  554. CDataObject *pDataObj = NULL;
  555. SPINTERNAL spInternal;
  556. nCount = HasPropSheetsOpen();
  557. ASSERT(nCount <= 1);
  558. if (nCount == 1)
  559. {
  560. //
  561. // Get the open page general and the page holder.
  562. //
  563. hr = GetOpenPropSheet(
  564. 0,
  565. (CPropertyPageHolderBase **)&pLogDataProp);
  566. ASSERT(SUCCEEDED(hr));
  567. pGenProp = &pLogDataProp->m_pageGeneral;
  568. //
  569. // Get the virtual index from the new data object and the data object
  570. // which is used by the page holder.
  571. //
  572. spInternal = ExtractInternalFormat(pDataObject);
  573. ASSERT(spInternal->HasVirtualIndex());
  574. nIndex = spInternal->GetVirtualIndex();
  575. pDataObj = reinterpret_cast<CDataObject*>(pLogDataProp->m_pDataObject);
  576. //
  577. // Change the selection and shift the focus :).
  578. //
  579. hr = pGenProp->MoveSelection(
  580. pLogDataProp,
  581. pDataObj,
  582. nIndex);
  583. ASSERT(SUCCEEDED(hr));
  584. pGenProp->SetFocus();
  585. //
  586. // Dont let MMC create another property sheet.
  587. //
  588. hr = S_FALSE;
  589. }
  590. return hr;
  591. }
  592. /*!--------------------------------------------------------------------------
  593. CLogDataHandler::CreatePropertyPages
  594. Handle the result notification. Create the filter property sheet
  595. Author: NSun
  596. Modified: vbhanu
  597. ---------------------------------------------------------------------------*/
  598. STDMETHODIMP
  599. CLogDataHandler::CreatePropertyPages(ITFSComponent *pComponent,
  600. MMC_COOKIE cookie,
  601. LPPROPERTYSHEETCALLBACK lpProvider,
  602. LPDATAOBJECT pDataObject,
  603. LONG_PTR handle)
  604. {
  605. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  606. HRESULT hr = hrOK;
  607. SPINTERNAL spInternal;
  608. SPITFSNode spNode;
  609. int nIndex;
  610. SPIComponentData spComponentData;
  611. CLogDataInfo LogDataInfo;
  612. CLogDataProperties * pLogDataProp;
  613. Assert(m_spNodeMgr);
  614. CORg( m_spNodeMgr->FindNode(cookie, &spNode) );
  615. CORg( m_spNodeMgr->GetComponentData(&spComponentData) );
  616. spInternal = ExtractInternalFormat(pDataObject);
  617. //
  618. // virtual listbox notifications come to the handler of the node that is
  619. // selected.
  620. //
  621. // assert that this notification is for a virtual listbox item
  622. Assert(spInternal);
  623. if (!spInternal->HasVirtualIndex())
  624. return hr;
  625. nIndex = spInternal->GetVirtualIndex();
  626. // Get the complete record
  627. CORg(m_spSpdInfo->GetSpecificLog(nIndex, &LogDataInfo));
  628. pLogDataProp = new CLogDataProperties(
  629. spNode,
  630. spComponentData,
  631. m_spTFSCompData,
  632. &LogDataInfo,
  633. m_spSpdInfo,
  634. NULL,
  635. pDataObject,
  636. m_spNodeMgr,
  637. pComponent);
  638. hr = pLogDataProp->CreateModelessSheet(lpProvider, handle);
  639. COM_PROTECT_ERROR_LABEL;
  640. return hr;
  641. }
  642. /*---------------------------------------------------------------------------
  643. CLogDataHandler::OnGetResultViewType
  644. Return the result view that this node is going to support
  645. Author: NSun
  646. ---------------------------------------------------------------------------*/
  647. HRESULT
  648. CLogDataHandler::OnGetResultViewType
  649. (
  650. ITFSComponent * pComponent,
  651. MMC_COOKIE cookie,
  652. LPOLESTR * ppViewType,
  653. long * pViewOptions
  654. )
  655. {
  656. if (cookie != NULL)
  657. {
  658. *pViewOptions = MMC_VIEW_OPTIONS_OWNERDATALIST;
  659. }
  660. return S_FALSE;
  661. }
  662. /*---------------------------------------------------------------------------
  663. CLogDataHandler::GetVirtualImage
  664. Returns the image index for virtual listbox items
  665. Author: NSun
  666. ---------------------------------------------------------------------------*/
  667. int
  668. CLogDataHandler::GetVirtualImage
  669. (
  670. int nIndex
  671. )
  672. {
  673. HRESULT hr;
  674. int nImgIndex = ICON_IDX_LOGDATA_UNKNOWN;
  675. CLogDataInfo LogData;
  676. PWZC_DB_RECORD pwzcDbRecord = NULL;
  677. CORg(m_spSpdInfo->GetLogDataInfo(nIndex, &LogData));
  678. pwzcDbRecord = &LogData.m_wzcDbRecord;
  679. switch (pwzcDbRecord->category)
  680. {
  681. case DBLOG_CATEG_INFO:
  682. nImgIndex = ICON_IDX_LOGDATA_INFORMATION;
  683. break;
  684. case DBLOG_CATEG_WARN:
  685. nImgIndex = ICON_IDX_LOGDATA_WARNING;
  686. break;
  687. case DBLOG_CATEG_ERR:
  688. nImgIndex = ICON_IDX_LOGDATA_ERROR;
  689. break;
  690. case DBLOG_CATEG_PACKET:
  691. nImgIndex = ICON_IDX_LOGDATA_INFORMATION;
  692. break;
  693. default:
  694. nImgIndex = ICON_IDX_LOGDATA_UNKNOWN;
  695. break;
  696. }
  697. COM_PROTECT_ERROR_LABEL;
  698. return nImgIndex;
  699. }
  700. /*---------------------------------------------------------------------------
  701. CLogDataHandler::GetVirtualString
  702. returns a pointer to the string for virtual listbox items
  703. Author: NSun
  704. ---------------------------------------------------------------------------*/
  705. LPCWSTR
  706. CLogDataHandler::GetVirtualString(int nIndex,
  707. int nCol)
  708. {
  709. HRESULT hr = S_OK;
  710. static CString strTemp;
  711. LPTSTR lptstrTemp = NULL;
  712. CLogDataInfo logData;
  713. PWZC_DB_RECORD pwzcDbRecord = NULL;
  714. strTemp.Empty();
  715. if (nCol >= DimensionOf(aColumns[IPFWMON_LOGDATA]))
  716. return NULL;
  717. CORg(m_spSpdInfo->GetLogDataInfo(nIndex, &logData));
  718. pwzcDbRecord = &logData.m_wzcDbRecord;
  719. switch (aColumns[IPFWMON_LOGDATA][nCol])
  720. {
  721. case IDS_COL_LOGDATA_MSG:
  722. if (pwzcDbRecord->message.pData != NULL)
  723. {
  724. strTemp = (LPWSTR) (pwzcDbRecord->message.pData);
  725. if (pwzcDbRecord->message.dwDataLen > MAX_SUMMARY_MESSAGE_SIZE)
  726. strTemp += ELLIPSIS;
  727. }
  728. break;
  729. case IDS_COL_LOGDATA_TIME:
  730. FileTimeToString(pwzcDbRecord->timestamp, &strTemp);
  731. break;
  732. case IDS_COL_LOGDATA_CAT:
  733. CategoryToString(pwzcDbRecord->category, strTemp);
  734. break;
  735. case IDS_COL_LOGDATA_COMP_ID:
  736. ComponentIDToString(pwzcDbRecord->componentid, strTemp);
  737. break;
  738. case IDS_COL_LOGDATA_LOCAL_MAC_ADDR:
  739. if (pwzcDbRecord->localmac.pData != NULL)
  740. strTemp = (LPWSTR)pwzcDbRecord->localmac.pData;
  741. break;
  742. case IDS_COL_LOGDATA_REMOTE_MAC_ADDR:
  743. if (pwzcDbRecord->remotemac.pData != NULL)
  744. strTemp = (LPWSTR)pwzcDbRecord->remotemac.pData;
  745. break;
  746. case IDS_COL_LOGDATA_SSID:
  747. if (pwzcDbRecord->ssid.pData != NULL)
  748. {
  749. lptstrTemp = strTemp.GetBuffer(pwzcDbRecord->ssid.dwDataLen);
  750. CopyAndStripNULL(lptstrTemp,
  751. (LPTSTR)pwzcDbRecord->ssid.pData,
  752. pwzcDbRecord->ssid.dwDataLen);
  753. strTemp.ReleaseBuffer();
  754. }
  755. break;
  756. default:
  757. Panic0("CLogDataHandler::GetVirtualString - Unknown column!\n");
  758. break;
  759. }
  760. COM_PROTECT_ERROR_LABEL;
  761. return strTemp;
  762. }
  763. /*---------------------------------------------------------------------------
  764. CLogDataHandler::CacheHint
  765. MMC tells us which items it will need before it requests things
  766. Author: NSun
  767. ---------------------------------------------------------------------------*/
  768. STDMETHODIMP
  769. CLogDataHandler::CacheHint
  770. (
  771. int nStartIndex,
  772. int nEndIndex
  773. )
  774. {
  775. HRESULT hr = hrOK;;
  776. Trace2("CacheHint - Start %d, End %d\n", nStartIndex, nEndIndex);
  777. return hr;
  778. }
  779. /*
  780. * CLogDataHandler::SortItems
  781. * Description: Sorting of the virtual listbox items
  782. * Parameters:
  783. * Returns:
  784. */
  785. HRESULT CLogDataHandler::SortItems(int nColumn, DWORD dwSortOptions,
  786. LPARAM lUserParam)
  787. {
  788. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  789. HRESULT hr = S_OK;
  790. BEGIN_WAIT_CURSOR
  791. hr = m_spSpdInfo->SortLogData();
  792. END_WAIT_CURSOR
  793. return hr;
  794. }
  795. /*!--------------------------------------------------------------------------
  796. CLogDataHandler::OnResultUpdateView
  797. Implementation of ITFSResultHandler::OnResultUpdateView
  798. Author: NSun
  799. ---------------------------------------------------------------------------*/
  800. HRESULT CLogDataHandler::OnResultUpdateView
  801. (
  802. ITFSComponent *pComponent,
  803. LPDATAOBJECT pDataObject,
  804. LPARAM data,
  805. LONG_PTR hint
  806. )
  807. {
  808. HRESULT hr = hrOK;
  809. SPITFSNode spSelectedNode;
  810. pComponent->GetSelectedNode(&spSelectedNode);
  811. if (spSelectedNode == NULL)
  812. return S_OK; // no selection for our IComponentData
  813. if ( hint == IPFWMON_UPDATE_STATUS )
  814. {
  815. SPINTERNAL spInternal = ExtractInternalFormat(pDataObject);
  816. ITFSNode * pNode = reinterpret_cast<ITFSNode *>(spInternal->m_cookie);
  817. SPITFSNode spSelectedNode;
  818. pComponent->GetSelectedNode(&spSelectedNode);
  819. if (pNode == spSelectedNode)
  820. {
  821. // if we are the selected node, then we need to update
  822. SPIResultData spResultData;
  823. CORg (pComponent->GetResultData(&spResultData));
  824. CORg (spResultData->SetItemCount((int) data, MMCLV_UPDATE_NOSCROLL));
  825. }
  826. }
  827. else
  828. {
  829. // we don't handle this message, let the base class do it.
  830. return CIpsmHandler::OnResultUpdateView(pComponent, pDataObject, data, hint);
  831. }
  832. COM_PROTECT_ERROR_LABEL;
  833. return hr;
  834. }
  835. /*!--------------------------------------------------------------------------
  836. CLogDataHandler::LoadColumns
  837. Set the correct column header and then call the base class
  838. Author: NSun
  839. ---------------------------------------------------------------------------*/
  840. HRESULT
  841. CLogDataHandler::LoadColumns
  842. (
  843. ITFSComponent * pComponent,
  844. MMC_COOKIE cookie,
  845. LPARAM arg,
  846. LPARAM lParam
  847. )
  848. {
  849. //set column info
  850. return CIpsmHandler::LoadColumns(pComponent, cookie, arg, lParam);
  851. }
  852. /*---------------------------------------------------------------------------
  853. Command handlers
  854. ---------------------------------------------------------------------------*/
  855. /*---------------------------------------------------------------------------
  856. CLogDataHandler::OnDelete
  857. Removes a service SA
  858. Author: NSun
  859. ---------------------------------------------------------------------------*/
  860. HRESULT
  861. CLogDataHandler::OnDelete
  862. (
  863. ITFSNode * pNode
  864. )
  865. {
  866. HRESULT hr = S_FALSE;
  867. return hr;
  868. }
  869. /*---------------------------------------------------------------------------
  870. CLogDataHandler::UpdateStatus
  871. -
  872. Author: NSun
  873. ---------------------------------------------------------------------------*/
  874. HRESULT
  875. CLogDataHandler::UpdateStatus
  876. (
  877. ITFSNode * pNode
  878. )
  879. {
  880. HRESULT hr = hrOK;
  881. SPIComponentData spComponentData;
  882. SPIConsole spConsole;
  883. IDataObject * pDataObject;
  884. SPIDataObject spDataObject;
  885. int i = 0;
  886. Trace0("CLogDataHandler::UpdateStatus - Updating status for Filter");
  887. // force the listbox to update. We do this by setting the count and
  888. // telling it to invalidate the data
  889. CORg(m_spNodeMgr->GetComponentData(&spComponentData));
  890. CORg(m_spNodeMgr->GetConsole(&spConsole));
  891. // grab a data object to use
  892. CORg(spComponentData->QueryDataObject((MMC_COOKIE) pNode,
  893. CCT_RESULT,
  894. &pDataObject) );
  895. spDataObject = pDataObject;
  896. i = m_spSpdInfo->GetLogDataCount();
  897. CORg(MaintainSelection());
  898. CORg(spConsole->UpdateAllViews(pDataObject, i, IPFWMON_UPDATE_STATUS));
  899. COM_PROTECT_ERROR_LABEL;
  900. return hr;
  901. }
  902. /*---------------------------------------------------------------------------
  903. Misc functions
  904. ---------------------------------------------------------------------------*/
  905. /*---------------------------------------------------------------------------
  906. CLogDataHandler::InitData
  907. Initializes data for this node
  908. Author: NSun
  909. ---------------------------------------------------------------------------*/
  910. HRESULT
  911. CLogDataHandler::InitData
  912. (
  913. ISpdInfo * pSpdInfo
  914. )
  915. {
  916. m_spSpdInfo.Set(pSpdInfo);
  917. return hrOK;
  918. }
  919. /*
  920. CLogDataHandler::GetSelectedItem
  921. Description:
  922. Returns the underlying LogData for a selected item
  923. Parameters:
  924. [out] pLogData - Holds a copy of the item. Caller must allocate space for
  925. the base holder. Inner items are allocated by CLogDataInfo
  926. [in] pResultData - Used to call GetNextItem
  927. Returns:
  928. S_OK on success
  929. */
  930. HRESULT CLogDataHandler::GetSelectedItem(int *pnIndex, CLogDataInfo *pLogData,
  931. IResultData *pResultData)
  932. {
  933. HRESULT hr = S_OK;
  934. RESULTDATAITEM rdi;
  935. if ( (NULL == pLogData) || (NULL == pnIndex) || (NULL == pResultData) )
  936. {
  937. hr = HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER);
  938. goto Error;
  939. }
  940. memset(&rdi, 0, sizeof(RESULTDATAITEM));
  941. rdi.mask = RDI_STATE | RDI_INDEX;
  942. //search from the beginning
  943. rdi.nIndex = -1;
  944. //for a selected item
  945. rdi.nState = LVIS_SELECTED;
  946. //start the search
  947. CORg(pResultData->GetNextItem(&rdi));
  948. //copy out the item
  949. *pnIndex = rdi.nIndex;
  950. CORg(m_spSpdInfo->GetLogDataInfo(rdi.nIndex, pLogData));
  951. COM_PROTECT_ERROR_LABEL;
  952. return hr;
  953. }
  954. /*
  955. CLogDataHandler::GetSelectedItemState
  956. Description:
  957. Gets the item ID and lparam of the item that was selected
  958. Parameters:
  959. [out] puiState - Holds the state of the item. Caller must allocate space.
  960. [in] pResultData - Used to call GetItem
  961. Returns:
  962. S_OK on success
  963. */
  964. HRESULT CLogDataHandler::GetSelectedItemState(UINT *puiState,
  965. IResultData *pResultData)
  966. {
  967. HRESULT hr = S_OK;
  968. RESULTDATAITEM rdi;
  969. if ( (NULL == puiState) || (NULL == pResultData) )
  970. {
  971. hr = HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER);
  972. goto Error;
  973. }
  974. memset(&rdi, 0, sizeof(RESULTDATAITEM));
  975. rdi.mask = RDI_STATE | RDI_INDEX;
  976. //search from the beginning
  977. rdi.nIndex = -1;
  978. //for a selected item
  979. rdi.nState = LVIS_SELECTED;
  980. //start the search
  981. CORg(pResultData->GetNextItem(&rdi));
  982. //copy out the state
  983. *puiState = (UINT) rdi.nState;
  984. COM_PROTECT_ERROR_LABEL;
  985. return hr;
  986. }
  987. /*
  988. CLogDataHandler::MaintainSelection
  989. Maintains the selection at the current selected item once new items
  990. have been added to the virtual list.
  991. Returns:
  992. S_OK on success
  993. */
  994. HRESULT CLogDataHandler::MaintainSelection()
  995. {
  996. UINT uiState = 0;
  997. HRESULT hr = S_OK;
  998. int nCount = 0;
  999. CLogDataProperties *pLogDataProp = NULL;
  1000. CLogDataGenProp *pGenProp = NULL;
  1001. CDataObject *pDataObj = NULL;
  1002. SPIResultData spResultData;
  1003. //If we dont have our component yet, ie no selection was made
  1004. if (NULL == m_pComponent)
  1005. goto Error;
  1006. //Ensure item at current selected index is not selected
  1007. CORg(m_pComponent->GetResultData(&spResultData));
  1008. CORg(GetSelectedItemState(&uiState, spResultData));
  1009. CORg(spResultData->ModifyItemState(m_nSelIndex, 0, 0,
  1010. LVIS_SELECTED | LVIS_FOCUSED));
  1011. //Find the new index of the current item and set it to the old state
  1012. CORg(m_spSpdInfo->FindIndex(&m_nSelIndex, &m_SelLogData));
  1013. if (m_nSelIndex < 0)
  1014. CORg(m_spSpdInfo->GetLastIndex(&m_nSelIndex));
  1015. CORg(spResultData->ModifyItemState(m_nSelIndex, 0, uiState, 0));
  1016. //
  1017. // Update any open property pages to the new index
  1018. //
  1019. nCount = HasPropSheetsOpen();
  1020. ASSERT(nCount <= 1);
  1021. if (nCount == 1)
  1022. {
  1023. //
  1024. // Get the open page general and the page holder.
  1025. //
  1026. hr = GetOpenPropSheet(
  1027. 0,
  1028. (CPropertyPageHolderBase **)&pLogDataProp);
  1029. ASSERT(SUCCEEDED(hr));
  1030. pGenProp = &pLogDataProp->m_pageGeneral;
  1031. //
  1032. // Change the selected index for the property page
  1033. //
  1034. pDataObj = reinterpret_cast<CDataObject*>(pLogDataProp->m_pDataObject);
  1035. pDataObj->SetVirtualIndex(m_nSelIndex);
  1036. }
  1037. COM_PROTECT_ERROR_LABEL;
  1038. return hr;
  1039. }
  1040. /*
  1041. HRESULT
  1042. CLogDataHandler::UpdateViewType(ITFSNode * pNode, FILTER_TYPE NewFltrType)
  1043. {
  1044. // clear the listbox then set the size
  1045. HRESULT hr = hrOK;
  1046. SPIComponentData spCompData;
  1047. SPIConsole spConsole;
  1048. IDataObject* pDataObject;
  1049. SPIDataObject spDataObject;
  1050. LONG_PTR command;
  1051. int i;
  1052. COM_PROTECT_TRY
  1053. {
  1054. m_FltrType = NewFltrType;
  1055. //tell the spddb to update its index manager for QM filter
  1056. m_spSpdInfo->ChangeLogDataViewType(m_FltrType);
  1057. i = m_spSpdInfo->GetLogDataCountOfCurrentViewType();
  1058. m_spNodeMgr->GetComponentData(&spCompData);
  1059. CORg ( spCompData->QueryDataObject((MMC_COOKIE) pNode, CCT_RESULT, &pDataObject) );
  1060. spDataObject = pDataObject;
  1061. CORg ( m_spNodeMgr->GetConsole(&spConsole) );
  1062. //update the result pane virtual list
  1063. CORg ( spConsole->UpdateAllViews(spDataObject, i, RESULT_PANE_CLEAR_VIRTUAL_LB) );
  1064. COM_PROTECT_ERROR_LABEL;
  1065. }
  1066. COM_PROTECT_CATCH
  1067. return hr;
  1068. }
  1069. */