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.

319 lines
8.1 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1999.
  5. //
  6. // File: I N E T C F G . H
  7. //
  8. // Contents: Implements the COM interfaces on the top-level NetCfg object.
  9. // These interfaces are: INetCfg and INetCfgLock. Also
  10. // implements a base C++ class inherited by sub-level NetCfg
  11. // objects which hold a reference to the top-level object.
  12. //
  13. // Notes:
  14. //
  15. // Author: shaunco 15 Jan 1999
  16. //
  17. //----------------------------------------------------------------------------
  18. #pragma once
  19. #include "iatl.h"
  20. #include "compdefs.h"
  21. #include "nccom.h"
  22. #include "ncres.h"
  23. #include "netcfgp.h"
  24. #include "netcfgn.h"
  25. #include "wrlock.h"
  26. // Flags for HrIsValidInterface.
  27. //
  28. enum IF_FLAGS
  29. {
  30. IF_DEFAULT = 0x00000000,
  31. IF_NEED_UNINITIALIZED = 0x00000001,
  32. IF_NEED_WRITE_LOCK = 0x00000002,
  33. IF_NEED_COMPONENT_DATA = 0x00000004,
  34. IF_REFUSE_REENTRANCY = 0x00000010,
  35. IF_ALLOW_INSTALL_OR_REMOVE = 0x00000020,
  36. IF_UNINITIALIZING = 0x00000040,
  37. IF_DONT_PREPARE_MODIFY_CONTEXT = 0x00000080,
  38. };
  39. enum RPL_FLAGS
  40. {
  41. RPL_ALLOW_INSTALL_REMOVE,
  42. RPL_DISALLOW,
  43. };
  44. class CNetConfig;
  45. class ATL_NO_VTABLE CImplINetCfg :
  46. public CComObjectRootEx <CComMultiThreadModel>,
  47. public CComCoClass<CImplINetCfg, &CLSID_CNetCfg>,
  48. public INetCfg,
  49. public INetCfgLock,
  50. public INetCfgInternalSetup,
  51. public INetCfgSpecialCase,
  52. public INetCfgPnpReconfigCallback
  53. {
  54. friend class CGlobalNotifyInterface;
  55. friend class CImplIEnumNetCfgBindingPath;
  56. friend class CImplIEnumNetCfgComponent;
  57. friend class CImplINetCfgBindingPath;
  58. friend class CImplINetCfgClass;
  59. friend class CImplINetCfgComponent;
  60. friend class CModifyContext;
  61. friend class CNetCfgInternalDiagnostic;
  62. friend class CNetConfig;
  63. friend class CNotifyObjectInterface;
  64. private:
  65. // This is our data. We own it (i.e. we created it) if Initialize is
  66. // called. We will delete it when Unintialize is called. We won't own
  67. // it if we were created by CNetConfig.
  68. //
  69. CNetConfig* m_pNetConfig;
  70. // m_apINetCfgClass is an array of cached INetCfgClass pointers.
  71. // These are created in QueryNetCfgClass (if needed) and released
  72. // during Uninitialize.
  73. //
  74. INetCfgClass* m_apINetCfgClass [NC_CELEMS];
  75. // This controls the write lock.
  76. //
  77. CWriteLock m_WriteLock;
  78. // Reentrancy Protection Levels. General reentrancy is prevented when
  79. // m_CurrentRpl is non-zero. Reentrancy for setup calls (Install or
  80. // Remove) is allowed when m_LastAllowedSetupRpl equals m_CurrentRpl.
  81. // Both are incremented when we call a notify object and we want to
  82. // prevent general reentrancy but allow Install or Remove. Only
  83. // m_CurrentRpl is incremented when we want to prevent all reentrancy.
  84. // See LowerRpl() and RaiseRpl().
  85. //
  86. ULONG m_CurrentRpl;
  87. ULONG m_LastAllowedSetupRpl;
  88. BOOLEAN m_fOwnNetConfig;
  89. private:
  90. HRESULT
  91. HrCheckForReentrancy (
  92. IN DWORD dwFlags);
  93. HRESULT
  94. HrLockAndTestForValidInterface (
  95. IN DWORD dwFlags);
  96. VOID
  97. LowerRpl (
  98. IN RPL_FLAGS Flags);
  99. VOID
  100. RaiseRpl (
  101. IN RPL_FLAGS Flags);
  102. public:
  103. CImplINetCfg ()
  104. {
  105. m_pNetConfig = NULL;
  106. m_CurrentRpl = 0;
  107. m_LastAllowedSetupRpl = 0;
  108. m_fOwnNetConfig = FALSE;
  109. ZeroMemory (m_apINetCfgClass, sizeof(m_apINetCfgClass));
  110. }
  111. VOID FinalRelease ()
  112. {
  113. // Should be NULL because we either delete it during Uninitialize,
  114. // or it is NULL'd for us via CGlobalNotifyInterface::ReleaseINetCfg
  115. // before they release us.
  116. //
  117. AssertH (!m_pNetConfig);
  118. // Release our cache of INetCfgClass pointers.
  119. //
  120. ReleaseIUnknownArray (celems(m_apINetCfgClass), (IUnknown**)m_apINetCfgClass);
  121. }
  122. HRESULT HrCoCreateWrapper (
  123. IN REFCLSID rclsid,
  124. IN LPUNKNOWN pUnkOuter,
  125. IN DWORD dwClsContext,
  126. IN REFIID riid,
  127. OUT LPVOID FAR* ppv);
  128. HRESULT HrIsValidInterface (
  129. DWORD dwFlags);
  130. BEGIN_COM_MAP(CImplINetCfg)
  131. COM_INTERFACE_ENTRY(INetCfg)
  132. COM_INTERFACE_ENTRY(INetCfgLock)
  133. COM_INTERFACE_ENTRY(INetCfgInternalSetup)
  134. COM_INTERFACE_ENTRY(INetCfgSpecialCase)
  135. COM_INTERFACE_ENTRY(INetCfgPnpReconfigCallback)
  136. END_COM_MAP()
  137. DECLARE_REGISTRY_RESOURCEID(IDR_REG_NETCFG)
  138. // INetCfg
  139. //
  140. STDMETHOD (Initialize) (
  141. IN PVOID pvReserved);
  142. STDMETHOD (Uninitialize) ();
  143. STDMETHOD (Validate) ();
  144. STDMETHOD (Cancel) ();
  145. STDMETHOD (Apply) ();
  146. STDMETHOD (EnumComponents) (
  147. IN const GUID* pguidClass OPTIONAL,
  148. OUT IEnumNetCfgComponent** ppIEnum);
  149. STDMETHOD (FindComponent) (
  150. IN PCWSTR pszInfId,
  151. OUT INetCfgComponent** ppIComp);
  152. STDMETHOD (QueryNetCfgClass) (
  153. IN const GUID* pguidClass,
  154. IN REFIID riid,
  155. OUT VOID** ppv);
  156. // INetCfgLock
  157. //
  158. STDMETHOD (AcquireWriteLock) (
  159. IN DWORD cmsTimeout,
  160. IN PCWSTR pszClientDescription,
  161. OUT PWSTR* ppszClientDescription);
  162. STDMETHOD (ReleaseWriteLock) ();
  163. STDMETHOD (IsWriteLocked) (
  164. OUT PWSTR* ppszClientDescription);
  165. // INetCfgInternalSetup
  166. //
  167. STDMETHOD (BeginBatchOperation) ();
  168. STDMETHOD (CommitBatchOperation) ();
  169. STDMETHOD (SelectWithFilterAndInstall) (
  170. IN HWND hwndParent,
  171. IN const GUID* pClassGuid,
  172. IN OBO_TOKEN* pOboToken,
  173. IN const CI_FILTER_INFO* pcfi,
  174. OUT INetCfgComponent** ppnccItem);
  175. STDMETHOD (EnumeratedComponentInstalled) (
  176. IN PVOID pComponent /* type of CComponent */);
  177. STDMETHOD (EnumeratedComponentUpdated) (
  178. IN PCWSTR pszPnpId);
  179. STDMETHOD (UpdateNonEnumeratedComponent) (
  180. IN INetCfgComponent* pIComp,
  181. IN DWORD dwSetupFlags,
  182. IN DWORD dwUpgradeFromBuildNo);
  183. STDMETHOD (EnumeratedComponentRemoved) (
  184. IN PCWSTR pszPnpId);
  185. // INetCfgSpecialCase
  186. //
  187. STDMETHOD (GetAdapterOrder) (
  188. OUT DWORD* pcAdapters,
  189. OUT INetCfgComponent*** papAdapters,
  190. OUT BOOL* pfWanAdaptersFirst);
  191. STDMETHOD (SetAdapterOrder) (
  192. IN DWORD cAdapters,
  193. IN INetCfgComponent** apAdapters,
  194. IN BOOL fWanAdaptersFirst);
  195. STDMETHOD (GetWanAdaptersFirst) (
  196. OUT BOOL* pfWanAdaptersFirst);
  197. STDMETHOD (SetWanAdaptersFirst) (
  198. IN BOOL fWanAdaptersFirst);
  199. // INetCfgPnpReconfigCallback
  200. //
  201. STDMETHOD (SendPnpReconfig) (
  202. IN NCPNP_RECONFIG_LAYER Layer,
  203. IN PCWSTR pszUpper,
  204. IN PCWSTR pszLower,
  205. IN PVOID pvData,
  206. IN DWORD dwSizeOfData);
  207. static HRESULT
  208. HrCreateInstance (
  209. CNetConfig* pNetConfig,
  210. CImplINetCfg** ppINetCfg);
  211. };
  212. //+---------------------------------------------------------------------------
  213. // CImplINetCfgHolder -
  214. //
  215. // No need for a critical section for these objects because they
  216. // use the lock provided by CImplINetCfg. i.e. use CComMultiThreadModelNoCS
  217. // instead of CComMultiThreadModel.
  218. //
  219. class ATL_NO_VTABLE CImplINetCfgHolder :
  220. public CComObjectRootEx <CComMultiThreadModelNoCS>
  221. {
  222. protected:
  223. CImplINetCfg* m_pINetCfg;
  224. protected:
  225. VOID HoldINetCfg (
  226. CImplINetCfg* pINetCfg);
  227. HRESULT HrLockAndTestForValidInterface (
  228. DWORD dwFlags);
  229. public:
  230. CImplINetCfgHolder ()
  231. {
  232. m_pINetCfg = NULL;
  233. }
  234. #if DBG
  235. ~CImplINetCfgHolder ()
  236. {
  237. AssertH (!m_pINetCfg);
  238. }
  239. #endif // DBG
  240. VOID FinalRelease ()
  241. {
  242. AssertH (m_pINetCfg);
  243. ReleaseObj (m_pINetCfg->GetUnknown());
  244. #if DBG
  245. m_pINetCfg = NULL;
  246. #endif // DBG
  247. CComObjectRootEx <CComMultiThreadModelNoCS>::FinalRelease();
  248. }
  249. VOID Lock ()
  250. {
  251. CComObjectRootEx <CComMultiThreadModelNoCS>::Lock();
  252. AssertH(m_pINetCfg);
  253. m_pINetCfg->Lock ();
  254. }
  255. VOID Unlock ()
  256. {
  257. AssertH(m_pINetCfg);
  258. m_pINetCfg->Unlock ();
  259. CComObjectRootEx <CComMultiThreadModelNoCS>::Unlock();
  260. }
  261. };