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.

331 lines
7.8 KiB

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