18 #ifndef QGSTILEDOWNLOADMANAGER_H
19 #define QGSTILEDOWNLOADMANAGER_H
27 #include <QNetworkAccessManager>
28 #include <QNetworkReply>
30 #include "qgis_core.h"
56 QByteArray
data()
const {
return mData; }
58 QUrl
url()
const {
return mUrl; }
60 QVariant attribute( QNetworkRequest::Attribute code );
62 QVariant header( QNetworkRequest::KnownHeaders header );
64 const QList<QNetworkReply::RawHeaderPair>
rawHeaderPairs()
const {
return mRawHeaderPairs; }
66 QNetworkReply::NetworkError
error()
const {
return mError; }
70 QNetworkRequest
request()
const {
return mRequest; }
77 void requestFinished( QByteArray data, QUrl url,
const QMap<QNetworkRequest::Attribute, QVariant> &attributes,
const QMap<QNetworkRequest::KnownHeaders, QVariant> &headers,
const QList<QNetworkReply::RawHeaderPair> rawHeaderPairs, QNetworkReply::NetworkError error,
const QString &errorString );
78 void cachedRangeRequestFinished();
88 QNetworkRequest mRequest;
89 bool mHasFinished =
false;
91 QNetworkReply::NetworkError mError = QNetworkReply::NoError;
94 QMap<QNetworkRequest::Attribute, QVariant> mAttributes;
95 QMap<QNetworkRequest::KnownHeaders, QVariant> mHeaders;
96 QList<QNetworkReply::RawHeaderPair> mRawHeaderPairs;
107 class QgsTileDownloadManagerReplyWorkerObject :
public QObject
111 QgsTileDownloadManagerReplyWorkerObject(
QgsTileDownloadManager *manager,
const QNetworkRequest &request )
112 : mManager( manager ), mRequest( request ) {}
115 void replyFinished();
118 void finished( QByteArray data, QUrl url,
const QMap<QNetworkRequest::Attribute, QVariant> &attributes,
const QMap<QNetworkRequest::KnownHeaders, QVariant> &headers,
const QList<QNetworkReply::RawHeaderPair> rawHeaderPairs, QNetworkReply::NetworkError error,
const QString &errorString );
123 QNetworkRequest mRequest;
132 class QgsTileDownloadManagerWorker :
public QObject
140 void startIdleTimer();
144 void idleTimerTimeout();
147 void requestFinished( QString url, QByteArray data );
209 bool isValid()
const {
return !request.url().isEmpty(); }
212 QNetworkRequest request;
214 QgsTileDownloadManagerReplyWorkerObject *objWorker =
nullptr;
216 QNetworkReply *networkReply =
nullptr;
230 int requestsTotal = 0;
232 int requestsMerged = 0;
234 int requestsEarlyDeleted = 0;
237 int networkRequestsStarted = 0;
239 int networkRequestsOk = 0;
241 int networkRequestsFailed = 0;
254 bool hasPendingRequests()
const;
260 bool waitForPendingRequests(
int msec = -1 )
const;
269 bool hasWorkerThreadRunning()
const;
281 void resetStatistics();
283 friend class QgsTileDownloadManagerWorker;
285 friend class QgsTileDownloadManagerReplyWorkerObject;
290 QueueEntry findEntryForRequest(
const QNetworkRequest &request );
291 void addEntry(
const QueueEntry &entry );
292 void updateEntry(
const QueueEntry &entry );
293 void removeEntry(
const QNetworkRequest &request );
294 void processStagedEntryRemovals();
296 void signalQueueModified();
298 bool isRangeRequest(
const QNetworkRequest &request );
299 bool isCachedRangeRequest(
const QNetworkRequest &request );
303 std::vector<QueueEntry> mQueue;
305 bool mStageQueueRemovals =
false;
306 std::vector< QNetworkRequest > mStagedQueueRemovals;
308 bool mShuttingDown =
false;
309 #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
310 mutable QMutex mMutex;
312 mutable QRecursiveMutex mMutex;
314 QThread *mWorkerThread =
nullptr;
315 QgsTileDownloadManagerWorker *mWorker =
nullptr;
318 int mIdleThreadTimeoutMs = 10000;
320 std::unique_ptr<QgsRangeRequestCache> mRangesCache;
323 #endif // QGSTILEDOWNLOADMANAGER_H