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.

1901 lines
54 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1997-2002 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // ClusNetI.cpp
  7. //
  8. // Description:
  9. // Implementation of the network interface classes for the MSCLUS
  10. // automation classes.
  11. //
  12. // Author:
  13. // Ramakrishna Rosanuru via David Potter (davidp) 5-Sep-1997
  14. // Galen Barbee (galenb) July 1998
  15. //
  16. // Revision History:
  17. // July 1998 GalenB Maaaaaajjjjjjjjjoooooorrrr clean up
  18. //
  19. // Notes:
  20. //
  21. /////////////////////////////////////////////////////////////////////////////
  22. #include "stdafx.h"
  23. #include "ClusterObject.h"
  24. #include "property.h"
  25. #include "clusneti.h"
  26. /////////////////////////////////////////////////////////////////////////////
  27. // Global variables
  28. /////////////////////////////////////////////////////////////////////////////
  29. static const IID * iidCClusNetInterface[] =
  30. {
  31. &IID_ISClusNetInterface
  32. };
  33. static const IID * iidCClusNetInterfaces[] =
  34. {
  35. &IID_ISClusNetInterface
  36. };
  37. static const IID * iidCClusNetworkNetInterfaces[] =
  38. {
  39. &IID_ISClusNetworkNetInterfaces
  40. };
  41. static const IID * iidCClusNodeNetInterfaces[] =
  42. {
  43. &IID_ISClusNodeNetInterfaces
  44. };
  45. //*************************************************************************//
  46. /////////////////////////////////////////////////////////////////////////////
  47. // CClusNetInterface class
  48. /////////////////////////////////////////////////////////////////////////////
  49. /////////////////////////////////////////////////////////////////////////////
  50. //++
  51. //
  52. // CClusNetInterface::CClusNetInterface
  53. //
  54. // Description:
  55. // Constructor.
  56. //
  57. // Arguments:
  58. // None.
  59. //
  60. // Return Value:
  61. // None.
  62. //
  63. //--
  64. /////////////////////////////////////////////////////////////////////////////
  65. CClusNetInterface::CClusNetInterface( void )
  66. {
  67. m_hNetInterface = NULL;
  68. m_pCommonProperties = NULL;
  69. m_pPrivateProperties = NULL;
  70. m_pCommonROProperties = NULL;
  71. m_pPrivateROProperties = NULL;
  72. m_pClusRefObject = NULL;
  73. m_piids = (const IID *) iidCClusNetInterface;
  74. m_piidsSize = ARRAYSIZE( iidCClusNetInterface );
  75. } //*** CClusNetInterface::CClusNetInterface()
  76. /////////////////////////////////////////////////////////////////////////////
  77. //++
  78. //
  79. // CClusNetInterface::~CClusNetInterface
  80. //
  81. // Description:
  82. // destructor.
  83. //
  84. // Arguments:
  85. // None.
  86. //
  87. // Return Value:
  88. // None.
  89. //
  90. //--
  91. /////////////////////////////////////////////////////////////////////////////
  92. CClusNetInterface::~CClusNetInterface( void )
  93. {
  94. if ( m_hNetInterface != NULL )
  95. {
  96. ::CloseClusterNetInterface( m_hNetInterface );
  97. } // if:
  98. if ( m_pCommonProperties != NULL )
  99. {
  100. m_pCommonProperties->Release();
  101. m_pCommonProperties = NULL;
  102. } // if: release the property collection
  103. if ( m_pPrivateProperties != NULL )
  104. {
  105. m_pPrivateProperties->Release();
  106. m_pPrivateProperties = NULL;
  107. } // if: release the property collection
  108. if ( m_pCommonROProperties != NULL )
  109. {
  110. m_pCommonROProperties->Release();
  111. m_pCommonROProperties = NULL;
  112. } // if: release the property collection
  113. if ( m_pPrivateROProperties != NULL )
  114. {
  115. m_pPrivateROProperties->Release();
  116. m_pPrivateROProperties = NULL;
  117. } // if: release the property collection
  118. if ( m_pClusRefObject != NULL )
  119. {
  120. m_pClusRefObject->Release();
  121. m_pClusRefObject = NULL;
  122. } // if: do we have a pointer to the cluster handle wrapper?
  123. } //*** CClusNetInterface::~CClusNetInterface()
  124. /////////////////////////////////////////////////////////////////////////////
  125. //++
  126. //
  127. // CClusNetInterface::Open
  128. //
  129. // Description:
  130. // Open the passed in network interface.
  131. //
  132. // Arguments:
  133. // pClusRefObject [IN] - Wraps the cluster handle.
  134. // bstrNetInterfaceName [IN] - The name of the interface to open.
  135. //
  136. // Return Value:
  137. // S_OK if successful, E_POINTER, or Win32 error as HRESULT.
  138. //
  139. //--
  140. /////////////////////////////////////////////////////////////////////////////
  141. HRESULT CClusNetInterface::Open(
  142. IN ISClusRefObject * pClusRefObject,
  143. IN BSTR bstrNetInterfaceName
  144. )
  145. {
  146. ASSERT( pClusRefObject != NULL );
  147. //ASSERT( bstrNetInterfaceName != NULL );
  148. HRESULT _hr = E_POINTER;
  149. if ( ( pClusRefObject != NULL ) && ( bstrNetInterfaceName != NULL ) )
  150. {
  151. HCLUSTER _hCluster;
  152. m_pClusRefObject = pClusRefObject;
  153. m_pClusRefObject->AddRef();
  154. _hr = m_pClusRefObject->get_Handle( (ULONG_PTR *) &_hCluster );
  155. if ( SUCCEEDED( _hr ) )
  156. {
  157. m_hNetInterface = OpenClusterNetInterface( _hCluster, bstrNetInterfaceName );
  158. if ( m_hNetInterface == 0 )
  159. {
  160. DWORD _sc = GetLastError();
  161. _hr = HRESULT_FROM_WIN32( _sc );
  162. } // if: it failed
  163. else
  164. {
  165. m_bstrNetInterfaceName = bstrNetInterfaceName;
  166. _hr = S_OK;
  167. } // else: it worked
  168. } // if: we have a cluster handle
  169. } // if: the args are not NULL
  170. return _hr;
  171. } //*** CClusNetInterface::Open()
  172. /////////////////////////////////////////////////////////////////////////////
  173. //++
  174. //
  175. // CClusNetInterface::GetProperties
  176. //
  177. // Description:
  178. // Creates a property collection for this object type
  179. // (Network Interface).
  180. //
  181. // Arguments:
  182. // ppProperties [OUT] - Catches the newly created collection.
  183. // bPrivate [IN] - Are these private properties? Or Common?
  184. // bReadOnly [IN] - Are these read only properties?
  185. //
  186. // Return Value:
  187. // S_OK if successful, or other HRESULT error.
  188. //
  189. //--
  190. /////////////////////////////////////////////////////////////////////////////
  191. HRESULT CClusNetInterface::GetProperties(
  192. ISClusProperties ** ppProperties,
  193. BOOL bPrivate,
  194. BOOL bReadOnly
  195. )
  196. {
  197. //ASSERT( ppProperties != NULL );
  198. HRESULT _hr = E_POINTER;
  199. if ( ppProperties != NULL )
  200. {
  201. *ppProperties = NULL;
  202. CComObject< CClusProperties > * pProperties = NULL;
  203. _hr = CComObject< CClusProperties >::CreateInstance( &pProperties );
  204. if ( SUCCEEDED( _hr ) )
  205. {
  206. CSmartPtr< CComObject< CClusProperties > > ptrProperties( pProperties );
  207. _hr = ptrProperties->Create( this, bPrivate, bReadOnly );
  208. if ( SUCCEEDED( _hr ) )
  209. {
  210. _hr = ptrProperties->Refresh();
  211. if ( SUCCEEDED( _hr ) )
  212. {
  213. _hr = ptrProperties->QueryInterface( IID_ISClusProperties, (void **) ppProperties );
  214. if ( SUCCEEDED( _hr ) )
  215. {
  216. ptrProperties->AddRef();
  217. if ( bPrivate )
  218. {
  219. if ( bReadOnly )
  220. {
  221. m_pPrivateROProperties = pProperties;
  222. }
  223. else
  224. {
  225. m_pPrivateProperties = pProperties;
  226. }
  227. }
  228. else
  229. {
  230. if ( bReadOnly )
  231. {
  232. m_pCommonROProperties = pProperties;
  233. }
  234. else
  235. {
  236. m_pCommonProperties = pProperties;
  237. }
  238. }
  239. }
  240. }
  241. }
  242. }
  243. }
  244. return _hr;
  245. } //*** CClusNetInterface::GetProperties()
  246. /////////////////////////////////////////////////////////////////////////////
  247. //++
  248. //
  249. // CClusNetInterface::get_Handle
  250. //
  251. // Description:
  252. // Return the raw handle to this objec (Netinterface).
  253. //
  254. // Arguments:
  255. // phandle [OUT] - Catches the handle.
  256. //
  257. // Return Value:
  258. // S_OK if successful, or E_POINTER if not.
  259. //
  260. //--
  261. /////////////////////////////////////////////////////////////////////////////
  262. STDMETHODIMP CClusNetInterface::get_Handle( OUT ULONG_PTR * phandle )
  263. {
  264. //ASSERT( phandle != NULL );
  265. HRESULT _hr = E_POINTER;
  266. if ( phandle != NULL )
  267. {
  268. *phandle = (ULONG_PTR) m_hNetInterface;
  269. _hr = S_OK;
  270. } // if: args are not NULL
  271. return _hr;
  272. } //*** CClusNetInterface::get_Handle()
  273. /////////////////////////////////////////////////////////////////////////////
  274. //++
  275. //
  276. // CClusNetInterface::get_Name
  277. //
  278. // Description:
  279. // Return the name of this object (Network Interface).
  280. //
  281. // Arguments:
  282. // pbstrNetInterfaceName [OUT] - Catches the name of this object.
  283. //
  284. // Return Value:
  285. // S_OK if successful, E_POINTER, or other HRESULT error.
  286. //
  287. //--
  288. /////////////////////////////////////////////////////////////////////////////
  289. STDMETHODIMP CClusNetInterface::get_Name( OUT BSTR * pbstrNetInterfaceName )
  290. {
  291. //ASSERT( pbstrNetInterfaceName != NULL );
  292. HRESULT _hr = E_POINTER;
  293. if ( pbstrNetInterfaceName != NULL )
  294. {
  295. *pbstrNetInterfaceName = m_bstrNetInterfaceName.Copy();
  296. _hr = S_OK;
  297. }
  298. return _hr;
  299. } //*** CClusNetInterface::get_Name()
  300. /////////////////////////////////////////////////////////////////////////////
  301. //++
  302. //
  303. // CClusNetInterface::get_State
  304. //
  305. // Description:
  306. // Return the current state of the object (Netinterface).
  307. //
  308. // Arguments:
  309. // cnisState [OUT] - Catches the state.
  310. //
  311. // Return Value:
  312. // S_OK if successful, E_POINTER, or Win32 error as HRESULT.
  313. //
  314. //--
  315. /////////////////////////////////////////////////////////////////////////////
  316. STDMETHODIMP CClusNetInterface::get_State(
  317. OUT CLUSTER_NETINTERFACE_STATE * cnisState
  318. )
  319. {
  320. //ASSERT( cnisState != NULL );
  321. HRESULT _hr = E_POINTER;
  322. if ( cnisState != NULL )
  323. {
  324. CLUSTER_NETINTERFACE_STATE _cnis = GetClusterNetInterfaceState( m_hNetInterface );
  325. if ( _cnis == ClusterNetInterfaceStateUnknown )
  326. {
  327. DWORD _sc = GetLastError();
  328. _hr = HRESULT_FROM_WIN32( _sc );
  329. }
  330. else
  331. {
  332. *cnisState = _cnis;
  333. _hr = S_OK;
  334. }
  335. }
  336. return _hr;
  337. } //*** CClusNetInterface::get_State()
  338. /////////////////////////////////////////////////////////////////////////////
  339. //++
  340. //
  341. // CClusNetInterface::get_CommonProperties
  342. //
  343. // Description:
  344. // Get this object's (Network Interface) common properties collection.
  345. //
  346. // Arguments:
  347. // ppProperties [OUT] - Catches the properties collection.
  348. //
  349. // Return Value:
  350. // S_OK if successful, or other HRESULT error.
  351. //
  352. //--
  353. /////////////////////////////////////////////////////////////////////////////
  354. STDMETHODIMP CClusNetInterface::get_CommonProperties(
  355. OUT ISClusProperties ** ppProperties
  356. )
  357. {
  358. //ASSERT( ppProperties != NULL );
  359. HRESULT _hr = E_POINTER;
  360. if ( ppProperties != NULL )
  361. {
  362. if ( m_pCommonProperties )
  363. {
  364. _hr = m_pCommonProperties->QueryInterface( IID_ISClusProperties, (void **) ppProperties );
  365. }
  366. else
  367. {
  368. _hr = GetProperties( ppProperties, FALSE, FALSE );
  369. }
  370. }
  371. return _hr;
  372. } //*** CClusNetInterface::get_CommonProperties()
  373. /////////////////////////////////////////////////////////////////////////////
  374. //++
  375. //
  376. // CClusNetInterface::get_PrivateProperties
  377. //
  378. // Description:
  379. // Get this object's (Network Interface) private properties collection.
  380. //
  381. // Arguments:
  382. // ppProperties [OUT] - Catches the properties collection.
  383. //
  384. // Return Value:
  385. // S_OK if successful, or other HRESULT error.
  386. //
  387. //--
  388. /////////////////////////////////////////////////////////////////////////////
  389. STDMETHODIMP CClusNetInterface::get_PrivateProperties(
  390. OUT ISClusProperties ** ppProperties
  391. )
  392. {
  393. //ASSERT( ppProperties != NULL );
  394. HRESULT _hr = E_POINTER;
  395. if ( ppProperties != NULL )
  396. {
  397. if ( m_pPrivateProperties )
  398. {
  399. _hr = m_pPrivateProperties->QueryInterface( IID_ISClusProperties, (void **) ppProperties );
  400. }
  401. else
  402. {
  403. _hr = GetProperties( ppProperties, TRUE, FALSE );
  404. }
  405. }
  406. return _hr;
  407. } //*** CClusNetInterface::get_PrivateProperties()
  408. /////////////////////////////////////////////////////////////////////////////
  409. //++
  410. //
  411. // CClusNetInterface::get_CommonROProperties
  412. //
  413. // Description:
  414. // Get this object's (Network Interface) common read only properties collection.
  415. //
  416. // Arguments:
  417. // ppProperties [OUT] - Catches the properties collection.
  418. //
  419. // Return Value:
  420. // S_OK if successful, or other HRESULT error.
  421. //
  422. //--
  423. /////////////////////////////////////////////////////////////////////////////
  424. STDMETHODIMP CClusNetInterface::get_CommonROProperties(
  425. OUT ISClusProperties ** ppProperties
  426. )
  427. {
  428. //ASSERT( ppProperties != NULL );
  429. HRESULT _hr = E_POINTER;
  430. if ( ppProperties != NULL )
  431. {
  432. if ( m_pCommonROProperties )
  433. {
  434. _hr = m_pCommonROProperties->QueryInterface( IID_ISClusProperties, (void **) ppProperties );
  435. }
  436. else
  437. {
  438. _hr = GetProperties( ppProperties, FALSE, TRUE );
  439. }
  440. }
  441. return _hr;
  442. } //*** CClusNetInterface::get_CommonROProperties()
  443. /////////////////////////////////////////////////////////////////////////////
  444. //++
  445. //
  446. // CClusNetInterface::get_PrivateROProperties
  447. //
  448. // Description:
  449. // Get this object's (Network Interface) private read only properties collection.
  450. //
  451. // Arguments:
  452. // ppProperties [OUT] - Catches the properties collection.
  453. //
  454. // Return Value:
  455. // S_OK if successful, or other HRESULT error.
  456. //
  457. //--
  458. /////////////////////////////////////////////////////////////////////////////
  459. STDMETHODIMP CClusNetInterface::get_PrivateROProperties(
  460. OUT ISClusProperties ** ppProperties
  461. )
  462. {
  463. //ASSERT( ppProperties != NULL );
  464. HRESULT _hr = E_POINTER;
  465. if ( ppProperties != NULL )
  466. {
  467. if ( m_pPrivateROProperties )
  468. {
  469. _hr = m_pPrivateROProperties->QueryInterface( IID_ISClusProperties, (void **) ppProperties );
  470. }
  471. else
  472. {
  473. _hr = GetProperties( ppProperties, TRUE, TRUE );
  474. }
  475. }
  476. return _hr;
  477. } //*** CClusNetInterface::get_PrivateROProperties()
  478. /////////////////////////////////////////////////////////////////////////////
  479. //++
  480. //
  481. // CClusNetInterface::get_Cluster
  482. //
  483. // Description:
  484. // Return the cluster this object (Netinterface) belongs to.
  485. //
  486. // Arguments:
  487. // ppCluster [OUT] - Catches the cluster.
  488. //
  489. // Return Value:
  490. // S_OK if successful, or other HRESULT error.
  491. //
  492. //--
  493. /////////////////////////////////////////////////////////////////////////////
  494. STDMETHODIMP CClusNetInterface::get_Cluster( OUT ISCluster ** ppCluster )
  495. {
  496. return ::HrGetCluster( ppCluster, m_pClusRefObject );
  497. } //*** CClusNetInterface::get_Cluster()
  498. /////////////////////////////////////////////////////////////////////////////
  499. //++
  500. //
  501. // CClusNetInterface::HrLoadProperties
  502. //
  503. // Description:
  504. // This virtual function does the actual load of the property list from
  505. // the cluster.
  506. //
  507. // Arguments:
  508. // rcplPropList [IN OUT] - The property list to load.
  509. // bReadOnly [IN] - Load the read only properties?
  510. // bPrivate [IN] - Load the common or the private properties?
  511. //
  512. // Return Value:
  513. // S_OK if successful, or other HRESULT error.
  514. //
  515. //--
  516. /////////////////////////////////////////////////////////////////////////////
  517. HRESULT CClusNetInterface::HrLoadProperties(
  518. IN OUT CClusPropList & rcplPropList,
  519. IN BOOL bReadOnly,
  520. IN BOOL bPrivate
  521. )
  522. {
  523. HRESULT _hr = S_FALSE;
  524. DWORD _dwControlCode = 0;
  525. DWORD _sc = ERROR_SUCCESS;
  526. if ( bReadOnly )
  527. {
  528. _dwControlCode = bPrivate
  529. ? CLUSCTL_NETINTERFACE_GET_RO_PRIVATE_PROPERTIES
  530. : CLUSCTL_NETINTERFACE_GET_RO_COMMON_PROPERTIES;
  531. }
  532. else
  533. {
  534. _dwControlCode = bPrivate
  535. ? CLUSCTL_NETINTERFACE_GET_PRIVATE_PROPERTIES
  536. : CLUSCTL_NETINTERFACE_GET_COMMON_PROPERTIES;
  537. } // else:
  538. _sc = rcplPropList.ScGetNetInterfaceProperties( m_hNetInterface, _dwControlCode );
  539. _hr = HRESULT_FROM_WIN32( _sc );
  540. return _hr;
  541. } //*** CClusNetInterface::HrLoadProperties()
  542. /////////////////////////////////////////////////////////////////////////////
  543. //++
  544. //
  545. // CClusNetInterface::ScWriteProperties
  546. //
  547. // Description:
  548. // This virtual function does the actual saving of the property list to
  549. // the cluster.
  550. //
  551. // Arguments:
  552. // rcplPropList [IN] - The property list to save.
  553. // bPrivate [IN] - Save the common or the private properties?
  554. //
  555. // Return Value:
  556. // ERROR_SUCCESS if successful, or other Win32 error if not.
  557. //
  558. //--
  559. /////////////////////////////////////////////////////////////////////////////
  560. DWORD CClusNetInterface::ScWriteProperties(
  561. const CClusPropList & rcplPropList,
  562. BOOL bPrivate
  563. )
  564. {
  565. DWORD _dwControlCode = bPrivate ? CLUSCTL_NETINTERFACE_SET_PRIVATE_PROPERTIES : CLUSCTL_NETINTERFACE_SET_COMMON_PROPERTIES;
  566. DWORD _nBytesReturned = 0;
  567. DWORD _sc = ERROR_SUCCESS;
  568. _sc = ClusterNetInterfaceControl(
  569. m_hNetInterface,
  570. NULL,
  571. _dwControlCode,
  572. rcplPropList,
  573. rcplPropList.CbBufferSize(),
  574. 0,
  575. 0,
  576. &_nBytesReturned
  577. );
  578. return _sc;
  579. } //*** CClusNetInterface::ScWriteProperties()
  580. //*************************************************************************//
  581. /////////////////////////////////////////////////////////////////////////////
  582. // CNetInterfaces class
  583. /////////////////////////////////////////////////////////////////////////////
  584. /////////////////////////////////////////////////////////////////////////////
  585. //++
  586. //
  587. // CNetInterfaces::CNetInterfaces
  588. //
  589. // Description:
  590. // Constructor.
  591. //
  592. // Arguments:
  593. // None.
  594. //
  595. // Return Value:
  596. // None.
  597. //
  598. //--
  599. /////////////////////////////////////////////////////////////////////////////
  600. CNetInterfaces::CNetInterfaces( void )
  601. {
  602. m_pClusRefObject = NULL;
  603. } //*** CNetInterfaces::CNetInterfaces()
  604. /////////////////////////////////////////////////////////////////////////////
  605. //++
  606. //
  607. // CNetInterfaces::~CNetInterfaces
  608. //
  609. // Description:
  610. // Destructor.
  611. //
  612. // Arguments:
  613. // None.
  614. //
  615. // Return Value:
  616. // None.
  617. //
  618. //--
  619. /////////////////////////////////////////////////////////////////////////////
  620. CNetInterfaces::~CNetInterfaces( void )
  621. {
  622. Clear();
  623. if ( m_pClusRefObject != NULL )
  624. {
  625. m_pClusRefObject->Release();
  626. m_pClusRefObject = NULL;
  627. } // if: do we have a pointer to the cluster handle wrapper?
  628. } //*** CNetInterfaces::~CNetInterfaces()
  629. /////////////////////////////////////////////////////////////////////////////
  630. //++
  631. //
  632. // CNetInterfaces::Create
  633. //
  634. // Description:
  635. // Finish the heavy weight construction.
  636. //
  637. // Arguments:
  638. // pClusRefObject [IN] - Wraps the cluster handle.
  639. //
  640. // Return Value:
  641. // S_OK if successful, E_POINTER if not.
  642. //
  643. //--
  644. /////////////////////////////////////////////////////////////////////////////
  645. HRESULT CNetInterfaces::Create( IN ISClusRefObject * pClusRefObject )
  646. {
  647. ASSERT( pClusRefObject != NULL );
  648. HRESULT _hr = E_POINTER;
  649. if ( pClusRefObject != NULL )
  650. {
  651. m_pClusRefObject = pClusRefObject;
  652. m_pClusRefObject->AddRef();
  653. _hr = S_OK;
  654. }
  655. return _hr;
  656. } //*** CNetInterfaces::Create()
  657. /////////////////////////////////////////////////////////////////////////////
  658. //++
  659. //
  660. // CNetInterfaces::Clear
  661. //
  662. // Description:
  663. // Empty the collection of net interfaces.
  664. //
  665. // Arguments:
  666. // None.
  667. //
  668. // Return Value:
  669. // None.
  670. //
  671. //--
  672. /////////////////////////////////////////////////////////////////////////////
  673. void CNetInterfaces::Clear( void )
  674. {
  675. ::ReleaseAndEmptyCollection< NetInterfacesList, CComObject< CClusNetInterface > >( m_NetInterfaceList );
  676. } //*** CNetInterfaces::Clear()
  677. /////////////////////////////////////////////////////////////////////////////
  678. //++
  679. //
  680. // CNetInterfaces::FindItem
  681. //
  682. // Description:
  683. // Find a net interface in the collection by name and return its index.
  684. //
  685. // Arguments:
  686. // pszNetInterfaceName [IN] - The name to look for.
  687. // pnIndex [OUT] - Catches the index.
  688. //
  689. // Return Value:
  690. // S_OK if successful, E_POINTER, or E_INVALIDARG.
  691. //
  692. //--
  693. /////////////////////////////////////////////////////////////////////////////
  694. HRESULT CNetInterfaces::FindItem(
  695. IN LPWSTR pszNetInterfaceName,
  696. OUT UINT * pnIndex
  697. )
  698. {
  699. //ASSERT( pszNetInterfaceName != NULL );
  700. //ASSERT( pnIndex != NULL );
  701. HRESULT _hr = E_POINTER;
  702. if ( ( pszNetInterfaceName != NULL ) && ( pnIndex != NULL ) )
  703. {
  704. CComObject< CClusNetInterface > * _pNetInterface = NULL;
  705. NetInterfacesList::iterator _first = m_NetInterfaceList.begin();
  706. NetInterfacesList::iterator _last = m_NetInterfaceList.end();
  707. int _idx = 0;
  708. _hr = E_INVALIDARG;
  709. for ( ; _first != _last; _first++, _idx++ )
  710. {
  711. _pNetInterface = *_first;
  712. if ( _pNetInterface && ( lstrcmpi( pszNetInterfaceName, _pNetInterface->Name() ) == 0 ) )
  713. {
  714. *pnIndex = _idx;
  715. _hr = S_OK;
  716. break;
  717. }
  718. }
  719. }
  720. return _hr;
  721. } //*** CNetInterfaces::FindItem( pszNetInterfaceName )
  722. /////////////////////////////////////////////////////////////////////////////
  723. //++
  724. //
  725. // CNetInterfaces::FindItem
  726. //
  727. // Description:
  728. // Find a net interface in the collection and return its index.
  729. //
  730. // Arguments:
  731. // pClusterNetInterface [IN] - The net interface to look for.
  732. // pnIndex [OUT] - Catches the index.
  733. //
  734. // Return Value:
  735. // S_OK if successful, E_POINTER, or E_INVALIDARG.
  736. //
  737. //--
  738. /////////////////////////////////////////////////////////////////////////////
  739. HRESULT CNetInterfaces::FindItem(
  740. IN ISClusNetInterface * pClusterNetInterface,
  741. OUT UINT * pnIndex
  742. )
  743. {
  744. //ASSERT( pClusterNetInterface != NULL );
  745. //ASSERT( pnIndex != NULL );
  746. HRESULT _hr = E_POINTER;
  747. if ( ( pClusterNetInterface != NULL ) && ( pnIndex != NULL ) )
  748. {
  749. CComBSTR _bstrName;
  750. _hr = pClusterNetInterface->get_Name( &_bstrName );
  751. if ( SUCCEEDED( _hr ) )
  752. {
  753. _hr = FindItem( _bstrName, pnIndex );
  754. }
  755. }
  756. return _hr;
  757. } //*** CNetInterfaces::FindItem( pClusterNetInterface )
  758. /////////////////////////////////////////////////////////////////////////////
  759. //++
  760. //
  761. // CNetInterfaces::GetIndex
  762. //
  763. // Description:
  764. // Convert the passed in variant index into the real index in the
  765. // collection.
  766. //
  767. // Arguments:
  768. // varIndex [IN] - The index to convert.
  769. // pnIndex [OUT] - Catches the index.
  770. //
  771. // Return Value:
  772. // S_OK if successful, E_POINTER, or E_INVALIDARG.
  773. //
  774. //--
  775. /////////////////////////////////////////////////////////////////////////////
  776. HRESULT CNetInterfaces::GetIndex(
  777. IN VARIANT varIndex,
  778. OUT UINT * pnIndex
  779. )
  780. {
  781. //ASSERT( pnIndex != NULL );
  782. HRESULT _hr = E_POINTER;
  783. if ( pnIndex != NULL )
  784. {
  785. UINT _nIndex = 0;
  786. CComVariant _v;
  787. *pnIndex = 0;
  788. _v.Copy( &varIndex );
  789. // Check to see if the index is a number.
  790. _hr = _v.ChangeType( VT_I4 );
  791. if ( SUCCEEDED( _hr ) )
  792. {
  793. _nIndex = _v.lVal;
  794. _nIndex--; // Adjust index to be 0 relative instead of 1 relative
  795. } // if: the index is a number
  796. else
  797. {
  798. // Check to see if the index is a string.
  799. _hr = _v.ChangeType( VT_BSTR );
  800. if ( SUCCEEDED( _hr ) )
  801. {
  802. // Search for the string.
  803. _hr = FindItem( _v.bstrVal, &_nIndex );
  804. } // if: the index is a string -- the net interface name
  805. } // else: not a number
  806. // We found an index, now check the range.
  807. if ( SUCCEEDED( _hr ) )
  808. {
  809. if ( _nIndex < m_NetInterfaceList.size() )
  810. {
  811. *pnIndex = _nIndex;
  812. } // if: index is in range
  813. else
  814. {
  815. _hr = E_INVALIDARG;
  816. } // else: index out of range
  817. } // if: did we find an index?
  818. } // if: args are not NULL
  819. return _hr;
  820. } //*** CNetInterfaces::GetIndex()
  821. /////////////////////////////////////////////////////////////////////////////
  822. //++
  823. //
  824. // CNetInterfaces::GetItem
  825. //
  826. // Description:
  827. // Return the item (Netinterface) by name.
  828. //
  829. // Arguments:
  830. // pszNetInterfaceName [IN] - The name of the item requested.
  831. // ppClusterNetInterface [OUT] - Catches the item.
  832. //
  833. // Return Value:
  834. // S_OK if successful, E_POINTER, or E_INVALIDARG.
  835. //
  836. //--
  837. /////////////////////////////////////////////////////////////////////////////
  838. HRESULT CNetInterfaces::GetItem(
  839. IN LPWSTR pszNetInterfaceName,
  840. OUT ISClusNetInterface ** ppClusterNetInterface
  841. )
  842. {
  843. //ASSERT( pszNetInterfaceName != NULL );
  844. //ASSERT( ppClusterNetInterface != NULL );
  845. HRESULT _hr = E_POINTER;
  846. if ( ( pszNetInterfaceName != NULL ) && ( ppClusterNetInterface != NULL ) )
  847. {
  848. CComObject< CClusNetInterface > * _pNetInterface = NULL;
  849. NetInterfacesList::iterator _first = m_NetInterfaceList.begin();
  850. NetInterfacesList::iterator _last = m_NetInterfaceList.end();
  851. _hr = E_INVALIDARG;
  852. for ( ; _first != _last; _first++ )
  853. {
  854. _pNetInterface = *_first;
  855. if ( _pNetInterface && ( lstrcmpi( pszNetInterfaceName, _pNetInterface->Name() ) == 0 ) )
  856. {
  857. _hr = _pNetInterface->QueryInterface( IID_ISClusNetInterface, (void **) ppClusterNetInterface );
  858. break;
  859. } // if: match?
  860. } // for:
  861. } // if: args are not NULL
  862. return _hr;
  863. } //*** CNetInterfaces::GetItem( pszNetInterfaceName )
  864. /////////////////////////////////////////////////////////////////////////////
  865. //++
  866. //
  867. // CNetInterfaces::GetItem
  868. //
  869. // Description:
  870. // Return the item (Netinterface) at the passed in index.
  871. //
  872. // Arguments:
  873. // nIndex [IN] - The index of the item requested.
  874. // ppClusterNetInterface [OUT] - Catches the item.
  875. //
  876. // Return Value:
  877. // S_OK if successful, E_POINTER, or E_INVALIDARG.
  878. //
  879. //--
  880. /////////////////////////////////////////////////////////////////////////////
  881. HRESULT CNetInterfaces::GetItem(
  882. IN UINT nIndex,
  883. OUT ISClusNetInterface ** ppClusterNetInterface
  884. )
  885. {
  886. //ASSERT( ppClusterNetInterface != NULL );
  887. HRESULT _hr = E_POINTER;
  888. if ( ppClusterNetInterface != NULL )
  889. {
  890. //
  891. // Automation collections are 1-relative for languages like VB.
  892. // We are 0-relative internally.
  893. //
  894. nIndex--;
  895. if ( nIndex < m_NetInterfaceList.size() )
  896. {
  897. CComObject< CClusNetInterface > * _pNetInterface = m_NetInterfaceList[ nIndex ];
  898. _hr = _pNetInterface->QueryInterface( IID_ISClusNetInterface, (void **) ppClusterNetInterface );
  899. } // if: index is in range
  900. else
  901. {
  902. _hr = E_INVALIDARG;
  903. } // else: index is out of range
  904. }
  905. return _hr;
  906. } //*** CNetInterfaces::GetItem( nIndex )
  907. /////////////////////////////////////////////////////////////////////////////
  908. //++
  909. //
  910. // CNetInterfaces::GetNetInterfaceItem
  911. //
  912. // Description:
  913. // Return the object (Netinterface) at the passed in index.
  914. //
  915. // Arguments:
  916. // varIndex [IN] - Contains the index.
  917. // ppClusterNetInterface [OUT] - Catches the item.
  918. //
  919. // Return Value:
  920. // S_OK if successful, E_POINTER, or E_INVALIDARG.
  921. //
  922. //--
  923. /////////////////////////////////////////////////////////////////////////////
  924. HRESULT CNetInterfaces::GetNetInterfaceItem(
  925. IN VARIANT varIndex,
  926. OUT ISClusNetInterface ** ppClusterNetInterface
  927. )
  928. {
  929. //ASSERT( ppClusterNetInterface != NULL );
  930. HRESULT _hr = E_POINTER;
  931. if ( ppClusterNetInterface != NULL )
  932. {
  933. CComObject< CClusNetInterface > * _pNetInterface = NULL;
  934. UINT _nIndex = 0;
  935. *ppClusterNetInterface = NULL;
  936. _hr = GetIndex( varIndex, &_nIndex );
  937. if ( SUCCEEDED( _hr ) )
  938. {
  939. _pNetInterface = m_NetInterfaceList[ _nIndex ];
  940. _hr = _pNetInterface->QueryInterface( IID_ISClusNetInterface, (void **) ppClusterNetInterface );
  941. } // if: we have a proper index
  942. } // if: args are not NULL
  943. return _hr;
  944. } //*** CNetInterfaces::GetNetInterfaceItem()
  945. //*************************************************************************//
  946. /////////////////////////////////////////////////////////////////////////////
  947. // CClusNetInterfaces class
  948. /////////////////////////////////////////////////////////////////////////////
  949. /////////////////////////////////////////////////////////////////////////////
  950. //++
  951. //
  952. // CClusNetInterfaces::CClusNetInterfaces
  953. //
  954. // Description:
  955. // Constructor.
  956. //
  957. // Arguments:
  958. // None.
  959. //
  960. // Return Value:
  961. // None.
  962. //
  963. //--
  964. /////////////////////////////////////////////////////////////////////////////
  965. CClusNetInterfaces::CClusNetInterfaces( void )
  966. {
  967. m_piids = (const IID *) iidCClusNetInterfaces;
  968. m_piidsSize = ARRAYSIZE( iidCClusNetInterfaces );
  969. } //*** CClusNetInterfaces::CClusNetInterfaces()
  970. /////////////////////////////////////////////////////////////////////////////
  971. //++
  972. //
  973. // CClusNetInterfaces::~CClusNetInterfaces
  974. //
  975. // Description:
  976. // Destructor.
  977. //
  978. // Arguments:
  979. // None.
  980. //
  981. // Return Value:
  982. // None.
  983. //
  984. //--
  985. /////////////////////////////////////////////////////////////////////////////
  986. CClusNetInterfaces::~CClusNetInterfaces( void )
  987. {
  988. Clear();
  989. } //*** CClusNetInterfaces::~CClusNetInterfaces()
  990. /////////////////////////////////////////////////////////////////////////////
  991. //++
  992. //
  993. // CClusNetInterfaces::get_Count
  994. //
  995. // Description:
  996. // Return the count of objects (Netinterfaces) in the collection.
  997. //
  998. // Arguments:
  999. // plCount [OUT] - Catches the count.
  1000. //
  1001. // Return Value:
  1002. // S_OK if successful, or E_POINTER.
  1003. //
  1004. //--
  1005. /////////////////////////////////////////////////////////////////////////////
  1006. STDMETHODIMP CClusNetInterfaces::get_Count( OUT long * plCount )
  1007. {
  1008. //ASSERT( plCount != NULL );
  1009. HRESULT _hr = E_POINTER;
  1010. if ( plCount != NULL )
  1011. {
  1012. *plCount = m_NetInterfaceList.size();
  1013. _hr = S_OK;
  1014. }
  1015. return _hr;
  1016. } //*** CClusNetInterfaces::get_Count()
  1017. /////////////////////////////////////////////////////////////////////////////
  1018. //++
  1019. //
  1020. // CClusNetInterfaces::get__NewEnum
  1021. //
  1022. // Description:
  1023. // Create and return a new enumeration for this collection.
  1024. //
  1025. // Arguments:
  1026. // ppunk [OUT] - Catches the new enumeration.
  1027. //
  1028. // Return Value:
  1029. // S_OK if successful, E_POINTER, or other HRESULT error.
  1030. //
  1031. //--
  1032. /////////////////////////////////////////////////////////////////////////////
  1033. STDMETHODIMP CClusNetInterfaces::get__NewEnum( IUnknown ** ppunk )
  1034. {
  1035. return ::HrNewIDispatchEnum< NetInterfacesList, CComObject< CClusNetInterface > >( ppunk, m_NetInterfaceList );
  1036. } //*** CClusNetInterfaces::get__NewEnum()
  1037. /////////////////////////////////////////////////////////////////////////////
  1038. //++
  1039. //
  1040. // CClusNetInterfaces::Refresh
  1041. //
  1042. // Description:
  1043. // Load the collection from the cluster database.
  1044. //
  1045. // Arguments:
  1046. // None.
  1047. //
  1048. // Return Value:
  1049. // S_OK if successful, E_POINTER, or Win32 error as HRESULT.
  1050. //
  1051. //--
  1052. /////////////////////////////////////////////////////////////////////////////
  1053. STDMETHODIMP CClusNetInterfaces::Refresh( void )
  1054. {
  1055. ASSERT( m_pClusRefObject != NULL );
  1056. HRESULT _hr = E_POINTER;
  1057. HCLUSENUM _hEnum = NULL;
  1058. HCLUSTER _hCluster;
  1059. DWORD _sc = ERROR_SUCCESS;
  1060. _hr = m_pClusRefObject->get_Handle( (ULONG_PTR *) &_hCluster );
  1061. if ( SUCCEEDED( _hr ) )
  1062. {
  1063. _hEnum = ::ClusterOpenEnum( _hCluster, CLUSTER_ENUM_NETINTERFACE );
  1064. if ( _hEnum != NULL )
  1065. {
  1066. int _nIndex = 0;
  1067. DWORD _dwType;
  1068. LPWSTR _pszName = NULL;
  1069. CComObject< CClusNetInterface > * _pNetInterface = NULL;
  1070. Clear();
  1071. for ( _nIndex = 0, _hr = S_OK; SUCCEEDED( _hr ); _nIndex++ )
  1072. {
  1073. _sc = ::WrapClusterEnum( _hEnum, _nIndex, &_dwType, &_pszName );
  1074. if ( _sc == ERROR_NO_MORE_ITEMS )
  1075. {
  1076. _hr = S_OK;
  1077. break;
  1078. }
  1079. else if ( _sc == ERROR_SUCCESS )
  1080. {
  1081. _hr = CComObject< CClusNetInterface >::CreateInstance( &_pNetInterface );
  1082. if ( SUCCEEDED( _hr ) )
  1083. {
  1084. CSmartPtr< ISClusRefObject > _ptrRefObject( m_pClusRefObject );
  1085. CSmartPtr< CComObject< CClusNetInterface > > _ptrNetInterface( _pNetInterface );
  1086. BSTR _bstr = NULL;
  1087. _bstr = SysAllocString( _pszName );
  1088. if ( _bstr == NULL )
  1089. {
  1090. _hr = E_OUTOFMEMORY;
  1091. }
  1092. else
  1093. {
  1094. _hr = _ptrNetInterface->Open( _ptrRefObject, _bstr );
  1095. if ( SUCCEEDED( _hr ) )
  1096. {
  1097. _ptrNetInterface->AddRef();
  1098. m_NetInterfaceList.insert( m_NetInterfaceList.end(), _ptrNetInterface );
  1099. }
  1100. else if ( HRESULT_CODE( _hr ) == ERROR_CLUSTER_NETINTERFACE_NOT_FOUND )
  1101. {
  1102. //
  1103. // It is possible for the net interface to have been deleted from the cluster
  1104. // in the time between creating the enum and opening the net interface. When
  1105. // that happens we need to simply skip that net interface and continue
  1106. // enumerating.
  1107. //
  1108. _hr = S_FALSE; // success code to keep us in the loop
  1109. } // else if: the cluster net interface was not found
  1110. SysFreeString( _bstr );
  1111. }
  1112. }
  1113. ::LocalFree( _pszName );
  1114. _pszName = NULL;
  1115. }
  1116. else
  1117. {
  1118. _hr = HRESULT_FROM_WIN32( _sc );
  1119. }
  1120. }
  1121. ::ClusterCloseEnum( _hEnum );
  1122. }
  1123. else
  1124. {
  1125. _sc = GetLastError();
  1126. _hr = HRESULT_FROM_WIN32( _sc );
  1127. }
  1128. }
  1129. return _hr;
  1130. } //*** CClusNetInterfaces::Refresh()
  1131. /////////////////////////////////////////////////////////////////////////////
  1132. //++
  1133. //
  1134. // CClusNetInterfaces::get_Item
  1135. //
  1136. // Description:
  1137. // Return the object (Netinterface) at the passed in index.
  1138. //
  1139. // Arguments:
  1140. // varIndex [IN] - Contains the index requested.
  1141. // ppClusterNetInterface [OUT] - Catches the item.
  1142. //
  1143. // Return Value:
  1144. // S_OK if successful, E_POINTER, or E_INVALIDARG.
  1145. //
  1146. //--
  1147. /////////////////////////////////////////////////////////////////////////////
  1148. STDMETHODIMP CClusNetInterfaces::get_Item(
  1149. IN VARIANT varIndex,
  1150. OUT ISClusNetInterface ** ppClusterNetInterface
  1151. )
  1152. {
  1153. //ASSERT( ppClusterNetInterface != NULL );
  1154. HRESULT _hr = E_POINTER;
  1155. if ( ppClusterNetInterface != NULL )
  1156. {
  1157. _hr = GetNetInterfaceItem( varIndex, ppClusterNetInterface );
  1158. }
  1159. return _hr;
  1160. } //*** CClusNetInterfaces::get_Item()
  1161. //*************************************************************************//
  1162. /////////////////////////////////////////////////////////////////////////////
  1163. // CClusNetworkNetInterfaces class
  1164. /////////////////////////////////////////////////////////////////////////////
  1165. /////////////////////////////////////////////////////////////////////////////
  1166. //++
  1167. //
  1168. // CClusNetworkNetInterfaces::CClusNetworkNetInterfaces
  1169. //
  1170. // Description:
  1171. // Constructor.
  1172. //
  1173. // Arguments:
  1174. // None.
  1175. //
  1176. // Return Value:
  1177. // None.
  1178. //
  1179. //--
  1180. /////////////////////////////////////////////////////////////////////////////
  1181. CClusNetworkNetInterfaces::CClusNetworkNetInterfaces( void )
  1182. {
  1183. m_piids = (const IID *) iidCClusNetworkNetInterfaces;
  1184. m_piidsSize = ARRAYSIZE( iidCClusNetworkNetInterfaces );
  1185. } //*** CClusNetworkNetInterfaces::CClusNetworkNetInterfaces()
  1186. /////////////////////////////////////////////////////////////////////////////
  1187. //++
  1188. //
  1189. // CClusNetworkNetInterfaces::~CClusNetworkNetInterfaces
  1190. //
  1191. // Description:
  1192. // Destructor.
  1193. //
  1194. // Arguments:
  1195. // None.
  1196. //
  1197. // Return Value:
  1198. // None.
  1199. //
  1200. //--
  1201. /////////////////////////////////////////////////////////////////////////////
  1202. CClusNetworkNetInterfaces::~CClusNetworkNetInterfaces( void )
  1203. {
  1204. Clear();
  1205. } //*** CClusNetworkNetInterfaces::~CClusNetworkNetInterfaces()
  1206. /////////////////////////////////////////////////////////////////////////////
  1207. //++
  1208. //
  1209. // CClusNetworkNetInterfaces::Create
  1210. //
  1211. // Description:
  1212. // Complete the heavy weight construction.
  1213. //
  1214. // Arguments:
  1215. // pClusRefObject [IN] - Wraps the cluster handle.
  1216. // hNetwork [IN] - The handle of the network whose netinterfaces
  1217. // this collection holds. The parent.
  1218. //
  1219. // Return Value:
  1220. // S_OK if successful, or E_POINTER is not.
  1221. //
  1222. //--
  1223. /////////////////////////////////////////////////////////////////////////////
  1224. HRESULT CClusNetworkNetInterfaces::Create(
  1225. IN ISClusRefObject * pClusRefObject,
  1226. IN HNETWORK hNetwork
  1227. )
  1228. {
  1229. HRESULT _hr = E_POINTER;
  1230. _hr = CNetInterfaces::Create( pClusRefObject );
  1231. if ( SUCCEEDED( _hr ) )
  1232. {
  1233. m_hNetwork = hNetwork;
  1234. } // if: args are not NULL
  1235. return _hr;
  1236. } //*** CClusNetworkNetInterfaces::Create()
  1237. /////////////////////////////////////////////////////////////////////////////
  1238. //++
  1239. //
  1240. // CClusNetworkNetInterfaces::get_Count
  1241. //
  1242. // Description:
  1243. // Return the count of objects (NetworkNetinterfaces) in the collection.
  1244. //
  1245. // Arguments:
  1246. // plCount [OUT] - Catches the count.
  1247. //
  1248. // Return Value:
  1249. // S_OK if successful, or E_POINTER.
  1250. //
  1251. //--
  1252. /////////////////////////////////////////////////////////////////////////////
  1253. STDMETHODIMP CClusNetworkNetInterfaces::get_Count( OUT long * plCount )
  1254. {
  1255. //ASSERT( plCount != NULL );
  1256. HRESULT _hr = E_POINTER;
  1257. if ( plCount != NULL )
  1258. {
  1259. *plCount = m_NetInterfaceList.size();
  1260. _hr = S_OK;
  1261. } // if: args are not NULL
  1262. return _hr;
  1263. } //*** CClusNetworkNetInterfaces::get_Count()
  1264. /////////////////////////////////////////////////////////////////////////////
  1265. //++
  1266. //
  1267. // CClusNetworkNetInterfaces::get__NewEnum
  1268. //
  1269. // Description:
  1270. // Create and return a new enumeration for this collection.
  1271. //
  1272. // Arguments:
  1273. // ppunk [OUT] - Catches the new enumeration.
  1274. //
  1275. // Return Value:
  1276. // S_OK if successful, E_POINTER, or other HRESULT error.
  1277. //
  1278. //--
  1279. /////////////////////////////////////////////////////////////////////////////
  1280. STDMETHODIMP CClusNetworkNetInterfaces::get__NewEnum( IUnknown ** ppunk )
  1281. {
  1282. return ::HrNewIDispatchEnum< NetInterfacesList, CComObject< CClusNetInterface > >( ppunk, m_NetInterfaceList );
  1283. } //*** CClusNetworkNetInterfaces::get__NewEnum()
  1284. /////////////////////////////////////////////////////////////////////////////
  1285. //++
  1286. //
  1287. // CClusNetworkNetInterfaces::Refresh
  1288. //
  1289. // Description:
  1290. // Load the collection from the cluster database.
  1291. //
  1292. // Arguments:
  1293. // None.
  1294. //
  1295. // Return Value:
  1296. // S_OK if successful, E_POINTER, or Win32 error as HRESULT.
  1297. //
  1298. //--
  1299. /////////////////////////////////////////////////////////////////////////////
  1300. STDMETHODIMP CClusNetworkNetInterfaces::Refresh( void )
  1301. {
  1302. HRESULT _hr = E_POINTER;
  1303. DWORD _sc = ERROR_SUCCESS;
  1304. if ( m_hNetwork != NULL )
  1305. {
  1306. HNETWORKENUM _hEnum = NULL;
  1307. _hEnum = ::ClusterNetworkOpenEnum( m_hNetwork, CLUSTER_NETWORK_ENUM_NETINTERFACES );
  1308. if ( _hEnum != NULL )
  1309. {
  1310. int _nIndex = 0;
  1311. DWORD _dwType;
  1312. LPWSTR _pszName = NULL;
  1313. CComObject< CClusNetInterface > * _pNetInterface = NULL;
  1314. Clear();
  1315. for ( _nIndex = 0, _hr = S_OK; SUCCEEDED( _hr ); _nIndex++ )
  1316. {
  1317. _sc = ::WrapClusterNetworkEnum( _hEnum, _nIndex, &_dwType, &_pszName );
  1318. if ( _sc == ERROR_NO_MORE_ITEMS )
  1319. {
  1320. _hr = S_OK;
  1321. break;
  1322. }
  1323. else if ( _sc == ERROR_SUCCESS )
  1324. {
  1325. _hr = CComObject< CClusNetInterface >::CreateInstance( &_pNetInterface );
  1326. if ( SUCCEEDED( _hr ) )
  1327. {
  1328. CSmartPtr< ISClusRefObject > _ptrRefObject( m_pClusRefObject );
  1329. CSmartPtr< CComObject< CClusNetInterface > > _ptrNetInterface( _pNetInterface );
  1330. BSTR _bstr = NULL;
  1331. _bstr = SysAllocString( _pszName );
  1332. if ( _bstr == NULL )
  1333. {
  1334. _hr = E_OUTOFMEMORY;
  1335. }
  1336. else
  1337. {
  1338. _hr = _ptrNetInterface->Open( _ptrRefObject, _bstr );
  1339. if ( SUCCEEDED( _hr ) )
  1340. {
  1341. _ptrNetInterface->AddRef();
  1342. m_NetInterfaceList.insert( m_NetInterfaceList.end(), _ptrNetInterface );
  1343. }
  1344. else if ( HRESULT_CODE( _hr ) == ERROR_CLUSTER_NETINTERFACE_NOT_FOUND )
  1345. {
  1346. //
  1347. // It is possible for the net interface to have been deleted from the cluster
  1348. // in the time between creating the enum and opening the net interface. When
  1349. // that happens we need to simply skip that net interface and continue
  1350. // enumerating.
  1351. //
  1352. _hr = S_FALSE; // success code to keep us in the loop
  1353. } // else if: the cluster net interface was not found
  1354. SysFreeString( _bstr );
  1355. }
  1356. }
  1357. ::LocalFree( _pszName );
  1358. _pszName = NULL;
  1359. }
  1360. else
  1361. {
  1362. _hr = HRESULT_FROM_WIN32( _sc );
  1363. }
  1364. }
  1365. ::ClusterNetworkCloseEnum( _hEnum );
  1366. }
  1367. else
  1368. {
  1369. _sc = GetLastError();
  1370. _hr = HRESULT_FROM_WIN32( _sc );
  1371. }
  1372. }
  1373. return _hr;
  1374. } //*** CClusNetworkNetInterfaces::Refresh()
  1375. /////////////////////////////////////////////////////////////////////////////
  1376. //++
  1377. //
  1378. // CClusNetworkNetInterfaces::get_Item
  1379. //
  1380. // Description:
  1381. // Return the object (NetworkNetinterface) at the passed in index.
  1382. //
  1383. // Arguments:
  1384. // varIndex [IN] - Contains the index requested.
  1385. // ppClusterNetInterface [OUT] - Catches the item.
  1386. //
  1387. // Return Value:
  1388. // S_OK if successful, E_POINTER, or E_INVALIDARG.
  1389. //
  1390. //--
  1391. /////////////////////////////////////////////////////////////////////////////
  1392. STDMETHODIMP CClusNetworkNetInterfaces::get_Item(
  1393. VARIANT varIndex,
  1394. ISClusNetInterface ** ppClusterNetInterface
  1395. )
  1396. {
  1397. //ASSERT( ppClusterNetInterface != NULL );
  1398. HRESULT _hr = E_POINTER;
  1399. if ( ppClusterNetInterface != NULL )
  1400. {
  1401. _hr = GetNetInterfaceItem( varIndex, ppClusterNetInterface );
  1402. }
  1403. return _hr;
  1404. } //*** CClusNetworkNetInterfaces::get_Item()
  1405. //*************************************************************************//
  1406. /////////////////////////////////////////////////////////////////////////////
  1407. // CClusNodeNetInterfaces class
  1408. /////////////////////////////////////////////////////////////////////////////
  1409. /////////////////////////////////////////////////////////////////////////////
  1410. //++
  1411. //
  1412. // CClusNodeNetInterfaces::CClusNodeNetInterfaces
  1413. //
  1414. // Description:
  1415. // Constructor.
  1416. //
  1417. // Arguments:
  1418. // None.
  1419. //
  1420. // Return Value:
  1421. // None.
  1422. //
  1423. //--
  1424. /////////////////////////////////////////////////////////////////////////////
  1425. CClusNodeNetInterfaces::CClusNodeNetInterfaces( void )
  1426. {
  1427. m_piids = (const IID *) iidCClusNetInterfaces;
  1428. m_piidsSize = ARRAYSIZE( iidCClusNetInterfaces );
  1429. } //*** CClusNodeNetInterfaces::CClusNodeNetInterfaces()
  1430. /////////////////////////////////////////////////////////////////////////////
  1431. //++
  1432. //
  1433. // CClusNodeNetInterfaces::~CClusNodeNetInterfaces
  1434. //
  1435. // Description:
  1436. // Destructor.
  1437. //
  1438. // Arguments:
  1439. // None.
  1440. //
  1441. // Return Value:
  1442. // None.
  1443. //
  1444. //--
  1445. /////////////////////////////////////////////////////////////////////////////
  1446. CClusNodeNetInterfaces::~CClusNodeNetInterfaces( void )
  1447. {
  1448. Clear();
  1449. } //*** CClusNodeNetInterfaces::~CClusNodeNetInterfaces()
  1450. /////////////////////////////////////////////////////////////////////////////
  1451. //++
  1452. //
  1453. // CClusNodeNetInterfaces::Create
  1454. //
  1455. // Description:
  1456. // Complete the heavy weight construction.
  1457. //
  1458. // Arguments:
  1459. // pClusRefObject [IN] - Wraps the cluster handle.
  1460. // hNode [IN] - The handle of the node whose netinterfaces
  1461. // this collection holds. The parent.
  1462. //
  1463. // Return Value:
  1464. // S_OK if successful, or E_POINTER is not.
  1465. //
  1466. //--
  1467. /////////////////////////////////////////////////////////////////////////////
  1468. HRESULT CClusNodeNetInterfaces::Create(
  1469. IN ISClusRefObject * pClusRefObject,
  1470. IN HNODE hNode
  1471. )
  1472. {
  1473. HRESULT _hr = E_POINTER;
  1474. _hr = CNetInterfaces::Create( pClusRefObject );
  1475. if ( SUCCEEDED( _hr ) )
  1476. {
  1477. m_hNode = hNode;
  1478. } // if: args are not NULL
  1479. return _hr;
  1480. } //*** CClusNodeNetInterfaces::Create()
  1481. /////////////////////////////////////////////////////////////////////////////
  1482. //++
  1483. //
  1484. // CClusNodeNetInterfaces::get_Count
  1485. //
  1486. // Description:
  1487. // Return the count of objects (NodeNetinterfaces) in the collection.
  1488. //
  1489. // Arguments:
  1490. // plCount [OUT] - Catches the count.
  1491. //
  1492. // Return Value:
  1493. // S_OK if successful, or E_POINTER.
  1494. //
  1495. //--
  1496. /////////////////////////////////////////////////////////////////////////////
  1497. STDMETHODIMP CClusNodeNetInterfaces::get_Count( OUT long * plCount )
  1498. {
  1499. //ASSERT( plCount != NULL );
  1500. HRESULT _hr = E_POINTER;
  1501. if ( plCount != NULL )
  1502. {
  1503. *plCount = m_NetInterfaceList.size();
  1504. _hr = S_OK;
  1505. } // if: args are not NULL
  1506. return _hr;
  1507. } //*** CClusNodeNetInterfaces::get_Count()
  1508. /////////////////////////////////////////////////////////////////////////////
  1509. //++
  1510. //
  1511. // CClusNodeNetInterfaces::get__NewEnum
  1512. //
  1513. // Description:
  1514. // Create and return a new enumeration for this collection.
  1515. //
  1516. // Arguments:
  1517. // ppunk [OUT] - Catches the new enumeration.
  1518. //
  1519. // Return Value:
  1520. // S_OK if successful, E_POINTER, or other HRESULT error.
  1521. //
  1522. //--
  1523. /////////////////////////////////////////////////////////////////////////////
  1524. STDMETHODIMP CClusNodeNetInterfaces::get__NewEnum( IUnknown ** ppunk )
  1525. {
  1526. return ::HrNewIDispatchEnum< NetInterfacesList, CComObject< CClusNetInterface > >( ppunk, m_NetInterfaceList );
  1527. } //*** CClusNodeNetInterfaces::get__NewEnum()
  1528. /////////////////////////////////////////////////////////////////////////////
  1529. //++
  1530. //
  1531. // CClusNodeNetInterfaces::Refresh
  1532. //
  1533. // Description:
  1534. // Load the collection from the cluster database.
  1535. //
  1536. // Arguments:
  1537. // None.
  1538. //
  1539. // Return Value:
  1540. // S_OK if successful, E_POINTER, or Win32 error as HRESULT.
  1541. //
  1542. //--
  1543. /////////////////////////////////////////////////////////////////////////////
  1544. STDMETHODIMP CClusNodeNetInterfaces::Refresh( void )
  1545. {
  1546. HRESULT _hr = E_POINTER;
  1547. DWORD _sc = ERROR_SUCCESS;
  1548. if ( m_hNode != NULL )
  1549. {
  1550. HNODEENUM _hEnum = NULL;
  1551. _hEnum = ::ClusterNodeOpenEnum( m_hNode, CLUSTER_NODE_ENUM_NETINTERFACES );
  1552. if ( _hEnum != NULL )
  1553. {
  1554. int _nIndex = 0;
  1555. DWORD _dwType;
  1556. LPWSTR _pszName = NULL;
  1557. CComObject< CClusNetInterface > * _pNetInterface = NULL;
  1558. Clear();
  1559. for ( _nIndex = 0, _hr = S_OK; SUCCEEDED( _hr ); _nIndex++ )
  1560. {
  1561. _sc = ::WrapClusterNodeEnum( _hEnum, _nIndex, &_dwType, &_pszName );
  1562. if ( _sc == ERROR_NO_MORE_ITEMS )
  1563. {
  1564. _hr = S_OK;
  1565. break;
  1566. }
  1567. else if ( _sc == ERROR_SUCCESS )
  1568. {
  1569. _hr = CComObject< CClusNetInterface >::CreateInstance( &_pNetInterface );
  1570. if ( SUCCEEDED( _hr ) )
  1571. {
  1572. CSmartPtr< ISClusRefObject > _ptrRefObject( m_pClusRefObject );
  1573. CSmartPtr< CComObject< CClusNetInterface > > _ptrNetInterface( _pNetInterface );
  1574. BSTR _bstr = NULL;
  1575. _bstr = SysAllocString( _pszName );
  1576. if ( _bstr == NULL )
  1577. {
  1578. _hr = E_OUTOFMEMORY;
  1579. }
  1580. else
  1581. {
  1582. _hr = _ptrNetInterface->Open( _ptrRefObject, _bstr );
  1583. if ( SUCCEEDED( _hr ) )
  1584. {
  1585. _ptrNetInterface->AddRef();
  1586. m_NetInterfaceList.insert( m_NetInterfaceList.end(), _ptrNetInterface );
  1587. }
  1588. else if ( HRESULT_CODE( _hr ) == ERROR_CLUSTER_NETINTERFACE_NOT_FOUND )
  1589. {
  1590. //
  1591. // It is possible for the net interface to have been deleted from the cluster
  1592. // in the time between creating the enum and opening the net interface. When
  1593. // that happens we need to simply skip that net interface and continue
  1594. // enumerating.
  1595. //
  1596. _hr = S_FALSE; // success code to keep us in the loop
  1597. } // else if: the cluster net interface was not found
  1598. SysFreeString( _bstr );
  1599. }
  1600. }
  1601. ::LocalFree( _pszName );
  1602. _pszName = NULL;
  1603. }
  1604. else
  1605. {
  1606. _hr = HRESULT_FROM_WIN32( _sc );
  1607. }
  1608. }
  1609. ::ClusterNodeCloseEnum( _hEnum );
  1610. }
  1611. else
  1612. {
  1613. _sc = GetLastError();
  1614. _hr = HRESULT_FROM_WIN32( _sc );
  1615. }
  1616. }
  1617. return _hr;
  1618. } //*** CClusNodeNetInterfaces::Refresh()
  1619. /////////////////////////////////////////////////////////////////////////////
  1620. //++
  1621. //
  1622. // CClusNodeNetInterfaces::get_Item
  1623. //
  1624. // Description:
  1625. // Return the object (NodeNetinterface) at the passed in index.
  1626. //
  1627. // Arguments:
  1628. // varIndex [IN] - Contains the index requested.
  1629. // ppClusterNetInterface [OUT] - Catches the item.
  1630. //
  1631. // Return Value:
  1632. // S_OK if successful, E_POINTER, or E_INVALIDARG.
  1633. //
  1634. //--
  1635. /////////////////////////////////////////////////////////////////////////////
  1636. STDMETHODIMP CClusNodeNetInterfaces::get_Item(
  1637. VARIANT varIndex,
  1638. ISClusNetInterface ** ppClusterNetInterface
  1639. )
  1640. {
  1641. //ASSERT( ppClusterNetInterface != NULL );
  1642. HRESULT _hr = E_POINTER;
  1643. if ( ppClusterNetInterface != NULL )
  1644. {
  1645. _hr = GetNetInterfaceItem( varIndex, ppClusterNetInterface );
  1646. }
  1647. return _hr;
  1648. } //*** CClusNodeNetInterfaces::get_Item()