home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pc3270sa.zip / apps / winaping / goview.cpp < prev    next >
Text File  |  2002-02-28  |  9KB  |  287 lines

  1. // goview.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "winaping.h"
  6. #include "constdef.h"
  7. #include "goview.h"
  8.  
  9. #include "winapdoc.h"
  10.  
  11. #ifdef _DEBUG
  12. #undef THIS_FILE
  13. static char BASED_CODE THIS_FILE[] = __FILE__;
  14. #endif
  15.  
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CGoView
  18.  
  19. IMPLEMENT_DYNCREATE(CGoView, CFormView)
  20.  
  21. CGoView::CGoView()
  22.         : CFormView(CGoView::IDD)
  23. {
  24.         //{{AFX_DATA_INIT(CGoView)
  25.         m_partner = _T("");
  26.         m_rate2 = _T("");
  27.         m_rate1 = _T("");
  28.         m_curriter = _T("");
  29.         m_alloctime = 0;
  30.         m_avgtime = 0;
  31.         m_confirmtime = 0;
  32.         m_maxtime = 0;
  33.         m_mintime = 0;
  34.         m_totbyte = _T("");
  35.         m_tottime = _T("");
  36.         //}}AFX_DATA_INIT
  37. }
  38.  
  39. CGoView::~CGoView()
  40. {
  41. }
  42.  
  43. void CGoView::DoDataExchange(CDataExchange* pDX)
  44. {
  45.         CFormView::DoDataExchange(pDX);
  46.         //{{AFX_DATA_MAP(CGoView)
  47.         DDX_Control(pDX, IDC_MSGAREA, m_msgArea);
  48.         DDX_Text(pDX, IDC_PARTNER, m_partner);
  49.         DDX_Text(pDX, IDC_RATE2, m_rate2);
  50.         DDX_Text(pDX, IDC_RATE1, m_rate1);
  51.         DDX_Text(pDX, IDC_CURRITER, m_curriter);
  52.         DDX_Text(pDX, IDC_ALLOCTIME, m_alloctime);
  53.         DDX_Text(pDX, IDC_AVGTIME, m_avgtime);
  54.         DDX_Text(pDX, IDC_CONFIRMTIME, m_confirmtime);
  55.         DDX_Text(pDX, IDC_MAXTIME, m_maxtime);
  56.         DDX_Text(pDX, IDC_MINTIME, m_mintime);
  57.         DDX_Text(pDX, IDC_TOTBYTE, m_totbyte);
  58.         DDX_Text(pDX, IDC_TOTTIME, m_tottime);
  59.         //}}AFX_DATA_MAP
  60. }
  61.  
  62.  
  63. BEGIN_MESSAGE_MAP(CGoView, CFormView)
  64.         //{{AFX_MSG_MAP(CGoView)
  65.                 // NOTE - the ClassWizard will add and remove mapping macros here.
  66.         ON_MESSAGE(WM_CPICCALL_ERR, OnCpiccallErr)    // user msg
  67.         ON_MESSAGE(WM_REFRESH,      OnRefresh)        // user msg
  68.         //}}AFX_MSG_MAP
  69. END_MESSAGE_MAP()
  70.  
  71.  
  72.  
  73. /////////////////////////////////////////////////////////////////////////////
  74. // CGoView diagnostics
  75.  
  76. #ifdef _DEBUG
  77. void CGoView::AssertValid() const
  78. {
  79. //      CFormView::AssertValid();          // ?????? FAILED HERE ???????????
  80. }
  81.  
  82. void CGoView::Dump(CDumpContext& dc) const
  83. {
  84.         CFormView::Dump(dc);
  85. }
  86. #endif //_DEBUG
  87.  
  88. /////////////////////////////////////////////////////////////////////////////
  89. // CGoView message handlers
  90.  
  91. void CGoView::OnInitialUpdate()
  92. {
  93.         // measure the font in the dialog
  94.         CClientDC       dc(this);
  95.         dc.GetTextMetrics(&tm);
  96.  
  97.         CFormView::OnInitialUpdate();
  98. }
  99.  
  100. //-----------------------------------------
  101. // This is to add a string to messages area
  102. void CGoView::RefreshMsg(CString str)
  103. {
  104. //  ((CListBox*) GetDlgItem(IDC_MSGAREA))->AddString(str);    ypc
  105.   CSize strExtent = m_msgArea.GetDC()->GetTextExtent(str);  //ypc
  106.   if (strExtent.cx > m_msgArea.GetHorizontalExtent())       //ypc
  107.           m_msgArea.SetHorizontalExtent(strExtent.cx);      //ypc
  108.   m_msgArea.AddString(str);                                 //ypc
  109. }
  110.  
  111. //-----------------------------------------------
  112. // This is to reset the screen and local counters
  113. void CGoView::Refresh0()
  114. {
  115.   CWinapingDoc* pDoc  = (CWinapingDoc*) GetDocument();
  116.   CListCtrl*    pList = (CListCtrl*) GetDlgItem(IDC_LISTVIEW);
  117.   verify_failed_msg_issued = FALSE;
  118.   total_byte_per_iter = (pDoc->pingInfo.packetSize) *
  119.                         (pDoc->pingInfo.consecutivePackets);
  120.   if (pDoc->pingInfo.echo) total_byte_per_iter *= 2;
  121.   grand_total_byte = 0;
  122.   grand_total_time = 0;
  123.  
  124.   //---------------------------------------------
  125.   // Clear local m_... variables for upper screen
  126.         m_alloctime   = 0;
  127.         m_avgtime     = 0;
  128.         m_confirmtime = 0;
  129.         m_curriter    = _T("");
  130.         m_maxtime     = 0;
  131.         m_mintime     = 0;
  132.         m_partner     = _T("");
  133.         m_rate2       = _T("");
  134.         m_rate1       = _T("");
  135.         m_totbyte     = _T("");
  136.         m_tottime     = _T("");
  137.  
  138.   //-------------------------------------------------------------
  139.   // Delete all items & cloumns in list view then rebuild columns
  140.   pList->DeleteAllItems();
  141.   BOOL rc;
  142.   do { rc = pList->DeleteColumn(0); }
  143.   while (rc != 0);
  144.  
  145.   int colnum = 0;
  146.   LV_COLUMN  lvc;
  147.   lvc.mask = LVCF_FMT|LVCF_SUBITEM|LVCF_TEXT|LVCF_WIDTH;
  148.   lvc.iSubItem = 0;
  149.  
  150.   lvc.pszText    = "Iteration";
  151.   lvc.fmt        = LVCFMT_CENTER;     // seems not working
  152.   lvc.cx         = (lstrlen(lvc.pszText)-3)*tm.tmAveCharWidth;
  153.   lvc.cchTextMax = lstrlen(lvc.pszText);
  154.   rc= pList->InsertColumn(colnum++, &lvc);
  155.  
  156.   lvc.pszText    = "Duration";
  157.   lvc.fmt        = LVCFMT_RIGHT;
  158.   lvc.cx         = (lstrlen(lvc.pszText)-1)*tm.tmAveCharWidth;
  159.   lvc.cchTextMax = lstrlen(lvc.pszText);
  160.   rc= pList->InsertColumn(colnum++, &lvc);
  161.  
  162.   if (pDoc->pingInfo.echo) lvc.pszText = "Data S/R";
  163.   else              lvc.pszText = "Data Sent";
  164.   lvc.fmt        = LVCFMT_CENTER;
  165.   lvc.cx         = (lstrlen(lvc.pszText)+1)*tm.tmAveCharWidth;
  166.   lvc.cchTextMax = lstrlen(lvc.pszText);
  167.   rc= pList->InsertColumn(colnum++, &lvc);
  168.  
  169.   lvc.pszText = "Rate (KB/s)";
  170.   lvc.fmt  = LVCFMT_RIGHT;
  171.   lvc.cx = lstrlen(lvc.pszText)*tm.tmAveCharWidth;
  172.   lvc.cchTextMax = lstrlen(lvc.pszText);
  173.   rc= pList->InsertColumn(colnum++, &lvc);
  174.  
  175.   lvc.pszText = "Rate (Mb/s)";
  176.   lvc.fmt  = LVCFMT_RIGHT;
  177.   lvc.cx = lstrlen(lvc.pszText)*tm.tmAveCharWidth;
  178.   lvc.cchTextMax = lstrlen(lvc.pszText);
  179.   rc= pList->InsertColumn(colnum++, &lvc);
  180.  
  181.   if (pDoc->pingInfo.verify) {
  182.     lvc.pszText    = "Verify OK";
  183.     lvc.cx         = (lstrlen(lvc.pszText)-2)*tm.tmAveCharWidth;
  184.     lvc.fmt        = LVCFMT_LEFT;
  185.     lvc.cchTextMax = lstrlen(lvc.pszText);
  186.     rc= pList->InsertColumn(colnum++, &lvc);
  187.     }
  188.  
  189.   //-----------------------
  190.   // Clear the message area
  191.   // ((CListBox*) GetDlgItem(IDC_MSGAREA))->ResetContent();   ypc
  192.   m_msgArea.ResetContent();                                 //ypc
  193.   m_msgArea.SetHorizontalExtent(0);                         //ypc
  194.  
  195.   UpdateData(FALSE);     // local m_ variables to dlg window
  196. }
  197.  
  198. LONG CGoView::OnRefresh(UINT currnum, LONG currtime) {
  199.   CWinapingDoc* pDoc = (CWinapingDoc*) GetDocument();
  200.   BOOL verifyok = TRUE;
  201.  
  202.   if (currtime < 0) {
  203.     verifyok = FALSE;
  204.     currtime = -currtime;
  205.     }
  206.   if (currnum == 0) {               // no iteration started yet
  207.     m_alloctime   = pDoc->alloctime;
  208.     m_confirmtime = pDoc->confirmtime;
  209.     m_partner     = pDoc->partner;
  210.     }
  211.   else {                                  // for each iteration done
  212.     CListCtrl*    pList = (CListCtrl*) GetDlgItem(IDC_LISTVIEW);
  213.     double rate;
  214.  
  215.     //-------------------------
  216.     // Recalculate summary info
  217.     m_curriter.Format(_T("%d/%d"), currnum, pDoc->pingInfo.iterations);
  218.     grand_total_byte += total_byte_per_iter;
  219.     m_totbyte.Format(_T("%.0f"), grand_total_byte);
  220.     grand_total_time += currtime;
  221.     m_tottime.Format(_T("%.0f"), grand_total_time);
  222.     if (m_maxtime < (DWORD) currtime)
  223.       m_maxtime = (DWORD) currtime;
  224.     if ((currnum == 1) | (m_mintime > (DWORD) currtime))
  225.       m_mintime = (DWORD) currtime;
  226.     m_avgtime = (DWORD) (grand_total_time/currnum);
  227.     if (grand_total_time == 0) rate = 0;
  228.     else rate = (grand_total_byte*1000)/(grand_total_time*1024);
  229.     m_rate1.Format(_T("%8.4f"), rate);
  230.     m_rate2.Format(_T("%8.4f"), (rate*8)/1000);
  231.  
  232.     //------------------------------
  233.     // Display the iteration details
  234.     // A small flaw here, but OK
  235.     // Since currnum always > 0, item 0 never get inserted
  236.     int     i;
  237.     CString str;
  238.     LV_ITEM lvi;
  239.  
  240.     lvi.mask     = LVIF_TEXT | LVIF_PARAM;
  241.     lvi.iItem    = 0;
  242.     lvi.iSubItem = 0;
  243.     str.Format(_T("%6d"), currnum);
  244.     lvi.pszText      = (LPSTR) (LPCSTR) str;
  245.     pList->InsertItem(&lvi);
  246.  
  247.     i = 1;
  248.     str.Format(_T("%d"), currtime);
  249.     pList->SetItemText(0, i++, (LPSTR) (LPCSTR) str);
  250.  
  251.     str.Format(_T("%d"), total_byte_per_iter);
  252.     pList->SetItemText(0, i++, (LPSTR) (LPCSTR) str);
  253.  
  254.     if (currtime == 0) rate = 0;
  255.     else rate = ((double)total_byte_per_iter*1000)/
  256.                 ((double)currtime*1024);
  257.     str.Format(_T("%8.4f"), rate);
  258.     pList->SetItemText(0, i++, (LPSTR) (LPCSTR) str);
  259.  
  260.     rate = (rate*8)/1000;
  261.     str.Format(_T("%8.4f"), rate);
  262.     pList->SetItemText(0, i++, (LPSTR) (LPCSTR) str);
  263.  
  264.     if (pDoc->pingInfo.verify) {
  265.       if (!verifyok) str=_T("Failed");
  266.       else                     str=_T("");
  267.       pList->SetItemText(0, i++, (LPSTR) (LPCSTR) str);
  268.       if (!verifyok && !verify_failed_msg_issued) {
  269.         verify_failed_msg_issued = TRUE;
  270.         str.Format(_T("First verification failed at iteration %d"), currnum);
  271.         RefreshMsg(str);
  272.         }
  273.       }
  274.     }
  275.  
  276.   UpdateData(FALSE);     // local m_ variables to dlg window
  277.  
  278.   return 0;
  279. }
  280.  
  281. LONG CGoView::OnCpiccallErr(UINT, LONG) {
  282.   CWinapingDoc* pDoc  = (CWinapingDoc*) GetDocument();
  283.   CString str = pDoc->cmcall + _T(" failed with rc: ") + pDoc->cmrcmsg;
  284.   RefreshMsg(str);
  285.   return 0;
  286. }
  287.