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.

186 lines
6.0 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: C O N M A N . H
  7. //
  8. // Contents: Connection manager.
  9. //
  10. // Notes:
  11. //
  12. // Author: shaunco 21 Sep 1997
  13. //
  14. //----------------------------------------------------------------------------
  15. #pragma once
  16. #include "nmbase.h"
  17. #include "nmres.h"
  18. #include <rasapip.h>
  19. #include "cmevent.h"
  20. #include "ncstl.h"
  21. #include "stlmap.h"
  22. // typedef map<IUnknown*, tstring> USERNOTIFYMAP;
  23. class CNotifySourceInfo
  24. {
  25. public:
  26. tstring szUserName;
  27. tstring szUserProfilesPath;
  28. DWORD dwCookie;
  29. };
  30. typedef map<IUnknown*, CNotifySourceInfo *> USERNOTIFYMAP;
  31. typedef USERNOTIFYMAP::iterator ITERUSERNOTIFYMAP;
  32. class ATL_NO_VTABLE CConnectionManager :
  33. public CComObjectRootEx <CComMultiThreadModel>,
  34. public CComCoClass <CConnectionManager, &CLSID_ConnectionManager>,
  35. public IConnectionPointContainerImpl <CConnectionManager>,
  36. public IConnectionPointImpl<CConnectionManager, &IID_INetConnectionNotifySink>,
  37. #if DBG
  38. public INetConnectionManagerDebug,
  39. #endif
  40. public INetConnectionManager,
  41. public INetConnectionRefresh,
  42. public INetConnectionCMUtil,
  43. public INetConnectionManagerEvents
  44. {
  45. private:
  46. // These static members are used by NotifyClientsOfEvent and
  47. // FinalRelease. Since NotifyClientsOfEvent occurs asynchrounously
  48. // on a different thread, we need to ensure that the instance of this
  49. // object remains around for the lifetime of that call. Therefore,
  50. // FinalRelease will wait until g_fInUse is FALSE. NotifyClientsOfEvent
  51. // sets g_fInUse to TRUE before using g_pConMan. FinalRelease sets
  52. // g_pConMan to NULL before waiting for g_fInUse to become FALSE.
  53. //
  54. // Note: using this method as opposed to AddRefing g_pConMan avoids the
  55. // circular refcount that would keep the service always running because
  56. // it AddRef'd its own object.
  57. //
  58. volatile static CConnectionManager* g_pConMan;
  59. volatile static BOOL g_fInUse;
  60. // m_ClassManagers is an array (STL vector) of pointers to the
  61. // INetConnectionManager interfaces implemented by our registered
  62. // class managers.
  63. //
  64. CLASSMANAGERMAP m_mapClassManagers;
  65. USERNOTIFYMAP m_mapNotify;
  66. LONG m_lRegisteredOneTime;
  67. HDEVNOTIFY m_hDevNotify;
  68. BOOL m_fRegisteredWithWmi;
  69. HANDLE m_hRegNotify;
  70. HANDLE m_hRegNotifyWait;
  71. HKEY m_hRegClassManagerKey;
  72. HRESULT HrEnsureRegisteredOrDeregisteredWithWmi (
  73. BOOL fRegister);
  74. HRESULT HrEnsureClassManagersLoaded ();
  75. public:
  76. CConnectionManager()
  77. {
  78. TraceTag (ttidConman, "New connection manager being created");
  79. AssertH (!g_pConMan);
  80. g_pConMan = this;
  81. m_lRegisteredOneTime = FALSE;
  82. m_hDevNotify = NULL;
  83. m_hRegNotify = NULL;
  84. m_hRegNotifyWait = NULL;
  85. m_hRegClassManagerKey = NULL;
  86. m_fRegisteredWithWmi = FALSE;
  87. }
  88. VOID FinalRelease ();
  89. DECLARE_CLASSFACTORY_DEFERRED_SINGLETON(CConnectionManager)
  90. DECLARE_REGISTRY_RESOURCEID(IDR_CONMAN)
  91. BEGIN_COM_MAP(CConnectionManager)
  92. COM_INTERFACE_ENTRY(INetConnectionManager)
  93. COM_INTERFACE_ENTRY(INetConnectionRefresh)
  94. COM_INTERFACE_ENTRY(INetConnectionCMUtil)
  95. COM_INTERFACE_ENTRY(INetConnectionManagerEvents)
  96. #if DBG
  97. COM_INTERFACE_ENTRY(INetConnectionManagerDebug)
  98. #endif
  99. COM_INTERFACE_ENTRY_IMPL(IConnectionPointContainer)
  100. END_COM_MAP()
  101. BEGIN_CONNECTION_POINT_MAP(CConnectionManager)
  102. CONNECTION_POINT_ENTRY(IID_INetConnectionNotifySink)
  103. END_CONNECTION_POINT_MAP()
  104. // INetConnectionManager
  105. STDMETHOD (EnumConnections) (
  106. NETCONMGR_ENUM_FLAGS Flags,
  107. IEnumNetConnection** ppEnum);
  108. // INetConnectionRefresh
  109. STDMETHOD (RefreshAll) ();
  110. STDMETHOD (ConnectionAdded) (INetConnection* pConnection);
  111. STDMETHOD (ConnectionDeleted) (const GUID* pguidId);
  112. STDMETHOD (ConnectionModified) (INetConnection* pConnection);
  113. STDMETHOD (ConnectionRenamed) (INetConnection* pConnection);
  114. STDMETHOD (ConnectionStatusChanged) (IN const GUID* pguidId, IN const NETCON_STATUS ncs );
  115. STDMETHOD (ShowBalloon) (IN const GUID *pguidId, IN const BSTR szCookie, IN const BSTR szBalloonText);
  116. STDMETHOD (DisableEvents) (IN const BOOL fDisable, IN const ULONG ulDisableTimeout);
  117. // INetConnectionManagerEvents
  118. STDMETHOD (RefreshConnections) ();
  119. STDMETHOD (Enable) ();
  120. STDMETHOD (Disable) (IN ULONG ulDisableTimeout);
  121. // INetConnectionCMUtil
  122. STDMETHOD (MapCMHiddenConnectionToOwner) (
  123. /*[in]*/ REFGUID guidHidden,
  124. /*[out]*/ GUID * pguidOwner);
  125. #if DBG
  126. // INetConnectionManagerDebug
  127. STDMETHOD (NotifyTestStart) ();
  128. STDMETHOD (NotifyTestStop) ();
  129. #endif
  130. // Override Advise so we know when to register for LAN device
  131. // notifications.
  132. //
  133. STDMETHOD (Advise) (
  134. IUnknown* pUnkSink,
  135. DWORD* pdwCookie);
  136. STDMETHOD (Unadvise) (
  137. DWORD dwCookie);
  138. public:
  139. static
  140. BOOL FHasActiveConnectionPoints ();
  141. static
  142. VOID NotifyClientsOfEvent (
  143. CONMAN_EVENT* pEvent);
  144. private:
  145. friend HRESULT GetClientAdvises(LPWSTR** pppszAdviseUsers, LPDWORD pdwCount);
  146. static VOID NTAPI RegChangeNotifyHandler(IN LPVOID pContext, IN BOOLEAN fTimerFired);
  147. };
  148. VOID FreeConmanEvent (CONMAN_EVENT* pEvent);
  149. HRESULT HrGetRasConnectionProperties(
  150. IN const RASENUMENTRYDETAILS* pDetails,
  151. OUT NETCON_PROPERTIES_EX** ppPropsEx);
  152. HRESULT HrGetIncomingConnectionPropertiesEx(
  153. IN const HANDLE hRasConn,
  154. IN const GUID* pguidId,
  155. IN const DWORD dwType,
  156. OUT NETCON_PROPERTIES_EX** ppPropsEx);
  157. HRESULT
  158. GetClientAdvises(LPWSTR** pppszAdviseUsers, LPDWORD pdwCount);