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.

3328 lines
61 KiB

  1. /*++
  2. Copyright (C) 1993-1999 Microsoft Corporation
  3. Module Name:
  4. control.cpp
  5. Abstract:
  6. Implementation of ISystemMonitor, IOleControl, ISpecifyPP,
  7. IProvideClassInfo interfaces.
  8. --*/
  9. #include "polyline.h"
  10. #include <strsafe.h>
  11. #include <sqlext.h>
  12. #include "unkhlpr.h"
  13. #include "unihelpr.h"
  14. #include "grphitem.h"
  15. #include "ctrprop.h"
  16. #include "grphprop.h"
  17. #include "genprop.h"
  18. #include "appearprop.h"
  19. #include "logsrc.h"
  20. #include "srcprop.h"
  21. //----------------------------------------------------------------------------
  22. // CImpISpecifyPP Interface Implementation
  23. //----------------------------------------------------------------------------
  24. // Standard IUnknown for contained interface
  25. IMPLEMENT_CONTAINED_INTERFACE(CPolyline, CImpISpecifyPP)
  26. STDMETHODIMP
  27. CImpISpecifyPP::GetPages (
  28. OUT CAUUID *pPages
  29. )
  30. /*++
  31. Routine Description:
  32. GetPages returns an allocated array of property page GUIDs for Sysmon graph.
  33. There are three pages: general, graph, and counter.
  34. Arguments:
  35. pPages - Pointer to GUID array header filled in by this routine
  36. Return Value:
  37. HRESULT - NOERROR or OUT_OF_MEMORY
  38. --*/
  39. {
  40. HRESULT hr = S_OK;
  41. IMalloc *pIMalloc = NULL;
  42. GUID *pGUID = NULL;
  43. if (pPages == NULL) {
  44. return E_POINTER;
  45. }
  46. try {
  47. pPages->cElems = 0;
  48. pPages->pElems = NULL;
  49. } catch (...) {
  50. return E_POINTER;
  51. }
  52. //
  53. // Get Ole Malloc and allocate array
  54. //
  55. if ( FAILED(CoGetMalloc(MEMCTX_TASK, &pIMalloc)) ) {
  56. return E_OUTOFMEMORY;
  57. }
  58. pGUID = (GUID*)pIMalloc->Alloc((CPROPPAGES) * sizeof(GUID));
  59. if (NULL != pGUID) {
  60. // Fill the structure
  61. pGUID[GENERAL_PROPPAGE] = CLSID_GeneralPropPage;
  62. pGUID[SOURCE_PROPPAGE] = CLSID_SourcePropPage;
  63. pGUID[COUNTER_PROPPAGE] = CLSID_CounterPropPage;
  64. pGUID[GRAPH_PROPPAGE] = CLSID_GraphPropPage;
  65. pGUID[APPEAR_PROPPAGE] = CLSID_AppearPropPage;
  66. try {
  67. pPages->cElems = CPROPPAGES;
  68. pPages->pElems = pGUID;
  69. } catch (...) {
  70. hr = E_POINTER;
  71. }
  72. }
  73. else {
  74. hr = E_OUTOFMEMORY;
  75. }
  76. if (FAILED(hr) && pGUID) {
  77. pIMalloc->Free(pGUID);
  78. }
  79. pIMalloc->Release();
  80. return hr;
  81. }
  82. //----------------------------------------------------------------------------
  83. // CImpIProvideClassInfo Interface Implementation
  84. //----------------------------------------------------------------------------
  85. // Standard IUnknown for contained interface
  86. IMPLEMENT_CONTAINED_INTERFACE(CPolyline, CImpIProvideClassInfo)
  87. STDMETHODIMP
  88. CImpIProvideClassInfo::GetClassInfo (
  89. OUT LPTYPEINFO *ppTI
  90. )
  91. /*++
  92. Routine Description:
  93. GetClassInfo returns an ITypeInfo interface to its type lib information.
  94. The interface is obtained by querying the contained ITypeLib interface.
  95. Arguments:
  96. ppTI - Pointer to returned ITypeInfo interface
  97. Return Value:
  98. HRESULT
  99. --*/
  100. {
  101. HRESULT hr = S_OK;
  102. if (ppTI == NULL) {
  103. return E_POINTER;
  104. }
  105. try {
  106. *ppTI = NULL;
  107. hr = m_pObj->m_pITypeLib->GetTypeInfoOfGuid(CLSID_SystemMonitor, ppTI);
  108. } catch (...) {
  109. hr = E_POINTER;
  110. }
  111. return hr;
  112. }
  113. //----------------------------------------------------------------------------
  114. // CImpISystemMonitor Interface Implementation
  115. //----------------------------------------------------------------------------
  116. // Standard IUnknown for contained interface
  117. IMPLEMENT_CONTAINED_INTERFACE(CPolyline, CImpISystemMonitor)
  118. STDMETHODIMP
  119. CImpISystemMonitor::put_Appearance (
  120. IN INT iAppearance
  121. )
  122. {
  123. HRESULT hr = E_INVALIDARG;
  124. //
  125. // 0 = Flat, 1 = 3D
  126. //
  127. if ( ( 0 == iAppearance ) || ( 1 == iAppearance ) ) {
  128. m_pObj->m_pCtrl->put_Appearance( iAppearance, FALSE );
  129. hr = NOERROR;
  130. }
  131. return hr;
  132. }
  133. STDMETHODIMP
  134. CImpISystemMonitor::get_Appearance (
  135. OUT INT *piAppearance
  136. )
  137. {
  138. HRESULT hr = S_OK;
  139. if (piAppearance == NULL) {
  140. return E_POINTER;
  141. }
  142. try {
  143. *piAppearance = m_pObj->m_Graph.Options.iAppearance;
  144. if (*piAppearance == NULL_APPEARANCE) {
  145. *piAppearance = m_pObj->m_pCtrl->Appearance();
  146. }
  147. } catch (...) {
  148. hr = E_POINTER;
  149. }
  150. return hr;
  151. }
  152. STDMETHODIMP
  153. CImpISystemMonitor::put_BackColor (
  154. IN OLE_COLOR Color
  155. )
  156. {
  157. m_pObj->m_pCtrl->put_BackPlotColor(Color, FALSE);
  158. return NOERROR;
  159. }
  160. STDMETHODIMP
  161. CImpISystemMonitor::get_BackColor (
  162. OUT OLE_COLOR *pColor
  163. )
  164. {
  165. HRESULT hr = S_OK;
  166. if (pColor == NULL) {
  167. return E_POINTER;
  168. }
  169. try {
  170. *pColor = m_pObj->m_Graph.Options.clrBackPlot;
  171. if (*pColor == NULL_COLOR) {
  172. *pColor = m_pObj->m_pCtrl->clrBackPlot();
  173. }
  174. } catch (...) {
  175. hr = E_POINTER;
  176. }
  177. return hr;
  178. }
  179. STDMETHODIMP
  180. CImpISystemMonitor::put_BackColorCtl (
  181. IN OLE_COLOR Color
  182. )
  183. {
  184. m_pObj->m_pCtrl->put_BackCtlColor(Color);
  185. return NOERROR;
  186. }
  187. STDMETHODIMP
  188. CImpISystemMonitor::get_BackColorCtl (
  189. OUT OLE_COLOR *pColor
  190. )
  191. {
  192. HRESULT hr = S_OK;
  193. if (pColor == NULL) {
  194. return E_POINTER;
  195. }
  196. try {
  197. // NT 5.0 Beta 1 files can be saved with NULL BackColorCtl.
  198. *pColor = m_pObj->m_Graph.Options.clrBackCtl;
  199. if (*pColor == NULL_COLOR) {
  200. *pColor = m_pObj->m_pCtrl->clrBackCtl();
  201. }
  202. } catch (...) {
  203. hr = E_POINTER;
  204. }
  205. return hr;
  206. }
  207. STDMETHODIMP
  208. CImpISystemMonitor::put_GridColor (
  209. IN OLE_COLOR Color
  210. )
  211. {
  212. m_pObj->m_pCtrl->put_GridColor(Color);
  213. return NOERROR;
  214. }
  215. STDMETHODIMP
  216. CImpISystemMonitor::get_GridColor (
  217. OUT OLE_COLOR *pColor
  218. )
  219. {
  220. HRESULT hr = S_OK;
  221. if (pColor == NULL) {
  222. return E_POINTER;
  223. }
  224. try {
  225. *pColor = m_pObj->m_Graph.Options.clrGrid;
  226. } catch (...) {
  227. hr = E_POINTER;
  228. }
  229. return hr;
  230. }
  231. STDMETHODIMP
  232. CImpISystemMonitor::put_TimeBarColor (
  233. IN OLE_COLOR Color )
  234. {
  235. m_pObj->m_pCtrl->put_TimeBarColor(Color);
  236. return NOERROR;
  237. }
  238. STDMETHODIMP
  239. CImpISystemMonitor::get_TimeBarColor (
  240. OUT OLE_COLOR *pColor )
  241. {
  242. HRESULT hr = S_OK;
  243. if (pColor == NULL) {
  244. return E_POINTER;
  245. }
  246. try {
  247. *pColor = m_pObj->m_Graph.Options.clrTimeBar;
  248. } catch (...) {
  249. hr = E_POINTER;
  250. }
  251. return hr;
  252. }
  253. STDMETHODIMP
  254. CImpISystemMonitor::put_BorderStyle (
  255. IN INT iBorderStyle
  256. )
  257. {
  258. HRESULT hr;
  259. // 0 = none, 1 = single.
  260. if ( ( 0 == iBorderStyle ) || ( 1 == iBorderStyle ) ) {
  261. m_pObj->m_pCtrl->put_BorderStyle( iBorderStyle, FALSE );
  262. hr = NOERROR;
  263. } else {
  264. hr = E_INVALIDARG;
  265. }
  266. return hr;
  267. }
  268. STDMETHODIMP
  269. CImpISystemMonitor::get_BorderStyle (
  270. OUT INT *piBorderStyle
  271. )
  272. {
  273. HRESULT hr = S_OK;
  274. if (piBorderStyle == NULL) {
  275. return E_POINTER;
  276. }
  277. try {
  278. *piBorderStyle = m_pObj->m_Graph.Options.iBorderStyle;
  279. if (*piBorderStyle == NULL_BORDERSTYLE) {
  280. *piBorderStyle = m_pObj->m_pCtrl->BorderStyle();
  281. }
  282. } catch (...) {
  283. hr = E_POINTER;
  284. }
  285. return hr;
  286. }
  287. STDMETHODIMP
  288. CImpISystemMonitor::put_ForeColor (
  289. IN OLE_COLOR Color
  290. )
  291. {
  292. m_pObj->m_pCtrl->put_FgndColor(Color, FALSE);
  293. return NOERROR;
  294. }
  295. STDMETHODIMP
  296. CImpISystemMonitor::get_ForeColor (
  297. OUT OLE_COLOR *pColor
  298. )
  299. {
  300. HRESULT hr = S_OK;
  301. if (pColor == NULL) {
  302. return E_POINTER;
  303. }
  304. try {
  305. *pColor = m_pObj->m_Graph.Options.clrFore;
  306. if (*pColor == NULL_COLOR) {
  307. *pColor = m_pObj->m_pCtrl->clrFgnd();
  308. }
  309. } catch (...) {
  310. hr = E_POINTER;
  311. }
  312. return hr;
  313. }
  314. STDMETHODIMP
  315. CImpISystemMonitor::putref_Font (
  316. IN IFontDisp *pFontDisp
  317. )
  318. {
  319. LPFONT pIFont = NULL;
  320. HRESULT hr = S_OK;
  321. if (pFontDisp == NULL) {
  322. return E_POINTER;
  323. }
  324. try {
  325. hr = pFontDisp->QueryInterface(IID_IFont, (PPVOID)&pIFont);
  326. if (SUCCEEDED(hr)) {
  327. hr = m_pObj->m_pCtrl->put_Font ( pIFont, FALSE );
  328. }
  329. } catch (...) {
  330. hr = E_POINTER;
  331. }
  332. if (FAILED(hr) && pIFont) {
  333. pIFont->Release();
  334. }
  335. return hr;
  336. }
  337. STDMETHODIMP
  338. CImpISystemMonitor::get_Font (
  339. OUT IFontDisp **ppFont
  340. )
  341. {
  342. HRESULT hr = S_OK;
  343. if (ppFont == NULL) {
  344. return E_POINTER;
  345. }
  346. try {
  347. *ppFont = NULL;
  348. hr = m_pObj->m_pCtrl->m_OleFont.GetFontDisp(ppFont);
  349. } catch (...) {
  350. hr = E_POINTER;
  351. }
  352. return hr;
  353. }
  354. STDMETHODIMP
  355. CImpISystemMonitor::put_ShowVerticalGrid (
  356. IN VARIANT_BOOL bVisible
  357. )
  358. /*++
  359. Routine Description:
  360. Shows/hides the vertical grid.
  361. Arguments:
  362. bVisible - Visibility (TRUE = show, FALSE = hide)
  363. Return Value:
  364. HRESULT
  365. --*/
  366. {
  367. m_pObj->m_Graph.Options.bVertGridChecked = bVisible;
  368. m_pObj->m_pCtrl->UpdateGraph(UPDGRPH_PLOT);
  369. return NOERROR;
  370. }
  371. STDMETHODIMP
  372. CImpISystemMonitor::get_ShowVerticalGrid (
  373. OUT VARIANT_BOOL *pbState
  374. )
  375. /*++
  376. Routine Description:
  377. Gets the vertical grid visibility state.
  378. Arguments:
  379. pbState - pointer to returned state (TRUE = visible, FALSE = hidden)
  380. Return Value:
  381. HRESULT
  382. --*/
  383. {
  384. HRESULT hr = S_OK;
  385. if (pbState == NULL) {
  386. return E_POINTER;
  387. }
  388. try {
  389. *pbState = (short)m_pObj->m_Graph.Options.bVertGridChecked;
  390. } catch (...) {
  391. hr = E_POINTER;
  392. }
  393. return hr;
  394. }
  395. STDMETHODIMP
  396. CImpISystemMonitor::put_ShowHorizontalGrid(
  397. IN VARIANT_BOOL bVisible
  398. )
  399. /*++
  400. Routine Description:
  401. Shows/hides the horizontal grid.
  402. Arguments:
  403. bVisible - Visibility (TRUE = show, FALSE = hide)
  404. Return Value:
  405. HRESULT
  406. --*/
  407. {
  408. m_pObj->m_Graph.Options.bHorzGridChecked = bVisible;
  409. m_pObj->m_pCtrl->UpdateGraph(UPDGRPH_PLOT);
  410. return NOERROR;
  411. }
  412. STDMETHODIMP
  413. CImpISystemMonitor::get_ShowHorizontalGrid (
  414. OUT VARIANT_BOOL *pbState
  415. )
  416. /*++
  417. Routine Description:
  418. Gets the horizontal grid visibility state.
  419. Arguments:
  420. pbState - pointer to returned state (TRUE = visible, FALSE = hidden)
  421. Return Value:
  422. HRESULT
  423. --*/
  424. {
  425. HRESULT hr = S_OK;
  426. if (pbState == NULL) {
  427. return E_POINTER;
  428. }
  429. try {
  430. *pbState = (short)m_pObj->m_Graph.Options.bHorzGridChecked;
  431. } catch (...) {
  432. hr = E_POINTER;
  433. }
  434. return hr;
  435. }
  436. STDMETHODIMP
  437. CImpISystemMonitor::put_Highlight(
  438. IN VARIANT_BOOL bState
  439. )
  440. /*++
  441. Routine Description:
  442. Sets the highlight state. If true, the selected counter is
  443. always highlighted in the graph.
  444. Arguments:
  445. bState - Highlight (TRUE = highlight, FALSE = no highlight)
  446. Return Value:
  447. HRESULT
  448. --*/
  449. {
  450. m_pObj->m_pCtrl->put_Highlight(bState);
  451. return NOERROR;
  452. }
  453. STDMETHODIMP
  454. CImpISystemMonitor::get_Highlight (
  455. OUT VARIANT_BOOL *pbState
  456. )
  457. /*++
  458. Routine Description:
  459. Gets the highlight state.
  460. Arguments:
  461. pbState - pointer to returned state (TRUE = highlight, FALSE = no highlight)
  462. Return Value:
  463. HRESULT
  464. --*/
  465. {
  466. HRESULT hr = S_OK;
  467. if (pbState == NULL) {
  468. return E_POINTER;
  469. }
  470. try {
  471. *pbState = (short)m_pObj->m_Graph.Options.bHighlight;
  472. } catch (...) {
  473. hr = E_POINTER;
  474. }
  475. return hr;
  476. }
  477. STDMETHODIMP
  478. CImpISystemMonitor::put_ShowLegend (
  479. IN VARIANT_BOOL bState
  480. )
  481. /*++
  482. Routine Description:
  483. Shows/hides the graph legend.
  484. Arguments:
  485. bVisible - Visibility (TRUE = show, FALSE = hide)
  486. Return Value:
  487. HRESULT
  488. --*/
  489. {
  490. m_pObj->m_Graph.Options.bLegendChecked = bState;
  491. m_pObj->m_pCtrl->UpdateGraph(UPDGRPH_LAYOUT);
  492. return NOERROR;
  493. }
  494. STDMETHODIMP
  495. CImpISystemMonitor::get_ShowLegend (
  496. OUT VARIANT_BOOL *pbState
  497. )
  498. /*++
  499. Routine Description:
  500. Gets the legend visibility state.
  501. Arguments:
  502. pbState - pointer to returned state (TRUE = visible, FALSE = hidden)
  503. Return Value:
  504. HRESULT
  505. --*/
  506. {
  507. HRESULT hr = S_OK;
  508. if (pbState == NULL) {
  509. return E_POINTER;
  510. }
  511. try {
  512. *pbState = (short)m_pObj->m_Graph.Options.bLegendChecked;
  513. } catch (...) {
  514. hr = E_POINTER;
  515. }
  516. return hr;
  517. }
  518. STDMETHODIMP
  519. CImpISystemMonitor::put_ShowToolbar (
  520. IN VARIANT_BOOL bState
  521. )
  522. /*++
  523. Routine Description:
  524. Shows/hides the graph toolbar
  525. Arguments:
  526. bState = Visibility (TRUE = show, FALSE = hide)
  527. Return Value:
  528. HRESULT
  529. --*/
  530. {
  531. m_pObj->m_Graph.Options.bToolbarChecked = bState;
  532. m_pObj->m_pCtrl->UpdateGraph(UPDGRPH_LAYOUT);
  533. return NOERROR;
  534. }
  535. STDMETHODIMP
  536. CImpISystemMonitor::get_ShowToolbar (
  537. OUT VARIANT_BOOL *pbState
  538. )
  539. /*++
  540. Routine Description:
  541. Gets the legend visibility state.
  542. Arguments:
  543. pbState - pointer to returned state (TRUE = visible, FALSE = hidden)
  544. Return Value:
  545. HRESULT
  546. --*/
  547. {
  548. HRESULT hr = S_OK;
  549. if (pbState == NULL) {
  550. return E_POINTER;
  551. }
  552. try {
  553. *pbState = (short)m_pObj->m_Graph.Options.bToolbarChecked;
  554. } catch (...) {
  555. hr = E_POINTER;
  556. }
  557. return hr;
  558. }
  559. STDMETHODIMP
  560. CImpISystemMonitor::put_ShowScaleLabels (
  561. IN VARIANT_BOOL bState
  562. )
  563. /*++
  564. Routine Description:
  565. Shows/hides the vertical scale numbers.
  566. Arguments:
  567. bVisible - Visibility (TRUE = show, FALSE = hide)
  568. Return Value:
  569. HRESULT
  570. --*/
  571. {
  572. m_pObj->m_Graph.Options.bLabelsChecked = bState;
  573. m_pObj->m_pCtrl->UpdateGraph(UPDGRPH_LAYOUT);
  574. return NOERROR;
  575. }
  576. STDMETHODIMP
  577. CImpISystemMonitor::get_ShowScaleLabels (
  578. OUT VARIANT_BOOL *pbState
  579. )
  580. /*++
  581. Routine Description:
  582. Gets the visibility state of the vertical scale numbers.
  583. Arguments:
  584. pbState - pointer to returned state (TRUE = visible, FALSE = hidden)
  585. Return Value:
  586. HRESULT
  587. --*/
  588. {
  589. HRESULT hr = S_OK;
  590. if (pbState == NULL) {
  591. return E_POINTER;
  592. }
  593. try {
  594. *pbState = (short)m_pObj->m_Graph.Options.bLabelsChecked;
  595. } catch (...) {
  596. hr = E_POINTER;
  597. }
  598. return hr;
  599. }
  600. STDMETHODIMP
  601. CImpISystemMonitor::put_ShowValueBar (
  602. IN VARIANT_BOOL bState
  603. )
  604. /*++
  605. Routine Description:
  606. Shows/hides the graph statistics bar.
  607. Arguments:
  608. bVisible - Visibility (TRUE = show, FALSE = hide)
  609. Return Value:
  610. HRESULT
  611. --*/
  612. {
  613. m_pObj->m_Graph.Options.bValueBarChecked = bState;
  614. m_pObj->m_pCtrl->UpdateGraph(UPDGRPH_LAYOUT);
  615. return NOERROR;
  616. }
  617. STDMETHODIMP
  618. CImpISystemMonitor::get_ShowValueBar(
  619. OUT VARIANT_BOOL *pbState
  620. )
  621. /*++
  622. Routine Description:
  623. Gets the statistics bar visibility state.
  624. Arguments:
  625. pbState - pointer to returned state (TRUE = visible, FALSE = hidden)
  626. Return Value:
  627. HRESULT
  628. --*/
  629. {
  630. HRESULT hr = S_OK;
  631. if (pbState == NULL) {
  632. return E_POINTER;
  633. }
  634. try {
  635. *pbState = (short)m_pObj->m_Graph.Options.bValueBarChecked;
  636. } catch (...) {
  637. hr = E_POINTER;
  638. }
  639. return hr;
  640. }
  641. STDMETHODIMP
  642. CImpISystemMonitor::put_MaximumScale (
  643. IN INT iValue
  644. )
  645. /*++
  646. Routine Description:
  647. Sets the vertical scale maximum value.
  648. Arguments:
  649. iValue - Maximum value
  650. Return Value:
  651. HRESULT
  652. --*/
  653. {
  654. if ( ( iValue <= MAX_VERTICAL_SCALE ) && (iValue > m_pObj->m_Graph.Options.iVertMin ) ) {
  655. m_pObj->m_Graph.Options.iVertMax = iValue;
  656. m_pObj->m_Graph.Scale.SetMaxValue(iValue);
  657. m_pObj->m_pCtrl->UpdateGraph(UPDGRPH_LAYOUT);
  658. return NOERROR;
  659. } else {
  660. return E_INVALIDARG;
  661. }
  662. }
  663. STDMETHODIMP
  664. CImpISystemMonitor::get_MaximumScale (
  665. OUT INT *piValue
  666. )
  667. /*++
  668. Routine Description:
  669. Gets the vertical scale's maximum value.
  670. Arguments:
  671. piValue = pointer to returned value
  672. Return Value:
  673. HRESULT
  674. --*/
  675. {
  676. HRESULT hr = S_OK;
  677. if (piValue == NULL) {
  678. return E_POINTER;
  679. }
  680. try {
  681. *piValue = m_pObj->m_Graph.Options.iVertMax;
  682. } catch (...) {
  683. hr = E_POINTER;
  684. }
  685. return hr;
  686. }
  687. STDMETHODIMP
  688. CImpISystemMonitor::put_MinimumScale (
  689. IN INT iValue
  690. )
  691. /*++
  692. Routine Description:
  693. Sets the vertical scale minimum value.
  694. Arguments:
  695. iValue - Minimum value
  696. Return Value:
  697. None.
  698. --*/
  699. {
  700. if ( ( iValue >= MIN_VERTICAL_SCALE ) && (iValue < m_pObj->m_Graph.Options.iVertMax ) ) {
  701. m_pObj->m_Graph.Options.iVertMin = iValue;
  702. m_pObj->m_Graph.Scale.SetMinValue(iValue);
  703. m_pObj->m_pCtrl->UpdateGraph(UPDGRPH_LAYOUT);
  704. return NOERROR;
  705. } else {
  706. return E_INVALIDARG;
  707. }
  708. }
  709. STDMETHODIMP
  710. CImpISystemMonitor::get_MinimumScale (
  711. OUT INT *piValue
  712. )
  713. /*++
  714. Routine Description:
  715. Gets the vertical scale's minimum value.
  716. Arguments:
  717. piValue = pointer to returned value
  718. Return Value:
  719. HRESULT
  720. --*/
  721. {
  722. HRESULT hr = S_OK;
  723. if (piValue == NULL) {
  724. return E_POINTER;
  725. }
  726. try {
  727. *piValue = m_pObj->m_Graph.Options.iVertMin;
  728. } catch (...) {
  729. hr = E_POINTER;
  730. }
  731. return hr;
  732. }
  733. STDMETHODIMP
  734. CImpISystemMonitor::put_UpdateInterval (
  735. IN FLOAT fValue
  736. )
  737. /*++
  738. Routine Description:
  739. Sets the graph sample interval.
  740. Arguments:
  741. fValue - Update interval in seconds (can be fraction)
  742. Return Value:
  743. HRESULT
  744. --*/
  745. {
  746. if ( ( fValue >= MIN_UPDATE_INTERVAL ) && (fValue <= MAX_UPDATE_INTERVAL ) ) {
  747. m_pObj->m_Graph.Options.fUpdateInterval = fValue;
  748. m_pObj->m_pCtrl->SetIntervalTimer();
  749. return NOERROR;
  750. } else {
  751. return E_INVALIDARG;
  752. }
  753. }
  754. STDMETHODIMP
  755. CImpISystemMonitor::get_UpdateInterval (
  756. OUT FLOAT *pfValue
  757. )
  758. /*++
  759. Routine Description:
  760. Gets the graph's sample interval measured in seconds.
  761. Arguments:
  762. pfValue = pointer to returned value
  763. Return Value:
  764. HRESULT
  765. --*/
  766. {
  767. HRESULT hr = S_OK;
  768. if (pfValue == NULL) {
  769. return E_POINTER;
  770. }
  771. try {
  772. *pfValue = m_pObj->m_Graph.Options.fUpdateInterval;
  773. } catch (...) {
  774. hr = E_POINTER;
  775. }
  776. return hr;
  777. }
  778. STDMETHODIMP
  779. CImpISystemMonitor::put_DisplayFilter (
  780. IN INT iValue
  781. )
  782. /*++
  783. Routine Description:
  784. Sets the graph display filter - samples per display interval.
  785. Arguments:
  786. iValue - Update interval in samples
  787. Return Value:
  788. HRESULT
  789. --*/
  790. {
  791. // TodoDisplayFilter: Support for display filter > sample filter.
  792. if ( iValue != 1 ) {
  793. return E_INVALIDARG;
  794. }
  795. else {
  796. m_pObj->m_Graph.Options.iDisplayFilter = iValue;
  797. // m_pObj->m_pCtrl->SetIntervalTimer();
  798. return NOERROR;
  799. }
  800. }
  801. STDMETHODIMP
  802. CImpISystemMonitor::get_DisplayFilter (
  803. OUT INT *piValue
  804. )
  805. /*++
  806. Routine Description:
  807. Gets the graph's display interval measured in samples.
  808. Arguments:
  809. piValue = pointer to returned value
  810. Return Value:
  811. HRESULT
  812. --*/
  813. {
  814. HRESULT hr = S_OK;
  815. if (piValue == NULL) {
  816. return E_POINTER;
  817. }
  818. try {
  819. *piValue = m_pObj->m_Graph.Options.iDisplayFilter;
  820. } catch (...) {
  821. hr = E_POINTER;
  822. }
  823. return hr;
  824. }
  825. STDMETHODIMP
  826. CImpISystemMonitor::put_DisplayType (
  827. IN eDisplayTypeConstant eDisplayType
  828. )
  829. /*++
  830. Routine Description:
  831. Selects display type (1 = line plot, 2 = histogram, 3 = Report)
  832. Arguments:
  833. eDisplayType - Display type
  834. Return Value:
  835. HRESULT
  836. --*/
  837. {
  838. INT iUpdate;
  839. if (eDisplayType < LINE_GRAPH || eDisplayType > REPORT_GRAPH) {
  840. return E_INVALIDARG;
  841. }
  842. if (m_pObj->m_Graph.Options.iDisplayType == REPORT_GRAPH || eDisplayType == REPORT_GRAPH) {
  843. iUpdate = UPDGRPH_VIEW;
  844. }
  845. else {
  846. iUpdate = UPDGRPH_PLOT;
  847. }
  848. m_pObj->m_Graph.Options.iDisplayType = eDisplayType;
  849. m_pObj->m_pCtrl->UpdateGraph(iUpdate);
  850. return NOERROR;
  851. }
  852. STDMETHODIMP
  853. CImpISystemMonitor::get_DisplayType (
  854. OUT eDisplayTypeConstant *peDisplayType
  855. )
  856. /*++
  857. Routine Description:
  858. Get graph display type (1 = line plot, 2 = histogram, 3 = Report)
  859. Arguments:
  860. peDisplayType = pointer to returned value
  861. Return Value:
  862. HRESULT
  863. --*/
  864. {
  865. HRESULT hr = S_OK;
  866. if (peDisplayType == NULL) {
  867. return E_POINTER;
  868. }
  869. try {
  870. *peDisplayType = (eDisplayTypeConstant)m_pObj->m_Graph.Options.iDisplayType;
  871. } catch (...) {
  872. hr = E_POINTER;
  873. }
  874. return hr;
  875. }
  876. STDMETHODIMP
  877. CImpISystemMonitor::put_ManualUpdate (
  878. IN VARIANT_BOOL bMode
  879. )
  880. /*++
  881. Routine Description:
  882. Sets/clears manual update mode. Manual mode suspends periodic updates
  883. of the graph.
  884. Arguments:
  885. bMode - Manual mode (TRUE = On, FALSE = Off)
  886. Return Value:
  887. HRESULT
  888. --*/
  889. {
  890. m_pObj->m_pCtrl->put_ManualUpdate ( bMode );
  891. return NOERROR;
  892. }
  893. STDMETHODIMP
  894. CImpISystemMonitor::get_ManualUpdate (
  895. OUT VARIANT_BOOL *pbState
  896. )
  897. /*++
  898. Routine Description:
  899. Gets manual update mode.
  900. Arguments:
  901. pbState = pointer to returned state (TRUE = On, FALSE = Off)
  902. Return Value:
  903. HRESULT
  904. --*/
  905. {
  906. HRESULT hr = S_OK;
  907. if (pbState == NULL) {
  908. return E_POINTER;
  909. }
  910. try {
  911. *pbState = (short)m_pObj->m_Graph.Options.bManualUpdate;
  912. } catch (...) {
  913. hr = E_POINTER;
  914. }
  915. return hr;
  916. }
  917. STDMETHODIMP
  918. CImpISystemMonitor::put_GraphTitle (
  919. IN BSTR bstrTitle
  920. )
  921. /*++
  922. Routine Description:
  923. Sets the graph title.
  924. Arguments:
  925. bstrTitle - Title string
  926. Return Value:
  927. HRESULT
  928. --*/
  929. {
  930. LPWSTR pszTitle = NULL;
  931. HRESULT hr = S_OK;
  932. BOOL bClearTitle = FALSE;
  933. if (bstrTitle == NULL) {
  934. bClearTitle = TRUE;
  935. }
  936. else {
  937. try {
  938. if (bstrTitle[0] == L'\0') {
  939. bClearTitle = TRUE;
  940. }
  941. else {
  942. pszTitle = new WCHAR [MAX_TITLE_CHARS + 1];
  943. if (pszTitle) {
  944. hr = StringCchCopy(pszTitle, MAX_TITLE_CHARS + 1, bstrTitle);
  945. if (hr == STRSAFE_E_INSUFFICIENT_BUFFER) {
  946. hr = S_FALSE;
  947. }
  948. if (m_pObj->m_Graph.Options.pszGraphTitle) {
  949. delete [] m_pObj->m_Graph.Options.pszGraphTitle;
  950. }
  951. m_pObj->m_Graph.Options.pszGraphTitle = pszTitle;
  952. }
  953. else {
  954. hr = E_OUTOFMEMORY;
  955. }
  956. }
  957. } catch (...) {
  958. hr = E_INVALIDARG;
  959. }
  960. }
  961. if (SUCCEEDED(hr)) {
  962. if (bClearTitle && m_pObj->m_Graph.Options.pszGraphTitle) {
  963. delete [] m_pObj->m_Graph.Options.pszGraphTitle;
  964. m_pObj->m_Graph.Options.pszGraphTitle = NULL;
  965. }
  966. m_pObj->m_pCtrl->UpdateGraph(UPDGRPH_LAYOUT);
  967. }
  968. else {
  969. if (pszTitle) {
  970. delete [] pszTitle;
  971. }
  972. }
  973. return hr;
  974. }
  975. STDMETHODIMP
  976. CImpISystemMonitor::get_GraphTitle (
  977. BSTR *pbsTitle
  978. )
  979. /*++
  980. Routine Description:
  981. Gets the graph title string. The caller is responsible for releasing the
  982. string memory.
  983. Arguments:
  984. pbsTitle - pointer to returned title (BSTR)
  985. Return Value:
  986. HResult
  987. --*/
  988. {
  989. HRESULT hr = S_OK;
  990. BSTR pTmpTitle = NULL;
  991. if (pbsTitle == NULL) {
  992. return E_POINTER;
  993. }
  994. if (m_pObj->m_Graph.Options.pszGraphTitle != NULL) {
  995. pTmpTitle = SysAllocString(m_pObj->m_Graph.Options.pszGraphTitle);
  996. if (pTmpTitle == NULL) {
  997. hr = E_OUTOFMEMORY;
  998. }
  999. }
  1000. try {
  1001. *pbsTitle = pTmpTitle;
  1002. } catch (...) {
  1003. hr = E_POINTER;
  1004. }
  1005. if (FAILED(hr) && pTmpTitle) {
  1006. SysFreeString(pTmpTitle);
  1007. }
  1008. return hr;
  1009. }
  1010. STDMETHODIMP
  1011. CImpISystemMonitor::put_LogFileName (
  1012. IN BSTR bstrLogFile
  1013. )
  1014. /*++
  1015. Routine Description:
  1016. Sets the log file name
  1017. Arguments:
  1018. bstrLogFile - File name string
  1019. Return Value:
  1020. HRESULT
  1021. --*/
  1022. {
  1023. HRESULT hr = S_OK;
  1024. LPWSTR pszLogFile = NULL;
  1025. LONG lCount;
  1026. //
  1027. // Ensure that the current log file count is 0 or 1
  1028. //
  1029. lCount = m_pObj->m_pCtrl->NumLogFiles();
  1030. if (lCount != 0 && lCount != 1) {
  1031. return E_FAIL;
  1032. }
  1033. //
  1034. // Get the current data source type
  1035. //
  1036. // Reset the data source type to null data source while completing this operation.
  1037. // TodoLogFiles: Possible to keep the previous put_LogFileName semantics,
  1038. // where new query is opened (successfully) before closing the previous query?
  1039. hr = m_pObj->m_pCtrl->put_DataSourceType ( sysmonNullDataSource );
  1040. if ( SUCCEEDED ( hr ) ) {
  1041. // TodoLogFiles: What if multiple files exist? Probably return error re: not supported.
  1042. if ( 1 == lCount ) {
  1043. hr = m_pObj->m_pCtrl->RemoveSingleLogFile ( m_pObj->m_pCtrl->FirstLogFile() );
  1044. }
  1045. if ( SUCCEEDED ( hr ) ) {
  1046. try {
  1047. if (bstrLogFile != NULL && bstrLogFile[0] != 0) {
  1048. //
  1049. // If non-null name
  1050. // Convert from BSTR to internal string, then add the item.
  1051. //
  1052. pszLogFile = bstrLogFile;
  1053. hr = m_pObj->m_pCtrl->AddSingleLogFile ( pszLogFile );
  1054. if ( SUCCEEDED ( hr ) ) {
  1055. //
  1056. // put_DataSourceType attempts to set the data source type to sysmonCurrentActivity
  1057. // if sysmonLogFiles fails.
  1058. //
  1059. hr = m_pObj->m_pCtrl->put_DataSourceType ( sysmonLogFiles );
  1060. }
  1061. }
  1062. } catch (...) {
  1063. hr = E_INVALIDARG;
  1064. }
  1065. }
  1066. }
  1067. return hr;
  1068. }
  1069. STDMETHODIMP
  1070. CImpISystemMonitor::get_LogFileName (
  1071. BSTR *pbsLogFile
  1072. )
  1073. /*++
  1074. Routine Description:
  1075. Gets the log file name. The caller is responsible for releasing the
  1076. string memory.
  1077. This is an obsolete method supported only for backward compatibility.
  1078. It cannot be used when multiple log files are loaded.
  1079. Arguments:
  1080. pbsLogFile - pointer to returned name (BSTR)
  1081. Return Value:
  1082. HResult
  1083. N.B. The code is duplicated with BuildFileList
  1084. --*/
  1085. {
  1086. HRESULT hr = NOERROR;
  1087. LPCWSTR pszFileName = NULL;
  1088. LPWSTR pszLogFile = NULL;
  1089. ULONG ulCchLogFileName = 0;
  1090. CLogFileItem * pLogFile;
  1091. LPWSTR pszLogFileCurrent;
  1092. if (pbsLogFile == NULL) {
  1093. return E_POINTER;
  1094. }
  1095. try {
  1096. *pbsLogFile = NULL;
  1097. } catch (...) {
  1098. return E_POINTER;
  1099. }
  1100. //
  1101. // First calculate how big the buffer should be
  1102. //
  1103. pLogFile = m_pObj->m_pCtrl->FirstLogFile();
  1104. while (pLogFile) {
  1105. pszFileName = pLogFile->GetPath();
  1106. ulCchLogFileName += (lstrlen(pszFileName) + 1);
  1107. pLogFile = pLogFile->Next();
  1108. }
  1109. ulCchLogFileName ++; // for the final NULL character
  1110. //
  1111. // Allocate the buffer
  1112. //
  1113. pszLogFile = new WCHAR [ ulCchLogFileName ];
  1114. if (pszLogFile) {
  1115. pLogFile = m_pObj->m_pCtrl->FirstLogFile();
  1116. pszLogFileCurrent = pszLogFile;
  1117. while (pLogFile) {
  1118. pszFileName = pLogFile->GetPath();
  1119. //
  1120. // We are sure we have enough space to hold the path
  1121. //
  1122. StringCchCopy(pszLogFileCurrent, lstrlen(pszFileName) + 1, pszFileName);
  1123. pszLogFileCurrent += lstrlen(pszFileName);
  1124. * pszLogFileCurrent = L'\0';
  1125. pszLogFileCurrent ++;
  1126. pLogFile = pLogFile->Next();
  1127. }
  1128. * pszLogFileCurrent = L'\0';
  1129. try {
  1130. * pbsLogFile = SysAllocStringLen(pszLogFile, ulCchLogFileName);
  1131. if (NULL == * pbsLogFile) {
  1132. hr = E_OUTOFMEMORY;
  1133. }
  1134. } catch (...) {
  1135. hr = E_POINTER;
  1136. }
  1137. delete [] pszLogFile;
  1138. }
  1139. else {
  1140. hr = E_OUTOFMEMORY;
  1141. }
  1142. return hr;
  1143. }
  1144. STDMETHODIMP
  1145. CImpISystemMonitor::put_DataSourceType (
  1146. IN eDataSourceTypeConstant eDataSourceType
  1147. )
  1148. /*++
  1149. Routine Description:
  1150. Selects data source type (1 = current activity, 2 = log files)
  1151. Arguments:
  1152. eDataSourceType - Data source type
  1153. Return Value:
  1154. HRESULT
  1155. --*/
  1156. {
  1157. if ( eDataSourceType != sysmonCurrentActivity
  1158. && eDataSourceType != sysmonLogFiles
  1159. && sysmonNullDataSource != eDataSourceType
  1160. && eDataSourceType != sysmonSqlLog) {
  1161. return E_INVALIDARG;
  1162. }
  1163. return m_pObj->m_pCtrl->put_DataSourceType( eDataSourceType );
  1164. }
  1165. STDMETHODIMP
  1166. CImpISystemMonitor::get_DataSourceType (
  1167. OUT eDataSourceTypeConstant *peDataSourceType
  1168. )
  1169. /*++
  1170. Routine Description:
  1171. Get data source type (1 = current activity, 2 = log files)
  1172. Arguments:
  1173. peDataSourceType = pointer to returned value
  1174. Return Value:
  1175. HRESULT
  1176. --*/
  1177. {
  1178. HRESULT hr = S_OK;
  1179. if (peDataSourceType == NULL) {
  1180. return E_POINTER;
  1181. }
  1182. try {
  1183. *peDataSourceType = sysmonCurrentActivity;
  1184. hr = m_pObj->m_pCtrl->get_DataSourceType ( *peDataSourceType );
  1185. } catch (...) {
  1186. hr = E_POINTER;
  1187. }
  1188. return hr;
  1189. }
  1190. STDMETHODIMP
  1191. CImpISystemMonitor::get_LogFiles (
  1192. ILogFiles **ppILogFiles
  1193. )
  1194. {
  1195. HRESULT hr = S_OK;
  1196. if (ppILogFiles == NULL) {
  1197. return E_POINTER;
  1198. }
  1199. try {
  1200. *ppILogFiles = m_pObj->m_pImpILogFiles;
  1201. if ( NULL != *ppILogFiles ) {
  1202. (*ppILogFiles)->AddRef();
  1203. }
  1204. } catch (...) {
  1205. hr = E_POINTER;
  1206. }
  1207. return hr;
  1208. }
  1209. STDMETHODIMP
  1210. CImpISystemMonitor::put_LogViewStart (
  1211. IN DATE dateStart
  1212. )
  1213. {
  1214. LONGLONG llTestStart;
  1215. if ( VariantDateToLLTime(dateStart, &llTestStart ) ) {
  1216. // No error. If start time is past current stop time, reset it to the current stop time.
  1217. if ( llTestStart <= m_pObj->m_pCtrl->m_DataSourceInfo.llStopDisp ){
  1218. if ( llTestStart >= m_pObj->m_pCtrl->m_DataSourceInfo.llBeginTime ) {
  1219. m_pObj->m_pCtrl->m_DataSourceInfo.llStartDisp = llTestStart;
  1220. } else {
  1221. m_pObj->m_pCtrl->m_DataSourceInfo.llStartDisp = m_pObj->m_pCtrl->m_DataSourceInfo.llBeginTime;
  1222. }
  1223. } else {
  1224. m_pObj->m_pCtrl->m_DataSourceInfo.llStartDisp = m_pObj->m_pCtrl->m_DataSourceInfo.llStopDisp;
  1225. }
  1226. m_pObj->m_pCtrl->UpdateGraph(UPDGRPH_LOGVIEW);
  1227. return NOERROR;
  1228. } else {
  1229. return E_FAIL;
  1230. }
  1231. }
  1232. STDMETHODIMP
  1233. CImpISystemMonitor::get_LogViewStart (
  1234. OUT DATE *pdateStart
  1235. )
  1236. {
  1237. HRESULT hr = S_OK;
  1238. if (pdateStart == NULL) {
  1239. return E_POINTER;
  1240. }
  1241. try {
  1242. if ( ! LLTimeToVariantDate(m_pObj->m_pCtrl->m_DataSourceInfo.llStartDisp, pdateStart)) {
  1243. hr = E_FAIL;
  1244. }
  1245. } catch (...) {
  1246. hr = E_POINTER;
  1247. }
  1248. return hr;
  1249. }
  1250. STDMETHODIMP
  1251. CImpISystemMonitor::put_LogViewStop (
  1252. IN DATE dateStop
  1253. )
  1254. {
  1255. LONGLONG llTestStop;
  1256. if ( VariantDateToLLTime(dateStop, &llTestStop ) ) {
  1257. // No error. If requested stop time is earlier than current start time, set it to
  1258. // the current start time.
  1259. if ( llTestStop >= m_pObj->m_pCtrl->m_DataSourceInfo.llStartDisp ) {
  1260. if ( llTestStop <= m_pObj->m_pCtrl->m_DataSourceInfo.llEndTime ) {
  1261. m_pObj->m_pCtrl->m_DataSourceInfo.llStopDisp = llTestStop;
  1262. } else {
  1263. m_pObj->m_pCtrl->m_DataSourceInfo.llStopDisp = m_pObj->m_pCtrl->m_DataSourceInfo.llEndTime;
  1264. }
  1265. } else {
  1266. m_pObj->m_pCtrl->m_DataSourceInfo.llStopDisp = m_pObj->m_pCtrl->m_DataSourceInfo.llStartDisp;
  1267. }
  1268. m_pObj->m_pCtrl->UpdateGraph(UPDGRPH_LOGVIEW);
  1269. return NOERROR;
  1270. } else {
  1271. return E_FAIL;
  1272. }
  1273. }
  1274. STDMETHODIMP
  1275. CImpISystemMonitor::get_LogViewStop (
  1276. OUT DATE *pdateStop )
  1277. {
  1278. HRESULT hr = S_OK;
  1279. if (pdateStop == NULL) {
  1280. return E_POINTER;
  1281. }
  1282. try {
  1283. if (!LLTimeToVariantDate(m_pObj->m_pCtrl->m_DataSourceInfo.llStopDisp, pdateStop)) {
  1284. hr = E_FAIL;
  1285. }
  1286. } catch (...) {
  1287. hr = E_POINTER;
  1288. }
  1289. return hr;
  1290. }
  1291. STDMETHODIMP
  1292. CImpISystemMonitor::put_YAxisLabel (
  1293. IN BSTR bstrLabel
  1294. )
  1295. /*++
  1296. Routine Description:
  1297. Sets the Y axis label string.
  1298. Arguments:
  1299. bstrLabel - Label string
  1300. Return Value:
  1301. HRESULT
  1302. --*/
  1303. {
  1304. LPWSTR pszTitle = NULL;
  1305. HRESULT hr = S_OK;
  1306. BOOL bClearTitle = FALSE;
  1307. if (bstrLabel == NULL) {
  1308. bClearTitle = TRUE;
  1309. }
  1310. else {
  1311. try {
  1312. if (bstrLabel[0] == 0) {
  1313. bClearTitle = TRUE;
  1314. }
  1315. else {
  1316. pszTitle = new WCHAR [MAX_TITLE_CHARS + 1];
  1317. if (pszTitle) {
  1318. hr = StringCchCopy(pszTitle, MAX_TITLE_CHARS + 1, bstrLabel);
  1319. if (hr == STRSAFE_E_INSUFFICIENT_BUFFER) {
  1320. hr = S_FALSE;
  1321. }
  1322. if (m_pObj->m_Graph.Options.pszYaxisTitle) {
  1323. delete [] m_pObj->m_Graph.Options.pszYaxisTitle;
  1324. }
  1325. m_pObj->m_Graph.Options.pszYaxisTitle = pszTitle;
  1326. }
  1327. else {
  1328. hr = E_OUTOFMEMORY;
  1329. }
  1330. }
  1331. } catch (...) {
  1332. hr = E_INVALIDARG;
  1333. }
  1334. }
  1335. if (SUCCEEDED(hr)) {
  1336. if (bClearTitle && m_pObj->m_Graph.Options.pszYaxisTitle) {
  1337. delete [] m_pObj->m_Graph.Options.pszYaxisTitle;
  1338. m_pObj->m_Graph.Options.pszYaxisTitle = NULL;
  1339. }
  1340. m_pObj->m_pCtrl->UpdateGraph(UPDGRPH_LAYOUT);
  1341. }
  1342. else {
  1343. if (pszTitle) {
  1344. delete [] pszTitle;
  1345. }
  1346. }
  1347. return hr;
  1348. }
  1349. STDMETHODIMP
  1350. CImpISystemMonitor::get_YAxisLabel (
  1351. BSTR *pbsTitle
  1352. )
  1353. /*++
  1354. Routine Description:
  1355. Gets the Y axis title string. The caller is responsible for releasing the
  1356. string memory.
  1357. Arguments:
  1358. pbsTitle - pointer to returned title (BSTR)
  1359. Return Value:
  1360. HRESULT
  1361. --*/
  1362. {
  1363. HRESULT hr = S_OK;
  1364. BSTR pTmpTitle = NULL;
  1365. if (pbsTitle == NULL) {
  1366. return E_POINTER;
  1367. }
  1368. if (m_pObj->m_Graph.Options.pszYaxisTitle != NULL) {
  1369. pTmpTitle = SysAllocString(m_pObj->m_Graph.Options.pszYaxisTitle);
  1370. if (pTmpTitle == NULL) {
  1371. hr = E_OUTOFMEMORY;
  1372. }
  1373. }
  1374. try {
  1375. *pbsTitle = pTmpTitle;
  1376. } catch (...) {
  1377. hr = E_POINTER;
  1378. }
  1379. if (FAILED(hr) && pTmpTitle) {
  1380. SysFreeString(pTmpTitle);
  1381. }
  1382. return hr;
  1383. }
  1384. STDMETHODIMP
  1385. CImpISystemMonitor::get_Counters (
  1386. ICounters **ppICounters
  1387. )
  1388. {
  1389. HRESULT hr = S_OK;
  1390. if (ppICounters == NULL) {
  1391. return E_POINTER;
  1392. }
  1393. try {
  1394. *ppICounters = m_pObj->m_pImpICounters;
  1395. (*ppICounters)->AddRef();
  1396. } catch (...) {
  1397. hr = E_POINTER;
  1398. }
  1399. return hr;
  1400. }
  1401. STDMETHODIMP
  1402. CImpISystemMonitor::put_ReadOnly (
  1403. IN VARIANT_BOOL bState
  1404. )
  1405. {
  1406. BOOL bStateLocal = FALSE;
  1407. if ( bState ) {
  1408. bStateLocal = TRUE;
  1409. }
  1410. m_pObj->m_Graph.Options.bReadOnly = bStateLocal;
  1411. m_pObj->m_pCtrl->UpdateGraph(UPDGRPH_VIEW);
  1412. return NOERROR;
  1413. }
  1414. STDMETHODIMP
  1415. CImpISystemMonitor::get_ReadOnly (
  1416. OUT VARIANT_BOOL *pbState
  1417. )
  1418. {
  1419. HRESULT hr = S_OK;
  1420. if (pbState == NULL) {
  1421. return E_POINTER;
  1422. }
  1423. try {
  1424. *pbState = (short)m_pObj->m_Graph.Options.bReadOnly;
  1425. } catch (...) {
  1426. hr = E_POINTER;
  1427. }
  1428. return hr;
  1429. }
  1430. STDMETHODIMP
  1431. CImpISystemMonitor::put_ReportValueType (
  1432. IN eReportValueTypeConstant eReportValueType
  1433. )
  1434. /*++
  1435. Routine Description:
  1436. Selects report value type
  1437. 0 = default value (current for live data, average for log file)
  1438. 1 = current value
  1439. 2 = average over the graph display interval
  1440. 3 = minimum for the graph display interval
  1441. 4 = maximum for the graph display interval
  1442. Arguments:
  1443. eReportValueType - Report valuex
  1444. Return Value:
  1445. HRESULT
  1446. --*/
  1447. {
  1448. if (eReportValueType < sysmonDefaultValue || eReportValueType > sysmonMaximum ) {
  1449. return E_INVALIDARG;
  1450. }
  1451. m_pObj->m_Graph.Options.iReportValueType = eReportValueType;
  1452. //
  1453. // Update the graph for both report and histogram views.
  1454. //
  1455. if (m_pObj->m_Graph.Options.iDisplayType != LINE_GRAPH ) {
  1456. m_pObj->m_pCtrl->UpdateGraph(UPDGRPH_VIEW);
  1457. }
  1458. return NOERROR;
  1459. }
  1460. STDMETHODIMP
  1461. CImpISystemMonitor::get_ReportValueType (
  1462. OUT eReportValueTypeConstant *peReportValueType
  1463. )
  1464. /*++
  1465. Routine Description:
  1466. Get report value type
  1467. 0 = default value (current for live data, average for log file)
  1468. 1 = current value
  1469. 2 = average over the graph display interval
  1470. 3 = minimum for the graph display interval
  1471. 4 = maximum for the graph display interval
  1472. Arguments:
  1473. peReportValueType = pointer to returned value
  1474. Return Value:
  1475. HRESULT
  1476. --*/
  1477. {
  1478. HRESULT hr = S_OK;
  1479. if (peReportValueType == NULL) {
  1480. return E_POINTER;
  1481. }
  1482. try {
  1483. *peReportValueType = (eReportValueTypeConstant)m_pObj->m_Graph.Options.iReportValueType;
  1484. } catch (...) {
  1485. hr = E_POINTER;
  1486. }
  1487. return hr;
  1488. }
  1489. STDMETHODIMP
  1490. CImpISystemMonitor::put_MonitorDuplicateInstances(
  1491. IN VARIANT_BOOL bState
  1492. )
  1493. /*++
  1494. Routine Description:
  1495. Allows/disallows monitoring of duplicate counter instances.
  1496. Arguments:
  1497. bState - TRUE = allow, FALSE = disallow)
  1498. Return Value:
  1499. HRESULT
  1500. --*/
  1501. {
  1502. m_pObj->m_Graph.Options.bMonitorDuplicateInstances = bState;
  1503. return NOERROR;
  1504. }
  1505. STDMETHODIMP
  1506. CImpISystemMonitor::get_MonitorDuplicateInstances (
  1507. OUT VARIANT_BOOL *pbState
  1508. )
  1509. /*++
  1510. Routine Description:
  1511. Gets the state of allowing monitoring of duplicate counter instances.
  1512. Arguments:
  1513. pbState - pointer to returned state ( TRUE = allow, FALSE = disallow )
  1514. Return Value:
  1515. HRESULT
  1516. --*/
  1517. {
  1518. HRESULT hr = S_OK;
  1519. if (pbState == NULL) {
  1520. return E_POINTER;
  1521. }
  1522. try {
  1523. *pbState = (short)m_pObj->m_Graph.Options.bMonitorDuplicateInstances;
  1524. } catch (...) {
  1525. hr = E_POINTER;
  1526. }
  1527. return hr;
  1528. }
  1529. STDMETHODIMP
  1530. CImpISystemMonitor::put_SqlDsnName (
  1531. IN BSTR bstrSqlDsnName
  1532. )
  1533. /*++
  1534. Routine Description:
  1535. Sets the SQL logset DSN name.
  1536. Return Value:
  1537. HRESULT
  1538. --*/
  1539. {
  1540. HRESULT hr = NOERROR;
  1541. LPWSTR szSqlDsnName = NULL;
  1542. BOOL bClearName = FALSE;
  1543. if (bstrSqlDsnName == NULL) {
  1544. bClearName = TRUE;
  1545. }
  1546. else {
  1547. try {
  1548. if (bstrSqlDsnName[0] == 0) {
  1549. bClearName = TRUE;
  1550. }
  1551. else {
  1552. szSqlDsnName = new WCHAR [SQL_MAX_DSN_LENGTH + 1];
  1553. if (szSqlDsnName) {
  1554. hr = StringCchCopy(szSqlDsnName, SQL_MAX_DSN_LENGTH + 1, bstrSqlDsnName);
  1555. if (hr == STRSAFE_E_INSUFFICIENT_BUFFER) {
  1556. hr = S_FALSE;
  1557. }
  1558. if (m_pObj->m_pCtrl->m_DataSourceInfo.szSqlDsnName) {
  1559. delete [] m_pObj->m_pCtrl->m_DataSourceInfo.szSqlDsnName;
  1560. }
  1561. m_pObj->m_pCtrl->m_DataSourceInfo.szSqlDsnName = szSqlDsnName;
  1562. }
  1563. else {
  1564. hr = E_OUTOFMEMORY;
  1565. }
  1566. }
  1567. } catch (...) {
  1568. hr = E_INVALIDARG;
  1569. }
  1570. }
  1571. if (SUCCEEDED(hr)) {
  1572. if (bClearName && m_pObj->m_pCtrl->m_DataSourceInfo.szSqlDsnName) {
  1573. delete [] m_pObj->m_pCtrl->m_DataSourceInfo.szSqlDsnName;
  1574. m_pObj->m_pCtrl->m_DataSourceInfo.szSqlDsnName = NULL;
  1575. }
  1576. }
  1577. else {
  1578. if (szSqlDsnName) {
  1579. delete [] szSqlDsnName;
  1580. }
  1581. }
  1582. return hr;
  1583. }
  1584. STDMETHODIMP
  1585. CImpISystemMonitor::get_SqlDsnName (
  1586. BSTR * bstrSqlDsnName
  1587. )
  1588. /*++
  1589. Routine Description:
  1590. Gets SQL DSN name string. The caller is responsible for releasing the
  1591. string memory.
  1592. Return Value:
  1593. HRESULT
  1594. --*/
  1595. {
  1596. HRESULT hr = S_OK;
  1597. BSTR pTmpName = NULL;
  1598. if (bstrSqlDsnName == NULL) {
  1599. return E_POINTER;
  1600. }
  1601. if (m_pObj->m_pCtrl->m_DataSourceInfo.szSqlDsnName != NULL) {
  1602. pTmpName = SysAllocString(m_pObj->m_pCtrl->m_DataSourceInfo.szSqlDsnName);
  1603. if (pTmpName == NULL) {
  1604. hr = E_OUTOFMEMORY;
  1605. }
  1606. }
  1607. try {
  1608. * bstrSqlDsnName = pTmpName;
  1609. } catch (...) {
  1610. hr = E_POINTER;
  1611. }
  1612. if (FAILED(hr) && pTmpName) {
  1613. SysFreeString(pTmpName);
  1614. }
  1615. return hr;
  1616. }
  1617. STDMETHODIMP
  1618. CImpISystemMonitor::put_SqlLogSetName (
  1619. IN BSTR bstrSqlLogSetName
  1620. )
  1621. /*++
  1622. Routine Description:
  1623. Sets the SQL logset DSN name.
  1624. Return Value:
  1625. HRESULT
  1626. --*/
  1627. {
  1628. HRESULT hr = NOERROR;
  1629. LPWSTR szSqlLogSetName = NULL;
  1630. BOOL bClearName = FALSE;
  1631. if (bstrSqlLogSetName == NULL) {
  1632. bClearName = TRUE;
  1633. }
  1634. else {
  1635. try {
  1636. if (bstrSqlLogSetName[0] == 0) {
  1637. bClearName = TRUE;
  1638. }
  1639. else {
  1640. szSqlLogSetName = new WCHAR [SLQ_MAX_LOG_SET_NAME_LEN + 1];
  1641. if (szSqlLogSetName) {
  1642. hr = StringCchCopy(szSqlLogSetName, SLQ_MAX_LOG_SET_NAME_LEN + 1, bstrSqlLogSetName);
  1643. if (hr == STRSAFE_E_INSUFFICIENT_BUFFER) {
  1644. hr = S_FALSE;
  1645. }
  1646. if (m_pObj->m_pCtrl->m_DataSourceInfo.szSqlLogSetName) {
  1647. delete [] m_pObj->m_pCtrl->m_DataSourceInfo.szSqlLogSetName;
  1648. }
  1649. m_pObj->m_pCtrl->m_DataSourceInfo.szSqlLogSetName = szSqlLogSetName;
  1650. }
  1651. else {
  1652. hr = E_OUTOFMEMORY;
  1653. }
  1654. }
  1655. } catch (...) {
  1656. hr = E_INVALIDARG;
  1657. }
  1658. }
  1659. if (SUCCEEDED(hr)) {
  1660. if (bClearName && m_pObj->m_pCtrl->m_DataSourceInfo.szSqlLogSetName) {
  1661. delete [] m_pObj->m_pCtrl->m_DataSourceInfo.szSqlLogSetName;
  1662. m_pObj->m_pCtrl->m_DataSourceInfo.szSqlLogSetName = NULL;
  1663. }
  1664. }
  1665. else {
  1666. if (szSqlLogSetName) {
  1667. delete [] szSqlLogSetName;
  1668. }
  1669. }
  1670. return hr;
  1671. }
  1672. STDMETHODIMP
  1673. CImpISystemMonitor::get_SqlLogSetName (
  1674. BSTR * bsSqlLogSetName
  1675. )
  1676. /*++
  1677. Routine Description:
  1678. Gets SQL DSN name string. The caller is responsible for releasing the
  1679. string memory.
  1680. Return Value:
  1681. HRESULT
  1682. --*/
  1683. {
  1684. HRESULT hr = S_OK;
  1685. BSTR pTmpName = NULL;
  1686. if (bsSqlLogSetName == NULL) {
  1687. return E_POINTER;
  1688. }
  1689. if (m_pObj->m_pCtrl->m_DataSourceInfo.szSqlLogSetName != NULL) {
  1690. pTmpName = SysAllocString(m_pObj->m_pCtrl->m_DataSourceInfo.szSqlLogSetName);
  1691. if (pTmpName == NULL) {
  1692. hr = E_OUTOFMEMORY;
  1693. }
  1694. }
  1695. try {
  1696. * bsSqlLogSetName = pTmpName;
  1697. } catch (...) {
  1698. hr = E_INVALIDARG;
  1699. }
  1700. if (FAILED(hr) && pTmpName) {
  1701. SysFreeString(pTmpName);
  1702. }
  1703. return hr;
  1704. }
  1705. STDMETHODIMP
  1706. CImpISystemMonitor::Counter (
  1707. IN INT iIndex,
  1708. OUT ICounterItem **ppItem
  1709. )
  1710. /*++
  1711. Routine Description:
  1712. Gets the ICounterItem interface for an indexed counter.
  1713. Index is one-based.
  1714. Arguments:
  1715. iIndex - Index of counter (0-based)
  1716. ppItem - pointer to returned interface pointer
  1717. Return Value:
  1718. HRESULT
  1719. --*/
  1720. {
  1721. HRESULT hr = S_OK;
  1722. CGraphItem *pGItem = NULL;
  1723. INT i;
  1724. //
  1725. // Check for valid index
  1726. //
  1727. if (iIndex < 0 || iIndex >= m_pObj->m_Graph.CounterTree.NumCounters()) {
  1728. return E_INVALIDARG;
  1729. }
  1730. if (ppItem == NULL) {
  1731. return E_POINTER;
  1732. }
  1733. try {
  1734. *ppItem = NULL;
  1735. //
  1736. // Traverse counter linked list to indexed item
  1737. //
  1738. pGItem = m_pObj->m_Graph.CounterTree.FirstCounter();
  1739. i = 0;
  1740. while (i++ < iIndex && pGItem != NULL) {
  1741. pGItem = pGItem->Next();
  1742. }
  1743. if (pGItem == NULL) {
  1744. hr = E_FAIL;
  1745. }
  1746. *ppItem = pGItem;
  1747. pGItem->AddRef();
  1748. } catch (...) {
  1749. hr = E_POINTER;
  1750. }
  1751. return hr;
  1752. }
  1753. STDMETHODIMP
  1754. CImpISystemMonitor::AddCounter (
  1755. IN BSTR bstrPath,
  1756. ICounterItem **ppItem
  1757. )
  1758. /*++
  1759. Routine Description:
  1760. Add counter specified by pathname to the control.
  1761. This method supports wildcard paths.
  1762. Arguments:
  1763. bstrPath - Pathname string
  1764. ppItem - pointer to returned interface pointer
  1765. Return Value:
  1766. HRESULT
  1767. --*/
  1768. {
  1769. HRESULT hr = S_OK;
  1770. if (ppItem == NULL) {
  1771. return E_POINTER;
  1772. }
  1773. try {
  1774. *ppItem = NULL;
  1775. //
  1776. // Delegate to control object
  1777. //
  1778. hr = m_pObj->m_pCtrl->AddCounter(bstrPath, (CGraphItem**)ppItem);
  1779. } catch (...) {
  1780. hr = E_POINTER;
  1781. }
  1782. return hr;
  1783. }
  1784. STDMETHODIMP
  1785. CImpISystemMonitor::DeleteCounter (
  1786. IN ICounterItem *pItem
  1787. )
  1788. /*++
  1789. Routine Description:
  1790. Deletes a counter from the control.
  1791. Arguments:
  1792. pItem - Pointer to counter's ICounterItem interface
  1793. Return Value:
  1794. HRESULT
  1795. --*/
  1796. {
  1797. HRESULT hr = S_OK;
  1798. if (pItem == NULL) {
  1799. return E_POINTER;
  1800. }
  1801. try {
  1802. //
  1803. // Delegate to control object
  1804. //
  1805. hr = m_pObj->m_pCtrl->DeleteCounter((PCGraphItem)pItem, TRUE);
  1806. } catch (...) {
  1807. hr = E_POINTER;
  1808. }
  1809. return hr;
  1810. }
  1811. STDMETHODIMP
  1812. CImpISystemMonitor::UpdateGraph (
  1813. VOID
  1814. )
  1815. /*++
  1816. Routine Description:
  1817. Apply pending visual changes to control. This routine must be called after
  1818. changing a counter's attributes.
  1819. Arguments:
  1820. None.
  1821. Return Value:
  1822. HRESULT
  1823. --*/
  1824. {
  1825. // Delegate to control object
  1826. m_pObj->m_pCtrl->UpdateGraph(0);
  1827. return NOERROR;
  1828. }
  1829. STDMETHODIMP
  1830. CImpISystemMonitor::CollectSample(
  1831. VOID
  1832. )
  1833. /*++
  1834. Routine Description:
  1835. Take a sample of all the counters assigned to the control.
  1836. Arguments:
  1837. None.
  1838. Return Value:
  1839. HRESULT.
  1840. --*/
  1841. {
  1842. // Request control to do a manual counter update
  1843. if (m_pObj->m_pCtrl->UpdateCounterValues(TRUE) == 0) {
  1844. return NOERROR;
  1845. }
  1846. else {
  1847. return E_FAIL;
  1848. }
  1849. }
  1850. STDMETHODIMP
  1851. CImpISystemMonitor::BrowseCounters(
  1852. VOID
  1853. )
  1854. /*++
  1855. Routine Description:
  1856. Display the browse counter dialog to allow counters
  1857. to be added.
  1858. Arguments:
  1859. None.
  1860. Return Value:
  1861. HRESULT.
  1862. --*/
  1863. {
  1864. // Delegate to control
  1865. return m_pObj->m_pCtrl->AddCounters();
  1866. }
  1867. STDMETHODIMP
  1868. CImpISystemMonitor::DisplayProperties(
  1869. VOID
  1870. )
  1871. /*++
  1872. Routine Description:
  1873. Display the graph control property pages
  1874. Arguments:
  1875. None.
  1876. Return Value:
  1877. HRESULT.
  1878. --*/
  1879. {
  1880. // Delegate to control
  1881. return m_pObj->m_pCtrl->DisplayProperties();
  1882. }
  1883. STDMETHODIMP
  1884. CImpISystemMonitor::Paste ()
  1885. /*++
  1886. Routine Description:
  1887. Pastes a list of counter paths from the clipboard to the control
  1888. Arguments:
  1889. NULL
  1890. Return Value:
  1891. HRESULT
  1892. --*/
  1893. {
  1894. // Delegate to control object
  1895. return m_pObj->m_pCtrl->Paste();
  1896. }
  1897. STDMETHODIMP
  1898. CImpISystemMonitor::Copy ()
  1899. /*++
  1900. Routine Description:
  1901. Copies a list of counter paths from the control to the clipboard
  1902. Arguments:
  1903. NULL
  1904. Return Value:
  1905. HRESULT
  1906. --*/
  1907. {
  1908. // Delegate to control object
  1909. return m_pObj->m_pCtrl->Copy();
  1910. }
  1911. STDMETHODIMP
  1912. CImpISystemMonitor::Reset ()
  1913. /*++
  1914. Routine Description:
  1915. deletes the current set of counters
  1916. Arguments:
  1917. NULL
  1918. Return Value:
  1919. HRESULT
  1920. --*/
  1921. {
  1922. // Delegate to control object
  1923. return m_pObj->m_pCtrl->Reset();
  1924. }
  1925. HRESULT
  1926. CImpISystemMonitor::SetLogFileRange (
  1927. LONGLONG llBegin,
  1928. LONGLONG llEnd
  1929. )
  1930. /*++
  1931. Routine Description:
  1932. Set the log file time range. This routine provides the Source
  1933. property page a way to give range to the control, so that the control
  1934. doesn't have to repeat the length PDH call to get it.
  1935. Arguments:
  1936. llBegin Begin time of the log (FILETIME format)
  1937. llEnd End time of log (FILETIME format)
  1938. Return Value:
  1939. HRESULT.
  1940. --*/
  1941. {
  1942. m_pObj->m_pCtrl->m_DataSourceInfo.llBeginTime = llBegin;
  1943. m_pObj->m_pCtrl->m_DataSourceInfo.llEndTime = llEnd;
  1944. return S_OK;
  1945. }
  1946. HRESULT
  1947. CImpISystemMonitor::GetLogFileRange (
  1948. OUT LONGLONG *pllBegin,
  1949. OUT LONGLONG *pllEnd
  1950. )
  1951. /*++
  1952. Routine Description:
  1953. Get the log file time range. This routine provides the Source
  1954. property page a way to get the range from the control, so it doesn't
  1955. have to make the length PDH call to get it.
  1956. Arguments:
  1957. pllBegin ptr to returned begin time of the log (FILETIME format)
  1958. pllEnd ptr to returned end time of log (FILETIME format)
  1959. Return Value:
  1960. HRESULT.
  1961. --*/
  1962. {
  1963. HRESULT hr = S_OK;
  1964. if (pllBegin == NULL || pllEnd == NULL) {
  1965. return E_POINTER;
  1966. }
  1967. try {
  1968. *pllBegin = m_pObj->m_pCtrl->m_DataSourceInfo.llBeginTime;
  1969. *pllEnd = m_pObj->m_pCtrl->m_DataSourceInfo.llEndTime;
  1970. } catch (...) {
  1971. hr = E_POINTER;
  1972. }
  1973. return hr;
  1974. }
  1975. /*
  1976. * The following methods, GetVisuals and SetVisuals, provide a means for the
  1977. * counter property page to save the user's color settings between invocations.
  1978. */
  1979. HRESULT
  1980. CImpISystemMonitor::GetVisuals (
  1981. OUT OLE_COLOR *pColor,
  1982. OUT INT *piColorIndex,
  1983. OUT INT *piWidthIndex,
  1984. OUT INT *piStyleIndex
  1985. )
  1986. {
  1987. HRESULT hr = S_OK;
  1988. if (pColor == NULL || piColorIndex == NULL || piWidthIndex == NULL || piStyleIndex == NULL) {
  1989. return E_POINTER;
  1990. }
  1991. try {
  1992. *pColor = m_pObj->m_pCtrl->m_clrCounter;
  1993. *piColorIndex = m_pObj->m_pCtrl->m_iColorIndex;
  1994. *piWidthIndex = m_pObj->m_pCtrl->m_iWidthIndex;
  1995. *piStyleIndex = m_pObj->m_pCtrl->m_iStyleIndex;
  1996. } catch (...) {
  1997. hr = E_POINTER;
  1998. }
  1999. return hr;
  2000. }
  2001. HRESULT
  2002. CImpISystemMonitor::SetVisuals (
  2003. IN OLE_COLOR Color,
  2004. IN INT iColorIndex,
  2005. IN INT iWidthIndex,
  2006. IN INT iStyleIndex
  2007. )
  2008. {
  2009. OleTranslateColor( Color, NULL, &m_pObj->m_pCtrl->m_clrCounter );
  2010. if (iColorIndex < 0 || iColorIndex > NumColorIndices() ||
  2011. iWidthIndex < 0 || iWidthIndex > NumWidthIndices() ||
  2012. iStyleIndex < 0 || iStyleIndex > NumStyleIndices()) {
  2013. return E_INVALIDARG;
  2014. }
  2015. m_pObj->m_pCtrl->m_iColorIndex = iColorIndex;
  2016. m_pObj->m_pCtrl->m_iWidthIndex = iWidthIndex;
  2017. m_pObj->m_pCtrl->m_iStyleIndex = iStyleIndex;
  2018. return S_OK;
  2019. }
  2020. HRESULT
  2021. CImpISystemMonitor::SetLogViewTempRange (
  2022. LONGLONG llStart,
  2023. LONGLONG llStop
  2024. )
  2025. /*++
  2026. Routine Description:
  2027. Set the log view temporary time range. This routine provides the Source
  2028. property page a way to give range to the control, so that the control
  2029. can draw temporary timeline guides on the line graph.
  2030. Arguments:
  2031. llStart Temporary log view start time (FILETIME format)
  2032. llEnd Temporary log view end time (FILETIME format)
  2033. Return Value:
  2034. HRESULT.
  2035. --*/
  2036. {
  2037. HRESULT hr;
  2038. DATE dateStart;
  2039. DATE dateStop;
  2040. LONGLONG llConvertedStart = MIN_TIME_VALUE;
  2041. LONGLONG llConvertedStop = MAX_TIME_VALUE;
  2042. BOOL bContinue = TRUE;
  2043. // Convert times to and from Variant date to strip off milliseconds.
  2044. // This will make them match the start and stop times processed by put_LogView*
  2045. // Special case MAX_TIME_VALUE, because that is the signal to not draw the stop
  2046. // guide line.
  2047. // Convert start time
  2048. if ( LLTimeToVariantDate ( llStart, &dateStart ) ) {
  2049. bContinue = VariantDateToLLTime (dateStart, &llConvertedStart );
  2050. }
  2051. // Convert stop time if not MAX_TIME_VALUE
  2052. if ( bContinue ) {
  2053. if ( MAX_TIME_VALUE != llStop ) {
  2054. if ( LLTimeToVariantDate ( llStop, &dateStop ) ) {
  2055. bContinue = VariantDateToLLTime ( dateStop, &llConvertedStop );
  2056. }
  2057. } else {
  2058. llConvertedStop = MAX_TIME_VALUE;
  2059. }
  2060. }
  2061. if ( bContinue ) {
  2062. m_pObj->m_pCtrl->SetLogViewTempTimeRange ( llConvertedStart, llConvertedStop );
  2063. hr = NOERROR;
  2064. } else {
  2065. hr = E_FAIL;
  2066. }
  2067. return hr;
  2068. }
  2069. STDMETHODIMP
  2070. CImpISystemMonitor::LogFile (
  2071. IN INT iIndex,
  2072. OUT ILogFileItem **ppItem
  2073. )
  2074. /*++
  2075. Routine Description:
  2076. Gets the ILogFileItem interface for an indexed log file.
  2077. Index is 0-based.
  2078. Arguments:
  2079. iIndex - Index of counter (0-based)
  2080. ppItem - pointer to returned interface pointer
  2081. Return Value:
  2082. HRESULT
  2083. --*/
  2084. {
  2085. HRESULT hr = S_OK;
  2086. CLogFileItem *pItem = NULL;
  2087. INT i;
  2088. //
  2089. // Check for valid index
  2090. //
  2091. if (iIndex < 0 || iIndex >= m_pObj->m_pCtrl->NumLogFiles()) {
  2092. return E_INVALIDARG;
  2093. }
  2094. if (ppItem == NULL) {
  2095. return E_POINTER;
  2096. }
  2097. try {
  2098. *ppItem = NULL;
  2099. // Traverse counter linked list to indexed item
  2100. pItem = m_pObj->m_pCtrl->FirstLogFile();
  2101. i = 0;
  2102. while (i++ < iIndex && pItem != NULL) {
  2103. pItem = pItem->Next();
  2104. }
  2105. if (pItem != NULL) {
  2106. *ppItem = pItem;
  2107. pItem->AddRef();
  2108. } else {
  2109. hr = E_FAIL;
  2110. }
  2111. } catch (...) {
  2112. hr = E_POINTER;
  2113. }
  2114. return hr;
  2115. }
  2116. STDMETHODIMP
  2117. CImpISystemMonitor::AddLogFile (
  2118. IN BSTR bstrPath,
  2119. ILogFileItem **ppItem
  2120. )
  2121. /*++
  2122. Routine Description:
  2123. Add log file specified by pathname to the control.
  2124. This method does not support wildcard paths.
  2125. Arguments:
  2126. bstrPath - Pathname string
  2127. ppItem - pointer to returned interface pointer
  2128. Return Value:
  2129. HRESULT
  2130. --*/
  2131. {
  2132. HRESULT hr = S_OK;
  2133. if (ppItem == NULL) {
  2134. return E_POINTER;
  2135. }
  2136. try {
  2137. *ppItem = NULL;
  2138. hr = m_pObj->m_pCtrl->AddSingleLogFile(bstrPath, (CLogFileItem**)ppItem);
  2139. } catch (...) {
  2140. hr = E_POINTER;
  2141. }
  2142. return hr;
  2143. }
  2144. STDMETHODIMP
  2145. CImpISystemMonitor::DeleteLogFile (
  2146. IN ILogFileItem *pItem
  2147. )
  2148. /*++
  2149. Routine Description:
  2150. Deletes a log file from the control.
  2151. Arguments:
  2152. pItem - Pointer to log file's ILogFileItem interface
  2153. Return Value:
  2154. HRESULT
  2155. --*/
  2156. {
  2157. HRESULT hr = S_OK;
  2158. if (pItem == NULL) {
  2159. return E_POINTER;
  2160. }
  2161. try {
  2162. // Delegate to control object
  2163. hr = m_pObj->m_pCtrl->RemoveSingleLogFile( (PCLogFileItem)pItem );
  2164. } catch (...) {
  2165. hr = E_POINTER;
  2166. }
  2167. return hr;
  2168. }
  2169. //IOleControl interface implementation
  2170. /*
  2171. * CImpIOleControl::CImpIOleControl
  2172. * CImpIOleControl::~CImpIOleControl
  2173. *
  2174. * Parameters (Constructor):
  2175. * pObj PCPolyline of the object we're in.
  2176. * pUnkOuter LPUNKNOWN to which we delegate.
  2177. */
  2178. CImpIOleControl::CImpIOleControl (
  2179. IN PCPolyline pObj,
  2180. IN LPUNKNOWN pUnkOuter
  2181. )
  2182. {
  2183. m_cRef = 0;
  2184. m_pObj = pObj;
  2185. m_pUnkOuter = pUnkOuter;
  2186. }
  2187. CImpIOleControl::~CImpIOleControl (
  2188. VOID
  2189. )
  2190. {
  2191. return;
  2192. }
  2193. /*
  2194. * CImpIOleControl::QueryInterface
  2195. * CImpIOleControl::AddRef
  2196. * CImpIOleControl::Release
  2197. */
  2198. STDMETHODIMP
  2199. CImpIOleControl::QueryInterface(
  2200. IN REFIID riid,
  2201. OUT LPVOID *ppv
  2202. )
  2203. {
  2204. HRESULT hr = S_OK;
  2205. if (ppv == NULL) {
  2206. return E_POINTER;
  2207. }
  2208. try {
  2209. *ppv = NULL;
  2210. hr = m_pUnkOuter->QueryInterface(riid, ppv);
  2211. } catch (...) {
  2212. hr = E_POINTER;
  2213. }
  2214. return hr;
  2215. }
  2216. STDMETHODIMP_( ULONG )
  2217. CImpIOleControl::AddRef(
  2218. VOID
  2219. )
  2220. {
  2221. ++m_cRef;
  2222. return m_pUnkOuter->AddRef();
  2223. }
  2224. STDMETHODIMP_(ULONG) CImpIOleControl::Release(void)
  2225. {
  2226. --m_cRef;
  2227. return m_pUnkOuter->Release();
  2228. }
  2229. /*
  2230. * CImpIOleControl::GetControlInfo
  2231. *
  2232. * Purpose:
  2233. * Fills a CONTROLINFO structure containing information about
  2234. * the controls mnemonics and other behavioral aspects.
  2235. *
  2236. * Parameters:
  2237. * pCI LPCONTROLINFO to the structure to fill
  2238. */
  2239. STDMETHODIMP
  2240. CImpIOleControl::GetControlInfo ( LPCONTROLINFO pCI )
  2241. {
  2242. HRESULT hr = S_OK;
  2243. if (pCI == NULL) {
  2244. return E_POINTER;
  2245. }
  2246. try {
  2247. *pCI=m_pObj->m_ctrlInfo;
  2248. } catch (...) {
  2249. hr = E_POINTER;
  2250. }
  2251. return hr;
  2252. }
  2253. /*
  2254. * CImpIOleControl::OnMnemonic
  2255. *
  2256. * Purpose:
  2257. * Notifies the control that a mnemonic was activated.
  2258. *
  2259. * Parameters:
  2260. * pMsg LPMSG containing the message that matches one of
  2261. * the control's mnemonics. The control uses this
  2262. * to distinguish which mnemonic was pressed.
  2263. */
  2264. STDMETHODIMP CImpIOleControl::OnMnemonic ( LPMSG /* pMsg */ )
  2265. {
  2266. //No mnemonics
  2267. return NOERROR;
  2268. }
  2269. /*
  2270. * CImpIOleControl::OnAmbientPropertyChange
  2271. *
  2272. * Purpose:
  2273. * Notifies the control that one or more of the container's ambient
  2274. * properties changed.
  2275. *
  2276. * Parameters:
  2277. * dispID DISPID identifying the property, which can
  2278. * be DISPID_UNKNOWN indicating that more than
  2279. * one changed.
  2280. */
  2281. STDMETHODIMP
  2282. CImpIOleControl::OnAmbientPropertyChange(DISPID dispID)
  2283. {
  2284. DWORD dwInitWhich;
  2285. switch (dispID) {
  2286. case DISPID_UNKNOWN:
  2287. {
  2288. dwInitWhich = INITAMBIENT_SHOWHATCHING | INITAMBIENT_UIDEAD
  2289. | INITAMBIENT_BACKCOLOR | INITAMBIENT_FORECOLOR
  2290. | INITAMBIENT_APPEARANCE | INITAMBIENT_USERMODE
  2291. | INITAMBIENT_FONT | INITAMBIENT_RTL;
  2292. // Update system colors here until MMC passes on WM_SYSCOLORCHANGE
  2293. m_pObj->m_pCtrl->UpdateNonAmbientSysColors();
  2294. break;
  2295. }
  2296. case DISPID_AMBIENT_SHOWHATCHING:
  2297. dwInitWhich = INITAMBIENT_SHOWHATCHING;
  2298. break;
  2299. case DISPID_AMBIENT_UIDEAD:
  2300. dwInitWhich = INITAMBIENT_UIDEAD;
  2301. break;
  2302. case DISPID_AMBIENT_APPEARANCE:
  2303. dwInitWhich = INITAMBIENT_APPEARANCE;
  2304. break;
  2305. case DISPID_AMBIENT_BACKCOLOR:
  2306. dwInitWhich = INITAMBIENT_BACKCOLOR;
  2307. break;
  2308. case DISPID_AMBIENT_FORECOLOR:
  2309. dwInitWhich = INITAMBIENT_FORECOLOR;
  2310. break;
  2311. case DISPID_AMBIENT_FONT:
  2312. dwInitWhich = INITAMBIENT_FONT;
  2313. break;
  2314. case DISPID_AMBIENT_USERMODE:
  2315. dwInitWhich = INITAMBIENT_USERMODE;
  2316. break;
  2317. case DISPID_AMBIENT_RIGHTTOLEFT:
  2318. dwInitWhich = INITAMBIENT_RTL;
  2319. break;
  2320. default:
  2321. return NOERROR;
  2322. }
  2323. m_pObj->AmbientsInitialize(dwInitWhich);
  2324. return NOERROR;
  2325. }
  2326. /*
  2327. * CImpIOleControl::FreezeEvents
  2328. *
  2329. * Purpose:
  2330. * Instructs the control to stop firing events or to continue
  2331. * firing them.
  2332. *
  2333. * Parameters:
  2334. * fFreeze BOOL indicating to freeze (TRUE) or thaw (FALSE)
  2335. * events from this control.
  2336. */
  2337. STDMETHODIMP
  2338. CImpIOleControl::FreezeEvents(BOOL fFreeze)
  2339. {
  2340. m_pObj->m_fFreezeEvents = fFreeze;
  2341. return NOERROR;
  2342. }
  2343. // Private methods
  2344. STDMETHODIMP
  2345. CImpISystemMonitor::GetSelectedCounter (
  2346. ICounterItem** ppItem
  2347. )
  2348. /*++
  2349. Routine Description:
  2350. Gets the ICounterItem interface for the selected counter.
  2351. Arguments:
  2352. ppItem - pointer to returned interface pointer
  2353. Return Value:
  2354. HResult
  2355. --*/
  2356. {
  2357. HRESULT hr = S_OK;
  2358. if (ppItem == NULL) {
  2359. return E_POINTER;
  2360. }
  2361. try {
  2362. *ppItem = m_pObj->m_pCtrl->m_pSelectedItem;
  2363. if ( NULL != *ppItem ) {
  2364. m_pObj->m_pCtrl->m_pSelectedItem->AddRef();
  2365. }
  2366. } catch (...) {
  2367. hr = E_POINTER;
  2368. }
  2369. return hr;
  2370. }
  2371. HLOG
  2372. CImpISystemMonitor::GetDataSourceHandle ( void )
  2373. {
  2374. return m_pObj->m_pCtrl->GetDataSourceHandle();
  2375. }