speedcalculator.h
1 //------------------------------------------------------------------------------
2 // speedcalculator.h
3 //------------------------------------------------------------------------------
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library 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 GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; 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 <QElapsedTimer>
27 #include <QVector>
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  QElapsedTimer clock;
130  qint64 dataSizeExpected;
131 
136  qint64 lastRegisterAttemptDataSize;
137 };
138 
139 #endif