2014-09-29 12:30:39 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Markus Goetz <markus@woboq.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef BANDWIDTHMANAGER_H
|
|
|
|
#define BANDWIDTHMANAGER_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QIODevice>
|
2020-08-21 03:03:29 +03:00
|
|
|
#include <list>
|
2014-09-29 12:30:39 +04:00
|
|
|
|
2014-12-02 16:20:13 +03:00
|
|
|
namespace OCC {
|
2014-09-29 12:30:39 +04:00
|
|
|
|
|
|
|
class UploadDevice;
|
|
|
|
class GETFileJob;
|
|
|
|
class OwncloudPropagator;
|
|
|
|
|
2015-06-29 19:56:09 +03:00
|
|
|
/**
|
|
|
|
* @brief The BandwidthManager class
|
|
|
|
* @ingroup libsync
|
2015-06-26 18:07:47 +03:00
|
|
|
*/
|
2014-09-29 12:30:39 +04:00
|
|
|
class BandwidthManager : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
BandwidthManager(OwncloudPropagator *p);
|
2021-08-17 13:39:31 +03:00
|
|
|
~BandwidthManager() override;
|
2014-09-29 12:30:39 +04:00
|
|
|
|
|
|
|
bool usingAbsoluteUploadLimit() { return _currentUploadLimit > 0; }
|
|
|
|
bool usingRelativeUploadLimit() { return _currentUploadLimit < 0; }
|
|
|
|
bool usingAbsoluteDownloadLimit() { return _currentDownloadLimit > 0; }
|
|
|
|
bool usingRelativeDownloadLimit() { return _currentDownloadLimit < 0; }
|
|
|
|
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void registerUploadDevice(UploadDevice *);
|
|
|
|
void unregisterUploadDevice(QObject *);
|
|
|
|
|
|
|
|
void registerDownloadJob(GETFileJob *);
|
|
|
|
void unregisterDownloadJob(QObject *);
|
|
|
|
|
|
|
|
void absoluteLimitTimerExpired();
|
|
|
|
void switchingTimerExpired();
|
|
|
|
|
|
|
|
void relativeUploadMeasuringTimerExpired();
|
|
|
|
void relativeUploadDelayTimerExpired();
|
|
|
|
|
2014-09-30 08:05:23 +04:00
|
|
|
void relativeDownloadMeasuringTimerExpired();
|
|
|
|
void relativeDownloadDelayTimerExpired();
|
|
|
|
|
2014-09-29 12:30:39 +04:00
|
|
|
private:
|
2017-04-28 11:03:49 +03:00
|
|
|
// for switching between absolute and relative bw limiting
|
|
|
|
QTimer _switchingTimer;
|
|
|
|
|
|
|
|
// FIXME this timer and this variable should be replaced
|
2014-09-29 12:30:39 +04:00
|
|
|
// by the propagator emitting the changed limit values to us as signal
|
2017-04-28 11:03:49 +03:00
|
|
|
OwncloudPropagator *_propagator;
|
2014-09-29 12:30:39 +04:00
|
|
|
|
2017-04-28 11:03:49 +03:00
|
|
|
// for absolute up/down bw limiting
|
|
|
|
QTimer _absoluteLimitTimer;
|
2014-09-29 12:30:39 +04:00
|
|
|
|
2017-04-28 11:03:49 +03:00
|
|
|
// FIXME merge these two lists
|
2020-08-21 03:03:29 +03:00
|
|
|
std::list<UploadDevice *> _absoluteUploadDeviceList;
|
|
|
|
std::list<UploadDevice *> _relativeUploadDeviceList;
|
2017-04-28 11:03:49 +03:00
|
|
|
|
2014-09-29 12:30:39 +04:00
|
|
|
QTimer _relativeUploadMeasuringTimer;
|
2017-04-28 11:03:49 +03:00
|
|
|
|
|
|
|
// for relative bw limiting, we need to wait this amount before measuring again
|
|
|
|
QTimer _relativeUploadDelayTimer;
|
|
|
|
|
|
|
|
// the device measured
|
|
|
|
UploadDevice *_relativeLimitCurrentMeasuredDevice;
|
|
|
|
|
|
|
|
// for measuring how much progress we made at start
|
|
|
|
qint64 _relativeUploadLimitProgressAtMeasuringRestart;
|
2014-09-29 12:30:39 +04:00
|
|
|
qint64 _currentUploadLimit;
|
|
|
|
|
2020-08-21 03:03:29 +03:00
|
|
|
std::list<GETFileJob *> _downloadJobList;
|
2014-09-30 08:05:23 +04:00
|
|
|
QTimer _relativeDownloadMeasuringTimer;
|
2017-04-28 11:03:49 +03:00
|
|
|
|
|
|
|
// for relative bw limiting, we need to wait this amount before measuring again
|
|
|
|
QTimer _relativeDownloadDelayTimer;
|
|
|
|
|
|
|
|
// the device measured
|
|
|
|
GETFileJob *_relativeLimitCurrentMeasuredJob;
|
|
|
|
|
|
|
|
// for measuring how much progress we made at start
|
|
|
|
qint64 _relativeDownloadLimitProgressAtMeasuringRestart;
|
|
|
|
|
2014-09-29 12:30:39 +04:00
|
|
|
qint64 _currentDownloadLimit;
|
|
|
|
};
|
2020-08-27 02:31:06 +03:00
|
|
|
|
|
|
|
} // namespace OCC
|
2014-09-29 12:30:39 +04:00
|
|
|
|
|
|
|
#endif
|