speedcalculator.h
1 //------------------------------------------------------------------------------
2 // speedcalculator.h
3 //------------------------------------------------------------------------------
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
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., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301, USA.
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2010 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #ifndef __SPEEDCALCULATOR_H__
24 #define __SPEEDCALCULATOR_H__
25 
26 #include <QVector>
27 #include <QTime>
28 
30 {
31  public:
33 
40  long double estimatedTimeUntilArrival() const;
41 
42  qint64 expectedDataSize() const { return dataSizeExpected; }
43 
50  long double getSpeed() const;
51 
59  qint64 lastRegisteredDataAmount() const;
60 
68  {
69  return lastRegisterAttemptDataSize;
70  }
71 
80  void registerDataAmount(qint64 totalAmountOfArrivedData);
81 
87  void setExpectedDataSize(qint64 size);
88 
96  void start();
97 
98  private:
99  class DataArrivalInfo
100  {
101  public:
105  qint64 totalAmountOfArrivedData;
106 
110  qint64 timeOfArrival;
111 
112  DataArrivalInfo()
113  {
114  this->totalAmountOfArrivedData = 0;
115  this->timeOfArrival = 0;
116  }
117 
118  DataArrivalInfo(qint64 totalAmountOfArrivedData, qint64 timeOfArrival)
119  {
120  this->totalAmountOfArrivedData = totalAmountOfArrivedData;
121  this->timeOfArrival = timeOfArrival;
122  }
123  };
124 
125  static const int NUM_ARRIVAL_DATA = 2;
126 
127  QVector<DataArrivalInfo> arrivalData;
128 
129 // QVector<long double> averageSpeeds;
130 
131  QTime clock;
132  qint64 dataSizeExpected;
133 
138  qint64 lastRegisterAttemptDataSize;
139 };
140 
141 #endif
void start()
Clears all values. Prepares SpeedCalculator for new speed measure.
qint64 lastRegisteredDataAmount() const
Last amount of data registered through registerDataAmount() method.
void registerDataAmount(qint64 totalAmountOfArrivedData)
Register new total amount of data.
long double getSpeed() const
In bytes per second.
void setExpectedDataSize(qint64 size)
Maximum expected size of the data.
qint64 lastRegisterAttemptedDataAmount() const
Last amount of data that was passed to registerDataAmount()
long double estimatedTimeUntilArrival() const
In seconds.