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.

200 lines
4.8 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1997 **/
  4. /**********************************************************************/
  5. /*
  6. ScopStat.cpp
  7. The scope statistics dialog
  8. FILE HISTORY:
  9. */
  10. #include "stdafx.h"
  11. #include "mScpStat.h"
  12. #include "mscope.h"
  13. #include "server.h"
  14. #ifdef _DEBUG
  15. #define new DEBUG_NEW
  16. #undef THIS_FILE
  17. static char THIS_FILE[] = __FILE__;
  18. #endif
  19. enum
  20. {
  21. SCOPE_STAT_TOTAL_ADDRESSES = 0,
  22. SCOPE_STAT_IN_USE,
  23. SCOPE_STAT_AVAILABLE,
  24. SCOPE_STAT_MAX
  25. };
  26. /*---------------------------------------------------------------------------
  27. CMScopeStats implementation
  28. ---------------------------------------------------------------------------*/
  29. const ContainerColumnInfo s_rgScopeStatsColumnInfo[] =
  30. {
  31. { IDS_STATS_TOTAL_ADDRESSES, 0, TRUE },
  32. { IDS_STATS_IN_USE, 0, TRUE },
  33. { IDS_STATS_AVAILABLE, 0, TRUE },
  34. };
  35. CMScopeStats::CMScopeStats()
  36. : StatsDialog(STATSDLG_VERTICAL)
  37. {
  38. SetColumnInfo(s_rgScopeStatsColumnInfo,
  39. DimensionOf(s_rgScopeStatsColumnInfo));
  40. }
  41. CMScopeStats::~CMScopeStats()
  42. {
  43. }
  44. BEGIN_MESSAGE_MAP(CMScopeStats, StatsDialog)
  45. //{{AFX_MSG_MAP(CMScopeStats)
  46. //}}AFX_MSG_MAP
  47. ON_MESSAGE(WM_NEW_STATS_AVAILABLE, OnNewStatsAvailable)
  48. END_MESSAGE_MAP()
  49. HRESULT CMScopeStats::RefreshData(BOOL fGrabNewData)
  50. {
  51. if (fGrabNewData)
  52. {
  53. DWORD dwError = 0;
  54. LPDHCP_MCAST_MIB_INFO pMibInfo = NULL;
  55. BEGIN_WAIT_CURSOR;
  56. dwError = ::DhcpGetMCastMibInfo(m_strServerAddress, &pMibInfo);
  57. END_WAIT_CURSOR;
  58. if (dwError != ERROR_SUCCESS)
  59. {
  60. ::DhcpMessageBox(dwError);
  61. return hrOK;
  62. }
  63. UpdateWindow(pMibInfo);
  64. if (pMibInfo)
  65. ::DhcpRpcFreeMemory(pMibInfo);
  66. }
  67. return hrOK;
  68. }
  69. BOOL CMScopeStats::OnInitDialog()
  70. {
  71. CString st;
  72. BOOL bRet;
  73. AfxFormatString1(st, IDS_MSCOPE_STATS_TITLE, m_strScopeName);
  74. SetWindowText((LPCTSTR) st);
  75. bRet = StatsDialog::OnInitDialog();
  76. // Set the default column widths to the width of the widest column
  77. SetColumnWidths(2 /* Number of Columns */);
  78. return bRet;
  79. }
  80. void CMScopeStats::Sort(UINT nColumnId)
  81. {
  82. // we don't sort any of our stats
  83. }
  84. afx_msg long CMScopeStats::OnNewStatsAvailable(UINT wParam, LONG lParam)
  85. {
  86. SPITFSNode spNode;
  87. CDhcpMScope * pScope;
  88. CDhcpServer * pServer;
  89. pScope = GETHANDLER(CDhcpMScope, m_spNode);
  90. pServer = pScope->GetServerObject();
  91. LPDHCP_MCAST_MIB_INFO pMibInfo = pServer->DuplicateMCastMibInfo();
  92. Assert(pMibInfo);
  93. if (!pMibInfo)
  94. return 0;
  95. UpdateWindow(pMibInfo);
  96. pServer->FreeDupMCastMibInfo(pMibInfo);
  97. return 0;
  98. }
  99. void CMScopeStats::UpdateWindow(LPDHCP_MCAST_MIB_INFO pMibInfo)
  100. {
  101. Assert (pMibInfo);
  102. UINT i;
  103. int nTotalAddresses = 0, nTotalInUse = 0, nTotalAvailable = 0;
  104. if (pMibInfo)
  105. {
  106. LPMSCOPE_MIB_INFO pScopeMibInfo = pMibInfo->ScopeInfo;
  107. // walk the list of scopes and calculate totals
  108. for (i = 0; i < pMibInfo->Scopes; i++)
  109. {
  110. if (pScopeMibInfo[i].MScopeId == m_dwScopeId)
  111. {
  112. nTotalAddresses += (pScopeMibInfo[i].NumAddressesInuse + pScopeMibInfo[i].NumAddressesFree);
  113. nTotalInUse = pScopeMibInfo[i].NumAddressesInuse;
  114. nTotalAvailable = pScopeMibInfo[i].NumAddressesFree;
  115. break;
  116. }
  117. }
  118. }
  119. int nPercent;
  120. CString st;
  121. TCHAR szFormat[] = _T("%d");
  122. TCHAR szPercentFormat[] = _T("%d (%d%%)");
  123. for (i = 0; i < SCOPE_STAT_MAX; i++)
  124. {
  125. if (!pMibInfo)
  126. st = _T("---");
  127. else
  128. {
  129. switch (i)
  130. {
  131. case SCOPE_STAT_TOTAL_ADDRESSES:
  132. st.Format(szFormat, nTotalAddresses);
  133. break;
  134. case SCOPE_STAT_IN_USE:
  135. if (nTotalAddresses > 0)
  136. nPercent = (int)(((LONGLONG)nTotalInUse * (LONGLONG)100) / nTotalAddresses);
  137. else
  138. nPercent = 0;
  139. st.Format(szPercentFormat, nTotalInUse, nPercent);
  140. break;
  141. case SCOPE_STAT_AVAILABLE:
  142. if (nTotalAddresses > 0)
  143. nPercent = (int)(((LONGLONG)nTotalAvailable * (LONGLONG)100) / nTotalAddresses);
  144. else
  145. nPercent = 0;
  146. st.Format(szPercentFormat, nTotalAvailable, nPercent);
  147. break;
  148. default:
  149. Panic1("Unknown scope stat id : %d", i);
  150. break;
  151. }
  152. }
  153. m_listCtrl.SetItemText(i, 1, (LPCTSTR) st);
  154. }
  155. }