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.

1624 lines
38 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2000-2001 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // CEnumClusCfgManagedResources.cpp
  7. //
  8. // Description:
  9. // This file contains the definition of the CEnumClusCfgManagedResources
  10. // class.
  11. //
  12. // The class CEnumClusCfgManagedResources is the enumeration of cluster
  13. // managed devices. It implements the IEnumClusCfgManagedResources
  14. // interface.
  15. //
  16. // Documentation:
  17. //
  18. // Header File:
  19. // CEnumClusCfgManagedResources.h
  20. //
  21. // Maintained By:
  22. // Galen Barbee (GalenB) 23-FEB-2000
  23. //
  24. //////////////////////////////////////////////////////////////////////////////
  25. //////////////////////////////////////////////////////////////////////////////
  26. // Include Files
  27. //////////////////////////////////////////////////////////////////////////////
  28. #include "pch.h"
  29. #include "CEnumClusCfgManagedResources.h"
  30. #include "CEnumUnknownQuorum.h"
  31. //////////////////////////////////////////////////////////////////////////////
  32. // Constant Definitions
  33. //////////////////////////////////////////////////////////////////////////////
  34. DEFINE_THISCLASS( "CEnumClusCfgManagedResources" );
  35. //*************************************************************************//
  36. /////////////////////////////////////////////////////////////////////////////
  37. // CEnumClusCfgManagedResources class
  38. /////////////////////////////////////////////////////////////////////////////
  39. //////////////////////////////////////////////////////////////////////////////
  40. //++
  41. //
  42. // CEnumClusCfgManagedResources::S_HrCreateInstance
  43. //
  44. // Description:
  45. // Create a CEnumClusCfgManagedResources instance.
  46. //
  47. // Arguments:
  48. // None.
  49. //
  50. // Return Values:
  51. // Pointer to CEnumClusCfgManagedResources instance.
  52. //
  53. //--
  54. //////////////////////////////////////////////////////////////////////////////
  55. HRESULT
  56. CEnumClusCfgManagedResources::S_HrCreateInstance( IUnknown ** ppunkOut )
  57. {
  58. TraceFunc( "" );
  59. HRESULT hr;
  60. CEnumClusCfgManagedResources * pccsd = NULL;
  61. if ( ppunkOut == NULL )
  62. {
  63. hr = THR( E_POINTER );
  64. goto Cleanup;
  65. } // if:
  66. pccsd = new CEnumClusCfgManagedResources();
  67. if ( pccsd == NULL )
  68. {
  69. hr = THR( E_OUTOFMEMORY );
  70. goto Cleanup;
  71. } // if: error allocating object
  72. hr = THR( pccsd->HrInit() );
  73. if ( FAILED( hr ) )
  74. {
  75. goto Cleanup;
  76. } // if: HrInit() failed
  77. hr = THR( pccsd->TypeSafeQI( IUnknown, ppunkOut ) );
  78. Cleanup:
  79. if ( FAILED( hr ) )
  80. {
  81. LogMsg( L"[SRV] CEnumClusCfgManagedResources::S_HrCreateInstance() failed. (hr = %#08x)", hr );
  82. } // if:
  83. if ( pccsd != NULL )
  84. {
  85. pccsd->Release();
  86. } // if:
  87. HRETURN( hr );
  88. } //*** CEnumClusCfgManagedResources::S_HrCreateInstance
  89. //////////////////////////////////////////////////////////////////////////////
  90. //++
  91. //
  92. // CEnumClusCfgManagedResources::CEnumClusCfgManagedResources
  93. //
  94. // Description:
  95. // Constructor of the CEnumClusCfgManagedResources class. This initializes
  96. // the m_cRef variable to 1 instead of 0 to account of possible
  97. // QueryInterface failure in DllGetClassObject.
  98. //
  99. // Arguments:
  100. // None.
  101. //
  102. // Return Value:
  103. // None.
  104. //
  105. // Remarks:
  106. // None.
  107. //
  108. //--
  109. //////////////////////////////////////////////////////////////////////////////
  110. CEnumClusCfgManagedResources::CEnumClusCfgManagedResources( void )
  111. : m_cRef( 1 )
  112. , m_lcid( LOCALE_NEUTRAL )
  113. {
  114. TraceFunc( "" );
  115. Assert( m_idxNextProvider == 0 );
  116. Assert( m_idxCurrentProvider == 0 );
  117. Assert( m_picccCallback == NULL );
  118. Assert( m_pIWbemServices == NULL );
  119. Assert( m_rgpProviders == NULL );
  120. Assert( m_cTotalResources == 0);
  121. Assert( !m_fLoadedDevices );
  122. Assert( m_bstrNodeName == NULL );
  123. // Increment the count of components in memory so the DLL hosting this
  124. // object cannot be unloaded.
  125. InterlockedIncrement( &g_cObjects );
  126. TraceFuncExit();
  127. } //*** CEnumClusCfgManagedResources::CEnumClusCfgManagedResources
  128. //////////////////////////////////////////////////////////////////////////////
  129. //++
  130. //
  131. // CEnumClusCfgManagedResources::~CEnumClusCfgManagedResources
  132. //
  133. // Description:
  134. // Desstructor of the CEnumClusCfgManagedResources class.
  135. //
  136. // Arguments:
  137. // None.
  138. //
  139. // Return Value:
  140. // None.
  141. //
  142. // Remarks:
  143. // None.
  144. //
  145. //--
  146. //////////////////////////////////////////////////////////////////////////////
  147. CEnumClusCfgManagedResources::~CEnumClusCfgManagedResources( void )
  148. {
  149. TraceFunc( "" );
  150. ULONG idx;
  151. if ( m_pIWbemServices != NULL )
  152. {
  153. m_pIWbemServices->Release();
  154. } // if:
  155. if ( m_picccCallback != NULL )
  156. {
  157. m_picccCallback->Release();
  158. } // if:
  159. for ( idx = 0; idx < m_idxNextProvider; idx++ )
  160. {
  161. ((*m_rgpProviders)[ idx ])->Release();
  162. } // for:
  163. TraceFree( m_rgpProviders );
  164. TraceSysFreeString( m_bstrNodeName );
  165. // There's going to be one less component in memory. Decrement component count.
  166. InterlockedDecrement( &g_cObjects );
  167. TraceFuncExit();
  168. } //*** CEnumClusCfgManagedResources::~CEnumClusCfgManagedResources
  169. //*************************************************************************//
  170. /////////////////////////////////////////////////////////////////////////////
  171. // CEnumClusCfgManagedResources -- IUknkown interface.
  172. /////////////////////////////////////////////////////////////////////////////
  173. //////////////////////////////////////////////////////////////////////////////
  174. //++
  175. //
  176. // STDMETHODIMP_( ULONG )
  177. // CEnumClusCfgManagedResources:: [IUNKNOWN] AddRef
  178. //
  179. // Description:
  180. // Increment the reference count of this object by one.
  181. //
  182. // Arguments:
  183. // None.
  184. //
  185. // Return Value:
  186. // The new reference count.
  187. //
  188. // Remarks:
  189. // None.
  190. //
  191. //--
  192. //////////////////////////////////////////////////////////////////////////////
  193. STDMETHODIMP_( ULONG )
  194. CEnumClusCfgManagedResources::AddRef( void )
  195. {
  196. TraceFunc( "[IUnknown]" );
  197. InterlockedIncrement( & m_cRef );
  198. RETURN( m_cRef );
  199. } //*** CEnumClusCfgManagedResources::AddRef
  200. //////////////////////////////////////////////////////////////////////////////
  201. //++
  202. //
  203. // STDMETHODIMP_( ULONG )
  204. // CEnumClusCfgManagedResources:: [IUNKNOWN] Release
  205. //
  206. // Description:
  207. // Decrement the reference count of this object by one.
  208. //
  209. // Arguments:
  210. // None.
  211. //
  212. // Return Value:
  213. // The new reference count.
  214. //
  215. // Remarks:
  216. // None.
  217. //
  218. //--
  219. //////////////////////////////////////////////////////////////////////////////
  220. STDMETHODIMP_( ULONG )
  221. CEnumClusCfgManagedResources::Release( void )
  222. {
  223. TraceFunc( "[IUnknown]" );
  224. LONG cRef;
  225. cRef = InterlockedDecrement( &m_cRef );
  226. if ( cRef == 0 )
  227. {
  228. TraceDo( delete this );
  229. } // if: reference count equal to zero
  230. RETURN( cRef );
  231. } //*** CEnumClusCfgManagedResources::Release
  232. //////////////////////////////////////////////////////////////////////////////
  233. //++
  234. //
  235. // CEnumClusCfgManagedResources:: [INKNOWN] QueryInterface
  236. //
  237. // Description:
  238. // Query this object for the passed in interface.
  239. //
  240. // Arguments:
  241. // IN REFIID riid,
  242. // Id of interface requested.
  243. //
  244. // OUT void ** ppv
  245. // Pointer to the requested interface.
  246. //
  247. // Return Value:
  248. // S_OK
  249. // If the interface is available on this object.
  250. //
  251. // E_NOINTERFACE
  252. // If the interface is not available.
  253. //
  254. // Remarks:
  255. // None.
  256. //
  257. //--
  258. //////////////////////////////////////////////////////////////////////////////
  259. STDMETHODIMP
  260. CEnumClusCfgManagedResources::QueryInterface( REFIID riid, void ** ppv )
  261. {
  262. TraceQIFunc( riid, ppv );
  263. HRESULT hr = E_NOINTERFACE;
  264. if ( IsEqualIID( riid, IID_IUnknown ) )
  265. {
  266. *ppv = static_cast< IEnumClusCfgManagedResources * >( this );
  267. hr = S_OK;
  268. } // if: IUnknown
  269. else if ( IsEqualIID( riid, IID_IEnumClusCfgManagedResources ) )
  270. {
  271. *ppv = TraceInterface( __THISCLASS__, IEnumClusCfgManagedResources, this, 0 );
  272. hr = S_OK;
  273. } // else if:
  274. else if ( IsEqualIID( riid, IID_IClusCfgWbemServices ) )
  275. {
  276. *ppv = TraceInterface( __THISCLASS__, IClusCfgWbemServices, this, 0 );
  277. hr = S_OK;
  278. } // else if:
  279. else if ( IsEqualIID( riid, IID_IClusCfgInitialize ) )
  280. {
  281. *ppv = TraceInterface( __THISCLASS__, IClusCfgInitialize, this, 0 );
  282. hr = S_OK;
  283. } // else if:
  284. if ( SUCCEEDED( hr ) )
  285. {
  286. ((IUnknown *) *ppv)->AddRef( );
  287. } // if: success
  288. QIRETURN_IGNORESTDMARSHALLING( hr, riid );
  289. } //*** CEnumClusCfgManagedResources::QueryInterface
  290. //*************************************************************************//
  291. /////////////////////////////////////////////////////////////////////////////
  292. // CEnumClusCfgManagedResources -- IClusCfgWbemServices interface.
  293. /////////////////////////////////////////////////////////////////////////////
  294. //////////////////////////////////////////////////////////////////////////////
  295. //++
  296. //
  297. // CEnumClusCfgManagedResources::SetWbemServices
  298. //
  299. // Description:
  300. // Set the WBEM services provider.
  301. //
  302. // Arguments:
  303. // IN IWbemServices pIWbemServicesIn
  304. //
  305. // Return Value:
  306. // S_OK
  307. // Success
  308. //
  309. // E_POINTER
  310. // The pIWbemServicesIn param is NULL.
  311. //
  312. // Remarks:
  313. // None.
  314. //
  315. //--
  316. //////////////////////////////////////////////////////////////////////////////
  317. STDMETHODIMP
  318. CEnumClusCfgManagedResources::SetWbemServices( IWbemServices * pIWbemServicesIn )
  319. {
  320. TraceFunc( "[IClusCfgWbemServices]" );
  321. HRESULT hr = S_OK;
  322. if ( pIWbemServicesIn == NULL )
  323. {
  324. hr = THR( E_POINTER );
  325. STATUS_REPORT( TASKID_Major_Find_Devices, TASKID_Minor_SetWbemServices_Enum_Resources, IDS_ERROR_NULL_POINTER, hr );
  326. goto Cleanup;
  327. } // if:
  328. m_pIWbemServices = pIWbemServicesIn;
  329. m_pIWbemServices->AddRef();
  330. Cleanup:
  331. HRETURN( hr );
  332. } //*** CEnumClusCfgManagedResources::SetWbemServices
  333. //*************************************************************************//
  334. /////////////////////////////////////////////////////////////////////////////
  335. // CEnumClusCfgManagedResources -- IClusCfgInitialize interface.
  336. /////////////////////////////////////////////////////////////////////////////
  337. //////////////////////////////////////////////////////////////////////////////
  338. //++
  339. //
  340. // CEnumClusCfgManagedResources::Initialize
  341. //
  342. // Description:
  343. // Initialize this component.
  344. //
  345. // Arguments:
  346. // IN IUknown * punkCallbackIn
  347. //
  348. // IN LCID lcidIn
  349. //
  350. // Return Value:
  351. // S_OK
  352. // Success
  353. //
  354. // Remarks:
  355. // None.
  356. //
  357. //--
  358. //////////////////////////////////////////////////////////////////////////////
  359. STDMETHODIMP
  360. CEnumClusCfgManagedResources::Initialize(
  361. IUnknown * punkCallbackIn,
  362. LCID lcidIn
  363. )
  364. {
  365. TraceFunc( "[IClusCfgInitialize]" );
  366. Assert( m_picccCallback == NULL );
  367. HRESULT hr = S_OK;
  368. m_lcid = lcidIn;
  369. if ( punkCallbackIn == NULL )
  370. {
  371. hr = THR( E_POINTER );
  372. goto Cleanup;
  373. } // if:
  374. hr = THR( punkCallbackIn->TypeSafeQI( IClusCfgCallback, &m_picccCallback ) );
  375. Cleanup:
  376. HRETURN( hr );
  377. } //*** CEnumClusCfgManagedResources::Initialize
  378. //*************************************************************************//
  379. /////////////////////////////////////////////////////////////////////////////
  380. // CEnumClusCfgManagedResources -- IEnumClusCfgManagedResources interface.
  381. /////////////////////////////////////////////////////////////////////////////
  382. //////////////////////////////////////////////////////////////////////////////
  383. //++
  384. //
  385. // CEnumClusCfgManagedResources::Next
  386. //
  387. // Description:
  388. //
  389. // Arguments:
  390. //
  391. // Return Value:
  392. //
  393. // Remarks:
  394. // None.
  395. //
  396. //--
  397. //////////////////////////////////////////////////////////////////////////////
  398. STDMETHODIMP
  399. CEnumClusCfgManagedResources::Next(
  400. ULONG cNumberRequestedIn,
  401. IClusCfgManagedResourceInfo ** rgpManagedResourceInfoOut,
  402. ULONG * pcNumberFetchedOut
  403. )
  404. {
  405. TraceFunc( "[IEnumClusCfgManagedResources]" );
  406. HRESULT hr;
  407. ULONG cFetched = 0;
  408. if ( rgpManagedResourceInfoOut == NULL )
  409. {
  410. hr = THR( E_POINTER );
  411. STATUS_REPORT( TASKID_Major_Find_Devices, TASKID_Minor_Next_Enum_Resources, IDS_ERROR_NULL_POINTER, hr );
  412. goto Cleanup;
  413. } // if:
  414. if ( !m_fLoadedDevices )
  415. {
  416. hr = THR( HrLoadEnum() );
  417. if ( FAILED( hr ) )
  418. {
  419. goto Cleanup;
  420. } // if:
  421. } // if:
  422. hr = STHR( HrDoNext( cNumberRequestedIn, rgpManagedResourceInfoOut, &cFetched ) );
  423. if ( FAILED( hr ) )
  424. {
  425. goto Cleanup;
  426. } // if:
  427. if ( pcNumberFetchedOut != NULL )
  428. {
  429. *pcNumberFetchedOut = cFetched;
  430. } // if:
  431. Cleanup:
  432. HRETURN( hr );
  433. } //*** CEnumClusCfgManagedResources::Next
  434. //////////////////////////////////////////////////////////////////////////////
  435. //++
  436. //
  437. // CEnumClusCfgManagedResources::Skip
  438. //
  439. // Description:
  440. //
  441. // Arguments:
  442. //
  443. // Return Value:
  444. //
  445. // Remarks:
  446. // None.
  447. //
  448. //--
  449. //////////////////////////////////////////////////////////////////////////////
  450. STDMETHODIMP
  451. CEnumClusCfgManagedResources::Skip( ULONG cNumberToSkipIn )
  452. {
  453. TraceFunc( "[IEnumClusCfgManagedResources]" );
  454. HRESULT hr = S_FALSE;
  455. if ( cNumberToSkipIn > 0 )
  456. {
  457. hr = STHR( HrDoSkip( cNumberToSkipIn ) );
  458. } // if:
  459. HRETURN( hr );
  460. } //*** CEnumClusCfgManagedResources::Skip
  461. //////////////////////////////////////////////////////////////////////////////
  462. //++
  463. //
  464. // CEnumClusCfgManagedResources::Reset
  465. //
  466. // Description:
  467. //
  468. // Arguments:
  469. //
  470. // Return Value:
  471. //
  472. // Remarks:
  473. // None.
  474. //
  475. //--
  476. //////////////////////////////////////////////////////////////////////////////
  477. STDMETHODIMP
  478. CEnumClusCfgManagedResources::Reset( void )
  479. {
  480. TraceFunc( "[IEnumClusCfgManagedResources]" );
  481. HRESULT hr;
  482. hr = THR( HrDoReset() );
  483. HRETURN( hr );
  484. } //*** CEnumClusCfgManagedResources::Reset
  485. //////////////////////////////////////////////////////////////////////////////
  486. //++
  487. //
  488. // CEnumClusCfgManagedResources::Clone
  489. //
  490. // Description:
  491. //
  492. // Arguments:
  493. //
  494. // Return Value:
  495. //
  496. // Remarks:
  497. // None.
  498. //
  499. //--
  500. //////////////////////////////////////////////////////////////////////////////
  501. STDMETHODIMP
  502. CEnumClusCfgManagedResources::Clone(
  503. IEnumClusCfgManagedResources ** ppEnumClusCfgManagedResourcesOut
  504. )
  505. {
  506. TraceFunc( "[IEnumClusCfgManagedResources]" );
  507. HRESULT hr = S_OK;
  508. if ( ppEnumClusCfgManagedResourcesOut == NULL )
  509. {
  510. hr = THR( E_POINTER );
  511. STATUS_REPORT( TASKID_Major_Find_Devices, TASKID_Minor_Clone_Enum_Resources, IDS_ERROR_NULL_POINTER, hr );
  512. goto Cleanup;
  513. } // else:
  514. hr = THR( HrDoClone( ppEnumClusCfgManagedResourcesOut ) );
  515. Cleanup:
  516. HRETURN( hr );
  517. } //*** CEnumClusCfgManagedResources::Clone
  518. //////////////////////////////////////////////////////////////////////////////
  519. //++
  520. //
  521. // CEnumClusCfgManagedResources::Count
  522. //
  523. // Description:
  524. //
  525. // Arguments:
  526. //
  527. // Return Value:
  528. //
  529. // Remarks:
  530. // None.
  531. //
  532. //--
  533. //////////////////////////////////////////////////////////////////////////////
  534. STDMETHODIMP
  535. CEnumClusCfgManagedResources::Count( DWORD * pnCountOut )
  536. {
  537. TraceFunc( "[IEnumClusCfgManagedResources]" );
  538. HRESULT hr = S_OK;
  539. if ( pnCountOut == NULL )
  540. {
  541. hr = THR( E_POINTER );
  542. goto Cleanup;
  543. } // if:
  544. if ( !m_fLoadedDevices )
  545. {
  546. hr = THR( HrLoadEnum() );
  547. if ( FAILED( hr ) )
  548. {
  549. goto Cleanup;
  550. } // if:
  551. } // if:
  552. *pnCountOut = m_cTotalResources;
  553. Cleanup:
  554. HRETURN( hr );
  555. } //*** CEnumClusCfgManagedResources::Count
  556. //*************************************************************************//
  557. /////////////////////////////////////////////////////////////////////////////
  558. // CEnumClusCfgManagedResources class -- Private Methods.
  559. /////////////////////////////////////////////////////////////////////////////
  560. //////////////////////////////////////////////////////////////////////////////
  561. //++
  562. //
  563. // CEnumClusCfgManagedResources::HrInit
  564. //
  565. // Description:
  566. // Initialize this component.
  567. //
  568. // Arguments:
  569. // None.
  570. //
  571. // Return Value:
  572. //
  573. //
  574. // Remarks:
  575. // None.
  576. //
  577. //--
  578. //////////////////////////////////////////////////////////////////////////////
  579. HRESULT
  580. CEnumClusCfgManagedResources::HrInit( void )
  581. {
  582. TraceFunc( "" );
  583. HRESULT hr = S_OK;
  584. hr = THR( HrGetComputerName( ComputerNameNetBIOS, &m_bstrNodeName ) );
  585. HRETURN( hr );
  586. } //*** CEnumClusCfgManagedResources::HrInit
  587. //////////////////////////////////////////////////////////////////////////////
  588. //++
  589. //
  590. // CEnumClusCfgManagedResources::HrLoadEnum
  591. //
  592. // Description:
  593. // Load this enumerator.
  594. //
  595. // Arguments:
  596. // None.
  597. //
  598. // Return Value:
  599. //
  600. //
  601. // Remarks:
  602. // None.
  603. //
  604. //--
  605. //////////////////////////////////////////////////////////////////////////////
  606. HRESULT
  607. CEnumClusCfgManagedResources::HrLoadEnum( void )
  608. {
  609. TraceFunc( "" );
  610. HRESULT hr;
  611. IUnknown * punk = NULL;
  612. ICatInformation * pici = NULL;
  613. CATID rgCatIds[ 1 ];
  614. IEnumCLSID * pieclsids = NULL;
  615. IEnumClusCfgManagedResources * pieccmr = NULL;
  616. CLSID clsid;
  617. ULONG cFetched;
  618. rgCatIds[ 0 ] = CATID_EnumClusCfgManagedResources;
  619. hr = THR( CoCreateInstance( CLSID_StdComponentCategoriesMgr, NULL, CLSCTX_INPROC_SERVER, IID_ICatInformation, (void **) &pici ) );
  620. if ( FAILED( hr ) )
  621. {
  622. goto Cleanup;
  623. }
  624. hr = THR( pici->EnumClassesOfCategories( 1, rgCatIds, 0, NULL, &pieclsids ) );
  625. if ( FAILED( hr ) )
  626. {
  627. goto Cleanup;
  628. } // if:
  629. for ( ; ; )
  630. {
  631. hr = STHR( pieclsids->Next( 1, &clsid, &cFetched ) );
  632. if ( FAILED( hr ) )
  633. {
  634. break;
  635. } // if:
  636. if ( ( hr == S_FALSE ) && ( cFetched == 0 ) )
  637. {
  638. hr = S_OK;
  639. break;
  640. } // if:
  641. hr = THR( HrCoCreateInternalInstance( clsid, NULL, CLSCTX_SERVER, IID_IEnumClusCfgManagedResources, (void **) &pieccmr ) );
  642. if ( FAILED( hr ) )
  643. {
  644. break;
  645. } // if:
  646. hr = THR( pieccmr->TypeSafeQI( IUnknown, &punk ) );
  647. if ( FAILED( hr ) )
  648. {
  649. break;
  650. } // if:
  651. punk = TraceInterface( L"IEnumClusCfgManagedResources", IUnknown, punk, 1 );
  652. pieccmr->Release();
  653. pieccmr = NULL;
  654. hr = STHR( HrInitializeAndSaveProvider( punk ) );
  655. if ( FAILED( hr ) )
  656. {
  657. goto Cleanup;
  658. } // if:
  659. if ( hr == S_OK )
  660. {
  661. m_fLoadedDevices = TRUE; // there is at least one provider loaded.
  662. } // if:
  663. punk->Release();
  664. punk = NULL;
  665. } // for:
  666. hr = STHR( HrLoadUnknownQuorumProvider() );
  667. Cleanup:
  668. if ( pieclsids != NULL )
  669. {
  670. pieclsids->Release();
  671. } // if:
  672. if ( pici != NULL )
  673. {
  674. pici->Release();
  675. } // if:
  676. if ( pieccmr != NULL )
  677. {
  678. pieccmr->Release();
  679. } // if:
  680. if ( punk != NULL )
  681. {
  682. punk->Release();
  683. } // if:
  684. HRETURN( hr );
  685. } //*** CEnumClusCfgManagedResources::HrLoadEnum
  686. //////////////////////////////////////////////////////////////////////////////
  687. //++
  688. //
  689. // CEnumClusCfgManagedResources::HrDoNext
  690. //
  691. // Description:
  692. // Gets the required number of elements from the contained physical disk
  693. // and optional 3rd party device enumerations.
  694. //
  695. // Arguments:
  696. //
  697. // Return Value:
  698. //
  699. // Remarks:
  700. // None.
  701. //
  702. //--
  703. //////////////////////////////////////////////////////////////////////////////
  704. HRESULT
  705. CEnumClusCfgManagedResources::HrDoNext(
  706. ULONG cNumberRequestedIn,
  707. IClusCfgManagedResourceInfo ** rgpManagedResourceInfoOut,
  708. ULONG * pcNumberFetchedOut
  709. )
  710. {
  711. TraceFunc( "" );
  712. HRESULT hr = S_FALSE;
  713. IEnumClusCfgManagedResources * peccsd = NULL;
  714. ULONG cRequested = cNumberRequestedIn;
  715. ULONG cFetched;
  716. ULONG cTotal = 0;
  717. IClusCfgManagedResourceInfo ** ppccmriTemp = rgpManagedResourceInfoOut;
  718. while ( m_idxCurrentProvider < m_idxNextProvider )
  719. {
  720. hr = THR( ((*m_rgpProviders)[ m_idxCurrentProvider ])->TypeSafeQI( IEnumClusCfgManagedResources, &peccsd ) );
  721. if ( FAILED( hr ) )
  722. {
  723. //
  724. // KB: 06 Apr 2000 GalenB
  725. //
  726. // This failure and the one below are a little trickery in action. If something
  727. // fails and we have already retrieved some elements from one, or more, of the enums
  728. // it makes sense to change the failure to S_FALSE and return what we have.
  729. // This makes cleanup easier since we don't have to reset the enums that have
  730. // already given us some elements. Then, if we're called again we should get
  731. // the same failure, with no retrieved elements and can simply return the
  732. // failure.
  733. //
  734. if ( cTotal > 0 )
  735. {
  736. hr = STHR( S_FALSE );
  737. } // if:
  738. goto Cleanup;
  739. } // if:
  740. hr = STHR( peccsd->Next( cRequested, ppccmriTemp, &cFetched ) );
  741. //
  742. // KB: 06 Apr 2000 GalenB
  743. //
  744. // Release the enum now to make things much easier. It is true that we will most
  745. // likely QI twice for each enum, but the effort to optimize this just doesn't
  746. // seem worth it.
  747. //
  748. peccsd->Release();
  749. peccsd = NULL;
  750. if ( FAILED( hr ) )
  751. {
  752. if ( cTotal > 0 )
  753. {
  754. hr = STHR( S_FALSE );
  755. } // if: See KB above...
  756. goto Cleanup;
  757. } // if:
  758. if ( hr == S_OK )
  759. {
  760. cTotal += cFetched;
  761. //
  762. // KB: 06 Apr 2000 GalenB
  763. //
  764. // We can only return S_OK if the number of elements returned is equal to
  765. // the number of elements requested. If the number request is greater than
  766. // the number returned then we must return S_FALSE.
  767. //
  768. Assert( cNumberRequestedIn == cTotal );
  769. *pcNumberFetchedOut = cTotal;
  770. break;
  771. } // if:
  772. if ( hr == S_FALSE )
  773. {
  774. //
  775. // KB: 06 Apr 2000 GalenB
  776. //
  777. // The only time that we can be certain that an enumerator is empty is to get S_FALSE
  778. // and no elements returned.
  779. //
  780. if ( cFetched == 0 )
  781. {
  782. m_idxCurrentProvider++;
  783. continue;
  784. } // if:
  785. cTotal += cFetched;
  786. *pcNumberFetchedOut = cTotal;
  787. cRequested -= cFetched;
  788. if ( cRequested > 0 )
  789. {
  790. ppccmriTemp += cFetched;
  791. continue;
  792. } // if: Safety check... Ensure that we still need more elements...
  793. else
  794. {
  795. hr = S_FALSE;
  796. LOG_STATUS_REPORT1( TASKID_Minor_MREnum_Negative_Item_Count, L"The managed resources enumerator tried to return more items than asked for.", hr );
  797. goto Cleanup;
  798. } // else: Should not get here...
  799. } // if:
  800. // should not get here...
  801. hr = S_FALSE;
  802. LOG_STATUS_REPORT1( TASKID_Minor_MREnum_Unknown_State, L"The mana b bged resources enumerator encountered an unknown state.", hr );
  803. goto Cleanup;
  804. } // while: more providers
  805. Cleanup:
  806. if ( peccsd != NULL )
  807. {
  808. peccsd->Release();
  809. } // if:
  810. HRETURN( hr );
  811. } //*** CEnumClusCfgManagedResources::HrDoNext
  812. //////////////////////////////////////////////////////////////////////////////
  813. //++
  814. //
  815. // CEnumClusCfgManagedResources::HrDoSkip
  816. //
  817. // Description:
  818. // Skips the required number of elements in the contained physical disk
  819. // and optional 3rd party device enumerations.
  820. //
  821. // Arguments:
  822. //
  823. // Return Value:
  824. //
  825. // Remarks:
  826. // None.
  827. //
  828. //--
  829. //////////////////////////////////////////////////////////////////////////////
  830. HRESULT
  831. CEnumClusCfgManagedResources::HrDoSkip( ULONG cNumberToSkipIn )
  832. {
  833. TraceFunc( "" );
  834. HRESULT hr = S_FALSE;
  835. IEnumClusCfgManagedResources * peccsd = NULL;
  836. ULONG cSkipped = 0;
  837. for ( ; m_idxCurrentProvider < m_idxNextProvider; )
  838. {
  839. hr = THR( ((*m_rgpProviders)[ m_idxCurrentProvider ])->TypeSafeQI( IEnumClusCfgManagedResources, &peccsd ) );
  840. if ( FAILED( hr ) )
  841. {
  842. goto Cleanup;
  843. } // if:
  844. do
  845. {
  846. hr = STHR( peccsd->Skip( 1 ) );
  847. if ( FAILED( hr ) )
  848. {
  849. goto Cleanup;
  850. } // if:
  851. if ( hr == S_FALSE )
  852. {
  853. m_idxCurrentProvider++;
  854. break;
  855. } // if:
  856. }
  857. while( cNumberToSkipIn >= (++cSkipped) );
  858. peccsd->Release();
  859. peccsd = NULL;
  860. if ( FAILED( hr ) )
  861. {
  862. goto Cleanup;
  863. } // if:
  864. if ( cNumberToSkipIn == cSkipped )
  865. {
  866. break;
  867. } // if:
  868. } // for:
  869. Cleanup:
  870. if ( peccsd != NULL )
  871. {
  872. peccsd->Release();
  873. } // if:
  874. HRETURN( hr );
  875. } //*** CEnumClusCfgManagedResources::HrDoSkip
  876. //////////////////////////////////////////////////////////////////////////////
  877. //++
  878. //
  879. // CEnumClusCfgManagedResources::HrDoReset
  880. //
  881. // Description:
  882. // Resets the elements in the contained physical disk and optional 3rd
  883. // party device enumerations.
  884. //
  885. // Arguments:
  886. //
  887. // Return Value:
  888. //
  889. // Remarks:
  890. // None.
  891. //
  892. //--
  893. //////////////////////////////////////////////////////////////////////////////
  894. HRESULT
  895. CEnumClusCfgManagedResources::HrDoReset( void )
  896. {
  897. TraceFunc( "" );
  898. HRESULT hr = S_FALSE;
  899. IEnumClusCfgManagedResources * peccsd;
  900. ULONG idx;
  901. m_idxCurrentProvider = 0;
  902. for ( idx = m_idxCurrentProvider; idx < m_idxNextProvider; idx++ )
  903. {
  904. hr = THR( ((*m_rgpProviders)[ idx ])->TypeSafeQI( IEnumClusCfgManagedResources, &peccsd ) );
  905. if ( FAILED( hr ) )
  906. {
  907. break;
  908. } // if:
  909. hr = STHR( peccsd->Reset() );
  910. peccsd->Release();
  911. if ( FAILED( hr ) )
  912. {
  913. break;
  914. } // if:
  915. } // for:
  916. HRETURN( hr );
  917. } //*** CEnumClusCfgManagedResources::HrDoReset
  918. //////////////////////////////////////////////////////////////////////////////
  919. //++
  920. //
  921. // CEnumClusCfgManagedResources::HrDoClone
  922. //
  923. // Description:
  924. // Clones the elements in the contained physical disk and optional 3rd
  925. // party device enumerations.
  926. //
  927. // Arguments:
  928. //
  929. // Return Value:
  930. //
  931. // Remarks:
  932. // None.
  933. //
  934. //--
  935. //////////////////////////////////////////////////////////////////////////////
  936. HRESULT
  937. CEnumClusCfgManagedResources::HrDoClone(
  938. IEnumClusCfgManagedResources ** ppEnumClusCfgManagedResourcesOut
  939. )
  940. {
  941. TraceFunc( "" );
  942. HRESULT hr = THR( E_NOTIMPL );
  943. HRETURN( hr );
  944. } //*** CEnumClusCfgManagedResources::HrDoClone
  945. /////////////////////////////////////////////////////////////////////////////
  946. //++
  947. //
  948. // CEnumClusCfgManagedResources:HrAddToProvidersArray
  949. //
  950. // Description:
  951. // Add the passed in punk to the array of punks that holds the enums.
  952. //
  953. // Arguments:
  954. //
  955. //
  956. // Return Value:
  957. // S_OK
  958. // Success
  959. //
  960. // E_OUTOFMEMORY
  961. // Couldn't allocate memeory.
  962. //
  963. // Remarks:
  964. // None.
  965. //
  966. //--
  967. //////////////////////////////////////////////////////////////////////////////
  968. HRESULT
  969. CEnumClusCfgManagedResources::HrAddToProvidersArray( IUnknown * punkIn )
  970. {
  971. TraceFunc( "" );
  972. HRESULT hr = S_OK;
  973. IUnknown * ((*rgpunks)[]) = NULL;
  974. IEnumClusCfgManagedResources * pieccmr = NULL;
  975. DWORD nAmountToAdd = 0;
  976. hr = punkIn->TypeSafeQI( IEnumClusCfgManagedResources, &pieccmr );
  977. if ( FAILED (hr) )
  978. {
  979. goto Cleanup;
  980. } // if:
  981. hr = pieccmr->Count( &nAmountToAdd );
  982. if ( FAILED (hr) )
  983. {
  984. goto Cleanup;
  985. } // if:
  986. rgpunks = (IUnknown *((*)[])) TraceReAlloc( m_rgpProviders, sizeof( IUnknown * ) * ( m_idxNextProvider + 1 ), HEAP_ZERO_MEMORY );
  987. if ( rgpunks == NULL )
  988. {
  989. hr = THR( E_OUTOFMEMORY );
  990. STATUS_REPORT( TASKID_Major_Find_Devices, TASKID_Minor_HrAddToProvidersArray, IDS_ERROR_OUTOFMEMORY, hr );
  991. goto Cleanup;
  992. } // if:
  993. m_rgpProviders = rgpunks;
  994. (*m_rgpProviders)[ m_idxNextProvider++ ] = punkIn;
  995. punkIn->AddRef();
  996. m_cTotalResources += nAmountToAdd;
  997. Cleanup:
  998. if ( pieccmr != NULL )
  999. {
  1000. pieccmr->Release();
  1001. }
  1002. HRETURN( hr );
  1003. } //*** CEnumClusCfgManagedResources::HrAddToProvidersArray
  1004. /////////////////////////////////////////////////////////////////////////////
  1005. //++
  1006. //
  1007. // CEnumClusCfgManagedResources:HrLoadUnknownQuorumProvider
  1008. //
  1009. // Description:
  1010. // Since we cannot resonable expect every 3rd party quorum vender
  1011. // to write a "provider" for their device for this setup wizard
  1012. // we need a proxy to represent that quorum device. The "unknown"
  1013. // is just such a proxy.
  1014. //
  1015. // Arguments:
  1016. // None.
  1017. //
  1018. // Return Value:
  1019. // S_OK
  1020. // Success
  1021. //
  1022. // E_OUTOFMEMORY
  1023. // Couldn't allocate memeory.
  1024. //
  1025. // Remarks:
  1026. // If this node is clustered and we do not find a device that is
  1027. // already the quorum then we need to make the "unknown" quorum
  1028. // the quorum device.
  1029. //
  1030. //--
  1031. //////////////////////////////////////////////////////////////////////////////
  1032. HRESULT
  1033. CEnumClusCfgManagedResources::HrLoadUnknownQuorumProvider( void )
  1034. {
  1035. TraceFunc( "" );
  1036. HRESULT hr = S_OK;
  1037. IUnknown * punk = NULL;
  1038. BOOL fNeedQuorum = FALSE;
  1039. BOOL fQuormIsOwnedByThisNode = FALSE;
  1040. BSTR bstrQuorumResourceName = NULL;
  1041. hr = STHR( HrIsClusterServiceRunning() );
  1042. if ( FAILED( hr ) )
  1043. {
  1044. goto Cleanup;
  1045. } // if:
  1046. if ( hr == S_OK )
  1047. {
  1048. hr = THR( HrIsThereAQuorumDevice() );
  1049. if ( FAILED( hr ) )
  1050. {
  1051. goto Cleanup;
  1052. } // if:
  1053. if ( hr == S_FALSE )
  1054. {
  1055. fNeedQuorum = TRUE;
  1056. } // if:
  1057. hr = THR( HrGetQuorumResourceName( &bstrQuorumResourceName, &fQuormIsOwnedByThisNode ) );
  1058. if ( FAILED( hr ) )
  1059. {
  1060. goto Cleanup;
  1061. } // if:
  1062. } // if:
  1063. //
  1064. // If there was not already a quorum, and if this node owns the quorum resource
  1065. // then we need the unknown quorum proxy to be set as default to the quorum device.
  1066. //
  1067. // If we are not running on a cluster node then both are false and the unknown
  1068. // quorum proxy will not be set by default to be the quorum.
  1069. //
  1070. hr = THR( CEnumUnknownQuorum::S_HrCreateInstance( bstrQuorumResourceName, ( fNeedQuorum && fQuormIsOwnedByThisNode ), &punk ) );
  1071. if ( FAILED( hr ) )
  1072. {
  1073. goto Cleanup;
  1074. } // if:
  1075. hr = THR( HrInitializeAndSaveProvider( punk ) );
  1076. Cleanup:
  1077. if ( punk != NULL )
  1078. {
  1079. punk->Release();
  1080. } // if:
  1081. TraceSysFreeString( bstrQuorumResourceName );
  1082. HRETURN( hr );
  1083. } //*** CEnumClusCfgManagedResources::HrLoadUnknownQuorumProvider
  1084. /////////////////////////////////////////////////////////////////////////////
  1085. //++
  1086. //
  1087. // CEnumClusCfgManagedResources:HrIsClusterServiceRunning
  1088. //
  1089. // Description:
  1090. // Is this node a member of a cluster and is the serice running?
  1091. //
  1092. // Arguments:
  1093. // None.
  1094. //
  1095. // Return Value:
  1096. // S_OK
  1097. // The node is clustered and the serivce is running.
  1098. //
  1099. // S_FALSE
  1100. // The node is not clustered, or the serivce is not running.
  1101. //
  1102. // Win32 Error
  1103. // something failed.
  1104. //
  1105. // Remarks:
  1106. // None.
  1107. //
  1108. //--
  1109. //////////////////////////////////////////////////////////////////////////////
  1110. HRESULT
  1111. CEnumClusCfgManagedResources::HrIsClusterServiceRunning( void )
  1112. {
  1113. TraceFunc( "" );
  1114. HRESULT hr = S_FALSE;
  1115. DWORD sc;
  1116. DWORD dwClusterState;
  1117. sc = TW32( GetNodeClusterState( NULL, &dwClusterState ) );
  1118. if ( sc != ERROR_SUCCESS )
  1119. {
  1120. hr = THR( HRESULT_FROM_WIN32( sc ) );
  1121. goto Cleanup;
  1122. } // if : GetClusterState() failed
  1123. if ( dwClusterState == ClusterStateRunning )
  1124. {
  1125. hr = S_OK;
  1126. } // if:
  1127. Cleanup:
  1128. HRETURN( hr );
  1129. } //*** CEnumClusCfgMana9gedResources::HrIsClusterServiceRunning
  1130. /////////////////////////////////////////////////////////////////////////////
  1131. //++
  1132. //
  1133. // CEnumClusCfgManagedResources:HrIsThereAQuorumDevice
  1134. //
  1135. // Description:
  1136. // Is there a quorum device in an enum somewhere?
  1137. //
  1138. // Arguments:
  1139. // None.
  1140. //
  1141. // Return Value:
  1142. // S_OK
  1143. // There is a quorum device.
  1144. //
  1145. // S_FALSE
  1146. // There is not a quorum device.
  1147. //
  1148. // Win32 Error
  1149. // something failed.
  1150. //
  1151. // Remarks:
  1152. // None.
  1153. //
  1154. //--
  1155. //////////////////////////////////////////////////////////////////////////////
  1156. HRESULT
  1157. CEnumClusCfgManagedResources::HrIsThereAQuorumDevice( void )
  1158. {
  1159. TraceFunc( "" );
  1160. Assert( m_idxCurrentProvider == 0 );
  1161. HRESULT hr = S_OK;
  1162. IClusCfgManagedResourceInfo * piccmri = NULL;
  1163. DWORD cFetched;
  1164. bool fFoundQuorum = false;
  1165. for ( ; ; )
  1166. {
  1167. hr = STHR( Next( 1, &piccmri, &cFetched ) );
  1168. if ( FAILED( hr ) )
  1169. {
  1170. goto Cleanup;
  1171. } // if:
  1172. if ( ( hr == S_FALSE ) && ( cFetched == 0 ) )
  1173. {
  1174. hr = S_OK;
  1175. break;
  1176. } // if:
  1177. hr = THR( piccmri->IsQuorumDevice() );
  1178. if ( FAILED( hr ) )
  1179. {
  1180. goto Cleanup;
  1181. } // if:
  1182. if ( hr == S_OK )
  1183. {
  1184. fFoundQuorum = true;
  1185. break;
  1186. } // if:
  1187. piccmri->Release();
  1188. piccmri = NULL;
  1189. } // for:
  1190. hr = THR( Reset() );
  1191. Cleanup:
  1192. if ( piccmri != NULL )
  1193. {
  1194. piccmri->Release();
  1195. } // if:
  1196. if ( SUCCEEDED( hr ) )
  1197. {
  1198. if ( fFoundQuorum )
  1199. {
  1200. hr = S_OK;
  1201. } // if:
  1202. else
  1203. {
  1204. hr = S_FALSE;
  1205. } // else:
  1206. } // if:
  1207. HRETURN( hr );
  1208. } //*** CEnumClusCfgManagedResources::HrIsThereAQuorumDevice
  1209. /////////////////////////////////////////////////////////////////////////////
  1210. //++
  1211. //
  1212. // CEnumClusCfgManagedResources:HrInitializeAndSaveProvider
  1213. //
  1214. // Description:
  1215. // Initialize the passed in enum and add it to the array of enums.
  1216. //
  1217. // Arguments:
  1218. //
  1219. // Return Value:
  1220. // S_OK
  1221. // Success.
  1222. //
  1223. // S_FALSE
  1224. // The provider was not saved.
  1225. //
  1226. // Win32 Error
  1227. // something failed.
  1228. //
  1229. // Remarks:
  1230. // None.
  1231. //
  1232. //--
  1233. //////////////////////////////////////////////////////////////////////////////
  1234. HRESULT
  1235. CEnumClusCfgManagedResources::HrInitializeAndSaveProvider( IUnknown * punkIn )
  1236. {
  1237. TraceFunc( "" );
  1238. HRESULT hr = S_OK;
  1239. //
  1240. // KB: 13-JUN-2000 GalenB
  1241. //
  1242. // If S_FALSE is returned don't add this to the array. S_FALSE
  1243. // indicates that this enumerator should not be run now.
  1244. //
  1245. hr = STHR( HrSetInitialize( punkIn, m_picccCallback, m_lcid ) );
  1246. if ( FAILED( hr ) )
  1247. {
  1248. goto Cleanup;
  1249. } // if:
  1250. if ( hr == S_FALSE )
  1251. {
  1252. goto Cleanup;
  1253. } // if:
  1254. hr = HrSetWbemServices( punkIn, m_pIWbemServices );
  1255. if ( FAILED( hr ) )
  1256. {
  1257. goto Cleanup;
  1258. } // if:
  1259. hr = THR( HrAddToProvidersArray( punkIn ) );
  1260. Cleanup:
  1261. HRETURN( hr );
  1262. } //*** CEnumClusCfgManagedResources::HrInitializeAndSaveProvider
  1263. /////////////////////////////////////////////////////////////////////////////
  1264. //++
  1265. //
  1266. // CEnumClusCfgManagedResources:HrGetQuorumResourceName
  1267. //
  1268. // Description:
  1269. // Get the quorum resource name and return whether or not this node
  1270. // owns the quorum.
  1271. //
  1272. // Arguments:
  1273. //
  1274. // Return Value:
  1275. // S_OK
  1276. // Success.
  1277. //
  1278. // Win32 Error
  1279. // something failed.
  1280. //
  1281. // Remarks:
  1282. // None.
  1283. //
  1284. //--
  1285. //////////////////////////////////////////////////////////////////////////////
  1286. HRESULT
  1287. CEnumClusCfgManagedResources::HrGetQuorumResourceName(
  1288. BSTR * pbstrQuorumResourceNameOut
  1289. , BOOL * pfQuormIsOwnedByThisNodeOut
  1290. )
  1291. {
  1292. TraceFunc( "" );
  1293. Assert( pbstrQuorumResourceNameOut != NULL );
  1294. Assert( pfQuormIsOwnedByThisNodeOut != NULL );
  1295. HRESULT hr = S_OK;
  1296. DWORD sc;
  1297. HCLUSTER hCluster = NULL;
  1298. BSTR bstrQuorumResourceName = NULL;
  1299. BSTR bstrNodeName = NULL;
  1300. HRESOURCE hQuorumResource = NULL;
  1301. hCluster = OpenCluster( NULL );
  1302. if ( hCluster == NULL )
  1303. {
  1304. sc = TW32( GetLastError() );
  1305. hr = HRESULT_FROM_WIN32( sc );
  1306. goto Cleanup;
  1307. } // if:
  1308. hr = THR( HrGetClusterQuorumResource( hCluster, &bstrQuorumResourceName, NULL, NULL ) );
  1309. if ( FAILED( hr ) )
  1310. {
  1311. goto Cleanup;
  1312. } // if:
  1313. hQuorumResource = OpenClusterResource( hCluster, bstrQuorumResourceName );
  1314. if ( hQuorumResource == NULL )
  1315. {
  1316. sc = TW32( GetLastError() );
  1317. hr = HRESULT_FROM_WIN32( sc );
  1318. goto Cleanup;
  1319. } // if:
  1320. hr = THR( HrGetClusterResourceState( hQuorumResource, &bstrNodeName, NULL, NULL ) );
  1321. if ( FAILED( hr ) )
  1322. {
  1323. goto Cleanup;
  1324. } // if:
  1325. //
  1326. // Give ownership away.
  1327. //
  1328. Assert( bstrQuorumResourceName != NULL );
  1329. *pbstrQuorumResourceNameOut = bstrQuorumResourceName;
  1330. bstrQuorumResourceName = NULL;
  1331. *pfQuormIsOwnedByThisNodeOut = ( _wcsicmp( m_bstrNodeName, bstrNodeName ) == 0 );
  1332. Cleanup:
  1333. if ( hQuorumResource != NULL )
  1334. {
  1335. CloseClusterResource( hQuorumResource );
  1336. } // if:
  1337. if ( hCluster != NULL )
  1338. {
  1339. CloseCluster( hCluster );
  1340. } // if:
  1341. TraceSysFreeString( bstrQuorumResourceName );
  1342. TraceSysFreeString( bstrNodeName );
  1343. HRETURN( hr );
  1344. } //*** CEnumClusCfgManagedResources::HrGetQuorumResourceName