src/core/speedcalculator.h
00001 //------------------------------------------------------------------------------
00002 // speedcalculator.h
00003 //------------------------------------------------------------------------------
00004 //
00005 // This program is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU General Public License
00007 // as published by the Free Software Foundation; either version 2
00008 // of the License, or (at your option) any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00018 // 02110-1301, USA.
00019 //
00020 //------------------------------------------------------------------------------
00021 // Copyright (C) 2010 "Zalewa" <zalewapl@gmail.com>
00022 //------------------------------------------------------------------------------
00023 #ifndef __SPEEDCALCULATOR_H__
00024 #define __SPEEDCALCULATOR_H__
00025 
00026 #include <QVector>
00027 #include <QTime>
00028 
00029 class SpeedCalculator
00030 {
00031         public:
00032                 SpeedCalculator();
00033 
00040                 long double                                     estimatedTimeUntilArrival() const;
00041 
00042                 qint64                                          expectedDataSize() const { return dataSizeExpected; }
00043 
00050                 long double                                     getSpeed() const;
00051 
00059                 qint64                      lastRegisteredDataAmount() const;
00060 
00067                 qint64                      lastRegisterAttemptedDataAmount() const
00068                 {
00069                         return lastRegisterAttemptDataSize;
00070                 }
00071 
00080                 void                                            registerDataAmount(qint64 totalAmountOfArrivedData);
00081 
00087                 void                                            setExpectedDataSize(qint64 size);
00088 
00096                 void                                            start();
00097 
00098         private:
00099                 class DataArrivalInfo
00100                 {
00101                         public:
00105                                 qint64                          totalAmountOfArrivedData;
00106 
00110                                 qint64                          timeOfArrival;
00111 
00112                                 DataArrivalInfo()
00113                                 {
00114                                         this->totalAmountOfArrivedData = 0;
00115                                         this->timeOfArrival = 0;
00116                                 }
00117 
00118                                 DataArrivalInfo(qint64 totalAmountOfArrivedData, qint64 timeOfArrival)
00119                                 {
00120                                         this->totalAmountOfArrivedData = totalAmountOfArrivedData;
00121                                         this->timeOfArrival = timeOfArrival;
00122                                 }
00123                 };
00124 
00125                 static const int                        NUM_ARRIVAL_DATA = 2;
00126 
00127                 QVector<DataArrivalInfo>        arrivalData;
00128 
00129 //              QVector<long double>            averageSpeeds;
00130 
00131                 QTime                                           clock;
00132                 qint64                                          dataSizeExpected;
00133 
00138                 qint64                                          lastRegisterAttemptDataSize;
00139 };
00140 
00141 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator