Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

Statistics.cpp

Go to the documentation of this file.
00001 //
00002 // Statistics.cpp
00003 //
00004 // Copyright (c) Shareaza Development Team, 2002-2005.
00005 // This file is part of SHAREAZA (www.shareaza.com)
00006 //
00007 // Shareaza is free software; you can redistribute it
00008 // and/or modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2 of
00010 // the License, or (at your option) any later version.
00011 //
00012 // Shareaza is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 //
00017 // You should have received a copy of the GNU General Public License
00018 // along with Shareaza; if not, write to the Free Software
00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 //
00021 
00022 #include "StdAfx.h"
00023 #include "Shareaza.h"
00024 #include "Statistics.h"
00025 #include "Network.h"
00026 #include "Neighbours.h"
00027 
00028 #ifdef _DEBUG
00029 #undef THIS_FILE
00030 static char THIS_FILE[]=__FILE__;
00031 #define new DEBUG_NEW
00032 #endif
00033 
00034 CStatistics Statistics;
00035 
00036 
00038 // CStatistics construction
00039 
00040 CStatistics::CStatistics()
00041 {
00042         ZeroMemory( &Today, sizeof(Today) );
00043         ZeroMemory( &Ever, sizeof(Ever) );
00044         ZeroMemory( &Current, sizeof(Current) );
00045 
00046         m_tUpdate = m_tSeconds = 0;
00047 }
00048 
00049 CStatistics::~CStatistics()
00050 {
00051 }
00052 
00054 // CStatistics update
00055 
00056 void CStatistics::Update()
00057 {
00058         DWORD tNow = GetTickCount();
00059 
00060         if ( tNow - m_tUpdate < 100 ) return;
00061         m_tUpdate = tNow;
00062 
00063         if ( tNow - m_tSeconds >= 1000 )
00064         {
00065                 if ( Network.IsWellConnected() )
00066                 {
00067                         Current.Timer.Connected ++;
00068                         if ( Neighbours.IsG2Hub() ) Current.Timer.Hub ++;
00069                         if ( Neighbours.IsG1Ultrapeer() ) Current.Timer.Ultrapeer ++;
00070                 }
00071 
00072                 m_tSeconds = tNow;
00073         }
00074 
00075         CopyMemory( &Last, &Current, sizeof(Current) );
00076         Add( &Today, &Current, sizeof(Current) );
00077         Add( &Ever, &Current, sizeof(Current) );
00078         ZeroMemory( &Current, sizeof(Current) );
00079 }
00080 
00082 // CStatistics adder
00083 
00084 void CStatistics::Add(LPVOID pTarget, LPCVOID pSource, int nCount)
00085 {
00086         QWORD* pqwTarget = (QWORD*)pTarget;
00087         QWORD* pqwSource = (QWORD*)pSource;
00088 
00089         for ( nCount /= sizeof(QWORD) ; nCount ; nCount-- )
00090         {
00091                 *pqwTarget += *pqwSource;
00092 
00093                 pqwTarget++;
00094                 pqwSource++;
00095         }
00096 }
00097 

Generated on Thu Dec 15 10:39:50 2005 for Shareaza 2.2.1.0 by  doxygen 1.4.2