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.

524 lines
12 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1999-2001 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // CPIClusCfgCallback.cpp
  7. //
  8. // Description:
  9. // IClusCfgCallback Connection Point implementation.
  10. //
  11. // Maintained By:
  12. // Galen Barbee (GalenB) 10-NOV-2000
  13. //
  14. //////////////////////////////////////////////////////////////////////////////
  15. #include "pch.h"
  16. #include "CPIClusCfgCallback.h"
  17. #include "EnumCPICCCB.h"
  18. DEFINE_THISCLASS("CCPIClusCfgCallback")
  19. // ************************************************************************
  20. //
  21. // Constructor / Destructor
  22. //
  23. // ************************************************************************
  24. //////////////////////////////////////////////////////////////////////////////
  25. //
  26. // HRESULT
  27. // CCPIClusCfgCallback::S_HrCreateInstance(
  28. // IUnknown ** ppunkOut
  29. // )
  30. //
  31. //////////////////////////////////////////////////////////////////////////////
  32. HRESULT
  33. CCPIClusCfgCallback::S_HrCreateInstance(
  34. IUnknown ** ppunkOut
  35. )
  36. {
  37. TraceFunc( "" );
  38. Assert( ppunkOut != NULL );
  39. HRESULT hr;
  40. CCPIClusCfgCallback * lpcc = new CCPIClusCfgCallback( );
  41. if ( lpcc != NULL )
  42. {
  43. hr = THR( lpcc->Init( ) );
  44. if ( SUCCEEDED( hr ) )
  45. {
  46. hr = THR( lpcc->TypeSafeQI( IUnknown, ppunkOut ) );
  47. } // if: success
  48. lpcc->Release( );
  49. } // if: got object
  50. else
  51. {
  52. hr = E_OUTOFMEMORY;
  53. } // else: out of memory
  54. HRETURN( hr );
  55. } // S_HrCreateInstance( )
  56. //
  57. // Constructor
  58. //
  59. CCPIClusCfgCallback::CCPIClusCfgCallback( void )
  60. {
  61. TraceFunc( "" );
  62. InterlockedIncrement( &g_cObjects );
  63. TraceFuncExit();
  64. } // CCPIClusCfgCallback( )
  65. //////////////////////////////////////////////////////////////////////////////
  66. //
  67. // STDMETHODIMP
  68. // CCPIClusCfgCallback::Init( )
  69. //
  70. //////////////////////////////////////////////////////////////////////////////
  71. STDMETHODIMP
  72. CCPIClusCfgCallback::Init( )
  73. {
  74. TraceFunc( "" );
  75. HRESULT hr = S_OK;
  76. // IUnknown stuff
  77. Assert( m_cRef == 0 );
  78. AddRef( ); // Add one count
  79. // IConnectionPoint
  80. Assert( m_penum == NULL );
  81. m_penum = new CEnumCPICCCB( );
  82. if ( m_penum == NULL )
  83. goto OutOfMemory;
  84. hr = THR( m_penum->Init( ) );
  85. if ( FAILED( hr ) )
  86. goto Cleanup;
  87. // IClusCfgCallback
  88. Cleanup:
  89. HRETURN( hr );
  90. OutOfMemory:
  91. hr = E_OUTOFMEMORY;
  92. goto Cleanup;
  93. } // Init( )
  94. //////////////////////////////////////////////////////////////////////////////
  95. //
  96. // CCPIClusCfgCallback::~CCPIClusCfgCallback( )
  97. //
  98. //////////////////////////////////////////////////////////////////////////////
  99. CCPIClusCfgCallback::~CCPIClusCfgCallback( )
  100. {
  101. TraceFunc( "" );
  102. if ( m_penum != NULL )
  103. {
  104. m_penum->Release( );
  105. }
  106. InterlockedDecrement( &g_cObjects );
  107. TraceFuncExit();
  108. } // ~CCPIClusCfgCallback( )
  109. // ************************************************************************
  110. //
  111. // IUnknown
  112. //
  113. // ************************************************************************
  114. //////////////////////////////////////////////////////////////////////////////
  115. //
  116. // STDMETHODIMP
  117. // CCPIClusCfgCallback::QueryInterface(
  118. // REFIID riid,
  119. // LPVOID *ppv
  120. // )
  121. //
  122. //////////////////////////////////////////////////////////////////////////////
  123. STDMETHODIMP
  124. CCPIClusCfgCallback::QueryInterface(
  125. REFIID riid,
  126. LPVOID *ppv
  127. )
  128. {
  129. TraceQIFunc( riid, ppv );
  130. HRESULT hr = E_NOINTERFACE;
  131. if ( IsEqualIID( riid, IID_IUnknown ) )
  132. {
  133. *ppv = static_cast< IConnectionPoint * >( this );
  134. hr = S_OK;
  135. } // if: IUnknown
  136. else if ( IsEqualIID( riid, IID_IConnectionPoint ) )
  137. {
  138. *ppv = TraceInterface( __THISCLASS__, IConnectionPoint, this, 0 );
  139. hr = S_OK;
  140. } // else if: IConnectionPoint
  141. else if ( IsEqualIID( riid, IID_IClusCfgCallback ) )
  142. {
  143. *ppv = TraceInterface( __THISCLASS__, IClusCfgCallback, this, 0 );
  144. hr = S_OK;
  145. } // else if: IClusCfgCallback
  146. if ( SUCCEEDED( hr ) )
  147. {
  148. ((IUnknown*) *ppv)->AddRef( );
  149. } // if: success
  150. QIRETURN_IGNORESTDMARSHALLING( hr, riid );
  151. } // QueryInterface( )
  152. //////////////////////////////////////////////////////////////////////////////
  153. //
  154. // STDMETHODIMP_(ULONG)
  155. // CCPIClusCfgCallback::AddRef( void )
  156. //
  157. //////////////////////////////////////////////////////////////////////////////
  158. STDMETHODIMP_(ULONG)
  159. CCPIClusCfgCallback::AddRef( void )
  160. {
  161. TraceFunc( "[IUnknown]" );
  162. InterlockedIncrement( &m_cRef );
  163. RETURN( m_cRef );
  164. } // AddRef( )
  165. //////////////////////////////////////////////////////////////////////////////
  166. //
  167. // STDMETHODIMP_(ULONG)
  168. // CCPIClusCfgCallback::Release( void )
  169. //
  170. //////////////////////////////////////////////////////////////////////////////
  171. STDMETHODIMP_(ULONG)
  172. CCPIClusCfgCallback::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. } // Release( )
  181. // ************************************************************************
  182. //
  183. // IConnectionPoint
  184. //
  185. // ************************************************************************
  186. //////////////////////////////////////////////////////////////////////////////
  187. //
  188. // STDMETHODIMP
  189. // CCPIClusCfgCallback::GetConnectionInterface(
  190. // IID * pIIDOut
  191. // )
  192. //
  193. //////////////////////////////////////////////////////////////////////////////
  194. STDMETHODIMP
  195. CCPIClusCfgCallback::GetConnectionInterface(
  196. IID * pIIDOut
  197. )
  198. {
  199. TraceFunc( "[IConnectionPoint] pIIDOut" );
  200. HRESULT hr = S_OK;
  201. if ( pIIDOut == NULL )
  202. goto InvalidPointer;
  203. *pIIDOut = IID_IClusCfgCallback;
  204. Cleanup:
  205. HRETURN( hr );
  206. InvalidPointer:
  207. hr = THR( E_POINTER );
  208. goto Cleanup;
  209. } // GetConnectionInterface( )
  210. //////////////////////////////////////////////////////////////////////////////
  211. //
  212. // STDMETHODIMP
  213. // CCPIClusCfgCallback::GetConnectionPointContainer(
  214. // IConnectionPointContainer * * ppcpcOut
  215. // )
  216. //
  217. //////////////////////////////////////////////////////////////////////////////
  218. STDMETHODIMP
  219. CCPIClusCfgCallback::GetConnectionPointContainer(
  220. IConnectionPointContainer * * ppcpcOut
  221. )
  222. {
  223. TraceFunc( "[IConnectionPoint] ppcpcOut" );
  224. HRESULT hr;
  225. IServiceProvider * psp = NULL;
  226. hr = THR( CoCreateInstance( CLSID_ServiceManager,
  227. NULL,
  228. CLSCTX_INPROC_SERVER,
  229. TypeSafeParams( IServiceProvider, &psp )
  230. ) );
  231. if ( FAILED( hr ) )
  232. goto Cleanup;
  233. hr = THR( psp->TypeSafeQS( CLSID_NotificationManager,
  234. IConnectionPointContainer,
  235. ppcpcOut
  236. ) );
  237. if ( FAILED( hr ) )
  238. goto Cleanup;
  239. Cleanup:
  240. if ( psp != NULL )
  241. {
  242. psp->Release( );
  243. }
  244. HRETURN( hr );
  245. } // GetConnectionPointContainer( )
  246. //////////////////////////////////////////////////////////////////////////////
  247. //
  248. // STDMETHODIMP
  249. // CCPIClusCfgCallback::Advise(
  250. // IUnknown * pUnkSinkIn,
  251. // DWORD * pdwCookieOut
  252. // )
  253. //
  254. //////////////////////////////////////////////////////////////////////////////
  255. STDMETHODIMP
  256. CCPIClusCfgCallback::Advise(
  257. IUnknown * pUnkSinkIn,
  258. DWORD * pdwCookieOut
  259. )
  260. {
  261. TraceFunc( "[IConnectionPoint]" );
  262. HRESULT hr;
  263. if ( pdwCookieOut == NULL )
  264. goto InvalidPointer;
  265. if ( pUnkSinkIn == NULL )
  266. goto InvalidArg;
  267. Assert( m_penum != NULL );
  268. hr = THR( m_penum->HrAddConnection( pUnkSinkIn, pdwCookieOut ) );
  269. if ( FAILED( hr ) )
  270. goto Cleanup;
  271. Cleanup:
  272. HRETURN( hr );
  273. InvalidPointer:
  274. hr = THR( E_POINTER );
  275. goto Cleanup;
  276. InvalidArg:
  277. hr = THR( E_INVALIDARG );
  278. goto Cleanup;
  279. } // Advise( )
  280. //////////////////////////////////////////////////////////////////////////////
  281. //
  282. // STDMETHODIMP
  283. // CCPIClusCfgCallback::Unadvise(
  284. // DWORD dwCookieIn
  285. // )
  286. //////////////////////////////////////////////////////////////////////////////
  287. STDMETHODIMP
  288. CCPIClusCfgCallback::Unadvise(
  289. DWORD dwCookieIn
  290. )
  291. {
  292. TraceFunc1( "[IConncetionPoint] dwCookieIn = %#x", dwCookieIn );
  293. HRESULT hr;
  294. Assert( m_penum != NULL );
  295. hr = THR( m_penum->HrRemoveConnection( dwCookieIn ) );
  296. HRETURN( hr );
  297. } // Unadvise( )
  298. //////////////////////////////////////////////////////////////////////////////
  299. //
  300. // STDMETHODIMP
  301. // CCPIClusCfgCallback::EnumConnections(
  302. // IEnumConnections * * ppEnumOut
  303. // )
  304. //
  305. //////////////////////////////////////////////////////////////////////////////
  306. STDMETHODIMP
  307. CCPIClusCfgCallback::EnumConnections(
  308. IEnumConnections * * ppEnumOut
  309. )
  310. {
  311. TraceFunc( "[IConnectionPoint] ppEnumOut" );
  312. HRESULT hr;
  313. if ( ppEnumOut == NULL )
  314. goto InvalidPointer;
  315. hr = THR( m_penum->Clone( ppEnumOut ) );
  316. Cleanup:
  317. HRETURN( hr );
  318. InvalidPointer:
  319. hr = THR( E_POINTER );
  320. goto Cleanup;
  321. } // EnumConnections( )
  322. //****************************************************************************
  323. //
  324. // IClusCfgCallback
  325. //
  326. //****************************************************************************
  327. //////////////////////////////////////////////////////////////////////////////
  328. //
  329. // STDMETHODIMP
  330. // CCPIClusCfgCallback::SendStatusReport(
  331. // LPCWSTR pcszNodeNameIn
  332. // , CLSID clsidTaskMajorIn
  333. // , CLSID clsidTaskMinorIn
  334. // , ULONG ulMinIn
  335. // , ULONG ulMaxIn
  336. // , ULONG ulCurrentIn
  337. // , HRESULT hrStatusIn
  338. // , LPCWSTR pcszDescriptionIn
  339. // , FILETIME * pftTimeIn
  340. // , LPCWSTR pcszReferenceIn
  341. // )
  342. //
  343. //////////////////////////////////////////////////////////////////////////////
  344. STDMETHODIMP
  345. CCPIClusCfgCallback::SendStatusReport(
  346. LPCWSTR pcszNodeNameIn
  347. , CLSID clsidTaskMajorIn
  348. , CLSID clsidTaskMinorIn
  349. , ULONG ulMinIn
  350. , ULONG ulMaxIn
  351. , ULONG ulCurrentIn
  352. , HRESULT hrStatusIn
  353. , LPCWSTR pcszDescriptionIn
  354. , FILETIME * pftTimeIn
  355. , LPCWSTR pcszReferenceIn
  356. )
  357. {
  358. TraceFunc( "[IClusCfgCallback]" );
  359. CONNECTDATA cd = { NULL };
  360. HRESULT hr;
  361. HRESULT hrResult = S_OK;
  362. IClusCfgCallback * pcccb;
  363. FILETIME ft;
  364. hr = THR( m_penum->Reset( ) );
  365. if ( FAILED( hr ) )
  366. goto Cleanup;
  367. for ( ;; )
  368. {
  369. if ( cd.pUnk != NULL )
  370. {
  371. cd.pUnk->Release( );
  372. cd.pUnk = NULL;
  373. }
  374. hr = STHR( m_penum->Next( 1, &cd, NULL ) );
  375. if ( FAILED( hr ) )
  376. break;
  377. if ( hr == S_FALSE )
  378. {
  379. hr = S_OK;
  380. break; // exit condition
  381. }
  382. hr = THR( cd.pUnk->TypeSafeQI( IClusCfgCallback, &pcccb ) );
  383. if ( FAILED( hr ) )
  384. continue; // ingore the error and continue
  385. if ( pftTimeIn == NULL )
  386. {
  387. GetSystemTimeAsFileTime( &ft );
  388. pftTimeIn = &ft;
  389. } // if:
  390. hr = THR( pcccb->SendStatusReport(
  391. pcszNodeNameIn
  392. , clsidTaskMajorIn
  393. , clsidTaskMinorIn
  394. , ulMinIn
  395. , ulMaxIn
  396. , ulCurrentIn
  397. , hrStatusIn
  398. , pcszDescriptionIn
  399. , pftTimeIn
  400. , pcszReferenceIn
  401. ) );
  402. if ( hr != S_OK )
  403. {
  404. hrResult = hr;
  405. }
  406. pcccb->Release( );
  407. }
  408. Cleanup:
  409. if ( cd.pUnk != NULL )
  410. {
  411. cd.pUnk->Release( );
  412. }
  413. HRETURN( hrResult );
  414. } // SendStatusReport( )