Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

194 lines
4.8 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // File: connstat.h
  4. //
  5. // Module: CMMON32.EXE
  6. //
  7. // Synopsis: Header for the CConnStatistics class.
  8. //
  9. // Copyright (c) 1998-1999 Microsoft Corporation
  10. //
  11. // Author: quintinb Created Header 08/16/99
  12. //
  13. //+----------------------------------------------------------------------------
  14. #ifndef CONNSTAT_H
  15. #define CONNSTAT_H
  16. #include <windows.h>
  17. #include <ras.h>
  18. #include <tapi.h>
  19. #include "RasApiDll.h"
  20. #include "SmplRing.h"
  21. //+---------------------------------------------------------------------------
  22. //
  23. // class CConnStatistics
  24. //
  25. // Description: A class to collect connection statistics
  26. // OpenByPerformanceKey() will start gathering data from registry
  27. // OpenByDevice will gathering data from TAPI device handle
  28. //
  29. // History: fengsun 10/01/97 Created
  30. // nickball 03/04/00 Heavily revised for NT5 usage
  31. //
  32. //----------------------------------------------------------------------------
  33. class CConnStatistics
  34. {
  35. public:
  36. CConnStatistics();
  37. ~CConnStatistics();
  38. void Update(); // Update the statistics
  39. DWORD GetBytesPerSecRead() const;
  40. DWORD GetBytesPerSecWrite() const;
  41. DWORD GetBytesRead() const;
  42. DWORD GetBytesWrite() const;
  43. DWORD GetBaudRate() const;
  44. DWORD GetDuration() const;
  45. void Open(HINSTANCE hInst,
  46. DWORD dwInitBytesRecv,
  47. DWORD dwInitBytesSend,
  48. HRASCONN hRasDial,
  49. HRASCONN hRAsTunnel);
  50. void Close(); // No more statistic information
  51. void SetDialupTwo(BOOL fAdapter2);
  52. DWORD GetInitBytesRead() const;
  53. DWORD GetInitBytesWrite() const;
  54. BOOL IsAvailable() const; // whether statistic information is available
  55. protected:
  56. void OpenByStatisticsApi(DWORD dwInitBytesRecv,
  57. DWORD dwInitBytesSend,
  58. HRASCONN hDial,
  59. HRASCONN hTunnel);
  60. void OpenByPerformanceKey(HINSTANCE hInst,
  61. DWORD dwInitBytesRecv,
  62. DWORD dwInitBytesSend);
  63. BOOL OpenByDevice(HRASCONN hrcRasConn);
  64. BOOL GetDeviceHandle(HRASCONN hrcRasConn);
  65. BOOL GetPerfData(DWORD& dwRead, DWORD& dwWrite, DWORD& dwBaudRate) const;
  66. BOOL GetTapiDeviceStats(DWORD& dwRead, DWORD& dwWrite, DWORD& dwBaudRate) const;
  67. void GetStatRegValues(HINSTANCE hInst);
  68. protected:
  69. struct CTraffic
  70. {
  71. DWORD dwRead;
  72. DWORD dwWrite;
  73. DWORD dwTime; // time in minisecond
  74. };
  75. enum {STAT_COUNT = 3};
  76. CSimpleRing<CTraffic, STAT_COUNT> m_TrafficRing;
  77. DWORD m_dwReadPerSecond;
  78. DWORD m_dwWritePerSecond;
  79. DWORD m_dwBaudRate;
  80. DWORD m_dwDuration;
  81. HANDLE m_hStatDevice; // the TAPI device handle
  82. HRASCONN m_hRasConn; // the RAS connection handle
  83. // For DUN 1.2, ICM uses perfmon counters for connection status data
  84. // however, these perfmon counters such as TotalBytesReceived are from last reboot
  85. // so we need to record the initial data in order to get correct value for this
  86. // particular connection
  87. HKEY m_hKey; // Performance registry handle
  88. DWORD m_dwInitBytesRead;
  89. DWORD m_dwInitBytesWrite;
  90. //
  91. // Registry names are different for PPP and PPTP
  92. //
  93. BOOL m_fAdapter2;
  94. BOOL m_fAdapterSet;
  95. //
  96. // Localized version of
  97. // "Dial-up Adapter"\TotalBytesRecvd"
  98. // "Dial-up Adapter"\TotalBytesXmit"
  99. // "Dial-up Adapter"\ConnectSpeed"
  100. //
  101. LPTSTR m_pszTotalBytesRecvd;
  102. LPTSTR m_pszTotalBytesXmit;
  103. LPTSTR m_pszConnectSpeed;
  104. // The link to rasapi32
  105. CRasApiDll m_RasApiDll;
  106. public:
  107. #ifdef DEBUG
  108. void AssertValid() const;
  109. #endif
  110. };
  111. //
  112. // Inline functions
  113. //
  114. inline DWORD CConnStatistics::GetInitBytesRead() const
  115. {
  116. return m_dwInitBytesRead;
  117. }
  118. inline DWORD CConnStatistics::GetInitBytesWrite() const
  119. {
  120. return m_dwInitBytesWrite;
  121. }
  122. inline void CConnStatistics::SetDialupTwo(BOOL fAdapter2)
  123. {
  124. m_fAdapterSet = TRUE;
  125. m_fAdapter2 = fAdapter2;
  126. }
  127. inline DWORD CConnStatistics::GetBytesPerSecRead() const
  128. {
  129. return m_dwReadPerSecond;
  130. }
  131. inline DWORD CConnStatistics::GetBytesPerSecWrite() const
  132. {
  133. return m_dwWritePerSecond;
  134. }
  135. inline DWORD CConnStatistics::GetDuration() const
  136. {
  137. return OS_NT5 ? (m_dwDuration) : 0;
  138. }
  139. inline DWORD CConnStatistics::GetBytesRead() const
  140. {
  141. return m_TrafficRing.GetLatest().dwRead;
  142. }
  143. inline DWORD CConnStatistics::GetBytesWrite() const
  144. {
  145. return m_TrafficRing.GetLatest().dwWrite;
  146. }
  147. inline BOOL CConnStatistics::IsAvailable() const
  148. {
  149. return OS_NT5 ? (m_hRasConn && m_RasApiDll.IsLoaded()) : (m_hKey || m_hStatDevice);
  150. }
  151. inline DWORD CConnStatistics::GetBaudRate() const
  152. {
  153. return m_dwBaudRate;
  154. }
  155. #endif