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.

242 lines
6.4 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1997 **/
  4. /**********************************************************************/
  5. /*
  6. SscpStat.h
  7. The superscope statistics dialog
  8. FILE HISTORY:
  9. */
  10. #include "stdafx.h"
  11. #include "sscpstat.h"
  12. #include "server.h"
  13. #ifdef _DEBUG
  14. #define new DEBUG_NEW
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18. enum
  19. {
  20. SUPERSCOPE_STAT_TOTAL_SCOPES = 0,
  21. SUPERSCOPE_STAT_TOTAL_ADDRESSES,
  22. SUPERSCOPE_STAT_IN_USE,
  23. SUPERSCOPE_STAT_AVAILABLE,
  24. SUPERSCOPE_STAT_MAX
  25. };
  26. /*---------------------------------------------------------------------------
  27. CSuperscopeStats implementation
  28. ---------------------------------------------------------------------------*/
  29. const ContainerColumnInfo s_rgSuperscopeStatsColumnInfo[] =
  30. {
  31. { IDS_STATS_TOTAL_SCOPES, 0, TRUE },
  32. { IDS_STATS_TOTAL_ADDRESSES, 0, TRUE },
  33. { IDS_STATS_IN_USE, 0, TRUE },
  34. { IDS_STATS_AVAILABLE, 0, TRUE },
  35. };
  36. CSuperscopeStats::CSuperscopeStats()
  37. : StatsDialog(STATSDLG_VERTICAL)
  38. {
  39. SetColumnInfo(s_rgSuperscopeStatsColumnInfo,
  40. DimensionOf(s_rgSuperscopeStatsColumnInfo));
  41. }
  42. CSuperscopeStats::~CSuperscopeStats()
  43. {
  44. }
  45. BEGIN_MESSAGE_MAP(CSuperscopeStats, StatsDialog)
  46. //{{AFX_MSG_MAP(CSuperscopeStats)
  47. //}}AFX_MSG_MAP
  48. ON_MESSAGE(WM_NEW_STATS_AVAILABLE, OnNewStatsAvailable)
  49. END_MESSAGE_MAP()
  50. HRESULT CSuperscopeStats::RefreshData(BOOL fGrabNewData)
  51. {
  52. if (fGrabNewData)
  53. {
  54. DWORD dwError = 0;
  55. LPDHCP_MIB_INFO pMibInfo = NULL;
  56. LPDHCP_SUPER_SCOPE_TABLE pSuperscopeTable = NULL;
  57. LPDHCP_SUPER_SCOPE_TABLE_ENTRY pSuperscopeTableEntry = NULL;
  58. // build up a list of scopes to get info from
  59. BEGIN_WAIT_CURSOR;
  60. dwError = ::DhcpGetSuperScopeInfoV4(m_strServerAddress, &pSuperscopeTable);
  61. if (dwError != ERROR_SUCCESS)
  62. {
  63. ::DhcpMessageBox(dwError);
  64. return dwError;
  65. }
  66. // walk the list returned by the server
  67. pSuperscopeTableEntry = pSuperscopeTable->pEntries;
  68. if (pSuperscopeTableEntry == NULL && pSuperscopeTable->cEntries != 0)
  69. {
  70. ASSERT(FALSE);
  71. return dwError; // Just in case
  72. }
  73. // clear the array out
  74. m_dwScopeArray.RemoveAll();
  75. // find any scope addresses that belong to this superscope and build our
  76. // array for later
  77. for (int iSuperscopeEntry = pSuperscopeTable->cEntries;
  78. iSuperscopeEntry > 0;
  79. iSuperscopeEntry--, pSuperscopeTableEntry++)
  80. {
  81. if (pSuperscopeTableEntry->SuperScopeName &&
  82. m_strSuperscopeName.Compare(pSuperscopeTableEntry->SuperScopeName) == 0)
  83. {
  84. m_dwScopeArray.Add(pSuperscopeTableEntry->SubnetAddress);
  85. }
  86. }
  87. dwError = ::DhcpGetMibInfo(m_strServerAddress, &pMibInfo);
  88. END_WAIT_CURSOR;
  89. if (dwError != ERROR_SUCCESS)
  90. {
  91. ::DhcpMessageBox(dwError);
  92. return dwError;
  93. }
  94. UpdateWindow(pMibInfo);
  95. if (pMibInfo)
  96. ::DhcpRpcFreeMemory(pMibInfo);
  97. }
  98. return hrOK;
  99. }
  100. BOOL CSuperscopeStats::OnInitDialog()
  101. {
  102. CString st, strScopeAddress;
  103. BOOL bRet;
  104. AfxFormatString1(st, IDS_SUPERSCOPE_STATS_TITLE, m_strSuperscopeName);
  105. SetWindowText((LPCTSTR) st);
  106. bRet = StatsDialog::OnInitDialog();
  107. // Set the default column widths to the width of the widest column
  108. SetColumnWidths(2 /* Number of Columns */);
  109. return bRet;
  110. }
  111. void CSuperscopeStats::Sort(UINT nColumnId)
  112. {
  113. // we don't sort any of our stats
  114. }
  115. afx_msg long CSuperscopeStats::OnNewStatsAvailable(UINT wParam, LONG lParam)
  116. {
  117. CDhcpSuperscope * pSuperscope;
  118. CDhcpServer * pServer;
  119. pSuperscope = GETHANDLER(CDhcpSuperscope, m_spNode);
  120. pServer = pSuperscope->GetServerObject();
  121. LPDHCP_MIB_INFO pMibInfo = pServer->DuplicateMibInfo();
  122. Assert(pMibInfo);
  123. if (!pMibInfo)
  124. return 0;
  125. UpdateWindow(pMibInfo);
  126. pServer->FreeDupMibInfo(pMibInfo);
  127. return 0;
  128. }
  129. void CSuperscopeStats::UpdateWindow(LPDHCP_MIB_INFO pMibInfo)
  130. {
  131. Assert (pMibInfo);
  132. UINT i, j;
  133. int nTotalAddresses = 0, nTotalInUse = 0, nTotalAvailable = 0;
  134. if (pMibInfo)
  135. {
  136. LPSCOPE_MIB_INFO pScopeMibInfo = pMibInfo->ScopeInfo;
  137. // walk the list of scopes and total the scopes that are in the superscope
  138. for (i = 0; i < pMibInfo->Scopes; i++)
  139. {
  140. for (j = 0; j < (UINT) m_dwScopeArray.GetSize(); j++)
  141. {
  142. if (pScopeMibInfo[i].Subnet == m_dwScopeArray[j])
  143. {
  144. nTotalAddresses += (pScopeMibInfo[i].NumAddressesInuse + pScopeMibInfo[i].NumAddressesFree);
  145. nTotalInUse += pScopeMibInfo[i].NumAddressesInuse;
  146. nTotalAvailable += pScopeMibInfo[i].NumAddressesFree;
  147. break;
  148. }
  149. }
  150. }
  151. }
  152. int nPercent;
  153. CString st;
  154. TCHAR szFormat[] = _T("%d");
  155. TCHAR szPercentFormat[] = _T("%d (%d%%)");
  156. for (i = 0; i < SUPERSCOPE_STAT_MAX; i++)
  157. {
  158. if (!pMibInfo)
  159. st = _T("---");
  160. else
  161. {
  162. switch (i)
  163. {
  164. case SUPERSCOPE_STAT_TOTAL_SCOPES:
  165. st.Format(szFormat, m_dwScopeArray.GetSize());
  166. break;
  167. case SUPERSCOPE_STAT_TOTAL_ADDRESSES:
  168. st.Format(szFormat, nTotalAddresses);
  169. break;
  170. case SUPERSCOPE_STAT_IN_USE:
  171. if (nTotalAddresses > 0)
  172. nPercent = (nTotalInUse * 100) / nTotalAddresses;
  173. else
  174. nPercent = 0;
  175. st.Format(szPercentFormat, nTotalInUse, nPercent);
  176. break;
  177. case SUPERSCOPE_STAT_AVAILABLE:
  178. if (nTotalAddresses > 0)
  179. nPercent = (nTotalAvailable * 100) / nTotalAddresses;
  180. else
  181. nPercent = 0;
  182. st.Format(szPercentFormat, nTotalAvailable, nPercent);
  183. break;
  184. default:
  185. Panic1("Unknown scope stat id : %d", i);
  186. break;
  187. }
  188. }
  189. m_listCtrl.SetItemText(i, 1, (LPCTSTR) st);
  190. }
  191. }