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.

720 lines
18 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1999
  6. //
  7. // File: pggen.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. // general.cpp : implementation file
  11. //
  12. #include "stdafx.h"
  13. #include "acsadmin.h"
  14. #include "acsdata.h"
  15. #include "pggen.h"
  16. #include "pglimit.h"
  17. #ifdef _DEBUG
  18. #define new DEBUG_NEW
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22. /////////////////////////////////////////////////////////////////////////////
  23. // CPgGeneral property page
  24. IMPLEMENT_DYNCREATE(CPgGeneral, CACSPage)
  25. CPgGeneral::CPgGeneral(CACSSubnetConfig* pConfig, CACSContainerObject<CACSSubnetServiceLimits>* pLimitsCont) : CACSPage(CPgGeneral::IDD)
  26. {
  27. ASSERT(pConfig);
  28. m_spConfig = pConfig;
  29. m_spLimitsCont = pLimitsCont;
  30. DataInit();
  31. }
  32. void CPgGeneral::DataInit()
  33. {
  34. //{{AFX_DATA_INIT(CPgGeneral)
  35. m_bEnableACS = ACS_SCADEF_ENABLEACSSERVICE;
  36. m_strDesc = _T(" ");
  37. m_uDataRate = 0;
  38. m_uPeakRate = 0;
  39. m_uTTDataRate = 0;
  40. m_uTTPeakRate = 0;
  41. m_bFlowDataChanged = FALSE;
  42. //}}AFX_DATA_INIT
  43. // service level limits list
  44. m_aLimitsRecord[Index_Aggregate].m_strNameToCompareWith = ACS_SUBNET_LIMITS_OBJ_AGGREGATE;
  45. m_aLimitsRecord[Index_Guaranteed].m_strNameToCompareWith = ACS_SUBNET_LIMITS_OBJ_GUARANTEEDSERVICE;
  46. m_aLimitsRecord[Index_ControlledLoad].m_strNameToCompareWith = ACS_SUBNET_LIMITS_OBJ_CONTROLLEDLOAD;
  47. m_aLimitsRecord[Index_Aggregate].m_nServiceType = ACS_SUBNET_LIMITS_SERVICETYPE_AGGREGATE;
  48. m_aLimitsRecord[Index_Guaranteed].m_nServiceType = ACS_SUBNET_LIMITS_SERVICETYPE_GUARANTEEDSERVICE;
  49. m_aLimitsRecord[Index_ControlledLoad].m_nServiceType = ACS_SUBNET_LIMITS_SERVICETYPE_CONTROLLEDLOAD;
  50. }
  51. CPgGeneral::CPgGeneral() : CACSPage(CPgGeneral::IDD)
  52. {
  53. DataInit();
  54. }
  55. CPgGeneral::~CPgGeneral()
  56. {
  57. }
  58. void CPgGeneral::DoDataExchange(CDataExchange* pDX)
  59. {
  60. CACSPage::DoDataExchange(pDX);
  61. //{{AFX_DATA_MAP(CPgGeneral)
  62. DDX_Control(pDX, IDC_BUTTONEDITSERVICELIMIT, m_btnEdit);
  63. DDX_Control(pDX, IDC_BUTTONDELETESERVICELIMIT, m_btnDelete);
  64. DDX_Control(pDX, IDC_BUTTONADDSERVICELIMIT, m_btnAdd);
  65. DDX_Control(pDX, IDC_LIST_SERVICELIMIT, m_listServiceLimit);
  66. DDX_Check(pDX, IDC_CHECK_ENABLEACS, m_bEnableACS);
  67. DDX_Text(pDX, IDC_EDIT_GEN_DESC, m_strDesc);
  68. DDV_MinChars(pDX, m_strDesc, 1);
  69. //}}AFX_DATA_MAP
  70. }
  71. BEGIN_MESSAGE_MAP(CPgGeneral, CACSPage)
  72. //{{AFX_MSG_MAP(CPgGeneral)
  73. ON_BN_CLICKED(IDC_CHECK_ENABLEACS, OnCheckEnableacs)
  74. ON_EN_CHANGE(IDC_EDIT_GEN_DESC, OnChangeEditGenDesc)
  75. ON_BN_CLICKED(IDC_BUTTONADDSERVICELIMIT, OnButtonaddservicelimit)
  76. ON_BN_CLICKED(IDC_BUTTONDELETESERVICELIMIT, OnButtondeleteservicelimit)
  77. ON_BN_CLICKED(IDC_BUTTONEDITSERVICELIMIT, OnButtoneditservicelimit)
  78. ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST_SERVICELIMIT, OnItemchangedListServicelimit)
  79. ON_NOTIFY(NM_DBLCLK, IDC_LIST_SERVICELIMIT, OnDblclkListServicelimit)
  80. //}}AFX_MSG_MAP
  81. END_MESSAGE_MAP()
  82. /////////////////////////////////////////////////////////////////////////////
  83. // CPgGeneral message handlers
  84. BOOL CPgGeneral::OnApply()
  85. {
  86. // Enable ACS
  87. m_spConfig->SetFlags(ATTR_FLAG_SAVE, ACS_SCAF_ENABLEACSSERVICE, true);
  88. m_spConfig->m_bENABLEACSSERVICE = m_bEnableACS;
  89. // description
  90. m_spConfig->SetFlags(ATTR_FLAG_SAVE, ACS_SCAF_DESCRIPTION, true);
  91. m_spConfig->m_strDESCRIPTION = m_strDesc;
  92. DWORD dwAttrFlags = ATTR_FLAGS_NONE;
  93. HRESULT hr = S_OK;
  94. dwAttrFlags |= (ACS_SCAF_ENABLEACSSERVICE);
  95. dwAttrFlags |= (ACS_SCAF_DESCRIPTION);
  96. AddFlags(dwAttrFlags); // prepare flags for saving
  97. // loop through the limits object
  98. for (int i = 0; i < _Index_Total_; i++)
  99. {
  100. // need to create new one
  101. if (m_aLimitsRecord[i].m_bExistAfterEdit)
  102. {
  103. if (!m_aLimitsRecord[i].m_bExistBeforeEdit)
  104. {
  105. CHECK_HR( hr = m_aLimitsRecord[i].m_spLimitsObj->Open(m_spLimitsCont, ACS_CLS_SUBNETLIMITS, m_aLimitsRecord[i].m_strNameToCompareWith, true, true));
  106. m_aLimitsRecord[i].m_bExistBeforeEdit = true;
  107. }
  108. // those need to be saved
  109. if (m_aLimitsRecord[i].m_dwSaveFlags)
  110. {
  111. CHECK_HR ( hr = m_aLimitsRecord[i].m_spLimitsObj->Save( m_aLimitsRecord[i].m_dwSaveFlags ));
  112. }
  113. }
  114. else
  115. {
  116. // those need to be Deleted
  117. if (m_aLimitsRecord[i].m_bExistBeforeEdit)
  118. {
  119. CHECK_HR( hr = m_aLimitsRecord[i].m_spLimitsObj->Delete());
  120. m_aLimitsRecord[i].m_bExistBeforeEdit = false;
  121. }
  122. }
  123. }
  124. L_ERR:
  125. // Call superclass first then set your local flag.
  126. BOOL result = CACSPage::OnApply();
  127. if ( hr != S_OK)
  128. {
  129. ReportError(hr, IDS_FAIL_SAVE_TRAFFIC, NULL);
  130. }
  131. else if(m_bFlowDataChanged)
  132. {
  133. AfxMessageBox(IDS_WRN_POLICY_EFFECTIVE_FROM_NEXT_RSVP);
  134. // Set modified to false since apply should have saved the state.
  135. m_bFlowDataChanged = false;
  136. }
  137. return result;
  138. }
  139. void CPgGeneral::OnCheckEnableacs()
  140. {
  141. // TODO: Add your control notification handler code here
  142. SetModified();
  143. EnableEverything();
  144. m_bFlowDataChanged = TRUE;
  145. }
  146. void CPgGeneral::EnableEverything()
  147. {
  148. UpdateData();
  149. CButton* pButton = (CButton*)GetDlgItem(IDC_CHECK_ENABLEACS);
  150. int nCheck = pButton->GetCheck();
  151. m_listServiceLimit.EnableWindow(nCheck);
  152. m_btnAdd.EnableWindow(nCheck);
  153. m_btnDelete.EnableWindow(nCheck);
  154. m_btnEdit.EnableWindow(nCheck);
  155. if(nCheck)
  156. {
  157. if(m_aAvailableTypes[0] == -1)
  158. {
  159. if(::GetFocus() == m_btnAdd.GetSafeHwnd())
  160. GetDlgItem(IDC_LIST_SERVICELIMIT)->SetFocus();
  161. m_btnAdd.EnableWindow(FALSE);
  162. }
  163. else
  164. m_btnAdd.EnableWindow(TRUE);
  165. if(m_listServiceLimit.GetSelectedCount() == 0)
  166. {
  167. if(::GetFocus() == m_btnDelete.GetSafeHwnd())
  168. GetDlgItem(IDC_LIST_SERVICELIMIT)->SetFocus();
  169. }
  170. m_btnDelete.EnableWindow(m_listServiceLimit.GetSelectedCount() != 0);
  171. if(m_listServiceLimit.GetSelectedCount() == 0)
  172. {
  173. if(::GetFocus() == m_btnEdit.GetSafeHwnd())
  174. GetDlgItem(IDC_LIST_SERVICELIMIT)->SetFocus();
  175. }
  176. m_btnEdit.EnableWindow(m_listServiceLimit.GetSelectedCount() != 0);
  177. }
  178. }
  179. void CPgGeneral::OnChangeEditGenDesc()
  180. {
  181. // TODO: If this is a RICHEDIT control, the control will not
  182. // send this notification unless you override the CACSPage::OnInitDialog()
  183. // function to send the EM_SETEVENTMASK message to the control
  184. // with the ENM_CHANGE flag ORed into the lParam mask.
  185. // TODO: Add your control notification handler code here
  186. SetModified();
  187. }
  188. int SetLimitsObjInListView(CListCtrl& list, CACSSubnetServiceLimits* pLimitsObj, ATTR_FLAG flag) // return the index of the item
  189. {
  190. // try to find the item in the list
  191. LVFINDINFO fi;
  192. ZeroMemory(&fi, sizeof(fi));
  193. fi.flags = LVFI_PARAM;
  194. fi.lParam = (LPARAM)pLimitsObj;
  195. int index = list.FindItem(&fi);
  196. // if not in the list, then add
  197. if (index == -1) // not found
  198. {
  199. CString name;
  200. UINT id = 0;
  201. // find out the name of the policy
  202. switch(pLimitsObj->m_dwServiceType)
  203. {
  204. case ACS_SUBNET_LIMITS_SERVICETYPE_AGGREGATE: id = IDS_AGGREGATEPOLICY; break;
  205. case ACS_SUBNET_LIMITS_SERVICETYPE_GUARANTEEDSERVICE: id= IDS_GPOLICY; break;
  206. case ACS_SUBNET_LIMITS_SERVICETYPE_CONTROLLEDLOAD: id = IDS_CLPOLICY; break;
  207. }
  208. if (id != 0)
  209. name.LoadString(id);
  210. // add the item into the list
  211. index = list.InsertItem(0, (LPTSTR)(LPCTSTR)name);
  212. if (index == -1)
  213. return index;
  214. // set the key
  215. list.SetItemData(index, (LPARAM)pLimitsObj);
  216. // set text for the 1st column
  217. list.SetItemText(index, 0, (LPTSTR)(LPCTSTR)name);
  218. }
  219. CString str;
  220. // data rate
  221. if (pLimitsObj->GetFlags(flag, ACS_SSLAF_MAX_PF_TOKENRATE) != 0)
  222. str.Format(_T("%d"), TOKBS(pLimitsObj->m_ddMAX_PF_TOKENRATE.LowPart));
  223. else
  224. str.LoadString(IDS_TEXT_UNLIMITED);
  225. list.SetItemText(index, 1, (LPTSTR)(LPCTSTR)str);
  226. // peak rate
  227. if (pLimitsObj->GetFlags(flag, ACS_SSLAF_MAX_PF_PEAKBW) != 0)
  228. str.Format(_T("%d"), TOKBS(pLimitsObj->m_ddMAX_PF_PEAKBW.LowPart));
  229. else
  230. str.LoadString(IDS_TEXT_UNLIMITED);
  231. list.SetItemText(index, 2, (LPTSTR)(LPCTSTR)str);
  232. // total data rate
  233. if (pLimitsObj->GetFlags(flag, ACS_SSLAF_ALLOCABLERSVPBW) != 0)
  234. str.Format(_T("%d"), TOKBS(pLimitsObj->m_ddALLOCABLERSVPBW.LowPart));
  235. else
  236. str.LoadString(IDS_TEXT_UNLIMITED);
  237. list.SetItemText(index, 3, (LPTSTR)(LPCTSTR)str);
  238. // total peak rate
  239. if (pLimitsObj->GetFlags(flag, ACS_SSLAF_MAXPEAKBW) != 0)
  240. str.Format(_T("%d"), TOKBS(pLimitsObj->m_ddMAXPEAKBW.LowPart));
  241. else
  242. str.LoadString(IDS_TEXT_UNLIMITED);
  243. list.SetItemText(index, 4, (LPTSTR)(LPCTSTR)str);
  244. list.SetItemState(index, LVIS_SELECTED|LVIS_FOCUSED, LVIS_SELECTED|LVIS_FOCUSED);
  245. list.SetFocus();
  246. return index;
  247. }
  248. void CPgGeneral::CalculateAvailableTypes()
  249. {
  250. // prepare available type list
  251. if (m_aLimitsRecord[Index_Aggregate].m_bExistAfterEdit)
  252. m_aAvailableTypes[0] = -1; // end of the list
  253. else
  254. {
  255. int index = 0;
  256. if (!m_aLimitsRecord[Index_Guaranteed].m_bExistAfterEdit)
  257. {
  258. m_aAvailableTypes[index ++] = ACS_SUBNET_LIMITS_SERVICETYPE_GUARANTEEDSERVICE;
  259. }
  260. if (!m_aLimitsRecord[Index_ControlledLoad].m_bExistAfterEdit)
  261. {
  262. m_aAvailableTypes[index++] = ACS_SUBNET_LIMITS_SERVICETYPE_CONTROLLEDLOAD;
  263. }
  264. if (!m_aLimitsRecord[Index_ControlledLoad].m_bExistAfterEdit && !m_aLimitsRecord[Index_Guaranteed].m_bExistAfterEdit)
  265. {
  266. m_aAvailableTypes[index++] = ACS_SUBNET_LIMITS_SERVICETYPE_AGGREGATE;
  267. }
  268. m_aAvailableTypes[index] = -1; // end of the list
  269. }
  270. }
  271. BOOL CPgGeneral::OnInitDialog()
  272. {
  273. HRESULT hr = S_OK;
  274. // Enable ACS
  275. if(m_spConfig->GetFlags(ATTR_FLAG_LOAD, ACS_SCAF_ENABLEACSSERVICE))
  276. m_bEnableACS = (m_spConfig->m_bENABLEACSSERVICE != 0);
  277. // description
  278. if(m_spConfig->GetFlags(ATTR_FLAG_LOAD, ACS_SCAF_DESCRIPTION))
  279. m_strDesc = m_spConfig->m_strDESCRIPTION;
  280. CACSPage::OnInitDialog();
  281. // initialize the list view
  282. ListView_SetExtendedListViewStyle(m_listServiceLimit.m_hWnd, LVS_EX_FULLROWSELECT);
  283. // Insert all the columns
  284. CString sName;
  285. CString sDataRate;
  286. CString sPeakRate;
  287. CString sTotalDataRate;
  288. CString sTotalPeakRate;
  289. /*
  290. IDS_COL_SUBLIMITS_NAME "Name"
  291. IDS_COL_SUBLIMITS_DATARATE "Data Rate"
  292. IDS_COL_SUBLIMITS_PEAKRATE "Peak Rate"
  293. IDS_COL_SUBLIMITS_TOTALDATARATE "Tot.Data Rate"
  294. IDS_COL_SUBLIMITS_TOTALPEAKRATE "Tot.Peak"
  295. */
  296. try{
  297. if( sName.LoadString(IDS_COL_SUBLIMITS_NAME)
  298. && sDataRate.LoadString(IDS_COL_SUBLIMITS_DATARATE)
  299. && sPeakRate.LoadString(IDS_COL_SUBLIMITS_PEAKRATE)
  300. && sTotalDataRate.LoadString(IDS_COL_SUBLIMITS_TOTALDATARATE)
  301. && sTotalPeakRate.LoadString(IDS_COL_SUBLIMITS_TOTALPEAKRATE))
  302. {
  303. RECT rect;
  304. m_listServiceLimit.GetClientRect(&rect);
  305. m_listServiceLimit.InsertColumn(1, sName, LVCFMT_LEFT, (rect.right - rect.left)/5 - 10);
  306. m_listServiceLimit.InsertColumn(2, sDataRate, LVCFMT_CENTER, (rect.right - rect.left)/5 + 1) ;
  307. m_listServiceLimit.InsertColumn(3, sPeakRate, LVCFMT_CENTER, (rect.right - rect.left)/5 + 2);
  308. m_listServiceLimit.InsertColumn(4, sTotalDataRate, LVCFMT_CENTER, (rect.right - rect.left)/5 + 23);
  309. m_listServiceLimit.InsertColumn(5, sTotalPeakRate, LVCFMT_CENTER, (rect.right - rect.left)/5);
  310. }
  311. }
  312. catch(CMemoryException&)
  313. {
  314. TRACEAfxMessageBox(256);
  315. }
  316. // Insert all the items
  317. // enumerat the container to list all the policy in place
  318. std::list<CACSSubnetServiceLimits*> ObjList;
  319. std::list<CACSSubnetServiceLimits*>::iterator it;
  320. ASSERT(m_spLimitsCont);
  321. hr = m_spLimitsCont->ListChildren(ObjList, ACS_CLS_SUBNETLIMITS);
  322. if(hr == ERROR_NO_SUCH_OBJECT) // object is not found in DS, it's fine, since, some subnet with no ACS info
  323. {
  324. hr = S_OK;
  325. return TRUE;
  326. }
  327. if (hr != S_OK)
  328. return TRUE;
  329. // prepare the list
  330. for( it = ObjList.begin(); it != ObjList.end(); it++)
  331. {
  332. CComPtr<CACSSubnetServiceLimits> spObj;
  333. spObj = *it; // this make a release call to the interface previously stored
  334. for(int i = 0; i < _Index_Total_; i++)
  335. {
  336. // put it in the list
  337. if(m_aLimitsRecord[i].m_strNameToCompareWith.CompareNoCase(spObj->GetName()) == 0)
  338. {
  339. m_aLimitsRecord[i].m_bExistBeforeEdit = true;
  340. m_aLimitsRecord[i].m_bExistAfterEdit = true;
  341. m_aLimitsRecord[i].m_spLimitsObj = spObj;
  342. // enforce the service type matches the name
  343. if(m_aLimitsRecord[i].m_nServiceType != spObj->m_dwServiceType)
  344. {
  345. // some processing needed
  346. spObj->m_dwServiceType = m_aLimitsRecord[i].m_nServiceType;
  347. }
  348. spObj->Reopen();
  349. }
  350. }
  351. }
  352. // populate the list
  353. for(int i = 0; i < _Index_Total_; i++)
  354. {
  355. if ( m_aLimitsRecord[i].m_bExistAfterEdit )
  356. {
  357. SetLimitsObjInListView(m_listServiceLimit, m_aLimitsRecord[i].m_spLimitsObj, ATTR_FLAG_LOAD);
  358. }
  359. }
  360. m_listServiceLimit.SetItemCount(256);
  361. CalculateAvailableTypes();
  362. EnableEverything();
  363. // TODO: Add extra initialization here
  364. return TRUE; // return TRUE unless you set the focus to a control
  365. // EXCEPTION: OCX Property Pages should return FALSE
  366. }
  367. void CPgGeneral::GetLimitsFromLimitsDlg(CPgSubLimit& dlg)
  368. {
  369. // TODO: Add your control notification handler code here
  370. //
  371. // start up the LIMIT dialog
  372. // get the data out and put into the
  373. CComPtr<CACSSubnetServiceLimits> spLimits;
  374. for(int i = 0; i < _Index_Total_; i++)
  375. {
  376. if (m_aLimitsRecord[i].m_nServiceType == dlg.m_nServiceType)
  377. {
  378. if ( !m_aLimitsRecord[i].m_spLimitsObj ) // not exist
  379. {
  380. CComObject<CACSSubnetServiceLimits>* pObj = NULL;
  381. CComObject<CACSSubnetServiceLimits>::CreateInstance(&pObj); // with 0 reference count
  382. m_aLimitsRecord[i].m_spLimitsObj = pObj;
  383. }
  384. spLimits = m_aLimitsRecord[i].m_spLimitsObj;
  385. m_aLimitsRecord[i].m_bExistAfterEdit = true;
  386. m_aLimitsRecord[i].m_dwSaveFlags = ( ACS_SSLAF_ALLOCABLERSVPBW
  387. | ACS_SSLAF_MAXPEAKBW
  388. | ACS_SSLAF_MAX_PF_TOKENRATE
  389. | ACS_SSLAF_MAX_PF_PEAKBW
  390. | ACS_SSLAF_SERVICETYPE );
  391. break;
  392. }
  393. }
  394. if (spLimits != NULL)
  395. {
  396. // copy the data over from dlg
  397. spLimits->m_dwServiceType = dlg.m_nServiceType;
  398. spLimits->SetFlags(ATTR_FLAG_SAVE, ACS_SSLAF_SERVICETYPE, true);
  399. // data rate
  400. if(dlg.m_nDataRateChoice)
  401. {
  402. spLimits->SetFlags(ATTR_FLAG_SAVE, ACS_SSLAF_MAX_PF_TOKENRATE, true);
  403. spLimits->m_ddMAX_PF_TOKENRATE.LowPart = FROMKBS(dlg.m_uDataRate); // in bps --> from kbps
  404. spLimits->m_ddMAX_PF_TOKENRATE.HighPart = 0;
  405. }
  406. else
  407. spLimits->SetFlags(ATTR_FLAG_SAVE, ACS_SSLAF_MAX_PF_TOKENRATE, false);
  408. // peak rate
  409. if(dlg.m_nPeakRateChoice)
  410. {
  411. spLimits->SetFlags(ATTR_FLAG_SAVE, ACS_SSLAF_MAX_PF_PEAKBW, true);
  412. spLimits->m_ddMAX_PF_PEAKBW.LowPart = FROMKBS(dlg.m_uPeakRate);
  413. spLimits->m_ddMAX_PF_PEAKBW.HighPart = 0;
  414. }
  415. else
  416. spLimits->SetFlags(ATTR_FLAG_SAVE, ACS_SSLAF_MAX_PF_PEAKBW, false);
  417. // total rate
  418. if(dlg.m_nTTDataRateChoice)
  419. {
  420. spLimits->SetFlags(ATTR_FLAG_SAVE, ACS_SSLAF_ALLOCABLERSVPBW, true);
  421. spLimits->m_ddALLOCABLERSVPBW.LowPart = FROMKBS(dlg.m_uTTDataRate);
  422. spLimits->m_ddALLOCABLERSVPBW.HighPart = 0;
  423. }
  424. else
  425. spLimits->SetFlags(ATTR_FLAG_SAVE, ACS_SSLAF_ALLOCABLERSVPBW, false);
  426. // total peak rate
  427. if(dlg.m_nTTPeakDataRateChoice)
  428. {
  429. spLimits->SetFlags(ATTR_FLAG_SAVE, ACS_SSLAF_MAXPEAKBW, true);
  430. spLimits->m_ddMAXPEAKBW.LowPart = FROMKBS(dlg.m_uTTPeakRate);
  431. spLimits->m_ddMAXPEAKBW.HighPart = 0;
  432. }
  433. else
  434. spLimits->SetFlags(ATTR_FLAG_SAVE, ACS_SSLAF_MAXPEAKBW, false);
  435. m_bFlowDataChanged = TRUE;
  436. SetLimitsObjInListView(m_listServiceLimit, (CACSSubnetServiceLimits*)spLimits, ATTR_FLAG_SAVE);
  437. CalculateAvailableTypes();
  438. EnableEverything();
  439. SetModified();
  440. }
  441. }
  442. void CPgGeneral::OnButtonaddservicelimit()
  443. {
  444. // TODO: Add your control notification handler code here
  445. //
  446. // start up the LIMIT dialog
  447. CPgSubLimit dlg(&m_aLimitsRecord[0], &m_aAvailableTypes[0], this);
  448. if (IDOK == dlg.DoModal())
  449. {
  450. GetLimitsFromLimitsDlg(dlg);
  451. }
  452. }
  453. int GetListViewSelected(CListCtrl& list) // single selection only
  454. {
  455. int count = list.GetItemCount();
  456. int index = -1;
  457. while(count--)
  458. {
  459. if(list.GetItemState(count, LVIS_SELECTED))
  460. {
  461. index = count;
  462. break;
  463. }
  464. }
  465. return index;
  466. }
  467. void CPgGeneral::OnButtondeleteservicelimit()
  468. {
  469. LPARAM param;
  470. int iSelected = GetListViewSelected(m_listServiceLimit);
  471. if (iSelected != -1)
  472. {
  473. param = m_listServiceLimit.GetItemData(iSelected);
  474. for(int i = 0; i < _Index_Total_; i++)
  475. {
  476. if ((CACSSubnetServiceLimits*)(m_aLimitsRecord[i].m_spLimitsObj) == (CACSSubnetServiceLimits*)param)
  477. {
  478. m_aLimitsRecord[i].m_bExistAfterEdit = false;
  479. break;
  480. }
  481. }
  482. m_listServiceLimit.DeleteItem(iSelected);
  483. m_bFlowDataChanged = TRUE;
  484. CalculateAvailableTypes();
  485. EnableEverything();
  486. SetModified();
  487. }
  488. }
  489. void CPgGeneral::SetLimitsToLimitsDlg(CPgSubLimit& dlg, CACSSubnetServiceLimits* pLimits)
  490. {
  491. if(NULL == pLimits) return;
  492. ATTR_FLAG flag = ATTR_FLAG_LOAD;
  493. for(int i = 0; i < _Index_Total_; i++)
  494. {
  495. if ((CACSSubnetServiceLimits*)(m_aLimitsRecord[i].m_spLimitsObj) == pLimits)
  496. {
  497. if (m_aLimitsRecord[i].m_dwSaveFlags != 0)
  498. flag = ATTR_FLAG_SAVE;
  499. break;
  500. }
  501. }
  502. // type
  503. dlg.m_nServiceType = pLimits->m_dwServiceType;
  504. // data rate
  505. if(pLimits->GetFlags(flag, ACS_SSLAF_MAX_PF_TOKENRATE))
  506. {
  507. dlg.m_nDataRateChoice = 1;
  508. dlg.m_uDataRate = TOKBS(pLimits->m_ddMAX_PF_TOKENRATE.LowPart);
  509. }
  510. else
  511. dlg.m_nDataRateChoice = 0;
  512. // peak rate
  513. if(pLimits->GetFlags(flag, ACS_SSLAF_MAX_PF_PEAKBW))
  514. {
  515. dlg.m_nPeakRateChoice = 1;
  516. dlg.m_uPeakRate = TOKBS(pLimits->m_ddMAX_PF_PEAKBW.LowPart);
  517. }
  518. else
  519. dlg.m_nPeakRateChoice = 0;
  520. // total rate
  521. if(pLimits->GetFlags(flag, ACS_SSLAF_ALLOCABLERSVPBW))
  522. {
  523. dlg.m_nTTDataRateChoice = 1;
  524. dlg.m_uTTDataRate = TOKBS(pLimits->m_ddALLOCABLERSVPBW.LowPart);
  525. }
  526. else
  527. dlg.m_nTTDataRateChoice = 0;
  528. // total peak rate
  529. if(pLimits->GetFlags(flag, ACS_SSLAF_MAXPEAKBW))
  530. {
  531. dlg.m_nTTPeakDataRateChoice = 1;
  532. dlg.m_uTTPeakRate = TOKBS(pLimits->m_ddMAXPEAKBW.LowPart);
  533. }
  534. else
  535. dlg.m_nTTPeakDataRateChoice = 0;
  536. }
  537. void CPgGeneral::OnButtoneditservicelimit()
  538. {
  539. // TODO: Add your control notification handler code here
  540. int iSelected = GetListViewSelected(m_listServiceLimit);
  541. CComPtr<CACSSubnetServiceLimits> spLimits;
  542. if (iSelected != -1)
  543. {
  544. int types[2];
  545. spLimits = (CACSSubnetServiceLimits*)m_listServiceLimit.GetItemData(iSelected);
  546. types[0] = spLimits->m_dwServiceType;
  547. types[1] = -1; // end of list
  548. CPgSubLimit dlg(&m_aLimitsRecord[0], &types[0], this);
  549. SetLimitsToLimitsDlg(dlg, (CACSSubnetServiceLimits*)spLimits);
  550. if (IDOK == dlg.DoModal())
  551. {
  552. GetLimitsFromLimitsDlg(dlg);
  553. }
  554. }
  555. }
  556. void CPgGeneral::OnItemchangedListServicelimit(NMHDR* pNMHDR, LRESULT* pResult)
  557. {
  558. SetModified();
  559. EnableEverything();
  560. *pResult = 0;
  561. }
  562. void CPgGeneral::OnDblclkListServicelimit(NMHDR* pNMHDR, LRESULT* pResult)
  563. {
  564. // TODO: Add your control notification handler code here
  565. OnButtoneditservicelimit();
  566. *pResult = 0;
  567. }