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.

237 lines
6.3 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1999.
  5. //
  6. // File: C O M P . H
  7. //
  8. // Contents: The basic datatype for a network component.
  9. //
  10. // Notes:
  11. //
  12. // Author: shaunco 15 Jan 1999
  13. //
  14. //----------------------------------------------------------------------------
  15. #pragma once
  16. #include "compdefs.h"
  17. #include "comprefs.h"
  18. #include "ecomp.h"
  19. #include "ncstring.h"
  20. #include "netcfgx.h"
  21. #include "notify.h"
  22. // Flags used when creating a CComponent instance.
  23. //
  24. enum CCI_FLAGS
  25. {
  26. CCI_DEFAULT = 0x00000000,
  27. CCI_ENSURE_EXTERNAL_DATA_LOADED = 0x00000001,
  28. };
  29. class CComponent : public CNetCfgDebug<CComponent>
  30. {
  31. friend class CExternalComponentData;
  32. friend class CImplINetCfgComponent;
  33. public:
  34. // The instance guid of the component. Assigned by the class installer
  35. // when the component is installed. The instance guid of a component
  36. // can NEVER change once it is installed.
  37. //
  38. GUID m_InstanceGuid;
  39. private:
  40. // The class of the component. It is private so that folks are forced
  41. // to use the Class() access method which asserts that the value is
  42. // in an allowable range. The class for a component can NEVER change
  43. // once it is installed.
  44. //
  45. NETCLASS m_Class;
  46. // Member to store the handle to the inf file of this component.
  47. // This is used to avoid the expense of opening the inf file more than
  48. // once over the lifetime of the component.
  49. //
  50. mutable HINF m_hinf;
  51. public:
  52. // The characteristics of the component. A combination of NCF_
  53. // flags defined in netcfgx.idl. The characteristics of a component
  54. // can NEVER change once it is installed.
  55. //
  56. DWORD m_dwCharacter;
  57. // The INF ID of the component. e.g. ms_tcpip. The INF ID of a component
  58. // can NEVER change once it is installed.
  59. //
  60. PCWSTR m_pszInfId;
  61. // The PnP Instance ID of the component. This is only
  62. // valid for components that are considered of class NET. It can
  63. // NEVER change once the component is installed.
  64. //
  65. PCWSTR m_pszPnpId;
  66. // This is the interface to the component's external data. External data
  67. // is under the instance key.
  68. //
  69. CExternalComponentData Ext;
  70. // This is the interface to the component's optional notify object.
  71. //
  72. CNotifyObjectInterface Notify;
  73. // This is the interface to the component's references. i.e. who
  74. // has installed this component.
  75. //
  76. CComponentReferences Refs;
  77. // This is a cached copy (addref'd) of this component's
  78. // INetCfgComponent interface. It is created via
  79. // HrGetINetCfgComponentInterface on the first call.
  80. //
  81. class CImplINetCfgComponent* m_pIComp;
  82. // Valid for NCF_FILTER components only. This is the
  83. // ordinal position that this filter gets within the range of
  84. // filter classes. See filtdevs.h for more info.
  85. //
  86. DWORD m_dwFilterClassOrdinal;
  87. // Valid for enumerated components only. This is the
  88. // SP_DEVINSTALL_PARAMS.Flags value the class installer was told to
  89. // use when installing the device. We need to honor this when starting
  90. // it.
  91. //
  92. DWORD m_dwDeipFlags;
  93. // When removing non-enumerated components, this string will hold
  94. // the name of the remove section valid in this component's INF.
  95. // We need to process this remove section (for delete files) after
  96. // we release the notify object so that the component has a chance to
  97. // properly delete the notify object dll.
  98. //
  99. tstring m_strRemoveSection;
  100. private:
  101. // Declare all constructors private so that no one except
  102. // HrCreateInstance can create instances of this class.
  103. //
  104. CComponent() {}
  105. public:
  106. ~CComponent();
  107. NETCLASS
  108. Class() const
  109. {
  110. AssertH (FIsValidNetClass(m_Class));
  111. return m_Class;
  112. }
  113. BOOL
  114. FCanDirectlyBindToFilter(
  115. IN const WCHAR* const pszFilterMediaTypes,
  116. IN const WCHAR* const pszLowerExclude ) const;
  117. BOOL
  118. FCanDirectlyBindTo (
  119. IN const CComponent* pLower,
  120. OUT const WCHAR** ppStart,
  121. OUT ULONG* pcch) const;
  122. BOOL
  123. FHasService() const
  124. {
  125. return (Ext.PszService()) ? TRUE : FALSE;
  126. }
  127. BOOL
  128. FIsBindable () const;
  129. BOOL
  130. FIsFilter () const
  131. {
  132. return m_dwCharacter & NCF_FILTER;
  133. }
  134. BOOL
  135. FIsWanAdapter () const;
  136. HINF
  137. GetCachedInfFile () const
  138. {
  139. return m_hinf;
  140. }
  141. HRESULT
  142. HrOpenInfFile (OUT HINF* phinf) const;
  143. void
  144. CloseInfFile () const
  145. {
  146. Assert(m_hinf);
  147. SetupCloseInfFile (m_hinf);
  148. m_hinf = NULL;
  149. }
  150. static
  151. HRESULT
  152. HrCreateInstance (
  153. IN const BASIC_COMPONENT_DATA* pData,
  154. IN DWORD dwFlags /* CCI_FLAGS */,
  155. IN const OBO_TOKEN* pOboToken, OPTIONAL
  156. OUT CComponent** ppComponent);
  157. HRESULT
  158. HrGetINetCfgComponentInterface (
  159. IN class CImplINetCfg* pINetCfg,
  160. OUT INetCfgComponent** ppIComp);
  161. INetCfgComponent*
  162. GetINetCfgComponentInterface () const;
  163. VOID
  164. ReleaseINetCfgComponentInterface ();
  165. HRESULT
  166. HrOpenDeviceInfo (
  167. OUT HDEVINFO* phdiOut,
  168. OUT SP_DEVINFO_DATA* pdeidOut) const;
  169. HRESULT
  170. HrOpenInstanceKey (
  171. IN REGSAM samDesired,
  172. OUT HKEY* phkey,
  173. OUT HDEVINFO* phdiOut OPTIONAL,
  174. OUT SP_DEVINFO_DATA* pdeidOut OPTIONAL) const;
  175. HRESULT
  176. HrOpenServiceKey (
  177. IN REGSAM samDesired,
  178. OUT HKEY* phkey) const;
  179. HRESULT
  180. HrStartOrStopEnumeratedComponent (
  181. IN DWORD dwFlag /* DICS_START or DICS_STOP */) const;
  182. PCWSTR
  183. PszGetPnpIdOrInfId () const
  184. {
  185. AssertH (FIsValidNetClass(m_Class));
  186. AssertH (FImplies(FIsEnumerated(m_Class),
  187. m_pszPnpId && *m_pszPnpId));
  188. if (!m_pszPnpId)
  189. {
  190. AssertH (m_pszInfId && *m_pszInfId);
  191. return m_pszInfId;
  192. }
  193. AssertH (m_pszPnpId && *m_pszPnpId);
  194. return m_pszPnpId;
  195. }
  196. };