home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 October / CHIP Turkiye Ekim 2000.iso / prog / naps / 04 / setup.exe / Gnucleus / ViewNode.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-24  |  7.7 KB  |  313 lines

  1. /********************************************************************************
  2.  
  3.     Gnucleus - A node application for the Gnutella network
  4.     Copyright (C) 2000 John Marshall
  5.  
  6.     This program is free software; you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License as published by
  8.     the Free Software Foundation; either version 2 of the License.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18.  
  19.     For support, questions, comments, etc...
  20.     E-Mail: 
  21.         swabby@c0re.net
  22.     
  23.     Address:
  24.         21 Cadogan Way
  25.         Nashua, NH, USA 03062
  26.  
  27. ********************************************************************************/
  28.  
  29. // ViewNode.cpp : implementation file
  30. //
  31.  
  32. #include "stdafx.h"
  33. #include "Gnucleus.h"
  34.  
  35. #include "GnucleusDoc.h"
  36. #include "ViewSearch.h"
  37. #include "ViewNode.h"
  38.  
  39. #include "GnuTransfer.h"
  40. #include "GnuHash.h"
  41. #include "GnuSock.h"
  42. #include "GnuControl.h"
  43.  
  44.  
  45. #ifdef _DEBUG
  46. #define new DEBUG_NEW
  47. #undef THIS_FILE
  48. static char THIS_FILE[] = __FILE__;
  49. #endif
  50.  
  51. /////////////////////////////////////////////////////////////////////////////
  52. // CViewNode
  53.  
  54. IMPLEMENT_DYNCREATE(CViewNode, CFormView)
  55.  
  56. CViewNode::CViewNode()
  57.     : CFormView(CViewNode::IDD)
  58. {
  59.     //{{AFX_DATA_INIT(CViewNode)
  60.     m_strNodeBadStat = _T("");
  61.     m_strNodeRecivedStat = _T("");
  62.     m_strNodeSentStat = _T("");
  63.     //}}AFX_DATA_INIT
  64. }
  65.  
  66. CViewNode::~CViewNode()
  67. {
  68. }
  69.  
  70. void CViewNode::DoDataExchange(CDataExchange* pDX)
  71. {
  72.     CFormView::DoDataExchange(pDX);
  73.     //{{AFX_DATA_MAP(CViewNode)
  74.     DDX_Control(pDX, IDC_CHK_QUERYHITS, m_chkQueryHits);
  75.     DDX_Control(pDX, IDC_CHK_PUSHES, m_chkPushes);
  76.     DDX_Control(pDX, IDC_CHK_UNKNOWNS, m_chkUnknowns);
  77.     DDX_Control(pDX, IDC_CHK_TTL, m_chkTTL);
  78.     DDX_Control(pDX, IDC_CHK_QUERIES, m_chkQueries);
  79.     DDX_Control(pDX, IDC_CHK_PONGS, m_chkPongs);
  80.     DDX_Control(pDX, IDC_CHK_DROPPED, m_chkDropped);
  81.     DDX_Control(pDX, IDC_CHK_GUID, m_chkGUID);
  82.     DDX_Control(pDX, IDC_CHK_HOPS, m_chkHops);
  83.     DDX_Control(pDX, IDC_CHK_PAYLOAD, m_chkPayload);
  84.     DDX_Control(pDX, IDC_CHK_PINGS, m_chkPings);
  85.     DDX_Control(pDX, IDC_EDT_LOG, m_ebLog);
  86.     DDX_Text(pDX, IDC_VIEW_NODE_BAD_STAT, m_strNodeBadStat);
  87.     DDX_Text(pDX, IDC_VIEW_NODE_RECIVED_STAT, m_strNodeRecivedStat);
  88.     DDX_Text(pDX, IDC_VIEW_NODE_SENT_STAT, m_strNodeSentStat);
  89.     //}}AFX_DATA_MAP
  90. }
  91.  
  92.  
  93. BEGIN_MESSAGE_MAP(CViewNode, CFormView)
  94.     //{{AFX_MSG_MAP(CViewNode)
  95.     ON_WM_SIZE()
  96.     ON_WM_TIMER()
  97.     ON_WM_CLOSE()
  98.     ON_BN_CLICKED(IDC_CHK_PINGS, OnChkPings)
  99.     ON_BN_CLICKED(IDC_CHK_PONGS, OnChkPongs)
  100.     ON_BN_CLICKED(IDC_CHK_QUERIES, OnChkQueries)
  101.     ON_BN_CLICKED(IDC_CHK_QUERYHITS, OnChkQueryhits)
  102.     ON_BN_CLICKED(IDC_CHK_UNKNOWNS, OnChkUnknowns)
  103.     ON_BN_CLICKED(IDC_CHK_GUID, OnChkGuid)
  104.     ON_BN_CLICKED(IDC_CHK_HOPS, OnChkHops)
  105.     ON_BN_CLICKED(IDC_CHK_TTL, OnChkTtl)
  106.     ON_BN_CLICKED(IDC_CHK_PAYLOAD, OnChkPayload)
  107.     ON_BN_CLICKED(IDC_CHK_DROPPED, OnChkDropped)
  108.     ON_BN_CLICKED(IDC_CHK_PUSHES, OnChkPushes)
  109.     ON_BN_CLICKED(IDC_BUTTON_FLUSH, OnButtonFlush)
  110.     //}}AFX_MSG_MAP
  111. END_MESSAGE_MAP()
  112.  
  113. /////////////////////////////////////////////////////////////////////////////
  114. // CViewNode diagnostics
  115.  
  116. #ifdef _DEBUG
  117. void CViewNode::AssertValid() const
  118. {
  119.     CFormView::AssertValid();
  120. }
  121.  
  122. void CViewNode::Dump(CDumpContext& dc) const
  123. {
  124.     CFormView::Dump(dc);
  125. }
  126. #endif //_DEBUG
  127.  
  128. /////////////////////////////////////////////////////////////////////////////
  129. // CViewNode message handlers
  130.  
  131. void CViewNode::OnInitialUpdate() 
  132. {
  133.     CFormView::OnInitialUpdate();
  134.     
  135.     // Get node address and port from the title
  136.     CString Title;
  137.     GetParentFrame()->GetWindowText(Title);
  138.  
  139.     Title.Delete(0, 5);
  140.     HostPort = Title;
  141.  
  142.     Node = ((CGnucleusDoc *) GetDocument())->GnuComm->GetNode(HostPort);
  143.     
  144.     if(Node != NULL)
  145.         Node->Log = "";
  146.  
  147.     // Set the time to update the log
  148.     UpdateTimer = SetTimer(1, 500, 0);    
  149.  
  150.     // Resize the window so all the controls adjust properly
  151.     CRect rect;
  152.  
  153.     GetParentFrame()->GetClientRect(&rect);
  154.     OnSize(SIZE_RESTORED, rect.right - 4, rect.bottom - 4);
  155. }
  156.  
  157. void CViewNode::OnSize(UINT nType, int cx, int cy) 
  158. {
  159.     if(m_ebLog.m_hWnd != NULL)
  160.     {
  161.         int top, left;
  162.  
  163.         LPRECT wndRect  = new RECT,
  164.                ctrlRect = new RECT;
  165.  
  166.         GetWindowRect(wndRect);
  167.         m_ebLog.GetWindowRect(ctrlRect);
  168.  
  169.         top  = ctrlRect->top  - wndRect->top  - 2;
  170.         left = ctrlRect->left - wndRect->left - 2;
  171.  
  172.         m_ebLog.MoveWindow(left, top, cx - left - 7, cy - top - 7);
  173.  
  174.         delete wndRect;
  175.         delete ctrlRect;
  176.     }
  177.  
  178.     CFormView::OnSize(nType, cx, cy);
  179. }
  180.  
  181. void CViewNode::OnTimer(UINT nIDEvent) 
  182. {
  183.  
  184.     if(nIDEvent == UpdateTimer)
  185.     {
  186.         Node = ((CGnucleusDoc *) GetDocument())->GnuComm->GetNode(HostPort);
  187.         
  188.         if(Node != NULL)
  189.         {
  190.             // Update the main edit box
  191.             CString Log = Node->Log, PastLog;
  192.             Node->Log = "";
  193.  
  194.             m_strNodeBadStat.Format("%u", Node->m_dwNumOfBadPackets);
  195.             m_strNodeRecivedStat.Format("%u", Node->m_dwNumOfRecivedPackets);
  196.             m_strNodeSentStat.Format("%u", Node->m_dwNumOfSentPackets);
  197.  
  198.             UpdateData(FALSE);
  199.  
  200.             m_ebLog.GetWindowText(PastLog);
  201.  
  202.             if(PastLog.GetLength() > 10000)
  203.                 Log += PastLog.Left(10000);
  204.             else
  205.                 Log += PastLog;
  206.  
  207.             m_ebLog.SetWindowText(Log);
  208.  
  209.             //Check the checks, sometimes its missed at start up
  210.             Node->logPings        = m_chkPings.GetCheck() ? 1 : 0; 
  211.             Node->logPongs        = m_chkPongs.GetCheck() ? 1 : 0; 
  212.             Node->logPushes       = m_chkPushes.GetCheck() ? 1 : 0; 
  213.             Node->logQueries      = m_chkQueries.GetCheck() ? 1 : 0; 
  214.             Node->logQueryReplies = m_chkQueryHits.GetCheck() ? 1 : 0; 
  215.             Node->logUnknowns      = m_chkUnknowns.GetCheck() ? 1 : 0; 
  216.         }
  217.         else    // close the window
  218.         {
  219.             SendMessage(WM_CLOSE);
  220.             //DestroyWindow();
  221.             return;                // can't call OnTimer after a destrywindow();
  222.         }
  223.             
  224.     }
  225.  
  226.     CFormView::OnTimer(nIDEvent);
  227. }
  228.  
  229. void CViewNode::OnClose() 
  230. {
  231.     Node = ((CGnucleusDoc *) GetDocument())->GnuComm->GetNode(HostPort);
  232.         
  233.     if(Node != NULL)
  234.     {
  235.         Node->logPings = Node->logPongs = Node->logQueries =
  236.             Node->logPushes = Node->logQueryReplies = Node->logUnknowns =
  237.             Node->logGUID = Node->logHops = Node->logTTL = Node->logPayload = 
  238.             Node->logDropped = 0;
  239.  
  240.         Node->Log = "";
  241.     }
  242.  
  243.     CFormView::OnClose();
  244. }
  245.  
  246. void CViewNode::OnChkPings() 
  247. {
  248.     if(Node != NULL)
  249.         Node->logPings = m_chkPings.GetCheck() ? 1 : 0;
  250. }
  251. void CViewNode::OnChkPongs() 
  252. {
  253.     if(Node != NULL)
  254.         Node->logPongs = m_chkPongs.GetCheck() ? 1 : 0;
  255. }
  256.  
  257. void CViewNode::OnChkPushes() 
  258. {
  259.     if(Node != NULL)
  260.         Node->logPushes = m_chkPushes.GetCheck() ? 1 : 0;}
  261.  
  262. void CViewNode::OnChkQueries() 
  263. {
  264.     if(Node != NULL)
  265.         Node->logQueries = m_chkQueries.GetCheck() ? 1 : 0;
  266. }
  267.  
  268. void CViewNode::OnChkQueryhits() 
  269. {
  270.     if(Node != NULL)
  271.         Node->logQueryReplies = m_chkQueryHits.GetCheck() ? 1 : 0;
  272. }
  273.  
  274. void CViewNode::OnChkUnknowns() 
  275. {
  276.     if(Node != NULL)
  277.         Node->logUnknowns = m_chkUnknowns.GetCheck() ? 1 : 0;}
  278.  
  279. void CViewNode::OnChkGuid() 
  280. {
  281.     if(Node != NULL)
  282.         Node->logGUID = m_chkGUID.GetCheck() ? 1 : 0;
  283. }
  284.  
  285. void CViewNode::OnChkHops() 
  286. {
  287.     // TODO: Add your control notification handler code here
  288.     
  289. }
  290.  
  291. void CViewNode::OnChkTtl() 
  292. {
  293.     // TODO: Add your control notification handler code here
  294.     
  295. }
  296.  
  297. void CViewNode::OnChkPayload() 
  298. {
  299.     // TODO: Add your control notification handler code here
  300.     
  301. }
  302.  
  303. void CViewNode::OnChkDropped() 
  304. {
  305.     // TODO: Add your control notification handler code here
  306.     
  307. }
  308.  
  309. void CViewNode::OnButtonFlush() 
  310. {
  311.     m_ebLog.SetWindowText("");    
  312. }
  313.