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.

402 lines
8.6 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2000-2001 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // ConnectionInfo.cpp
  7. //
  8. // Description:
  9. // CConnectionInfo implementation.
  10. //
  11. // Maintained By:
  12. // David Potter (DavidP) 14-JUN-2001
  13. // Geoffrey Pease (GPease) 02-FEB-2000
  14. //
  15. //////////////////////////////////////////////////////////////////////////////
  16. #include "pch.h"
  17. #include "ConnectionInfo.h"
  18. DEFINE_THISCLASS("CConnectionInfo")
  19. // ************************************************************************
  20. //
  21. // Constructor / Destructor
  22. //
  23. // ************************************************************************
  24. //////////////////////////////////////////////////////////////////////////////
  25. //
  26. // HRESULT
  27. // CConnectionInfo::S_HrCreateInstance(
  28. // OBJECTCOOKIE cookieParentIn
  29. // )
  30. //
  31. //////////////////////////////////////////////////////////////////////////////
  32. HRESULT
  33. CConnectionInfo::S_HrCreateInstance(
  34. IUnknown ** ppunkOut,
  35. OBJECTCOOKIE cookieParentIn
  36. )
  37. {
  38. TraceFunc1( "ppunkOut, cookieParentIn = %u", cookieParentIn );
  39. HRESULT hr = S_OK;
  40. CConnectionInfo * pci = NULL;
  41. Assert( ppunkOut != NULL );
  42. if ( ppunkOut == NULL )
  43. {
  44. hr = THR( E_POINTER );
  45. goto Cleanup;
  46. }
  47. pci = new CConnectionInfo;
  48. if ( pci == NULL )
  49. {
  50. hr = THR( E_OUTOFMEMORY );
  51. goto Cleanup;
  52. }
  53. hr = THR( pci->HrInit( cookieParentIn ) );
  54. if ( FAILED( hr ) )
  55. {
  56. goto Cleanup;
  57. }
  58. hr = THR( pci->TypeSafeQI( IUnknown, ppunkOut ) );
  59. if ( FAILED( hr ) )
  60. {
  61. goto Cleanup;
  62. }
  63. Cleanup:
  64. if ( pci != NULL )
  65. {
  66. pci->Release();
  67. }
  68. HRETURN( hr );
  69. } //*** CConnectionInfo::S_HrCreateInstance
  70. //////////////////////////////////////////////////////////////////////////////
  71. //
  72. // CConnectionInfo::CConnectionInfo
  73. //
  74. //////////////////////////////////////////////////////////////////////////////
  75. CConnectionInfo::CConnectionInfo( void )
  76. : m_cRef( 1 )
  77. {
  78. TraceFunc( "" );
  79. InterlockedIncrement( &g_cObjects );
  80. TraceFuncExit();
  81. } //*** CConnectionInfo::CConnectionInfo
  82. //////////////////////////////////////////////////////////////////////////////
  83. //
  84. // STDMETHODIMP
  85. // CConnectionInfo::HrInit(
  86. // OBJECTCOOKIE cookieParentIn
  87. // )
  88. //
  89. //////////////////////////////////////////////////////////////////////////////
  90. STDMETHODIMP
  91. CConnectionInfo::HrInit(
  92. OBJECTCOOKIE cookieParentIn
  93. )
  94. {
  95. TraceFunc( "" );
  96. HRESULT hr = S_OK;
  97. // IUnknown stuff
  98. Assert( m_cRef == 1 );
  99. // IConnectionInfo
  100. Assert( m_pcc == NULL );
  101. m_cookieParent = cookieParentIn;
  102. HRETURN( hr );
  103. } //*** CConnectionInfo::HrInit
  104. //////////////////////////////////////////////////////////////////////////////
  105. //
  106. // CConnectionInfo::~CConnectionInfo
  107. //
  108. //////////////////////////////////////////////////////////////////////////////
  109. CConnectionInfo::~CConnectionInfo( void )
  110. {
  111. TraceFunc( "" );
  112. if ( m_pcc != NULL )
  113. {
  114. m_pcc->Release();
  115. } // if:
  116. InterlockedDecrement( &g_cObjects );
  117. TraceFuncExit();
  118. } //*** CConnectionInfo::~CConnectionInfo
  119. // ************************************************************************
  120. //
  121. // IUnknown
  122. //
  123. // ************************************************************************
  124. //////////////////////////////////////////////////////////////////////////////
  125. //++
  126. //
  127. // CConnectionInfo::QueryInterface
  128. //
  129. // Description:
  130. // Query this object for the passed in interface.
  131. //
  132. // Arguments:
  133. // riidIn
  134. // Id of interface requested.
  135. //
  136. // ppvOut
  137. // Pointer to the requested interface.
  138. //
  139. // Return Value:
  140. // S_OK
  141. // If the interface is available on this object.
  142. //
  143. // E_NOINTERFACE
  144. // If the interface is not available.
  145. //
  146. // E_POINTER
  147. // ppvOut was NULL.
  148. //
  149. // Remarks:
  150. // None.
  151. //
  152. //--
  153. //////////////////////////////////////////////////////////////////////////////
  154. STDMETHODIMP
  155. CConnectionInfo::QueryInterface(
  156. REFIID riidin
  157. , LPVOID * ppvOut
  158. )
  159. {
  160. TraceQIFunc( riidin, ppvOut );
  161. HRESULT hr = S_OK;
  162. //
  163. // Validate arguments.
  164. //
  165. Assert( ppvOut != NULL );
  166. if ( ppvOut == NULL )
  167. {
  168. hr = THR( E_POINTER );
  169. goto Cleanup;
  170. }
  171. //
  172. // Handle known interfaces.
  173. //
  174. if ( IsEqualIID( riidin, IID_IUnknown ) )
  175. {
  176. *ppvOut = static_cast< IConnectionInfo * >( this );
  177. } // if: IUnknown
  178. else if ( IsEqualIID( riidin, IID_IConnectionInfo ) )
  179. {
  180. *ppvOut = TraceInterface( __THISCLASS__, IConnectionInfo, this, 0 );
  181. } // else if: IConnectionInfo
  182. else
  183. {
  184. *ppvOut = NULL;
  185. hr = E_NOINTERFACE;
  186. } // else
  187. //
  188. // Add a reference to the interface if successful.
  189. //
  190. if ( SUCCEEDED( hr ) )
  191. {
  192. ((IUnknown *) *ppvOut)->AddRef();
  193. } // if: success
  194. Cleanup:
  195. QIRETURN_IGNORESTDMARSHALLING( hr, riidin );
  196. } //*** CConnectionInfo::QueryInterface
  197. //////////////////////////////////////////////////////////////////////////////
  198. //
  199. // STDMETHODIMP_(ULONG)
  200. // CConnectionInfo::AddRef
  201. //
  202. //////////////////////////////////////////////////////////////////////////////
  203. STDMETHODIMP_( ULONG )
  204. CConnectionInfo::AddRef( void )
  205. {
  206. TraceFunc( "[IUnknown]" );
  207. InterlockedIncrement( &m_cRef );
  208. CRETURN( m_cRef );
  209. } //*** CConnectionInfo::AddRef
  210. //////////////////////////////////////////////////////////////////////////////
  211. //
  212. // STDMETHODIMP_(ULONG)
  213. // CConnectionInfo::Release
  214. //
  215. //////////////////////////////////////////////////////////////////////////////
  216. STDMETHODIMP_( ULONG )
  217. CConnectionInfo::Release( void )
  218. {
  219. TraceFunc( "[IUnknown]" );
  220. LONG cRef;
  221. cRef = InterlockedDecrement( &m_cRef );
  222. if ( cRef == 0 )
  223. {
  224. TraceDo( delete this );
  225. }
  226. CRETURN( cRef );
  227. } //*** CConnectionInfo::Release
  228. //****************************************************************************
  229. //
  230. // IConnectionInfo
  231. //
  232. //****************************************************************************
  233. //////////////////////////////////////////////////////////////////////////////
  234. //
  235. // STDMETHODIMP
  236. // CConnectionInfo::GetConnection(
  237. // IConfigurationConnection ** pccOut
  238. // )
  239. //
  240. //////////////////////////////////////////////////////////////////////////////
  241. STDMETHODIMP
  242. CConnectionInfo::GetConnection(
  243. IConfigurationConnection ** pccOut
  244. )
  245. {
  246. TraceFunc( "[IConnectionInfo]" );
  247. Assert( pccOut != NULL );
  248. HRESULT hr = S_OK;
  249. if ( pccOut == NULL )
  250. {
  251. hr = THR( E_POINTER );
  252. goto Cleanup;
  253. } // if:
  254. if ( m_pcc == NULL )
  255. {
  256. *pccOut = NULL;
  257. hr = S_FALSE;
  258. }
  259. else
  260. {
  261. *pccOut = m_pcc;
  262. (*pccOut)->AddRef();
  263. }
  264. Cleanup:
  265. HRETURN( hr );
  266. } //*** CConnectionInfo::GetConnection
  267. //////////////////////////////////////////////////////////////////////////////
  268. //
  269. // STDMETHODIMP
  270. // CConnectionInfo::SetConnection(
  271. // IConfigurationConnection * pccIn
  272. // )
  273. //
  274. //////////////////////////////////////////////////////////////////////////////
  275. STDMETHODIMP
  276. CConnectionInfo::SetConnection(
  277. IConfigurationConnection * pccIn
  278. )
  279. {
  280. TraceFunc( "[IConnectionInfo]" );
  281. HRESULT hr = S_OK;
  282. if ( m_pcc != NULL )
  283. {
  284. m_pcc->Release();
  285. m_pcc = NULL;
  286. }
  287. m_pcc = pccIn;
  288. if ( m_pcc != NULL )
  289. {
  290. m_pcc->AddRef();
  291. }
  292. HRETURN( hr );
  293. } //*** CConnectionInfo::SetConnection
  294. //////////////////////////////////////////////////////////////////////////////
  295. //
  296. // STDMETHODIMP
  297. // CConnectionInfo::GetParent(
  298. // OBJECTCOOKIE * pcookieOut
  299. // )
  300. //
  301. //////////////////////////////////////////////////////////////////////////////
  302. STDMETHODIMP
  303. CConnectionInfo::GetParent(
  304. OBJECTCOOKIE * pcookieOut
  305. )
  306. {
  307. TraceFunc( "[IConnectionInfo]" );
  308. HRESULT hr = S_OK;
  309. if ( pcookieOut == NULL )
  310. goto InvalidPointer;
  311. Assert( m_cookieParent != NULL );
  312. *pcookieOut = m_cookieParent;
  313. if ( m_cookieParent == NULL )
  314. {
  315. hr = S_FALSE;
  316. }
  317. Cleanup:
  318. HRETURN( hr );
  319. InvalidPointer:
  320. hr = THR( E_INVALIDARG );
  321. goto Cleanup;
  322. } //*** CConnectionInfo::GetParent