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.

316 lines
6.6 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1999-2000 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // CHandleProvider.h
  7. //
  8. // Description:
  9. // HandleProvider implementation.
  10. //
  11. // Maintained By:
  12. //
  13. //////////////////////////////////////////////////////////////////////////////
  14. #include "pch.h"
  15. #include "CHandleProvider.h"
  16. DEFINE_THISCLASS("CHandleProvider")
  17. // ************************************************************************
  18. //
  19. // Constructor / Destructor
  20. //
  21. // ************************************************************************
  22. //////////////////////////////////////////////////////////////////////////////
  23. //++
  24. //
  25. // HRESULT
  26. // CHandleProvider ::S_HrCreateInstance(
  27. // IUnknown ** ppunkOut
  28. // )
  29. //
  30. //--
  31. //////////////////////////////////////////////////////////////////////////////
  32. HRESULT
  33. CHandleProvider::S_HrCreateInstance(
  34. IUnknown ** ppunkOut
  35. )
  36. {
  37. TraceFunc( "" );
  38. Assert( ppunkOut != NULL );
  39. HRESULT hr;
  40. CHandleProvider * pcc = new CHandleProvider ;
  41. if ( pcc != NULL )
  42. {
  43. hr = THR( pcc->Init( ) );
  44. if ( SUCCEEDED( hr ) )
  45. {
  46. hr = THR( pcc->TypeSafeQI( IUnknown, ppunkOut ) );
  47. }
  48. pcc->Release( );
  49. }
  50. else
  51. {
  52. hr = THR( E_OUTOFMEMORY );
  53. }
  54. HRETURN( hr );
  55. } //*** CHandleProvider::S_HrCreateInstance( )
  56. //////////////////////////////////////////////////////////////////////////////
  57. //++
  58. //
  59. // CHandleProvider::CHandleProvider( void )
  60. //
  61. //--
  62. //////////////////////////////////////////////////////////////////////////////
  63. CHandleProvider::CHandleProvider ( void )
  64. {
  65. TraceFunc( "" );
  66. InterlockedIncrement( &g_cObjects );
  67. TraceFuncExit();
  68. } //*** CHandleProvider::CHandleProvider ( )
  69. //////////////////////////////////////////////////////////////////////////////
  70. //++
  71. //
  72. // CHandleProvider ::~CHandleProvider( void )
  73. //
  74. //--
  75. //////////////////////////////////////////////////////////////////////////////
  76. CHandleProvider::~CHandleProvider( void )
  77. {
  78. TraceFunc( "" );
  79. TraceSysFreeString( m_bstrClusterName );
  80. if( m_hCluster != NULL )
  81. {
  82. CloseCluster( m_hCluster );
  83. }
  84. InterlockedDecrement( &g_cObjects );
  85. TraceFuncExit();
  86. } //*** CHandleProvider::~CHandleProvider ( )
  87. //////////////////////////////////////////////////////////////////////////////
  88. //++
  89. //
  90. // STDMETHODIMP
  91. // CHandleProvider::Init( void )
  92. //
  93. //--
  94. //////////////////////////////////////////////////////////////////////////////
  95. STDMETHODIMP
  96. CHandleProvider::Init( void )
  97. {
  98. TraceFunc( "" );
  99. HRESULT hr = S_OK;
  100. // IUnknown stuff
  101. Assert( m_cRef == 0 );
  102. AddRef( ); // Add one count
  103. // IClusterHandleProvider
  104. Assert( m_bstrClusterName == NULL );
  105. Assert( m_hCluster == NULL );
  106. HRETURN( hr );
  107. } //*** CHandleProvider ::Init( )
  108. // ************************************************************************
  109. //
  110. // IUnknown
  111. //
  112. // ************************************************************************
  113. //////////////////////////////////////////////////////////////////////////////
  114. //++
  115. //
  116. // STDMETHODIMP
  117. // CHandleProvider ::QueryInterface(
  118. // REFIID riidIn,
  119. // LPVOID * ppvOut
  120. // )
  121. //
  122. //--
  123. //////////////////////////////////////////////////////////////////////////////
  124. STDMETHODIMP
  125. CHandleProvider::QueryInterface(
  126. REFIID riidIn,
  127. LPVOID * ppvOut
  128. )
  129. {
  130. TraceQIFunc( riidIn, ppvOut );
  131. HRESULT hr = E_NOINTERFACE;
  132. if ( IsEqualIID( riidIn, IID_IUnknown ) )
  133. {
  134. *ppvOut = static_cast< IClusterHandleProvider * >( this );
  135. hr = S_OK;
  136. } // if: IUnknown
  137. else if ( IsEqualIID( riidIn, IID_IClusterHandleProvider ) )
  138. {
  139. *ppvOut = TraceInterface( __THISCLASS__, IClusterHandleProvider, this, 0 );
  140. hr = S_OK;
  141. } // else if: IClusterHandleProvider
  142. if ( SUCCEEDED( hr ) )
  143. {
  144. ((IUnknown*) *ppvOut)->AddRef( );
  145. } // if: success
  146. QIRETURN_IGNORESTDMARSHALLING( hr, riidIn );
  147. } //*** CHandleProvider ::QueryInterface( )
  148. //////////////////////////////////////////////////////////////////////////////
  149. //++
  150. //
  151. // STDMETHODIMP_( ULONG )
  152. // CHandleProvider ::AddRef( void )
  153. //
  154. //--
  155. //////////////////////////////////////////////////////////////////////////////
  156. STDMETHODIMP_( ULONG )
  157. CHandleProvider::AddRef( void )
  158. {
  159. TraceFunc( "[IUnknown]" );
  160. InterlockedIncrement( &m_cRef );
  161. RETURN( m_cRef );
  162. } //*** CHandleProvider ::AddRef( )
  163. //////////////////////////////////////////////////////////////////////////////
  164. //++
  165. //
  166. // STDMETHODIMP_( ULONG )
  167. // CHandleProvider ::Release( void )
  168. //
  169. //--
  170. //////////////////////////////////////////////////////////////////////////////
  171. STDMETHODIMP_( ULONG )
  172. CHandleProvider::Release( void )
  173. {
  174. TraceFunc( "[IUnknown]" );
  175. InterlockedDecrement( &m_cRef );
  176. if ( m_cRef )
  177. RETURN( m_cRef );
  178. TraceDo( delete this );
  179. RETURN(0);
  180. } //*** CHandleProvider ::Release( )
  181. // ************************************************************************
  182. //
  183. // IClusterHandleProvider
  184. //
  185. // ************************************************************************
  186. //////////////////////////////////////////////////////////////////////////////
  187. //++
  188. //
  189. // STDMETHODIMP
  190. // CHandleProvider::OpenCluster(
  191. // bstrClusterName
  192. // )
  193. //
  194. //--
  195. //////////////////////////////////////////////////////////////////////////////
  196. STDMETHODIMP
  197. CHandleProvider::OpenCluster(
  198. BSTR bstrClusterName
  199. )
  200. {
  201. TraceFunc( "[IClusterHandleProvider]" );
  202. Assert( bstrClusterName != NULL );
  203. HRESULT hr = S_OK;
  204. DWORD sc;
  205. HCLUSTER hCluster;
  206. hCluster = ::OpenCluster( bstrClusterName );
  207. if( hCluster == NULL )
  208. {
  209. sc = GetLastError();
  210. hr = HRESULT_FROM_WIN32( sc );
  211. goto Exit;
  212. }
  213. m_hCluster = hCluster;
  214. Exit:
  215. HRETURN( hr );
  216. } //*** CHandleProvider::OpenCluster()
  217. //////////////////////////////////////////////////////////////////////////////
  218. //++
  219. //
  220. // STDMETHODIMP
  221. // CHandleProvider ::GetClusterHandle(
  222. // void ** ppvClusterHandle
  223. // )
  224. //
  225. //--
  226. //////////////////////////////////////////////////////////////////////////////
  227. STDMETHODIMP
  228. CHandleProvider::GetClusterHandle(
  229. HCLUSTER * pphClusterHandleOut
  230. )
  231. {
  232. TraceFunc( "[IClusterHandleProvider]" );
  233. HRESULT hr = S_OK;
  234. if( pphClusterHandleOut == NULL )
  235. {
  236. hr = THR( E_POINTER );
  237. goto Exit;
  238. }
  239. if( m_hCluster == NULL )
  240. {
  241. hr = THR( E_FAIL );
  242. goto Exit;
  243. }
  244. // Copy the handle.
  245. *pphClusterHandleOut = m_hCluster;
  246. Exit:
  247. HRETURN( hr );
  248. } //*** CHandleProvider::GetClusterHandle()