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.

1839 lines
43 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1997-1999 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. if ( m_pClusRefObject != NULL )
  1058. {
  1059. HCLUSENUM _hEnum = NULL;
  1060. HCLUSTER _hCluster;
  1061. DWORD _sc = ERROR_SUCCESS;
  1062. _hr = m_pClusRefObject->get_Handle( (ULONG_PTR *) &_hCluster );
  1063. if ( SUCCEEDED( _hr ) )
  1064. {
  1065. _hEnum = ::ClusterOpenEnum( _hCluster, CLUSTER_ENUM_NETINTERFACE );
  1066. if ( _hEnum != NULL )
  1067. {
  1068. int _nIndex = 0;
  1069. DWORD _dwType;
  1070. LPWSTR _pszName = NULL;
  1071. CComObject< CClusNetInterface > * _pNetInterface = NULL;
  1072. Clear();
  1073. for ( _nIndex = 0, _hr = S_OK; SUCCEEDED( _hr ); _nIndex++ )
  1074. {
  1075. _sc = ::WrapClusterEnum( _hEnum, _nIndex, &_dwType, &_pszName );
  1076. if ( _sc == ERROR_NO_MORE_ITEMS )
  1077. {
  1078. _hr = S_OK;
  1079. break;
  1080. }
  1081. else if ( _sc == ERROR_SUCCESS )
  1082. {
  1083. _hr = CComObject< CClusNetInterface >::CreateInstance( &_pNetInterface );
  1084. if ( SUCCEEDED( _hr ) )
  1085. {
  1086. CSmartPtr< ISClusRefObject > _ptrRefObject( m_pClusRefObject );
  1087. CSmartPtr< CComObject< CClusNetInterface > > _ptrNetInterface( _pNetInterface );
  1088. _hr = _ptrNetInterface->Open( _ptrRefObject, _pszName );
  1089. if ( SUCCEEDED( _hr ) )
  1090. {
  1091. _ptrNetInterface->AddRef();
  1092. m_NetInterfaceList.insert( m_NetInterfaceList.end(), _ptrNetInterface );
  1093. }
  1094. }
  1095. ::LocalFree( _pszName );
  1096. _pszName = NULL;
  1097. }
  1098. else
  1099. {
  1100. _hr = HRESULT_FROM_WIN32( _sc );
  1101. }
  1102. }
  1103. ::ClusterCloseEnum( _hEnum );
  1104. }
  1105. else
  1106. {
  1107. _sc = GetLastError();
  1108. _hr = HRESULT_FROM_WIN32( _sc );
  1109. }
  1110. }
  1111. }
  1112. return _hr;
  1113. } //*** CClusNetInterfaces::Refresh()
  1114. /////////////////////////////////////////////////////////////////////////////
  1115. //++
  1116. //
  1117. // CClusNetInterfaces::get_Item
  1118. //
  1119. // Description:
  1120. // Return the object (Netinterface) at the passed in index.
  1121. //
  1122. // Arguments:
  1123. // varIndex [IN] - Contains the index requested.
  1124. // ppClusterNetInterface [OUT] - Catches the item.
  1125. //
  1126. // Return Value:
  1127. // S_OK if successful, E_POINTER, or E_INVALIDARG.
  1128. //
  1129. //--
  1130. /////////////////////////////////////////////////////////////////////////////
  1131. STDMETHODIMP CClusNetInterfaces::get_Item(
  1132. IN VARIANT varIndex,
  1133. OUT ISClusNetInterface ** ppClusterNetInterface
  1134. )
  1135. {
  1136. //ASSERT( ppClusterNetInterface != NULL );
  1137. HRESULT _hr = E_POINTER;
  1138. if ( ppClusterNetInterface != NULL )
  1139. {
  1140. _hr = GetNetInterfaceItem( varIndex, ppClusterNetInterface );
  1141. }
  1142. return _hr;
  1143. } //*** CClusNetInterfaces::get_Item()
  1144. //*************************************************************************//
  1145. /////////////////////////////////////////////////////////////////////////////
  1146. // CClusNetworkNetInterfaces class
  1147. /////////////////////////////////////////////////////////////////////////////
  1148. /////////////////////////////////////////////////////////////////////////////
  1149. //++
  1150. //
  1151. // CClusNetworkNetInterfaces::CClusNetworkNetInterfaces
  1152. //
  1153. // Description:
  1154. // Constructor.
  1155. //
  1156. // Arguments:
  1157. // None.
  1158. //
  1159. // Return Value:
  1160. // None.
  1161. //
  1162. //--
  1163. /////////////////////////////////////////////////////////////////////////////
  1164. CClusNetworkNetInterfaces::CClusNetworkNetInterfaces( void )
  1165. {
  1166. m_piids = (const IID *) iidCClusNetworkNetInterfaces;
  1167. m_piidsSize = ARRAYSIZE( iidCClusNetworkNetInterfaces );
  1168. } //*** CClusNetworkNetInterfaces::CClusNetworkNetInterfaces()
  1169. /////////////////////////////////////////////////////////////////////////////
  1170. //++
  1171. //
  1172. // CClusNetworkNetInterfaces::~CClusNetworkNetInterfaces
  1173. //
  1174. // Description:
  1175. // Destructor.
  1176. //
  1177. // Arguments:
  1178. // None.
  1179. //
  1180. // Return Value:
  1181. // None.
  1182. //
  1183. //--
  1184. /////////////////////////////////////////////////////////////////////////////
  1185. CClusNetworkNetInterfaces::~CClusNetworkNetInterfaces( void )
  1186. {
  1187. Clear();
  1188. } //*** CClusNetworkNetInterfaces::~CClusNetworkNetInterfaces()
  1189. /////////////////////////////////////////////////////////////////////////////
  1190. //++
  1191. //
  1192. // CClusNetworkNetInterfaces::Create
  1193. //
  1194. // Description:
  1195. // Complete the heavy weight construction.
  1196. //
  1197. // Arguments:
  1198. // pClusRefObject [IN] - Wraps the cluster handle.
  1199. // hNetwork [IN] - The handle of the network whose netinterfaces
  1200. // this collection holds. The parent.
  1201. //
  1202. // Return Value:
  1203. // S_OK if successful, or E_POINTER is not.
  1204. //
  1205. //--
  1206. /////////////////////////////////////////////////////////////////////////////
  1207. HRESULT CClusNetworkNetInterfaces::Create(
  1208. IN ISClusRefObject * pClusRefObject,
  1209. IN HNETWORK hNetwork
  1210. )
  1211. {
  1212. HRESULT _hr = E_POINTER;
  1213. _hr = CNetInterfaces::Create( pClusRefObject );
  1214. if ( SUCCEEDED( _hr ) )
  1215. {
  1216. m_hNetwork = hNetwork;
  1217. } // if: args are not NULL
  1218. return _hr;
  1219. } //*** CClusNetworkNetInterfaces::Create()
  1220. /////////////////////////////////////////////////////////////////////////////
  1221. //++
  1222. //
  1223. // CClusNetworkNetInterfaces::get_Count
  1224. //
  1225. // Description:
  1226. // Return the count of objects (NetworkNetinterfaces) in the collection.
  1227. //
  1228. // Arguments:
  1229. // plCount [OUT] - Catches the count.
  1230. //
  1231. // Return Value:
  1232. // S_OK if successful, or E_POINTER.
  1233. //
  1234. //--
  1235. /////////////////////////////////////////////////////////////////////////////
  1236. STDMETHODIMP CClusNetworkNetInterfaces::get_Count( OUT long * plCount )
  1237. {
  1238. //ASSERT( plCount != NULL );
  1239. HRESULT _hr = E_POINTER;
  1240. if ( plCount != NULL )
  1241. {
  1242. *plCount = m_NetInterfaceList.size();
  1243. _hr = S_OK;
  1244. } // if: args are not NULL
  1245. return _hr;
  1246. } //*** CClusNetworkNetInterfaces::get_Count()
  1247. /////////////////////////////////////////////////////////////////////////////
  1248. //++
  1249. //
  1250. // CClusNetworkNetInterfaces::get__NewEnum
  1251. //
  1252. // Description:
  1253. // Create and return a new enumeration for this collection.
  1254. //
  1255. // Arguments:
  1256. // ppunk [OUT] - Catches the new enumeration.
  1257. //
  1258. // Return Value:
  1259. // S_OK if successful, E_POINTER, or other HRESULT error.
  1260. //
  1261. //--
  1262. /////////////////////////////////////////////////////////////////////////////
  1263. STDMETHODIMP CClusNetworkNetInterfaces::get__NewEnum( IUnknown ** ppunk )
  1264. {
  1265. return ::HrNewIDispatchEnum< NetInterfacesList, CComObject< CClusNetInterface > >( ppunk, m_NetInterfaceList );
  1266. } //*** CClusNetworkNetInterfaces::get__NewEnum()
  1267. /////////////////////////////////////////////////////////////////////////////
  1268. //++
  1269. //
  1270. // CClusNetworkNetInterfaces::Refresh
  1271. //
  1272. // Description:
  1273. // Load the collection from the cluster database.
  1274. //
  1275. // Arguments:
  1276. // None.
  1277. //
  1278. // Return Value:
  1279. // S_OK if successful, E_POINTER, or Win32 error as HRESULT.
  1280. //
  1281. //--
  1282. /////////////////////////////////////////////////////////////////////////////
  1283. STDMETHODIMP CClusNetworkNetInterfaces::Refresh( void )
  1284. {
  1285. HRESULT _hr = E_POINTER;
  1286. DWORD _sc = ERROR_SUCCESS;
  1287. if ( m_hNetwork != NULL )
  1288. {
  1289. HNETWORKENUM _hEnum = NULL;
  1290. _hEnum = ::ClusterNetworkOpenEnum( m_hNetwork, CLUSTER_NETWORK_ENUM_NETINTERFACES );
  1291. if ( _hEnum != NULL )
  1292. {
  1293. int _nIndex = 0;
  1294. DWORD _dwType;
  1295. LPWSTR _pszName = NULL;
  1296. CComObject< CClusNetInterface > * _pNetInterface = NULL;
  1297. Clear();
  1298. for ( _nIndex = 0, _hr = S_OK; SUCCEEDED( _hr ); _nIndex++ )
  1299. {
  1300. _sc = ::WrapClusterNetworkEnum( _hEnum, _nIndex, &_dwType, &_pszName );
  1301. if ( _sc == ERROR_NO_MORE_ITEMS )
  1302. {
  1303. _hr = S_OK;
  1304. break;
  1305. }
  1306. else if ( _sc == ERROR_SUCCESS )
  1307. {
  1308. _hr = CComObject< CClusNetInterface >::CreateInstance( &_pNetInterface );
  1309. if ( SUCCEEDED( _hr ) )
  1310. {
  1311. CSmartPtr< ISClusRefObject > _ptrRefObject( m_pClusRefObject );
  1312. CSmartPtr< CComObject< CClusNetInterface > > _ptrNetInterface( _pNetInterface );
  1313. _hr = _ptrNetInterface->Open( _ptrRefObject, _pszName );
  1314. if ( SUCCEEDED( _hr ) )
  1315. {
  1316. _ptrNetInterface->AddRef();
  1317. m_NetInterfaceList.insert( m_NetInterfaceList.end(), _ptrNetInterface );
  1318. }
  1319. }
  1320. ::LocalFree( _pszName );
  1321. _pszName = NULL;
  1322. }
  1323. else
  1324. {
  1325. _hr = HRESULT_FROM_WIN32( _sc );
  1326. }
  1327. }
  1328. ::ClusterNetworkCloseEnum( _hEnum );
  1329. }
  1330. else
  1331. {
  1332. _sc = GetLastError();
  1333. _hr = HRESULT_FROM_WIN32( _sc );
  1334. }
  1335. }
  1336. return _hr;
  1337. } //*** CClusNetworkNetInterfaces::Refresh()
  1338. /////////////////////////////////////////////////////////////////////////////
  1339. //++
  1340. //
  1341. // CClusNetworkNetInterfaces::get_Item
  1342. //
  1343. // Description:
  1344. // Return the object (NetworkNetinterface) at the passed in index.
  1345. //
  1346. // Arguments:
  1347. // varIndex [IN] - Contains the index requested.
  1348. // ppClusterNetInterface [OUT] - Catches the item.
  1349. //
  1350. // Return Value:
  1351. // S_OK if successful, E_POINTER, or E_INVALIDARG.
  1352. //
  1353. //--
  1354. /////////////////////////////////////////////////////////////////////////////
  1355. STDMETHODIMP CClusNetworkNetInterfaces::get_Item(
  1356. VARIANT varIndex,
  1357. ISClusNetInterface ** ppClusterNetInterface
  1358. )
  1359. {
  1360. //ASSERT( ppClusterNetInterface != NULL );
  1361. HRESULT _hr = E_POINTER;
  1362. if ( ppClusterNetInterface != NULL )
  1363. {
  1364. _hr = GetNetInterfaceItem( varIndex, ppClusterNetInterface );
  1365. }
  1366. return _hr;
  1367. } //*** CClusNetworkNetInterfaces::get_Item()
  1368. //*************************************************************************//
  1369. /////////////////////////////////////////////////////////////////////////////
  1370. // CClusNodeNetInterfaces class
  1371. /////////////////////////////////////////////////////////////////////////////
  1372. /////////////////////////////////////////////////////////////////////////////
  1373. //++
  1374. //
  1375. // CClusNodeNetInterfaces::CClusNodeNetInterfaces
  1376. //
  1377. // Description:
  1378. // Constructor.
  1379. //
  1380. // Arguments:
  1381. // None.
  1382. //
  1383. // Return Value:
  1384. // None.
  1385. //
  1386. //--
  1387. /////////////////////////////////////////////////////////////////////////////
  1388. CClusNodeNetInterfaces::CClusNodeNetInterfaces( void )
  1389. {
  1390. m_piids = (const IID *) iidCClusNetInterfaces;
  1391. m_piidsSize = ARRAYSIZE( iidCClusNetInterfaces );
  1392. } //*** CClusNodeNetInterfaces::CClusNodeNetInterfaces()
  1393. /////////////////////////////////////////////////////////////////////////////
  1394. //++
  1395. //
  1396. // CClusNodeNetInterfaces::~CClusNodeNetInterfaces
  1397. //
  1398. // Description:
  1399. // Destructor.
  1400. //
  1401. // Arguments:
  1402. // None.
  1403. //
  1404. // Return Value:
  1405. // None.
  1406. //
  1407. //--
  1408. /////////////////////////////////////////////////////////////////////////////
  1409. CClusNodeNetInterfaces::~CClusNodeNetInterfaces( void )
  1410. {
  1411. Clear();
  1412. } //*** CClusNodeNetInterfaces::~CClusNodeNetInterfaces()
  1413. /////////////////////////////////////////////////////////////////////////////
  1414. //++
  1415. //
  1416. // CClusNodeNetInterfaces::Create
  1417. //
  1418. // Description:
  1419. // Complete the heavy weight construction.
  1420. //
  1421. // Arguments:
  1422. // pClusRefObject [IN] - Wraps the cluster handle.
  1423. // hNode [IN] - The handle of the node whose netinterfaces
  1424. // this collection holds. The parent.
  1425. //
  1426. // Return Value:
  1427. // S_OK if successful, or E_POINTER is not.
  1428. //
  1429. //--
  1430. /////////////////////////////////////////////////////////////////////////////
  1431. HRESULT CClusNodeNetInterfaces::Create(
  1432. IN ISClusRefObject * pClusRefObject,
  1433. IN HNODE hNode
  1434. )
  1435. {
  1436. HRESULT _hr = E_POINTER;
  1437. _hr = CNetInterfaces::Create( pClusRefObject );
  1438. if ( SUCCEEDED( _hr ) )
  1439. {
  1440. m_hNode = hNode;
  1441. } // if: args are not NULL
  1442. return _hr;
  1443. } //*** CClusNodeNetInterfaces::Create()
  1444. /////////////////////////////////////////////////////////////////////////////
  1445. //++
  1446. //
  1447. // CClusNodeNetInterfaces::get_Count
  1448. //
  1449. // Description:
  1450. // Return the count of objects (NodeNetinterfaces) in the collection.
  1451. //
  1452. // Arguments:
  1453. // plCount [OUT] - Catches the count.
  1454. //
  1455. // Return Value:
  1456. // S_OK if successful, or E_POINTER.
  1457. //
  1458. //--
  1459. /////////////////////////////////////////////////////////////////////////////
  1460. STDMETHODIMP CClusNodeNetInterfaces::get_Count( OUT long * plCount )
  1461. {
  1462. //ASSERT( plCount != NULL );
  1463. HRESULT _hr = E_POINTER;
  1464. if ( plCount != NULL )
  1465. {
  1466. *plCount = m_NetInterfaceList.size();
  1467. _hr = S_OK;
  1468. } // if: args are not NULL
  1469. return _hr;
  1470. } //*** CClusNodeNetInterfaces::get_Count()
  1471. /////////////////////////////////////////////////////////////////////////////
  1472. //++
  1473. //
  1474. // CClusNodeNetInterfaces::get__NewEnum
  1475. //
  1476. // Description:
  1477. // Create and return a new enumeration for this collection.
  1478. //
  1479. // Arguments:
  1480. // ppunk [OUT] - Catches the new enumeration.
  1481. //
  1482. // Return Value:
  1483. // S_OK if successful, E_POINTER, or other HRESULT error.
  1484. //
  1485. //--
  1486. /////////////////////////////////////////////////////////////////////////////
  1487. STDMETHODIMP CClusNodeNetInterfaces::get__NewEnum( IUnknown ** ppunk )
  1488. {
  1489. return ::HrNewIDispatchEnum< NetInterfacesList, CComObject< CClusNetInterface > >( ppunk, m_NetInterfaceList );
  1490. } //*** CClusNodeNetInterfaces::get__NewEnum()
  1491. /////////////////////////////////////////////////////////////////////////////
  1492. //++
  1493. //
  1494. // CClusNodeNetInterfaces::Refresh
  1495. //
  1496. // Description:
  1497. // Load the collection from the cluster database.
  1498. //
  1499. // Arguments:
  1500. // None.
  1501. //
  1502. // Return Value:
  1503. // S_OK if successful, E_POINTER, or Win32 error as HRESULT.
  1504. //
  1505. //--
  1506. /////////////////////////////////////////////////////////////////////////////
  1507. STDMETHODIMP CClusNodeNetInterfaces::Refresh( void )
  1508. {
  1509. HRESULT _hr = E_POINTER;
  1510. DWORD _sc = ERROR_SUCCESS;
  1511. if ( m_hNode != NULL )
  1512. {
  1513. HNODEENUM _hEnum = NULL;
  1514. _hEnum = ::ClusterNodeOpenEnum( m_hNode, CLUSTER_NODE_ENUM_NETINTERFACES );
  1515. if ( _hEnum != NULL )
  1516. {
  1517. int _nIndex = 0;
  1518. DWORD _dwType;
  1519. LPWSTR _pszName = NULL;
  1520. CComObject< CClusNetInterface > * _pNetInterface = NULL;
  1521. Clear();
  1522. for ( _nIndex = 0, _hr = S_OK; SUCCEEDED( _hr ); _nIndex++ )
  1523. {
  1524. _sc = ::WrapClusterNodeEnum( _hEnum, _nIndex, &_dwType, &_pszName );
  1525. if ( _sc == ERROR_NO_MORE_ITEMS )
  1526. {
  1527. _hr = S_OK;
  1528. break;
  1529. }
  1530. else if ( _sc == ERROR_SUCCESS )
  1531. {
  1532. _hr = CComObject< CClusNetInterface >::CreateInstance( &_pNetInterface );
  1533. if ( SUCCEEDED( _hr ) )
  1534. {
  1535. CSmartPtr< ISClusRefObject > _ptrRefObject( m_pClusRefObject );
  1536. CSmartPtr< CComObject< CClusNetInterface > > _ptrNetInterface( _pNetInterface );
  1537. _hr = _ptrNetInterface->Open( _ptrRefObject, _pszName );
  1538. if ( SUCCEEDED( _hr ) )
  1539. {
  1540. _ptrNetInterface->AddRef();
  1541. m_NetInterfaceList.insert( m_NetInterfaceList.end(), _ptrNetInterface );
  1542. }
  1543. }
  1544. ::LocalFree( _pszName );
  1545. _pszName = NULL;
  1546. }
  1547. else
  1548. {
  1549. _hr = HRESULT_FROM_WIN32( _sc );
  1550. }
  1551. }
  1552. ::ClusterNodeCloseEnum( _hEnum );
  1553. }
  1554. else
  1555. {
  1556. _sc = GetLastError();
  1557. _hr = HRESULT_FROM_WIN32( _sc );
  1558. }
  1559. }
  1560. return _hr;
  1561. } //*** CClusNodeNetInterfaces::Refresh()
  1562. /////////////////////////////////////////////////////////////////////////////
  1563. //++
  1564. //
  1565. // CClusNodeNetInterfaces::get_Item
  1566. //
  1567. // Description:
  1568. // Return the object (NodeNetinterface) at the passed in index.
  1569. //
  1570. // Arguments:
  1571. // varIndex [IN] - Contains the index requested.
  1572. // ppClusterNetInterface [OUT] - Catches the item.
  1573. //
  1574. // Return Value:
  1575. // S_OK if successful, E_POINTER, or E_INVALIDARG.
  1576. //
  1577. //--
  1578. /////////////////////////////////////////////////////////////////////////////
  1579. STDMETHODIMP CClusNodeNetInterfaces::get_Item(
  1580. VARIANT varIndex,
  1581. ISClusNetInterface ** ppClusterNetInterface
  1582. )
  1583. {
  1584. //ASSERT( ppClusterNetInterface != NULL );
  1585. HRESULT _hr = E_POINTER;
  1586. if ( ppClusterNetInterface != NULL )
  1587. {
  1588. _hr = GetNetInterfaceItem( varIndex, ppClusterNetInterface );
  1589. }
  1590. return _hr;
  1591. } //*** CClusNodeNetInterfaces::get_Item()