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.

185 lines
6.3 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 "map"
  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 (IN BOOL fRegister);
  73. HRESULT HrEnsureClassManagersLoaded ();
  74. public:
  75. CConnectionManager() throw()
  76. {
  77. TraceTag (ttidConman, "New connection manager being created");
  78. AssertH (!g_pConMan);
  79. g_pConMan = this;
  80. m_lRegisteredOneTime = FALSE;
  81. m_hDevNotify = NULL;
  82. m_hRegNotify = NULL;
  83. m_hRegNotifyWait = NULL;
  84. m_hRegClassManagerKey = NULL;
  85. m_fRegisteredWithWmi = FALSE;
  86. }
  87. VOID FinalRelease () throw();
  88. DECLARE_CLASSFACTORY_DEFERRED_SINGLETON(CConnectionManager)
  89. DECLARE_REGISTRY_RESOURCEID(IDR_CONMAN)
  90. BEGIN_COM_MAP(CConnectionManager)
  91. COM_INTERFACE_ENTRY(INetConnectionManager)
  92. COM_INTERFACE_ENTRY(INetConnectionRefresh)
  93. COM_INTERFACE_ENTRY(INetConnectionCMUtil)
  94. COM_INTERFACE_ENTRY(INetConnectionManagerEvents)
  95. #if DBG
  96. COM_INTERFACE_ENTRY(INetConnectionManagerDebug)
  97. #endif
  98. COM_INTERFACE_ENTRY_IMPL(IConnectionPointContainer)
  99. END_COM_MAP()
  100. BEGIN_CONNECTION_POINT_MAP(CConnectionManager)
  101. CONNECTION_POINT_ENTRY(IID_INetConnectionNotifySink)
  102. END_CONNECTION_POINT_MAP()
  103. // INetConnectionManager
  104. STDMETHOD (EnumConnections) (
  105. IN NETCONMGR_ENUM_FLAGS Flags,
  106. OUT IEnumNetConnection** ppEnum);
  107. // INetConnectionRefresh
  108. STDMETHOD (RefreshAll) ();
  109. STDMETHOD (ConnectionAdded) (IN INetConnection* pConnection);
  110. STDMETHOD (ConnectionDeleted) (IN const GUID* pguidId);
  111. STDMETHOD (ConnectionModified) (IN INetConnection* pConnection);
  112. STDMETHOD (ConnectionRenamed) (IN INetConnection* pConnection);
  113. STDMETHOD (ConnectionStatusChanged) (IN const GUID* pguidId, IN const NETCON_STATUS ncs );
  114. STDMETHOD (ShowBalloon) (IN const GUID *pguidId, IN const BSTR szCookie, IN const BSTR szBalloonText);
  115. STDMETHOD (DisableEvents) (IN const BOOL fDisable, IN const ULONG ulDisableTimeout);
  116. // INetConnectionManagerEvents
  117. STDMETHOD (RefreshConnections) ();
  118. STDMETHOD (Enable) ();
  119. STDMETHOD (Disable) (IN ULONG ulDisableTimeout);
  120. // INetConnectionCMUtil
  121. STDMETHOD (MapCMHiddenConnectionToOwner) (
  122. /*[in]*/ REFGUID guidHidden,
  123. /*[out]*/ GUID * pguidOwner);
  124. #if DBG
  125. // INetConnectionManagerDebug
  126. STDMETHOD (NotifyTestStart) ();
  127. STDMETHOD (NotifyTestStop) ();
  128. #endif
  129. // Override Advise so we know when to register for LAN device
  130. // notifications.
  131. //
  132. STDMETHOD (Advise) (
  133. IUnknown* pUnkSink,
  134. DWORD* pdwCookie);
  135. STDMETHOD (Unadvise) (
  136. DWORD dwCookie);
  137. public:
  138. static
  139. BOOL FHasActiveConnectionPoints () throw();
  140. static
  141. VOID NotifyClientsOfEvent (
  142. IN const CONMAN_EVENT* pEvent) throw();
  143. private:
  144. friend HRESULT GetClientAdvises(OUT LPWSTR** pppszAdviseUsers, OUT LPDWORD pdwCount);
  145. static VOID NTAPI RegChangeNotifyHandler(IN OUT LPVOID pContext, IN BOOLEAN fTimerFired) throw();
  146. };
  147. VOID FreeConmanEvent (IN TAKEOWNERSHIP CONMAN_EVENT* pEvent) throw();
  148. HRESULT HrGetRasConnectionProperties(
  149. IN const RASENUMENTRYDETAILS* pDetails,
  150. OUT NETCON_PROPERTIES_EX** ppPropsEx);
  151. HRESULT HrGetIncomingConnectionPropertiesEx(
  152. IN const HANDLE hRasConn,
  153. IN const GUID* pguidId,
  154. IN const DWORD dwType,
  155. OUT NETCON_PROPERTIES_EX** ppPropsEx);
  156. HRESULT
  157. GetClientAdvises(OUT LPWSTR** pppszAdviseUsers, OUT LPDWORD pdwCount);