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.

781 lines
17 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1999-2002 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. #include <ClusterUtils.h>
  19. DEFINE_THISCLASS("CCPIClusCfgCallback")
  20. // ************************************************************************
  21. //
  22. // Constructor / Destructor
  23. //
  24. // ************************************************************************
  25. //////////////////////////////////////////////////////////////////////////////
  26. //++
  27. //
  28. // CCPIClusCfgCallback::S_HrCreateInstance
  29. //
  30. // Description:
  31. // Create an object of this type.
  32. //
  33. // Arguments:
  34. // ppunkOut - IUnknown pointer for this interface.
  35. //
  36. // Return Values:
  37. // S_OK - Success.
  38. // E_POINTER - A required output argument was not specified.
  39. // E_OUTOFMEMORY - Memory could not be allocated.
  40. // Other HRESULTs.
  41. //
  42. //--
  43. //////////////////////////////////////////////////////////////////////////////
  44. HRESULT
  45. CCPIClusCfgCallback::S_HrCreateInstance(
  46. IUnknown ** ppunkOut
  47. )
  48. {
  49. TraceFunc( "" );
  50. HRESULT hr = S_OK;
  51. CCPIClusCfgCallback * pcc = NULL;
  52. Assert( ppunkOut != NULL );
  53. if ( ppunkOut == NULL )
  54. {
  55. hr = THR( E_POINTER );
  56. goto Cleanup;
  57. }
  58. pcc = new CCPIClusCfgCallback();
  59. if ( pcc == NULL )
  60. {
  61. hr = THR( E_OUTOFMEMORY );
  62. goto Cleanup;
  63. }
  64. hr = THR( pcc->HrInit() );
  65. if ( FAILED( hr ) )
  66. {
  67. goto Cleanup;
  68. }
  69. hr = THR( pcc->TypeSafeQI( IUnknown, ppunkOut ) );
  70. if ( FAILED( hr ) )
  71. {
  72. goto Cleanup;
  73. }
  74. Cleanup:
  75. if ( pcc != NULL )
  76. {
  77. pcc->Release();
  78. }
  79. HRETURN( hr );
  80. } //*** CCPIClusCfgCallback::S_HrCreateInstance
  81. //////////////////////////////////////////////////////////////////////////////
  82. //++
  83. //
  84. // CCPIClusCfgCallback::CCPIClusCfgCallback
  85. //
  86. // Description:
  87. // Default constructor.
  88. //
  89. // Arguments:
  90. // None.
  91. //
  92. // Return Values:
  93. // None.
  94. //
  95. //--
  96. //////////////////////////////////////////////////////////////////////////////
  97. CCPIClusCfgCallback::CCPIClusCfgCallback( void )
  98. : m_cRef( 1 )
  99. {
  100. TraceFunc( "" );
  101. InterlockedIncrement( &g_cObjects );
  102. TraceFuncExit();
  103. } //*** CCPIClusCfgCallback::CCPIClusCfgCallback
  104. //////////////////////////////////////////////////////////////////////////////
  105. //++
  106. //
  107. // CCPIClusCfgCallback::HrInit
  108. //
  109. // Description:
  110. // Initialize the object after it has been constructed.
  111. //
  112. // Arguments:
  113. // None.
  114. //
  115. // Return Values:
  116. // S_OK - Success.
  117. // E_OUTOFMEMORY - Error allocating memory.
  118. // Other HRESULTs.
  119. //
  120. //--
  121. //////////////////////////////////////////////////////////////////////////////
  122. STDMETHODIMP
  123. CCPIClusCfgCallback::HrInit( void )
  124. {
  125. TraceFunc( "" );
  126. HRESULT hr = S_OK;
  127. // IUnknown stuff
  128. Assert( m_cRef == 1 );
  129. // IConnectionPoint
  130. Assert( m_penum == NULL );
  131. m_penum = new CEnumCPICCCB();
  132. if ( m_penum == NULL )
  133. {
  134. hr = THR( E_OUTOFMEMORY );
  135. goto Cleanup;
  136. }
  137. hr = THR( m_penum->HrInit() );
  138. if ( FAILED( hr ) )
  139. {
  140. goto Cleanup;
  141. }
  142. // IClusCfgCallback
  143. Cleanup:
  144. HRETURN( hr );
  145. } //*** CCPIClusCfgCallback::HrInit
  146. //////////////////////////////////////////////////////////////////////////////
  147. //++
  148. //
  149. // CCPIClusCfgCallback::~CCPIClusCfgCallback
  150. //
  151. // Description:
  152. // Destructor.
  153. //
  154. // Arguments:
  155. // None.
  156. //
  157. // Return Values:
  158. // None.
  159. //
  160. //--
  161. //////////////////////////////////////////////////////////////////////////////
  162. CCPIClusCfgCallback::~CCPIClusCfgCallback( void )
  163. {
  164. TraceFunc( "" );
  165. if ( m_penum != NULL )
  166. {
  167. m_penum->Release();
  168. }
  169. InterlockedDecrement( &g_cObjects );
  170. TraceFuncExit();
  171. } //*** CCPIClusCfgCallback::~CCPIClusCfgCallback
  172. //****************************************************************************
  173. //
  174. // IUnknown
  175. //
  176. //****************************************************************************
  177. //////////////////////////////////////////////////////////////////////////////
  178. //++
  179. //
  180. // CCPIClusCfgCallback::QueryInterface
  181. //
  182. // Description:
  183. // Query this object for the passed in interface.
  184. //
  185. // Arguments:
  186. // riidIn
  187. // Id of interface requested.
  188. //
  189. // ppvOut
  190. // Pointer to the requested interface.
  191. //
  192. // Return Value:
  193. // S_OK
  194. // If the interface is available on this object.
  195. //
  196. // E_NOINTERFACE
  197. // If the interface is not available.
  198. //
  199. // E_POINTER
  200. // ppvOut was NULL.
  201. //
  202. //--
  203. //////////////////////////////////////////////////////////////////////////////
  204. STDMETHODIMP
  205. CCPIClusCfgCallback::QueryInterface(
  206. REFIID riidIn
  207. , LPVOID * ppvOut
  208. )
  209. {
  210. TraceQIFunc( riidIn, ppvOut );
  211. HRESULT hr = S_OK;
  212. //
  213. // Validate arguments.
  214. //
  215. Assert( ppvOut != NULL );
  216. if ( ppvOut == NULL )
  217. {
  218. hr = THR( E_POINTER );
  219. goto Cleanup;
  220. }
  221. //
  222. // Handle known interfaces.
  223. //
  224. if ( IsEqualIID( riidIn, IID_IUnknown ) )
  225. {
  226. *ppvOut = static_cast< IConnectionPoint * >( this );
  227. } // if: IUnknown
  228. else if ( IsEqualIID( riidIn, IID_IConnectionPoint ) )
  229. {
  230. *ppvOut = TraceInterface( __THISCLASS__, IConnectionPoint, this, 0 );
  231. } // else if: IConnectionPoint
  232. else if ( IsEqualIID( riidIn, IID_IClusCfgCallback ) )
  233. {
  234. *ppvOut = TraceInterface( __THISCLASS__, IClusCfgCallback, this, 0 );
  235. } // else if: IClusCfgCallback
  236. else
  237. {
  238. *ppvOut = NULL;
  239. hr = E_NOINTERFACE;
  240. } // else
  241. //
  242. // Add a reference to the interface if successful.
  243. //
  244. if ( SUCCEEDED( hr ) )
  245. {
  246. ((IUnknown*) *ppvOut)->AddRef();
  247. } // if: success
  248. Cleanup:
  249. QIRETURN_IGNORESTDMARSHALLING( hr, riidIn );
  250. } //*** CCPIClusCfgCallback::QueryInterface
  251. //////////////////////////////////////////////////////////////////////////////
  252. //++
  253. //
  254. // CCPIClusCfgCallback::AddRef
  255. //
  256. // Description:
  257. //
  258. // Arguments:
  259. // None.
  260. //
  261. // Return Values:
  262. //
  263. //--
  264. //////////////////////////////////////////////////////////////////////////////
  265. STDMETHODIMP_( ULONG )
  266. CCPIClusCfgCallback::AddRef( void )
  267. {
  268. TraceFunc( "[IUnknown]" );
  269. InterlockedIncrement( &m_cRef );
  270. CRETURN( m_cRef );
  271. } //*** CCPIClusCfgCallback::AddRef
  272. //////////////////////////////////////////////////////////////////////////////
  273. //++
  274. //
  275. // CCPIClusCfgCallback::Release
  276. //
  277. // Description:
  278. //
  279. // Arguments:
  280. // None.
  281. //
  282. // Return Values:
  283. //
  284. //--
  285. //
  286. //////////////////////////////////////////////////////////////////////////////
  287. STDMETHODIMP_( ULONG )
  288. CCPIClusCfgCallback::Release( void )
  289. {
  290. TraceFunc( "[IUnknown]" );
  291. LONG cRef;
  292. cRef = InterlockedDecrement( &m_cRef );
  293. if ( cRef == 0 )
  294. {
  295. TraceDo( delete this );
  296. }
  297. CRETURN( cRef );
  298. } //*** CCPIClusCfgCallback::Release
  299. //****************************************************************************
  300. //
  301. // IConnectionPoint
  302. //
  303. //****************************************************************************
  304. //////////////////////////////////////////////////////////////////////////////
  305. //++
  306. //
  307. // [IConnectionPoint]
  308. // CCPIClusCfgCallback::GetConnectionInterface
  309. //
  310. // Description:
  311. // Get the interface ID for the connection point.
  312. //
  313. // Arguments:
  314. // pIIDOut - Interface ID that is returned.
  315. //
  316. // Return Values:
  317. // S_OK - Success.
  318. // E_POINTER - A required output argument was not specified.
  319. //
  320. //--
  321. //////////////////////////////////////////////////////////////////////////////
  322. STDMETHODIMP
  323. CCPIClusCfgCallback::GetConnectionInterface(
  324. IID * pIIDOut
  325. )
  326. {
  327. TraceFunc( "[IConnectionPoint] pIIDOut" );
  328. HRESULT hr = S_OK;
  329. if ( pIIDOut == NULL )
  330. {
  331. hr = THR( E_POINTER );
  332. goto Cleanup;
  333. }
  334. *pIIDOut = IID_IClusCfgCallback;
  335. Cleanup:
  336. HRETURN( hr );
  337. } //*** CCPIClusCfgCallback::GetConnectionInterface
  338. //////////////////////////////////////////////////////////////////////////////
  339. //++
  340. //
  341. // [IConnectionPoint]
  342. // CCPIClusCfgCallback::GetConnectionPointContainer
  343. //
  344. // Description:
  345. // Get the connection point container.
  346. //
  347. // Arguments:
  348. // ppcpcOut - Connection point container interface that is returned.
  349. //
  350. // Return Values:
  351. // S_OK - Success.
  352. // Other HRESULTs.
  353. //
  354. //--
  355. //////////////////////////////////////////////////////////////////////////////
  356. STDMETHODIMP
  357. CCPIClusCfgCallback::GetConnectionPointContainer(
  358. IConnectionPointContainer * * ppcpcOut
  359. )
  360. {
  361. TraceFunc( "[IConnectionPoint] ppcpcOut" );
  362. HRESULT hr;
  363. IServiceProvider * psp = NULL;
  364. hr = THR( CoCreateInstance( CLSID_ServiceManager,
  365. NULL,
  366. CLSCTX_INPROC_SERVER,
  367. TypeSafeParams( IServiceProvider, &psp )
  368. ) );
  369. if ( FAILED( hr ) )
  370. {
  371. goto Cleanup;
  372. }
  373. hr = THR( psp->TypeSafeQS( CLSID_NotificationManager,
  374. IConnectionPointContainer,
  375. ppcpcOut
  376. ) );
  377. if ( FAILED( hr ) )
  378. {
  379. goto Cleanup;
  380. }
  381. Cleanup:
  382. if ( psp != NULL )
  383. {
  384. psp->Release();
  385. }
  386. HRETURN( hr );
  387. } //*** CCPIClusCfgCallback::GetConnectionPointContainer
  388. //////////////////////////////////////////////////////////////////////////////
  389. //++
  390. //
  391. // [IConnectionPoint]
  392. // CCPIClusCfgCallback::Advise
  393. //
  394. // Description:
  395. // Register to receive notifications.
  396. //
  397. // Arguments:
  398. // pUnkSinkIn
  399. // Interface to use for notifications. Must support IClusCfgCallback.
  400. //
  401. // pdwCookieOut
  402. // Cookie representing advise request. Used in call to Unadvise.
  403. //
  404. // Return Values:
  405. // S_OK
  406. // Success.
  407. //
  408. // E_POINTER
  409. // A required output argument was not specified.
  410. //
  411. // E_INVALIDARG
  412. // A required input argument was not specified.
  413. //
  414. // Other HRESULTs.
  415. //
  416. //--
  417. //////////////////////////////////////////////////////////////////////////////
  418. STDMETHODIMP
  419. CCPIClusCfgCallback::Advise(
  420. IUnknown * pUnkSinkIn
  421. , DWORD * pdwCookieOut
  422. )
  423. {
  424. TraceFunc( "[IConnectionPoint]" );
  425. HRESULT hr;
  426. if ( pdwCookieOut == NULL )
  427. {
  428. hr = THR( E_POINTER );
  429. goto Cleanup;
  430. }
  431. if ( pUnkSinkIn == NULL )
  432. {
  433. hr = THR( E_INVALIDARG );
  434. goto Cleanup;
  435. }
  436. Assert( m_penum != NULL );
  437. hr = THR( m_penum->HrAddConnection( pUnkSinkIn, pdwCookieOut ) );
  438. if ( FAILED( hr ) )
  439. goto Cleanup;
  440. Cleanup:
  441. HRETURN( hr );
  442. } //*** CCPIClusCfgCallback::Advise
  443. //////////////////////////////////////////////////////////////////////////////
  444. //++
  445. //
  446. // [IConnectionPoint]
  447. // CCPIClusCfgCallback::Unadvise
  448. //
  449. // Description:
  450. // Unregister for notifications.
  451. //
  452. // Arguments:
  453. // dwCookieIn - Cookie returned from Advise.
  454. //
  455. // Return Values:
  456. // S_OK - Success.
  457. // Other HRESULTs.
  458. //
  459. //////////////////////////////////////////////////////////////////////////////
  460. STDMETHODIMP
  461. CCPIClusCfgCallback::Unadvise(
  462. DWORD dwCookieIn
  463. )
  464. {
  465. TraceFunc1( "[IConncetionPoint] dwCookieIn = %#x", dwCookieIn );
  466. HRESULT hr;
  467. Assert( m_penum != NULL );
  468. hr = THR( m_penum->HrRemoveConnection( dwCookieIn ) );
  469. HRETURN( hr );
  470. } //*** CCPIClusCfgCallback::Unadvise
  471. //////////////////////////////////////////////////////////////////////////////
  472. //++
  473. //
  474. // [IConnectionPoint]
  475. // CCPIClusCfgCallback::EnumConnections
  476. //
  477. // Description:
  478. // Enumerate connections in the container.
  479. //
  480. // Arguments:
  481. // ppEnumOut
  482. // Interface to enumerator being returned. Caller must call Release()
  483. // on this interface when done with it.
  484. //
  485. // Return Values:
  486. // S_OK - Success.
  487. // E_POINTER - A required output argument was not specified.
  488. //
  489. //--
  490. //////////////////////////////////////////////////////////////////////////////
  491. STDMETHODIMP
  492. CCPIClusCfgCallback::EnumConnections(
  493. IEnumConnections * * ppEnumOut
  494. )
  495. {
  496. TraceFunc( "[IConnectionPoint] ppEnumOut" );
  497. HRESULT hr;
  498. if ( ppEnumOut == NULL )
  499. {
  500. hr = THR( E_POINTER );
  501. goto Cleanup;
  502. }
  503. hr = THR( m_penum->Clone( ppEnumOut ) );
  504. Cleanup:
  505. HRETURN( hr );
  506. } //*** CCPIClusCfgCallback::EnumConnections
  507. //****************************************************************************
  508. //
  509. // IClusCfgCallback
  510. //
  511. //****************************************************************************
  512. //////////////////////////////////////////////////////////////////////////////
  513. //++
  514. //
  515. // [IClusCfgCallback]
  516. // CCPIClusCfgCallback::SendStatusReport
  517. //
  518. // Description:
  519. // Send a status report.
  520. //
  521. // Arguments:
  522. // pcszNodeNameIn
  523. // clsidTaskMajorIn
  524. // clsidTaskMinorIn
  525. // ulMinIn
  526. // ulMaxIn
  527. // ulCurrentIn
  528. // hrStatusIn
  529. // pcszDescriptionIn
  530. // pftTimeIn
  531. // pcszReferenceIn
  532. //
  533. // Return Values:
  534. // S_OK - Success.
  535. // Other HRESULTs from connection points.
  536. //
  537. //--
  538. //////////////////////////////////////////////////////////////////////////////
  539. STDMETHODIMP
  540. CCPIClusCfgCallback::SendStatusReport(
  541. LPCWSTR pcszNodeNameIn
  542. , CLSID clsidTaskMajorIn
  543. , CLSID clsidTaskMinorIn
  544. , ULONG ulMinIn
  545. , ULONG ulMaxIn
  546. , ULONG ulCurrentIn
  547. , HRESULT hrStatusIn
  548. , LPCWSTR pcszDescriptionIn
  549. , FILETIME * pftTimeIn
  550. , LPCWSTR pcszReferenceIn
  551. )
  552. {
  553. TraceFunc( "[IClusCfgCallback]" );
  554. CONNECTDATA cd = { NULL };
  555. HRESULT hr;
  556. HRESULT hrResult = S_OK;
  557. IClusCfgCallback * pcccb;
  558. FILETIME ft;
  559. BSTR bstrReferenceString = NULL;
  560. LPCWSTR pcszReference = NULL;
  561. IEnumConnections * pec = NULL;
  562. //
  563. // If no reference string was specified, see if there is one available
  564. // for the specified HRESULT.
  565. //
  566. if ( ( pcszReferenceIn == NULL )
  567. && ( hrStatusIn != S_OK )
  568. && ( hrStatusIn != S_FALSE )
  569. )
  570. {
  571. hr = STHR( HrGetReferenceStringFromHResult( hrStatusIn, &bstrReferenceString ) );
  572. if ( hr == S_OK )
  573. {
  574. pcszReference = bstrReferenceString;
  575. }
  576. } // if: no reference string was specified
  577. else
  578. {
  579. pcszReference = pcszReferenceIn;
  580. }
  581. //
  582. // Clone the enumerator in case we are re-entered on the same thread.
  583. //
  584. hr = THR( m_penum->Clone( &pec ) );
  585. if ( FAILED( hr ) )
  586. {
  587. goto Cleanup;
  588. }
  589. //
  590. // Reset the enumerator to the first element.
  591. //
  592. hr = THR( pec->Reset() );
  593. if ( FAILED( hr ) )
  594. {
  595. goto Cleanup;
  596. }
  597. //
  598. // Loop through each connection point in the container and send it
  599. // the notification.
  600. //
  601. for ( ;; )
  602. {
  603. if ( cd.pUnk != NULL )
  604. {
  605. cd.pUnk->Release();
  606. cd.pUnk = NULL;
  607. }
  608. hr = STHR( pec->Next( 1, &cd, NULL ) );
  609. if ( FAILED( hr ) )
  610. break;
  611. if ( hr == S_FALSE )
  612. {
  613. hr = S_OK;
  614. break; // exit condition
  615. }
  616. hr = THR( cd.pUnk->TypeSafeQI( IClusCfgCallback, &pcccb ) );
  617. if ( FAILED( hr ) )
  618. {
  619. continue; // igore the error and continue
  620. }
  621. if ( pftTimeIn == NULL )
  622. {
  623. GetSystemTimeAsFileTime( &ft );
  624. pftTimeIn = &ft;
  625. } // if:
  626. hr = THR( pcccb->SendStatusReport(
  627. pcszNodeNameIn
  628. , clsidTaskMajorIn
  629. , clsidTaskMinorIn
  630. , ulMinIn
  631. , ulMaxIn
  632. , ulCurrentIn
  633. , hrStatusIn
  634. , pcszDescriptionIn
  635. , pftTimeIn
  636. , pcszReference
  637. ) );
  638. if ( hr != S_OK )
  639. {
  640. hrResult = hr;
  641. }
  642. pcccb->Release();
  643. } // for: ever (each connection point)
  644. Cleanup:
  645. if ( cd.pUnk != NULL )
  646. {
  647. cd.pUnk->Release();
  648. } // if:
  649. if ( pec != NULL )
  650. {
  651. pec->Release();
  652. } // if:
  653. TraceSysFreeString( bstrReferenceString );
  654. HRETURN( hrResult );
  655. } //*** CCPIClusCfgCallback::SendStatusReport