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.

215 lines
6.0 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1998.
  5. //
  6. // File: S M E N G . H
  7. //
  8. // Contents: The engine that provides statistics to the status monitor
  9. //
  10. // Notes:
  11. //
  12. // Author: CWill 7 Oct 1997
  13. //
  14. //----------------------------------------------------------------------------
  15. #pragma once
  16. #include "cfpidl.h"
  17. #include "ncnetcon.h"
  18. #include "smutil.h"
  19. #include "hnetbcon.h"
  20. typedef struct tagPersistConn
  21. {
  22. BYTE* pbBuf;
  23. ULONG ulSize;
  24. CLSID clsid;
  25. } PersistConn;
  26. extern CRITICAL_SECTION g_csStatmonData;
  27. class CPspStatusMonitorGen;
  28. class CPspStatusMonitorTool;
  29. class CPspStatusMonitorRas;
  30. class CPspStatusMonitorIpcfg;
  31. #define _ATL_DEBUG_INTERFACES
  32. class ATL_NO_VTABLE CNetStatisticsEngine :
  33. public CComObjectRootEx <CComObjectThreadModel>,
  34. public IConnectionPointImpl <CNetStatisticsEngine,
  35. &IID_INetConnectionStatisticsNotifySink>,
  36. public IConnectionPointContainerImpl <CNetStatisticsEngine>,
  37. public INetStatisticsEngine
  38. {
  39. public:
  40. ~CNetStatisticsEngine(VOID);
  41. BEGIN_COM_MAP(CNetStatisticsEngine)
  42. COM_INTERFACE_ENTRY(INetStatisticsEngine)
  43. COM_INTERFACE_ENTRY_IMPL(IConnectionPointContainer)
  44. END_COM_MAP()
  45. BEGIN_CONNECTION_POINT_MAP(CNetStatisticsEngine)
  46. CONNECTION_POINT_ENTRY(IID_INetConnectionStatisticsNotifySink)
  47. END_CONNECTION_POINT_MAP()
  48. // INetStatisticsEngine
  49. //
  50. public:
  51. STDMETHOD(StartStatistics)(VOID);
  52. STDMETHOD(StopStatistics)(VOID);
  53. STDMETHOD(ShowStatusMonitor)(VOID);
  54. STDMETHOD(CloseStatusMonitor)(VOID);
  55. STDMETHOD(UpdateStatistics)(BOOL* pfNoLongerConnected);
  56. STDMETHOD(UpdateTitle)(PCWSTR pszwNewName);
  57. STDMETHOD(UpdateRasLinkList)();
  58. STDMETHOD(GetGuidId)(GUID* pguidId);
  59. STDMETHOD(GetStatistics)(STATMON_ENGINEDATA** ppseAllData);
  60. // Secret interfaces
  61. //
  62. public:
  63. HRESULT HrInitStatEngine(const CONFOLDENTRY& pccfe);
  64. VOID SetParent(CNetStatisticsCentral * pnsc)
  65. {
  66. AssertH(NULL == m_pnsc);
  67. m_pnsc = pnsc;
  68. ::AddRefObj(m_pnsc);
  69. }
  70. VOID SetPropsheetWindow(HWND hwnd)
  71. {
  72. m_hwndPsh = hwnd;
  73. }
  74. VOID UnSetCreatingDialog()
  75. {
  76. m_fCreatingDialog = FALSE;
  77. }
  78. HRESULT HrGetConnectionFromBlob (INetConnection** ppCon)
  79. {
  80. return HrGetConnectionFromPersistData(
  81. m_PersistConn.clsid,
  82. m_PersistConn.pbBuf,
  83. m_PersistConn.ulSize,
  84. IID_INetConnection,
  85. reinterpret_cast<VOID**>(ppCon));
  86. }
  87. // Callback for the property sheet page
  88. //
  89. public:
  90. static INT CALLBACK PshCallback(HWND hwndDlg, UINT uMsg, LPARAM lParam);
  91. static DWORD MonitorThread(CNetStatisticsEngine * pnse);
  92. // Utility functions
  93. //
  94. private:
  95. // Connection class specific functions
  96. //
  97. private:
  98. virtual HRESULT HrUpdateData(DWORD* pdwChangeFlags, BOOL* pfNoLongerConnected) PURE;
  99. protected:
  100. CNetStatisticsEngine(VOID);
  101. protected:
  102. // Net Statistics Central object
  103. //
  104. CNetStatisticsCentral * m_pnsc;
  105. // Property sheet data
  106. //
  107. CPspStatusMonitorGen* m_ppsmg;
  108. CPspStatusMonitorTool* m_ppsmt;
  109. CPspStatusMonitorRas* m_ppsmr;
  110. CPspStatusMonitorIpcfg* m_ppsms;
  111. // Connection data
  112. //
  113. STATMON_ENGINEDATA* m_psmEngineData;
  114. // Connection identifiers
  115. //
  116. GUID m_guidId;
  117. NETCON_MEDIATYPE m_ncmType;
  118. NETCON_SUBMEDIATYPE m_ncsmType;
  119. DWORD m_dwCharacter;
  120. PersistConn m_PersistConn;
  121. LONG m_cStatRef;
  122. BOOL m_fRefreshIcon;
  123. HWND m_hwndPsh;
  124. DWORD m_dwChangeFlags;
  125. // This boolean synchronizes the thread that creates the property sheet
  126. // in CNetStatisticsEngine::ShowStatusMonitor
  127. BOOL m_fCreatingDialog;
  128. };
  129. class CRasStatEngine : public CNetStatisticsEngine
  130. {
  131. public:
  132. CRasStatEngine();
  133. VOID put_RasConn(HRASCONN hRasConn);
  134. VOID put_MediaType(NETCON_MEDIATYPE ncmType, NETCON_SUBMEDIATYPE ncsmType);
  135. VOID put_Character(DWORD dwCharacter);
  136. HRESULT HrUpdateData(DWORD* pdwChangeFlags, BOOL* pfNoLongerConnected);
  137. private:
  138. HRASCONN m_hRasConn;
  139. };
  140. class CLanStatEngine : public CNetStatisticsEngine
  141. {
  142. public:
  143. CLanStatEngine();
  144. HRESULT put_Device(tstring* pstrName);
  145. VOID put_MediaType(NETCON_MEDIATYPE ncmType, NETCON_SUBMEDIATYPE ncsmType);
  146. HRESULT HrUpdateData(DWORD* pdwChangeFlags, BOOL* pfNoLongerConnected);
  147. private:
  148. tstring m_strDevice;
  149. UNICODE_STRING m_ustrDevice;
  150. };
  151. class CSharedAccessStatEngine : public CNetStatisticsEngine
  152. {
  153. public:
  154. CSharedAccessStatEngine();
  155. HRESULT HrUpdateData(DWORD* pdwChangeFlags, BOOL* pfNoLongerConnected);
  156. HRESULT Initialize(NETCON_MEDIATYPE MediaType, INetSharedAccessConnection* pNetSharedAccessConnection);
  157. HRESULT FinalConstruct(VOID);
  158. HRESULT FinalRelease(VOID);
  159. private:
  160. static HRESULT GetStringStateVariable(IUPnPService* pService, LPWSTR pszVariableName, BSTR* pString);
  161. static HRESULT InvokeVoidAction(IUPnPService * pService, LPTSTR pszCommand, VARIANT* pOutParams);
  162. static DWORD WINAPI StaticUpdateStats(LPVOID lpParameter);
  163. HRESULT UpdateStats();
  164. WCHAR m_szLocalDeviceGuidStorage[64]; // enough for \Device\{...GUID...}
  165. UNICODE_STRING m_LocalDeviceGuid;
  166. IGlobalInterfaceTable* m_pGlobalInterfaceTable;
  167. DWORD m_dwCommonInterfaceCookie;
  168. DWORD m_dwWANConnectionCookie;
  169. BOOL m_bRequested;
  170. NETCON_STATUS m_Status;
  171. ULONG m_ulTotalBytesSent;
  172. ULONG m_ulTotalBytesReceived;
  173. ULONG m_ulTotalPacketsSent;
  174. ULONG m_ulTotalPacketsReceived;
  175. ULONG m_ulUptime;
  176. ULONG m_ulSpeedbps;
  177. };
  178. HRESULT HrGetAutoNetSetting(PWSTR pszGuid, DHCP_ADDRESS_TYPE * pAddrType);
  179. HRESULT HrGetAutoNetSetting(REFGUID pGuidId, DHCP_ADDRESS_TYPE * pAddrType);