File indexing completed on 2025-01-05 04:37:20

0001 /*
0002     SPDX-FileCopyrightText: 2005 Joris Guisson <joris.guisson@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 #ifndef NETSPEED_H
0007 #define NETSPEED_H
0008 
0009 #include <QLinkedList>
0010 #include <QPair>
0011 #include <deque>
0012 #include <util/constants.h>
0013 
0014 namespace net
0015 {
0016 /**
0017     @author Joris Guisson <joris.guisson@gmail.com>
0018 
0019     Measures the download and upload speed.
0020 */
0021 class Speed
0022 {
0023     QAtomicInt rate;
0024     bt::Uint32 bytes;
0025     std::deque<QPair<bt::Uint32, bt::TimeStamp>> dlrate;
0026 
0027 public:
0028     Speed();
0029     virtual ~Speed();
0030 
0031     void onData(bt::Uint32 bytes, bt::TimeStamp ts);
0032     void update(bt::TimeStamp now);
0033     int getRate() const
0034     {
0035         return rate;
0036     }
0037 };
0038 
0039 }
0040 
0041 #endif