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.

334 lines
7.0 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2000-2001 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // GroupHandle.cpp
  7. //
  8. // Description:
  9. // Object Manager implementation.
  10. //
  11. // Maintained By:
  12. // Geoffrey Pease (GPease) 22-NOV-1999
  13. //
  14. //////////////////////////////////////////////////////////////////////////////
  15. #include "Pch.h"
  16. #include "GroupHandle.h"
  17. DEFINE_THISCLASS("CGroupHandle")
  18. // ************************************************************************
  19. //
  20. // Constructor / Destructor
  21. //
  22. // ************************************************************************
  23. //////////////////////////////////////////////////////////////////////////////
  24. //
  25. // HRESULT
  26. // CGroupHandle::S_HrCreateInstance(
  27. // CGroupHandle ** ppunkOut,
  28. // HGROUP hGroupIn
  29. // )
  30. //
  31. //////////////////////////////////////////////////////////////////////////////
  32. HRESULT
  33. CGroupHandle::S_HrCreateInstance(
  34. CGroupHandle ** ppunkOut,
  35. HGROUP hGroupIn
  36. )
  37. {
  38. TraceFunc( "" );
  39. HRESULT hr = S_OK;
  40. CGroupHandle * pgh = NULL;
  41. Assert( ppunkOut != NULL );
  42. if ( ppunkOut == NULL )
  43. {
  44. hr = THR( E_POINTER );
  45. goto Cleanup;
  46. }
  47. pgh = new CGroupHandle;
  48. if ( pgh == NULL )
  49. {
  50. hr = THR( E_POINTER );
  51. goto Cleanup;
  52. }
  53. hr = THR( pgh->HrInit( hGroupIn ) );
  54. if ( FAILED( hr ) )
  55. {
  56. goto Cleanup;
  57. }
  58. *ppunkOut = pgh;
  59. (*ppunkOut)->AddRef();
  60. Cleanup:
  61. if ( pgh != NULL )
  62. {
  63. pgh->Release();
  64. }
  65. HRETURN( hr );
  66. } //*** CGroupHandle::S_HrCreateInstance
  67. //////////////////////////////////////////////////////////////////////////////
  68. //
  69. // CGroupHandle::CGroupHandle
  70. //
  71. //////////////////////////////////////////////////////////////////////////////
  72. CGroupHandle::CGroupHandle( void )
  73. : m_cRef( 1 )
  74. {
  75. TraceFunc( "" );
  76. InterlockedIncrement( &g_cObjects );
  77. TraceFuncExit();
  78. } //*** CGroupHandle::CGroupHandle
  79. //////////////////////////////////////////////////////////////////////////////
  80. //
  81. // STDMETHODIMP
  82. // CGroupHandle::HrInit(
  83. // HGROUP hGroupIn
  84. // )
  85. //
  86. //////////////////////////////////////////////////////////////////////////////
  87. STDMETHODIMP
  88. CGroupHandle::HrInit(
  89. HGROUP hGroupIn
  90. )
  91. {
  92. TraceFunc( "" );
  93. HRESULT hr = S_OK;
  94. // IUnknown stuff
  95. Assert( m_cRef == 1 );
  96. // IPrivateGroupHandle
  97. Assert( m_hGroup == NULL );
  98. m_hGroup = hGroupIn;
  99. HRETURN( hr );
  100. } //*** CGroupHandle::HrInit
  101. //////////////////////////////////////////////////////////////////////////////
  102. //
  103. // CGroupHandle::~CGroupHandle
  104. //
  105. //////////////////////////////////////////////////////////////////////////////
  106. CGroupHandle::~CGroupHandle( void )
  107. {
  108. TraceFunc( "" );
  109. if ( m_hGroup != NULL )
  110. {
  111. CloseClusterGroup( m_hGroup );
  112. }
  113. InterlockedDecrement( &g_cObjects );
  114. TraceFuncExit();
  115. } //*** CGroupHandle::~CGroupHandle
  116. // ************************************************************************
  117. //
  118. // IUnknown
  119. //
  120. // ************************************************************************
  121. //////////////////////////////////////////////////////////////////////////////
  122. //++
  123. //
  124. // CGroupHandle::QueryInterface
  125. //
  126. // Description:
  127. // Query this object for the passed in interface.
  128. //
  129. // Arguments:
  130. // riidIn
  131. // Id of interface requested.
  132. //
  133. // ppvOut
  134. // Pointer to the requested interface.
  135. //
  136. // Return Value:
  137. // S_OK
  138. // If the interface is available on this object.
  139. //
  140. // E_NOINTERFACE
  141. // If the interface is not available.
  142. //
  143. // E_POINTER
  144. // ppvOut was NULL.
  145. //
  146. // Remarks:
  147. // None.
  148. //
  149. //--
  150. //////////////////////////////////////////////////////////////////////////////
  151. STDMETHODIMP
  152. CGroupHandle::QueryInterface(
  153. REFIID riidIn
  154. , LPVOID * ppvOut
  155. )
  156. {
  157. TraceQIFunc( riidIn, ppvOut );
  158. HRESULT hr = S_OK;
  159. //
  160. // Validate arguments.
  161. //
  162. Assert( ppvOut != NULL );
  163. if ( ppvOut == NULL )
  164. {
  165. hr = THR( E_POINTER );
  166. goto Cleanup;
  167. }
  168. //
  169. // Handle known interfaces.
  170. //
  171. if ( IsEqualIID( riidIn, IID_IUnknown ) )
  172. {
  173. *ppvOut = static_cast< IUnknown * >( this );
  174. } // if: IUnknown
  175. #if 0
  176. else if ( IsEqualIID( riidIn, IID_IGroupHandle ) )
  177. {
  178. *ppvOut = TraceInterface( __THISCLASS__, IGroupHandle, this, 0 );
  179. } // else if: IGroupHandle
  180. #endif
  181. else
  182. {
  183. *ppvOut = NULL;
  184. hr = E_NOINTERFACE;
  185. }
  186. //
  187. // Add a reference to the interface if successful.
  188. //
  189. if ( SUCCEEDED( hr ) )
  190. {
  191. ((IUnknown *) *ppvOut)->AddRef();
  192. } // if: success
  193. Cleanup:
  194. QIRETURN_IGNORESTDMARSHALLING( hr, riidIn );
  195. } //*** CGroupHandle::QueryInterface
  196. //////////////////////////////////////////////////////////////////////////////
  197. //
  198. // STDMETHODIMP_(ULONG)
  199. // CGroupHandle::AddRef
  200. //
  201. //////////////////////////////////////////////////////////////////////////////
  202. STDMETHODIMP_( ULONG )
  203. CGroupHandle::AddRef( void )
  204. {
  205. TraceFunc( "[IUnknown]" );
  206. InterlockedIncrement( &m_cRef );
  207. CRETURN( m_cRef );
  208. } //*** CGroupHandle::AddRef
  209. //////////////////////////////////////////////////////////////////////////////
  210. //
  211. // STDMETHODIMP_(ULONG)
  212. // CGroupHandle::Release
  213. //
  214. //////////////////////////////////////////////////////////////////////////////
  215. STDMETHODIMP_( ULONG )
  216. CGroupHandle::Release( void )
  217. {
  218. TraceFunc( "[IUnknown]" );
  219. LONG cRef;
  220. cRef = InterlockedDecrement( &m_cRef );
  221. if ( cRef == 0 )
  222. {
  223. TraceDo( delete this );
  224. }
  225. CRETURN( cRef );
  226. } //*** CGroupHandle::Release
  227. //****************************************************************************
  228. //
  229. // IPrivateGroupHandle
  230. //
  231. //****************************************************************************
  232. //////////////////////////////////////////////////////////////////////////////
  233. //
  234. // STDMETHODIMP
  235. // CGroupHandle::SetHandle(
  236. // HGROUP hGroupIn
  237. // )
  238. //
  239. //////////////////////////////////////////////////////////////////////////////
  240. STDMETHODIMP
  241. CGroupHandle::SetHandle(
  242. HGROUP hGroupIn
  243. )
  244. {
  245. TraceFunc( "[IPrivateGroupHandle]" );
  246. HRESULT hr = S_OK;
  247. m_hGroup = hGroupIn;
  248. HRETURN( hr );
  249. } //*** CGroupHandle::SetHandle
  250. //////////////////////////////////////////////////////////////////////////////
  251. //
  252. // STDMETHODIMP
  253. // CGroupHandle::GetHandle(
  254. // HGROUP * phGroupOut
  255. // )
  256. //
  257. //////////////////////////////////////////////////////////////////////////////
  258. STDMETHODIMP
  259. CGroupHandle::GetHandle(
  260. HGROUP * phGroupOut
  261. )
  262. {
  263. TraceFunc( "[IPrivateGroupHandle]" );
  264. HRESULT hr = S_OK;
  265. Assert( phGroupOut != NULL );
  266. *phGroupOut = m_hGroup;
  267. HRETURN( hr );
  268. } //*** CGroupHandle::GetHandle