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.

1015 lines
25 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1996-1999 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // NetIFace.cpp
  7. //
  8. // Abstract:
  9. // Implementation of the CNetInterface class.
  10. //
  11. // Author:
  12. // David Potter (davidp) May 28, 1997
  13. //
  14. // Revision History:
  15. //
  16. // Notes:
  17. //
  18. /////////////////////////////////////////////////////////////////////////////
  19. #include "stdafx.h"
  20. #include "CluAdmin.h"
  21. #include "ConstDef.h"
  22. #include "NetIFace.h"
  23. #include "ClusItem.inl"
  24. #include "Cluster.h"
  25. #include "NetIProp.h"
  26. #include "ExcOper.h"
  27. #include "TraceTag.h"
  28. #ifdef _DEBUG
  29. #define new DEBUG_NEW
  30. #undef THIS_FILE
  31. static char THIS_FILE[] = __FILE__;
  32. #endif
  33. /////////////////////////////////////////////////////////////////////////////
  34. // Global Variables
  35. /////////////////////////////////////////////////////////////////////////////
  36. #ifdef _DEBUG
  37. CTraceTag g_tagNetIFace(_T("Document"), _T("NETWORK INTERFACE"), 0);
  38. CTraceTag g_tagNetIFaceNotify(_T("Notify"), _T("NETIFACE NOTIFY"), 0);
  39. CTraceTag g_tagNetIFaceRegNotify(_T("Notify"), _T("NETIFACE REG NOTIFY"), 0);
  40. #endif
  41. /////////////////////////////////////////////////////////////////////////////
  42. // CNetInterface
  43. /////////////////////////////////////////////////////////////////////////////
  44. IMPLEMENT_DYNCREATE(CNetInterface, CClusterItem)
  45. /////////////////////////////////////////////////////////////////////////////
  46. // Message Maps
  47. BEGIN_MESSAGE_MAP(CNetInterface, CClusterItem)
  48. //{{AFX_MSG_MAP(CNetInterface)
  49. ON_UPDATE_COMMAND_UI(ID_FILE_PROPERTIES, OnUpdateProperties)
  50. //}}AFX_MSG_MAP
  51. END_MESSAGE_MAP()
  52. /////////////////////////////////////////////////////////////////////////////
  53. //++
  54. //
  55. // CNetInterface::CNetInterface
  56. //
  57. // Routine Description:
  58. // Default constructor.
  59. //
  60. // Arguments:
  61. // None.
  62. //
  63. // Return Value:
  64. // None.
  65. //
  66. //--
  67. /////////////////////////////////////////////////////////////////////////////
  68. CNetInterface::CNetInterface(void)
  69. : CClusterItem(NULL, IDS_ITEMTYPE_NETIFACE)
  70. {
  71. CommonConstruct();
  72. } //*** CResoruce::CNetInterface()
  73. /////////////////////////////////////////////////////////////////////////////
  74. //++
  75. //
  76. // CNetInterface::CommonConstruct
  77. //
  78. // Routine Description:
  79. // Common construction.
  80. //
  81. // Arguments:
  82. // None.
  83. //
  84. // Return Value:
  85. // None.
  86. //
  87. //--
  88. /////////////////////////////////////////////////////////////////////////////
  89. void CNetInterface::CommonConstruct(void)
  90. {
  91. m_idmPopupMenu = IDM_NETIFACE_POPUP;
  92. m_hnetiface = NULL;
  93. m_dwCharacteristics = CLUS_CHAR_UNKNOWN;
  94. m_dwFlags = 0;
  95. m_pciNode = NULL;
  96. m_pciNetwork = NULL;
  97. // Set the object type image.
  98. m_iimgObjectType = GetClusterAdminApp()->Iimg(IMGLI_NETIFACE);
  99. // Setup the property array.
  100. {
  101. m_rgProps[epropName].Set(CLUSREG_NAME_NETIFACE_NAME, m_strName, m_strName);
  102. m_rgProps[epropNode].Set(CLUSREG_NAME_NETIFACE_NODE, m_strNode, m_strNode);
  103. m_rgProps[epropNetwork].Set(CLUSREG_NAME_NETIFACE_NETWORK, m_strNetwork, m_strNetwork);
  104. m_rgProps[epropAdapter].Set(CLUSREG_NAME_NETIFACE_ADAPTER_NAME, m_strAdapter, m_strAdapter);
  105. m_rgProps[epropAddress].Set(CLUSREG_NAME_NETIFACE_ADDRESS, m_strAddress, m_strAddress);
  106. m_rgProps[epropDescription].Set(CLUSREG_NAME_NETIFACE_DESC, m_strDescription, m_strDescription);
  107. } // Setup the property array
  108. } //*** CNetInterface::CommonConstruct()
  109. /////////////////////////////////////////////////////////////////////////////
  110. //++
  111. //
  112. // CNetInterface::~CNetInterface
  113. //
  114. // Routine Description:
  115. // Destructor.
  116. //
  117. // Arguments:
  118. // None.
  119. //
  120. // Return Value:
  121. // None.
  122. //
  123. //--
  124. /////////////////////////////////////////////////////////////////////////////
  125. CNetInterface::~CNetInterface(void)
  126. {
  127. // Cleanup this object.
  128. Cleanup();
  129. // Close the network interface handle.
  130. if (Hnetiface() != NULL)
  131. CloseClusterNetInterface(Hnetiface());
  132. } //*** CNetInterface::~CNetInterface
  133. /////////////////////////////////////////////////////////////////////////////
  134. //++
  135. //
  136. // CNetInterface::Cleanup
  137. //
  138. // Routine Description:
  139. // Cleanup the item.
  140. //
  141. // Arguments:
  142. // None.
  143. //
  144. // Return Value:
  145. // None.
  146. //
  147. // Exceptions Thrown:
  148. // None.
  149. //
  150. //--
  151. /////////////////////////////////////////////////////////////////////////////
  152. void CNetInterface::Cleanup(void)
  153. {
  154. // Remove ourselves from the node's list.
  155. if (PciNode() != NULL)
  156. {
  157. PciNode()->RemoveNetInterface(this);
  158. PciNode()->Release();
  159. m_pciNode = NULL;
  160. } // if: there is a node
  161. // Remove ourselves from the network's list.
  162. if (PciNetwork() != NULL)
  163. {
  164. PciNetwork()->RemoveNetInterface(this);
  165. PciNetwork()->Release();
  166. m_pciNetwork = NULL;
  167. } // if: there is a network
  168. // Remove the item from the network interface list.
  169. {
  170. POSITION posPci;
  171. posPci = Pdoc()->LpciNetInterfaces().Find(this);
  172. if (posPci != NULL)
  173. {
  174. Pdoc()->LpciNetInterfaces().RemoveAt(posPci);
  175. } // if: found in the document's list
  176. } // Remove the item from the network interface list
  177. } //*** CNetInterface::Cleanup()
  178. /////////////////////////////////////////////////////////////////////////////
  179. //++
  180. //
  181. // CNetInterface::Init
  182. //
  183. // Routine Description:
  184. // Initialize the item.
  185. //
  186. // Arguments:
  187. // pdoc [IN OUT] Document to which this item belongs.
  188. // lpszName [IN] Name of the item.
  189. //
  190. // Return Value:
  191. // None.
  192. //
  193. // Exceptions Thrown:
  194. // CNTException Errors from OpenClusterNetInterface() or
  195. // GetClusterNetInterfaceKey().
  196. // Any exceptions thrown by new.
  197. //
  198. //--
  199. /////////////////////////////////////////////////////////////////////////////
  200. void CNetInterface::Init(IN OUT CClusterDoc * pdoc, IN LPCTSTR lpszName)
  201. {
  202. DWORD dwStatus = ERROR_SUCCESS;
  203. LONG lResult;
  204. CString strName(lpszName); // Required if built non-Unicode
  205. CWaitCursor wc;
  206. ASSERT(Hnetiface() == NULL);
  207. ASSERT(Hkey() == NULL);
  208. // Call the base class method.
  209. CClusterItem::Init(pdoc, lpszName);
  210. try
  211. {
  212. // Open the network interface.
  213. m_hnetiface = OpenClusterNetInterface(Hcluster(), strName);
  214. if (Hnetiface() == NULL)
  215. {
  216. dwStatus = GetLastError();
  217. ThrowStaticException(dwStatus, IDS_OPEN_NETIFACE_ERROR, lpszName);
  218. } // if: error opening the cluster network interface
  219. // Get the network interface registry key.
  220. m_hkey = GetClusterNetInterfaceKey(Hnetiface(), MAXIMUM_ALLOWED);
  221. if (Hkey() == NULL)
  222. ThrowStaticException(GetLastError(), IDS_GET_NETIFACE_KEY_ERROR, lpszName);
  223. ASSERT(Pcnk() != NULL);
  224. Trace(g_tagClusItemNotify, _T("CNetInterface::Init() - Registering for network interface notifications (%08.8x) for '%s'"), Pcnk(), StrName());
  225. // Register for network interface notifications.
  226. lResult = RegisterClusterNotify(
  227. GetClusterAdminApp()->HchangeNotifyPort(),
  228. ( CLUSTER_CHANGE_NETINTERFACE_STATE
  229. | CLUSTER_CHANGE_NETINTERFACE_DELETED
  230. | CLUSTER_CHANGE_NETINTERFACE_PROPERTY),
  231. Hnetiface(),
  232. (DWORD_PTR) Pcnk()
  233. );
  234. if (lResult != ERROR_SUCCESS)
  235. {
  236. dwStatus = lResult;
  237. ThrowStaticException(dwStatus, IDS_NETIFACE_NOTIF_REG_ERROR, lpszName);
  238. } // if: error registering for network interface notifications
  239. // Register for registry notifications.
  240. if (Hkey() != NULL)
  241. {
  242. lResult = RegisterClusterNotify(
  243. GetClusterAdminApp()->HchangeNotifyPort(),
  244. (CLUSTER_CHANGE_REGISTRY_NAME
  245. | CLUSTER_CHANGE_REGISTRY_ATTRIBUTES
  246. | CLUSTER_CHANGE_REGISTRY_VALUE
  247. | CLUSTER_CHANGE_REGISTRY_SUBTREE),
  248. Hkey(),
  249. (DWORD_PTR) Pcnk()
  250. );
  251. if (lResult != ERROR_SUCCESS)
  252. {
  253. dwStatus = lResult;
  254. ThrowStaticException(dwStatus, IDS_NETIFACE_NOTIF_REG_ERROR, lpszName);
  255. } // if: error registering for registry notifications
  256. } // if: there is a key
  257. // Read the initial state.
  258. UpdateState();
  259. } // try
  260. catch (CException *)
  261. {
  262. if (Hkey() != NULL)
  263. {
  264. ClusterRegCloseKey(Hkey());
  265. m_hkey = NULL;
  266. } // if: registry key opened
  267. if (Hnetiface() != NULL)
  268. {
  269. CloseClusterNetInterface(Hnetiface());
  270. m_hnetiface = NULL;
  271. } // if: network interface opened
  272. m_bReadOnly = TRUE;
  273. throw;
  274. } // catch: CException
  275. } //*** CNetInterface::Init()
  276. /////////////////////////////////////////////////////////////////////////////
  277. //++
  278. //
  279. // CNetInterface::ReadItem
  280. //
  281. // Routine Description:
  282. // Read the item parameters from the cluster database.
  283. //
  284. // Arguments:
  285. // None.
  286. //
  287. // Return Value:
  288. // None.
  289. //
  290. // Exceptions Thrown:
  291. // CNTException Errors from CClusterItem::DwReadValue().
  292. // Any exceptions thrown by ConstructList or CList::AddTail().
  293. //
  294. //--
  295. /////////////////////////////////////////////////////////////////////////////
  296. void CNetInterface::ReadItem(void)
  297. {
  298. DWORD dwStatus;
  299. DWORD dwRetStatus = ERROR_SUCCESS;
  300. CWaitCursor wc;
  301. ASSERT_VALID(this);
  302. if (Hnetiface() != NULL)
  303. {
  304. m_rgProps[epropDescription].m_value.pstr = &m_strDescription;
  305. // Call the base class method.
  306. CClusterItem::ReadItem();
  307. // Read and parse the common properties.
  308. {
  309. CClusPropList cpl;
  310. dwStatus = cpl.ScGetNetInterfaceProperties(
  311. Hnetiface(),
  312. CLUSCTL_NETINTERFACE_GET_COMMON_PROPERTIES
  313. );
  314. if (dwStatus == ERROR_SUCCESS)
  315. dwStatus = DwParseProperties(cpl);
  316. if (dwStatus != ERROR_SUCCESS)
  317. dwRetStatus = dwStatus;
  318. } // Read and parse the common properties
  319. // Read and parse the read-only common properties.
  320. if (dwRetStatus == ERROR_SUCCESS)
  321. {
  322. CClusPropList cpl;
  323. dwStatus = cpl.ScGetNetInterfaceProperties(
  324. Hnetiface(),
  325. CLUSCTL_NETINTERFACE_GET_RO_COMMON_PROPERTIES
  326. );
  327. if (dwStatus == ERROR_SUCCESS)
  328. dwStatus = DwParseProperties(cpl);
  329. if (dwStatus != ERROR_SUCCESS)
  330. dwRetStatus = dwStatus;
  331. } // if: no error yet
  332. // Find the node object.
  333. {
  334. CClusterNode * pciNode;
  335. pciNode = Pdoc()->LpciNodes().PciNodeFromName(StrNode());
  336. if (pciNode != m_pciNode)
  337. {
  338. if (m_pciNode != NULL)
  339. {
  340. m_pciNode->RemoveNetInterface(this);
  341. m_pciNode->Release();
  342. } // if: old node
  343. m_pciNode = pciNode;
  344. if (m_pciNode != NULL)
  345. {
  346. m_pciNode->AddRef();
  347. m_pciNode->AddNetInterface(this);
  348. } // if: new node
  349. } // if: node changed (should never happen)
  350. } // Find the node object
  351. // Find the network object.
  352. {
  353. CNetwork * pciNetwork;
  354. pciNetwork = Pdoc()->LpciNetworks().PciNetworkFromName(StrNetwork());
  355. if (pciNetwork != m_pciNetwork)
  356. {
  357. if (m_pciNetwork != NULL)
  358. {
  359. m_pciNetwork->RemoveNetInterface(this);
  360. m_pciNetwork->Release();
  361. } // if: old network
  362. m_pciNetwork = pciNetwork;
  363. if (m_pciNetwork != NULL)
  364. {
  365. m_pciNetwork->AddRef();
  366. m_pciNetwork->AddNetInterface(this);
  367. } // if: new network
  368. } // if: netowrk changed (should never happen)
  369. } // Find the network object
  370. // Read the characteristics flag.
  371. if (dwRetStatus == ERROR_SUCCESS)
  372. {
  373. DWORD cbReturned;
  374. dwStatus = ClusterNetInterfaceControl(
  375. Hnetiface(),
  376. NULL,
  377. CLUSCTL_NETINTERFACE_GET_CHARACTERISTICS,
  378. NULL,
  379. NULL,
  380. &m_dwCharacteristics,
  381. sizeof(m_dwCharacteristics),
  382. &cbReturned
  383. );
  384. if (dwStatus != ERROR_SUCCESS)
  385. dwRetStatus = dwStatus;
  386. else
  387. {
  388. ASSERT(cbReturned == sizeof(m_dwCharacteristics));
  389. } // else: data retrieved successfully
  390. } // if: no error yet
  391. // Read the flags.
  392. if (dwRetStatus == ERROR_SUCCESS)
  393. {
  394. DWORD cbReturned;
  395. dwStatus = ClusterNetInterfaceControl(
  396. Hnetiface(),
  397. NULL,
  398. CLUSCTL_NETINTERFACE_GET_FLAGS,
  399. NULL,
  400. NULL,
  401. &m_dwFlags,
  402. sizeof(m_dwFlags),
  403. &cbReturned
  404. );
  405. if (dwStatus != ERROR_SUCCESS)
  406. dwRetStatus = dwStatus;
  407. else
  408. {
  409. ASSERT(cbReturned == sizeof(m_dwFlags));
  410. } // else: data retrieved successfully
  411. } // if: no error yet
  412. // Construct the list of extensions.
  413. ReadExtensions();
  414. } // if: network interface is available
  415. // Read the initial state.
  416. UpdateState();
  417. // If any errors occurred, throw an exception.
  418. if (dwRetStatus != ERROR_SUCCESS)
  419. {
  420. m_bReadOnly = TRUE;
  421. // if (dwRetStatus != ERROR_FILE_NOT_FOUND)
  422. ThrowStaticException(dwRetStatus, IDS_READ_NETIFACE_PROPS_ERROR, StrName());
  423. } // if: error reading properties
  424. MarkAsChanged(FALSE);
  425. } //*** CNetInterface::ReadItem()
  426. /////////////////////////////////////////////////////////////////////////////
  427. //++
  428. //
  429. // CNetInterface::ReadExtensions
  430. //
  431. // Routine Description:
  432. // Read extension lists.
  433. //
  434. // Arguments:
  435. // None.
  436. //
  437. // Return Value:
  438. // None.
  439. //
  440. // Exceptions Thrown:
  441. // None.
  442. //
  443. //--
  444. /////////////////////////////////////////////////////////////////////////////
  445. void CNetInterface::ReadExtensions(void)
  446. {
  447. } //*** CNetInterface::ReadExtensions()
  448. /////////////////////////////////////////////////////////////////////////////
  449. //++
  450. //
  451. // CNetInterface::PlstrExtension
  452. //
  453. // Routine Description:
  454. // Return the list of admin extensions.
  455. //
  456. // Arguments:
  457. // None.
  458. //
  459. // Return Value:
  460. // plstr List of extensions.
  461. // NULL No extension associated with this object.
  462. //
  463. // Exceptions Thrown:
  464. // None.
  465. //
  466. //--
  467. /////////////////////////////////////////////////////////////////////////////
  468. const CStringList * CNetInterface::PlstrExtensions(void) const
  469. {
  470. return &Pdoc()->PciCluster()->LstrNetworkExtensions();
  471. } //*** CNetInterface::PlstrExtensions()
  472. /////////////////////////////////////////////////////////////////////////////
  473. //++
  474. //
  475. // CNetInterface::SetCommonProperties
  476. //
  477. // Routine Description:
  478. // Set the common properties for this network interface in the cluster
  479. // database.
  480. //
  481. // Arguments:
  482. // rstrDesc [IN] Description string.
  483. // bValidateOnly [IN] Only validate the data.
  484. //
  485. // Return Value:
  486. // None.
  487. //
  488. // Exceptions Thrown:
  489. // Any exceptions thrown by CClusterItem::SetCommonProperties().
  490. //
  491. //--
  492. /////////////////////////////////////////////////////////////////////////////
  493. void CNetInterface::SetCommonProperties(
  494. IN const CString & rstrDesc,
  495. IN BOOL bValidateOnly
  496. )
  497. {
  498. CNTException nte(ERROR_SUCCESS, 0, NULL, NULL, FALSE /*bAutoDelete*/);
  499. m_rgProps[epropDescription].m_value.pstr = (CString *) &rstrDesc;
  500. try
  501. {
  502. CClusterItem::SetCommonProperties(bValidateOnly);
  503. } // try
  504. catch (CNTException * pnte)
  505. {
  506. nte.SetOperation(
  507. pnte->Sc(),
  508. pnte->IdsOperation(),
  509. pnte->PszOperArg1(),
  510. pnte->PszOperArg2()
  511. );
  512. } // catch: CNTException
  513. m_rgProps[epropDescription].m_value.pstr = &m_strDescription;
  514. if (nte.Sc() != ERROR_SUCCESS)
  515. ThrowStaticException(
  516. nte.Sc(),
  517. nte.IdsOperation(),
  518. nte.PszOperArg1(),
  519. nte.PszOperArg2()
  520. );
  521. } //*** CNetInterface::SetCommonProperties()
  522. /////////////////////////////////////////////////////////////////////////////
  523. //++
  524. //
  525. // CNetInterface::DwSetCommonProperties
  526. //
  527. // Routine Description:
  528. // Set the common properties for this network interface in the cluster
  529. // database.
  530. //
  531. // Arguments:
  532. // rcpl [IN] Property list to set.
  533. // bValidateOnly [IN] Only validate the data.
  534. //
  535. // Return Value:
  536. // Any status returned by ClusterNetInterfaceControl().
  537. //
  538. //--
  539. /////////////////////////////////////////////////////////////////////////////
  540. DWORD CNetInterface::DwSetCommonProperties(
  541. IN const CClusPropList & rcpl,
  542. IN BOOL bValidateOnly
  543. )
  544. {
  545. DWORD dwStatus;
  546. CWaitCursor wc;
  547. ASSERT(Hnetiface());
  548. if ((rcpl.PbPropList() != NULL) && (rcpl.CbPropList() > 0))
  549. {
  550. DWORD cbProps;
  551. DWORD dwControl;
  552. if (bValidateOnly)
  553. dwControl = CLUSCTL_NETINTERFACE_VALIDATE_COMMON_PROPERTIES;
  554. else
  555. dwControl = CLUSCTL_NETINTERFACE_SET_COMMON_PROPERTIES;
  556. // Set common properties.
  557. dwStatus = ClusterNetInterfaceControl(
  558. Hnetiface(),
  559. NULL, // hNode
  560. dwControl,
  561. rcpl.PbPropList(),
  562. rcpl.CbPropList(),
  563. NULL, // lpOutBuffer
  564. 0, // nOutBufferSize
  565. &cbProps
  566. );
  567. } // if: there is data to set
  568. else
  569. dwStatus = ERROR_SUCCESS;
  570. return dwStatus;
  571. } //*** CNetInterface::DwSetCommonProperties()
  572. /////////////////////////////////////////////////////////////////////////////
  573. //++
  574. //
  575. // CNetInterface::UpdateState
  576. //
  577. // Routine Description:
  578. // Update the current state of the item.
  579. //
  580. // Arguments:
  581. // None.
  582. //
  583. // Return Value:
  584. // None.
  585. //
  586. //--
  587. /////////////////////////////////////////////////////////////////////////////
  588. void CNetInterface::UpdateState(void)
  589. {
  590. CClusterAdminApp * papp = GetClusterAdminApp();
  591. Trace(g_tagNetIFace, _T("(%s) (%s (%x)) - Updating state"), Pdoc()->StrNode(), StrName(), this);
  592. // Get the current state of the network interface.
  593. if (Hnetiface() == NULL)
  594. m_cnis = ClusterNetInterfaceStateUnknown;
  595. else
  596. {
  597. CWaitCursor wc;
  598. m_cnis = GetClusterNetInterfaceState(Hnetiface());
  599. } // else: network interface is available
  600. // Save the current state image index.
  601. switch (Cnis())
  602. {
  603. case ClusterNetInterfaceStateUnknown:
  604. case ClusterNetInterfaceUnavailable:
  605. m_iimgState = papp->Iimg(IMGLI_NETIFACE_UNKNOWN);
  606. break;
  607. case ClusterNetInterfaceUp:
  608. m_iimgState = papp->Iimg(IMGLI_NETIFACE);
  609. break;
  610. case ClusterNetInterfaceUnreachable:
  611. m_iimgState = papp->Iimg(IMGLI_NETIFACE_UNREACHABLE);
  612. break;
  613. case ClusterNetInterfaceFailed:
  614. m_iimgState = papp->Iimg(IMGLI_NETIFACE_FAILED);
  615. break;
  616. default:
  617. Trace(g_tagNetIFace, _T("(%s) (%s (%x)) - UpdateState: Unknown state '%d' for network interface '%s'"), Pdoc()->StrNode(), StrName(), this, Cnis(), StrName());
  618. m_iimgState = (UINT) -1;
  619. break;
  620. } // switch: Crs()
  621. // Call the base class method.
  622. CClusterItem::UpdateState();
  623. } //*** CNetInterface::UpdateState()
  624. /////////////////////////////////////////////////////////////////////////////
  625. //++
  626. //
  627. // CNetInterface::BGetColumnData
  628. //
  629. // Routine Description:
  630. // Returns a string with the column data.
  631. //
  632. // Arguments:
  633. // colid [IN] Column ID.
  634. // rstrText [OUT] String in which to return the text for the column.
  635. //
  636. // Return Value:
  637. // TRUE Column data returned.
  638. // FALSE Column ID not recognized.
  639. //
  640. //--
  641. /////////////////////////////////////////////////////////////////////////////
  642. BOOL CNetInterface::BGetColumnData(IN COLID colid, OUT CString & rstrText)
  643. {
  644. BOOL bSuccess;
  645. switch (colid)
  646. {
  647. case IDS_COLTEXT_STATE:
  648. GetStateName(rstrText);
  649. bSuccess = TRUE;
  650. break;
  651. case IDS_COLTEXT_NODE:
  652. rstrText = StrNode();
  653. bSuccess = TRUE;
  654. break;
  655. case IDS_COLTEXT_NETWORK:
  656. if (PciNetwork() == NULL)
  657. rstrText = StrNetwork();
  658. else
  659. rstrText = PciNetwork()->StrName();
  660. bSuccess = TRUE;
  661. break;
  662. case IDS_COLTEXT_ADAPTER:
  663. rstrText = StrAdapter();
  664. bSuccess = TRUE;
  665. break;
  666. case IDS_COLTEXT_ADDRESS:
  667. rstrText = StrAddress();
  668. bSuccess = TRUE;
  669. break;
  670. default:
  671. bSuccess = CClusterItem::BGetColumnData(colid, rstrText);
  672. break;
  673. } // switch: colid
  674. return bSuccess;
  675. } //*** CNetInterface::BGetColumnData()
  676. /////////////////////////////////////////////////////////////////////////////
  677. //++
  678. //
  679. // CNetInterface::GetTreeName
  680. //
  681. // Routine Description:
  682. // Returns a string to be used in a tree control.
  683. //
  684. // Arguments:
  685. // rstrName [OUT] String in which to return the name.
  686. //
  687. // Return Value:
  688. // None.
  689. //
  690. //--
  691. /////////////////////////////////////////////////////////////////////////////
  692. #ifdef _DISPLAY_STATE_TEXT_IN_TREE
  693. void CNetInterface::GetTreeName(OUT CString & rstrName) const
  694. {
  695. CString strState;
  696. GetStateName(strState);
  697. rstrName.Format(_T("%s (%s)"), StrName(), strState);
  698. } //*** CNetInterface::GetTreeName()
  699. #endif
  700. /////////////////////////////////////////////////////////////////////////////
  701. //++
  702. //
  703. // CNetInterface::GetStateName
  704. //
  705. // Routine Description:
  706. // Returns a string with the name of the current state.
  707. //
  708. // Arguments:
  709. // rstrState [OUT] String in which to return the name of the current state.
  710. //
  711. // Return Value:
  712. // None.
  713. //
  714. //--
  715. /////////////////////////////////////////////////////////////////////////////
  716. void CNetInterface::GetStateName(OUT CString & rstrState) const
  717. {
  718. switch (Cnis())
  719. {
  720. case ClusterNetInterfaceStateUnknown:
  721. rstrState.LoadString(IDS_UNKNOWN);
  722. break;
  723. case ClusterNetInterfaceUp:
  724. rstrState.LoadString(IDS_UP);
  725. break;
  726. case ClusterNetInterfaceUnreachable:
  727. rstrState.LoadString(IDS_UNREACHABLE);
  728. break;
  729. case ClusterNetInterfaceFailed:
  730. rstrState.LoadString(IDS_FAILED);
  731. break;
  732. case ClusterNetInterfaceUnavailable:
  733. rstrState.LoadString(IDS_UNAVAILABLE);
  734. break;
  735. default:
  736. rstrState.Empty();
  737. break;
  738. } // switch: Crs()
  739. } //*** CNetInterface::GetStateName()
  740. /////////////////////////////////////////////////////////////////////////////
  741. //++
  742. //
  743. // CNetInterface::OnUpdateProperties
  744. //
  745. // Routine Description:
  746. // Determines whether menu items corresponding to ID_FILE_PROPERTIES
  747. // should be enabled or not.
  748. //
  749. // Arguments:
  750. // pCmdUI [IN OUT] Command routing object.
  751. //
  752. // Return Value:
  753. // None.
  754. //
  755. //--
  756. /////////////////////////////////////////////////////////////////////////////
  757. void CNetInterface::OnUpdateProperties(CCmdUI * pCmdUI)
  758. {
  759. pCmdUI->Enable(TRUE);
  760. } //*** CNetInterface::OnUpdateProperties()
  761. /////////////////////////////////////////////////////////////////////////////
  762. //++
  763. //
  764. // CNetInterface::BDisplayProperties
  765. //
  766. // Routine Description:
  767. // Display properties for the object.
  768. //
  769. // Arguments:
  770. // bReadOnly [IN] Don't allow edits to the object properties.
  771. //
  772. // Return Value:
  773. // TRUE OK pressed.
  774. // FALSE OK not pressed.
  775. //
  776. //--
  777. /////////////////////////////////////////////////////////////////////////////
  778. BOOL CNetInterface::BDisplayProperties(IN BOOL bReadOnly)
  779. {
  780. BOOL bChanged = FALSE;
  781. CNetInterfacePropSheet sht(AfxGetMainWnd());
  782. // Do this in case this object is deleted while we are operating on it.
  783. AddRef();
  784. // If the object has changed, read it.
  785. if (BChanged())
  786. ReadItem();
  787. // Display the property sheet.
  788. try
  789. {
  790. sht.SetReadOnly(bReadOnly);
  791. if (sht.BInit(this, IimgObjectType()))
  792. bChanged = ((sht.DoModal() == IDOK) && !bReadOnly);
  793. } // try
  794. catch (CException * pe)
  795. {
  796. pe->Delete();
  797. } // catch: CException
  798. Release();
  799. return bChanged;
  800. } //*** CNetInterface::BDisplayProperties()
  801. /////////////////////////////////////////////////////////////////////////////
  802. //++
  803. //
  804. // CNetInterface::OnClusterNotify
  805. //
  806. // Routine Description:
  807. // Handler for the WM_CAM_CLUSTER_NOTIFY message.
  808. // Processes cluster notifications for this object.
  809. //
  810. // Arguments:
  811. // pnotify [IN OUT] Object describing the notification.
  812. //
  813. // Return Value:
  814. // Value returned from the application method.
  815. //
  816. //--
  817. /////////////////////////////////////////////////////////////////////////////
  818. LRESULT CNetInterface::OnClusterNotify(IN OUT CClusterNotify * pnotify)
  819. {
  820. ASSERT(pnotify != NULL);
  821. ASSERT_VALID(this);
  822. try
  823. {
  824. switch (pnotify->m_dwFilterType)
  825. {
  826. case CLUSTER_CHANGE_NETINTERFACE_STATE:
  827. Trace(g_tagNetIFaceNotify, _T("(%s) - Network Interface '%s' (%x) state changed (%s)"), Pdoc()->StrNode(), StrName(), this, pnotify->m_strName);
  828. UpdateState();
  829. break;
  830. case CLUSTER_CHANGE_NETINTERFACE_DELETED:
  831. Trace(g_tagNetIFaceNotify, _T("(%s) - Network Interface '%s' (%x) deleted (%s)"), Pdoc()->StrNode(), StrName(), this, pnotify->m_strName);
  832. if (Pdoc()->BClusterAvailable())
  833. Delete();
  834. break;
  835. case CLUSTER_CHANGE_NETINTERFACE_PROPERTY:
  836. Trace(g_tagNetIFaceNotify, _T("(%s) - Network Interface '%s' (%x) properties changed (%s)"), Pdoc()->StrNode(), StrName(), this, pnotify->m_strName);
  837. if (Pdoc()->BClusterAvailable())
  838. ReadItem();
  839. break;
  840. case CLUSTER_CHANGE_REGISTRY_NAME:
  841. Trace(g_tagNetIFaceNotify, _T("(%s) - Registry namespace '%s' changed (%s %s (%x))"), Pdoc()->StrNode(), pnotify->m_strName, StrType(), StrName(), this);
  842. MarkAsChanged();
  843. break;
  844. case CLUSTER_CHANGE_REGISTRY_ATTRIBUTES:
  845. Trace(g_tagNetIFaceNotify, _T("(%s) - Registry attributes for '%s' changed (%s %s (%x))"), Pdoc()->StrNode(), pnotify->m_strName, StrType(), StrName(), this);
  846. MarkAsChanged();
  847. break;
  848. case CLUSTER_CHANGE_REGISTRY_VALUE:
  849. Trace(g_tagNetIFaceNotify, _T("(%s) - Registry value '%s' changed (%s %s (%x))"), Pdoc()->StrNode(), pnotify->m_strName, StrType(), StrName(), this);
  850. MarkAsChanged();
  851. break;
  852. default:
  853. Trace(g_tagNetIFaceNotify, _T("(%s) - Unknown network interface notification (%x) for '%s' (%x) (%s)"), Pdoc()->StrNode(), pnotify->m_dwFilterType, StrName(), this, pnotify->m_strName);
  854. } // switch: dwFilterType
  855. } // try
  856. catch (CException * pe)
  857. {
  858. // Don't display anything on notification errors.
  859. // If it's really a problem, the user will see it when
  860. // refreshing the view.
  861. //pe->ReportError();
  862. pe->Delete();
  863. } // catch: CException
  864. delete pnotify;
  865. return 0;
  866. } //*** CNetInterface::OnClusterNotify()
  867. //*************************************************************************//
  868. /////////////////////////////////////////////////////////////////////////////
  869. // Global Functions
  870. /////////////////////////////////////////////////////////////////////////////
  871. /////////////////////////////////////////////////////////////////////////////
  872. //++
  873. //
  874. // DeleteAllItemData
  875. //
  876. // Routine Description:
  877. // Deletes all item data in a CList.
  878. //
  879. // Arguments:
  880. // rlp [IN OUT] List whose data is to be deleted.
  881. //
  882. // Return Value:
  883. // None.
  884. //
  885. //--
  886. /////////////////////////////////////////////////////////////////////////////
  887. #ifdef NEVER
  888. void DeleteAllItemData(IN OUT CNetInterfaceList & rlp)
  889. {
  890. POSITION pos;
  891. CNetInterface * pci;
  892. // Delete all the items in the Contained list.
  893. pos = rlp.GetHeadPosition();
  894. while (pos != NULL)
  895. {
  896. pci = rlp.GetNext(pos);
  897. ASSERT_VALID(pci);
  898. // Trace(g_tagClusItemDelete, _T("DeleteAllItemData(rlp) - Deleting network interface cluster item '%s' (%x)"), pci->StrName(), pci);
  899. pci->Delete();
  900. } // while: more items in the list
  901. } //*** DeleteAllItemData()
  902. #endif