Support client builds on VS2019
authorV.C <c******@rediffmail.com>
Fri, 21 Aug 2020 00:03:29 +0000 (00:03 +0000)
committerV.C <c******@rediffmail.com>
Wed, 26 Aug 2020 02:45:20 +0000 (02:45 +0000)
Scenario: Build fails on Qt 5.15.0 + VS2019 16.7.2
Root cause: QLinkedList seems to be depreciated. Advise to use std::list instead.
Fix: Used std::list insead of QLinkedList.

Signed-off-by: V.C <c******@rediffmail.com>
src/libsync/bandwidthmanager.cpp
src/libsync/bandwidthmanager.h

index 63ea83d3c25eca8136122195ba58dcfa7b8a9e4e..edeeb196ebf60d772879d3f76d74287be3d5b58f 100644 (file)
@@ -91,8 +91,8 @@ BandwidthManager::~BandwidthManager() = default;
 
 void BandwidthManager::registerUploadDevice(UploadDevice *p)
 {
-    _absoluteUploadDeviceList.append(p);
-    _relativeUploadDeviceList.append(p);
+    _absoluteUploadDeviceList.push_back(p);
+    _relativeUploadDeviceList.push_back(p);
     QObject::connect(p, &QObject::destroyed, this, &BandwidthManager::unregisterUploadDevice);
 
     if (usingAbsoluteUploadLimit()) {
@@ -110,8 +110,8 @@ void BandwidthManager::registerUploadDevice(UploadDevice *p)
 void BandwidthManager::unregisterUploadDevice(QObject *o)
 {
     auto p = reinterpret_cast<UploadDevice *>(o); // note, we might already be in the ~QObject
-    _absoluteUploadDeviceList.removeAll(p);
-    _relativeUploadDeviceList.removeAll(p);
+    _absoluteUploadDeviceList.remove(p);
+    _relativeUploadDeviceList.remove(p);
     if (p == _relativeLimitCurrentMeasuredDevice) {
         _relativeLimitCurrentMeasuredDevice = nullptr;
         _relativeUploadLimitProgressAtMeasuringRestart = 0;
@@ -120,7 +120,7 @@ void BandwidthManager::unregisterUploadDevice(QObject *o)
 
 void BandwidthManager::registerDownloadJob(GETFileJob *j)
 {
-    _downloadJobList.append(j);
+    _downloadJobList.push_back(j);
     QObject::connect(j, &QObject::destroyed, this, &BandwidthManager::unregisterDownloadJob);
 
     if (usingAbsoluteDownloadLimit()) {
@@ -138,7 +138,7 @@ void BandwidthManager::registerDownloadJob(GETFileJob *j)
 void BandwidthManager::unregisterDownloadJob(QObject *o)
 {
     auto *j = reinterpret_cast<GETFileJob *>(o); // note, we might already be in the ~QObject
-    _downloadJobList.removeAll(j);
+    _downloadJobList.remove(j);
     if (_relativeLimitCurrentMeasuredJob == j) {
         _relativeLimitCurrentMeasuredJob = nullptr;
         _relativeDownloadLimitProgressAtMeasuringRestart = 0;
@@ -147,7 +147,7 @@ void BandwidthManager::unregisterDownloadJob(QObject *o)
 
 void BandwidthManager::relativeUploadMeasuringTimerExpired()
 {
-    if (!usingRelativeUploadLimit() || _relativeUploadDeviceList.count() == 0) {
+    if (!usingRelativeUploadLimit() || _relativeUploadDeviceList.size() == 0) {
         // Not in this limiting mode, just wait 1 sec to continue the cycle
         _relativeUploadDelayTimer.setInterval(1000);
         _relativeUploadDelayTimer.start();
@@ -160,7 +160,7 @@ void BandwidthManager::relativeUploadMeasuringTimerExpired()
         return;
     }
 
-    qCDebug(lcBandwidthManager) << _relativeUploadDeviceList.count() << "Starting Delay";
+    qCDebug(lcBandwidthManager) << _relativeUploadDeviceList.size() << "Starting Delay";
 
     qint64 relativeLimitProgressMeasured = (_relativeLimitCurrentMeasuredDevice->_readWithProgress
                                                + _relativeLimitCurrentMeasuredDevice->_read)
@@ -191,7 +191,7 @@ void BandwidthManager::relativeUploadMeasuringTimerExpired()
     _relativeUploadDelayTimer.setInterval(realWaitTimeMsec);
     _relativeUploadDelayTimer.start();
 
-    int deviceCount = _relativeUploadDeviceList.count();
+    size_t deviceCount = _relativeUploadDeviceList.size();
     qint64 quotaPerDevice = relativeLimitProgressDifference * (uploadLimitPercent / 100.0) / deviceCount + 1.0;
     Q_FOREACH (UploadDevice *ud, _relativeUploadDeviceList) {
         ud->setBandwidthLimited(true);
@@ -211,15 +211,16 @@ void BandwidthManager::relativeUploadDelayTimerExpired()
         return; // oh, not actually needed
     }
 
-    if (_relativeUploadDeviceList.isEmpty()) {
+    if (_relativeUploadDeviceList.empty()) {
         return;
     }
 
-    qCDebug(lcBandwidthManager) << _relativeUploadDeviceList.count() << "Starting measuring";
+    qCDebug(lcBandwidthManager) << _relativeUploadDeviceList.size() << "Starting measuring";
 
     // Take first device and then append it again (= we round robin all devices)
-    _relativeLimitCurrentMeasuredDevice = _relativeUploadDeviceList.takeFirst();
-    _relativeUploadDeviceList.append(_relativeLimitCurrentMeasuredDevice);
+    _relativeLimitCurrentMeasuredDevice = _relativeUploadDeviceList.front();
+    _relativeUploadDeviceList.pop_front();
+    _relativeUploadDeviceList.push_back(_relativeLimitCurrentMeasuredDevice);
 
     _relativeUploadLimitProgressAtMeasuringRestart = (_relativeLimitCurrentMeasuredDevice->_readWithProgress
                                                          + _relativeLimitCurrentMeasuredDevice->_read)
@@ -241,7 +242,7 @@ void BandwidthManager::relativeUploadDelayTimerExpired()
 // for downloads:
 void BandwidthManager::relativeDownloadMeasuringTimerExpired()
 {
-    if (!usingRelativeDownloadLimit() || _downloadJobList.count() == 0) {
+    if (!usingRelativeDownloadLimit() || _downloadJobList.size() == 0) {
         // Not in this limiting mode, just wait 1 sec to continue the cycle
         _relativeDownloadDelayTimer.setInterval(1000);
         _relativeDownloadDelayTimer.start();
@@ -254,7 +255,7 @@ void BandwidthManager::relativeDownloadMeasuringTimerExpired()
         return;
     }
 
-    qCDebug(lcBandwidthManager) << _downloadJobList.count() << "Starting Delay";
+    qCDebug(lcBandwidthManager) << _downloadJobList.size() << "Starting Delay";
 
     qint64 relativeLimitProgressMeasured = _relativeLimitCurrentMeasuredJob->currentDownloadPosition();
     qint64 relativeLimitProgressDifference = relativeLimitProgressMeasured - _relativeDownloadLimitProgressAtMeasuringRestart;
@@ -280,7 +281,7 @@ void BandwidthManager::relativeDownloadMeasuringTimerExpired()
     _relativeDownloadDelayTimer.setInterval(realWaitTimeMsec);
     _relativeDownloadDelayTimer.start();
 
-    int jobCount = _downloadJobList.count();
+    size_t jobCount = _downloadJobList.size();
     qint64 quota = relativeLimitProgressDifference * (downloadLimitPercent / 100.0);
     if (quota > 20 * 1024) {
         qCInfo(lcBandwidthManager) << "ADJUSTING QUOTA FROM " << quota << " TO " << quota - 20 * 1024;
@@ -305,16 +306,17 @@ void BandwidthManager::relativeDownloadDelayTimerExpired()
         return; // oh, not actually needed
     }
 
-    if (_downloadJobList.isEmpty()) {
-        qCDebug(lcBandwidthManager) << _downloadJobList.count() << "No jobs?";
+    if (_downloadJobList.empty()) {
+        qCDebug(lcBandwidthManager) << _downloadJobList.size() << "No jobs?";
         return;
     }
 
-    qCDebug(lcBandwidthManager) << _downloadJobList.count() << "Starting measuring";
+    qCDebug(lcBandwidthManager) << _downloadJobList.size() << "Starting measuring";
 
     // Take first device and then append it again (= we round robin all devices)
-    _relativeLimitCurrentMeasuredJob = _downloadJobList.takeFirst();
-    _downloadJobList.append(_relativeLimitCurrentMeasuredJob);
+    _relativeLimitCurrentMeasuredJob = _downloadJobList.front();
+    _downloadJobList.pop_front();
+    _downloadJobList.push_back(_relativeLimitCurrentMeasuredJob);
 
     _relativeDownloadLimitProgressAtMeasuringRestart = _relativeLimitCurrentMeasuredJob->currentDownloadPosition();
     _relativeLimitCurrentMeasuredJob->setBandwidthLimited(false);
@@ -373,17 +375,17 @@ void BandwidthManager::switchingTimerExpired()
 
 void BandwidthManager::absoluteLimitTimerExpired()
 {
-    if (usingAbsoluteUploadLimit() && _absoluteUploadDeviceList.count() > 0) {
-        qint64 quotaPerDevice = _currentUploadLimit / qMax(1, _absoluteUploadDeviceList.count());
-        qCDebug(lcBandwidthManager) << quotaPerDevice << _absoluteUploadDeviceList.count() << _currentUploadLimit;
+    if (usingAbsoluteUploadLimit() && _absoluteUploadDeviceList.size() > 0) {
+        qint64 quotaPerDevice = _currentUploadLimit / qMax((std::list<UploadDevice *>::size_type)1, _absoluteUploadDeviceList.size());
+        qCDebug(lcBandwidthManager) << quotaPerDevice << _absoluteUploadDeviceList.size() << _currentUploadLimit;
         Q_FOREACH (UploadDevice *device, _absoluteUploadDeviceList) {
             device->giveBandwidthQuota(quotaPerDevice);
             qCDebug(lcBandwidthManager) << "Gave " << quotaPerDevice / 1024.0 << " kB to" << device;
         }
     }
-    if (usingAbsoluteDownloadLimit() && _downloadJobList.count() > 0) {
-        qint64 quotaPerJob = _currentDownloadLimit / qMax(1, _downloadJobList.count());
-        qCDebug(lcBandwidthManager) << quotaPerJob << _downloadJobList.count() << _currentDownloadLimit;
+    if (usingAbsoluteDownloadLimit() && _downloadJobList.size() > 0) {
+        qint64 quotaPerJob = _currentDownloadLimit / qMax((std::list<GETFileJob *>::size_type)1, _downloadJobList.size());
+        qCDebug(lcBandwidthManager) << quotaPerJob << _downloadJobList.size() << _currentDownloadLimit;
         Q_FOREACH (GETFileJob *j, _downloadJobList) {
             j->giveBandwidthQuota(quotaPerJob);
             qCDebug(lcBandwidthManager) << "Gave " << quotaPerJob / 1024.0 << " kB to" << j;
index 691e11162d0879adf71e6b109b6c6cadf069de2a..15d949fbcb159fb1ddb4d79aa031f07673927e51 100644 (file)
@@ -16,9 +16,9 @@
 #define BANDWIDTHMANAGER_H
 
 #include <QObject>
-#include <QLinkedList>
 #include <QTimer>
 #include <QIODevice>
+#include <list>
 
 namespace OCC {
 
@@ -71,8 +71,8 @@ private:
     QTimer _absoluteLimitTimer;
 
     // FIXME merge these two lists
-    QLinkedList<UploadDevice *> _absoluteUploadDeviceList;
-    QLinkedList<UploadDevice *> _relativeUploadDeviceList;
+    std::list<UploadDevice *> _absoluteUploadDeviceList;
+    std::list<UploadDevice *> _relativeUploadDeviceList;
 
     QTimer _relativeUploadMeasuringTimer;
 
@@ -86,7 +86,7 @@ private:
     qint64 _relativeUploadLimitProgressAtMeasuringRestart;
     qint64 _currentUploadLimit;
 
-    QLinkedList<GETFileJob *> _downloadJobList;
+    std::list<GETFileJob *> _downloadJobList;
     QTimer _relativeDownloadMeasuringTimer;
 
     // for relative bw limiting, we need to wait this amount before measuring again