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.

205 lines
6.7 KiB

  1. #include "precomp.h"
  2. #pragma hdrstop
  3. #include "private.h"
  4. #include "PortsPage.h"
  5. #include "PortsCtrl.h"
  6. #include "portsctrl.tmh"
  7. using namespace std;
  8. /////////////////////////////////////////////////////////////////////////////
  9. // CPortsCtrl dialog
  10. CPortsCtrl::CPortsCtrl(ENGINEHANDLE ehClusterOrInterfaceId,
  11. NLB_EXTENDED_CLUSTER_CONFIGURATION * pNlbCfg,
  12. bool fIsClusterLevel,
  13. CWnd * pParent /*=NULL*/)
  14. :CDialog(CPortsCtrl::IDD, pParent),
  15. m_ehClusterOrInterfaceId( ehClusterOrInterfaceId ),
  16. m_isClusterLevel( fIsClusterLevel ),
  17. m_pNlbCfg( pNlbCfg ),
  18. m_sort_column( 0 ),
  19. m_sort_ascending( true)
  20. {
  21. }
  22. void CPortsCtrl::DoDataExchange(CDataExchange* pDX)
  23. {
  24. CDialog::DoDataExchange(pDX);
  25. DDX_Control(pDX, IDC_LIST_PORT_RULE, m_portList);
  26. DDX_Control(pDX, IDC_BUTTON_ENABLE, m_Enable);
  27. DDX_Control(pDX, IDC_BUTTON_DISABLE, m_Disable);
  28. DDX_Control(pDX, IDC_BUTTON_DRAIN, m_Drain);
  29. DDX_Control(pDX, IDOK, m_Close);
  30. }
  31. BEGIN_MESSAGE_MAP(CPortsCtrl, CDialog)
  32. ON_NOTIFY(LVN_COLUMNCLICK, IDC_LIST_PORT_RULE, OnColumnClick)
  33. ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST_PORT_RULE, OnSelchanged )
  34. ON_BN_CLICKED(IDC_BUTTON_ENABLE, OnEnable)
  35. ON_BN_CLICKED(IDC_BUTTON_DISABLE, OnDisable)
  36. ON_BN_CLICKED(IDC_BUTTON_DRAIN, OnDrain)
  37. END_MESSAGE_MAP()
  38. /////////////////////////////////////////////////////////////////////////////
  39. // CPortsCtrl message handlers
  40. BOOL CPortsCtrl::OnInitDialog()
  41. {
  42. TRACE_INFO(L"-> %!FUNC!");
  43. CDialog::OnInitDialog();
  44. // Add column headers & form port rule list
  45. PortListUtils::LoadFromNlbCfg(m_pNlbCfg, REF m_portList, m_isClusterLevel, FALSE);
  46. // If the number of port rules is zero, then, gray out the enable, disable & drain buttons
  47. if (m_portList.GetItemCount() == 0)
  48. {
  49. m_Enable.EnableWindow(FALSE);
  50. m_Disable.EnableWindow(FALSE);
  51. m_Drain.EnableWindow(FALSE);
  52. }
  53. else // there is one or more port rules
  54. {
  55. // selection the first item in list.
  56. m_portList.SetItemState( 0, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED );
  57. }
  58. TRACE_INFO(L"<- %!FUNC! returns TRUE");
  59. return TRUE; // return TRUE unless you set the focus to a control
  60. }
  61. void CPortsCtrl::OnColumnClick(NMHDR* pNMHDR, LRESULT* pResult)
  62. {
  63. PortListUtils::OnColumnClick((LPNMLISTVIEW) pNMHDR,
  64. REF m_portList,
  65. m_isClusterLevel,
  66. REF m_sort_ascending,
  67. REF m_sort_column);
  68. *pResult = 0;
  69. }
  70. void CPortsCtrl::OnSelchanged(NMHDR* pNMHDR, LRESULT * pResult)
  71. {
  72. TRACE_INFO(L"-> %!FUNC!");
  73. // If no port rule is selected, then gray out the enable, disable and drain buttons.
  74. if (m_portList.GetFirstSelectedItemPosition() == NULL)
  75. {
  76. m_Enable.EnableWindow(FALSE);
  77. m_Disable.EnableWindow(FALSE);
  78. m_Drain.EnableWindow(FALSE);
  79. }
  80. else // a port rule is selected, check if the enable, disable, drain buttons are grayed out. If they are, enable them
  81. {
  82. if (m_Enable.IsWindowEnabled() == FALSE)
  83. {
  84. m_Enable.EnableWindow(TRUE);
  85. m_Disable.EnableWindow(TRUE);
  86. m_Drain.EnableWindow(TRUE);
  87. }
  88. }
  89. /*
  90. LPNMLISTVIEW lv = (LPNMLISTVIEW)pNMHDR;
  91. TRACE_INFO(L"%!FUNC! iItem : %d", lv->iItem);
  92. TRACE_INFO(L"%!FUNC! iSubItem : %d", lv->iSubItem);
  93. TRACE_INFO(L"%!FUNC! uNewState : %u", lv->uNewState);
  94. TRACE_INFO(L"%!FUNC! uOldState : %u", lv->uOldState);
  95. TRACE_INFO(L"%!FUNC! uChanged : %u", lv->uChanged);
  96. */
  97. *pResult = 0;
  98. TRACE_INFO(L"<- %!FUNC!");
  99. return;
  100. }
  101. void CPortsCtrl::OnEnable()
  102. {
  103. CWaitCursor wait;
  104. SetDlgItemText(IDC_OPER_STATUS_TEXT, GETRESOURCEIDSTRING(IDS_INFO_ENABLING_PORTS));
  105. mfn_DoPortControlOperation(WLBS_PORT_ENABLE);
  106. SetDlgItemText(IDC_OPER_STATUS_TEXT, GETRESOURCEIDSTRING(IDS_INFO_DONE));
  107. return;
  108. }
  109. void CPortsCtrl::OnDisable()
  110. {
  111. CWaitCursor wait;
  112. SetDlgItemText(IDC_OPER_STATUS_TEXT, GETRESOURCEIDSTRING(IDS_INFO_DISABLING_PORTS));
  113. mfn_DoPortControlOperation(WLBS_PORT_DISABLE);
  114. SetDlgItemText(IDC_OPER_STATUS_TEXT, GETRESOURCEIDSTRING(IDS_INFO_DONE));
  115. return;
  116. }
  117. void CPortsCtrl::OnDrain()
  118. {
  119. CWaitCursor wait;
  120. SetDlgItemText(IDC_OPER_STATUS_TEXT, GETRESOURCEIDSTRING(IDS_INFO_DRAINING_PORTS));
  121. mfn_DoPortControlOperation(WLBS_PORT_DRAIN);
  122. SetDlgItemText(IDC_OPER_STATUS_TEXT, GETRESOURCEIDSTRING(IDS_INFO_DONE));
  123. return;
  124. }
  125. NLBERROR CPortsCtrl::mfn_DoPortControlOperation(WLBS_OPERATION_CODES Opcode)
  126. {
  127. CString szVipArray[WLBS_MAX_RULES], szTemp;
  128. DWORD pdwStartPortArray[WLBS_MAX_RULES];
  129. DWORD dwNumOfPortRules;
  130. POSITION pos = m_portList.GetFirstSelectedItemPosition();
  131. if (pos == NULL)
  132. {
  133. return NLBERR_INTERNAL_ERROR;
  134. }
  135. // Loop thru the selected port rules and get the VIP & Start Port
  136. dwNumOfPortRules = 0;
  137. do
  138. {
  139. int index = m_portList.GetNextSelectedItem(REF pos);
  140. // Get VIP, Note : 0 is the column index for VIP
  141. szVipArray[dwNumOfPortRules] = m_portList.GetItemText( index, 0 );
  142. // Check for "All Vip" and replace "All" with "255.255.255.255"
  143. if (!lstrcmpi(szVipArray[dwNumOfPortRules], GETRESOURCEIDSTRING(IDS_REPORT_VIP_ALL)))
  144. {
  145. szVipArray[dwNumOfPortRules] = CVY_DEF_ALL_VIP;
  146. }
  147. // Get Start Port, Note : 1 is the column index for Start Port
  148. szTemp = m_portList.GetItemText( index, 1);
  149. pdwStartPortArray[dwNumOfPortRules] = _wtol(szTemp);
  150. ++dwNumOfPortRules;
  151. }
  152. while (pos);
  153. if (m_isClusterLevel)
  154. {
  155. return gEngine.ControlClusterOnCluster(m_ehClusterOrInterfaceId,
  156. Opcode,
  157. szVipArray,
  158. pdwStartPortArray,
  159. dwNumOfPortRules);
  160. }
  161. else
  162. {
  163. return gEngine.ControlClusterOnInterface(m_ehClusterOrInterfaceId,
  164. Opcode,
  165. szVipArray,
  166. pdwStartPortArray,
  167. dwNumOfPortRules,
  168. TRUE
  169. );
  170. }
  171. return NLBERR_INTERNAL_ERROR;
  172. }