1#pragma once
2
3#include <mbgl/storage/offline.hpp>
4#include <mbgl/storage/resource.hpp>
5
6#include <list>
7#include <unordered_set>
8#include <memory>
9#include <deque>
10
11namespace mbgl {
12
13class OfflineDatabase;
14class FileSource;
15class AsyncRequest;
16class Response;
17class Tileset;
18
19namespace style {
20class Parser;
21} // namespace style
22
23/**
24 * Coordinates the request and storage of all resources for an offline region.
25
26 * @private
27 */
28class OfflineDownload {
29public:
30 OfflineDownload(int64_t id, OfflineRegionDefinition&&, OfflineDatabase& offline, FileSource& online);
31 ~OfflineDownload();
32
33 void setObserver(std::unique_ptr<OfflineRegionObserver>);
34 void setState(OfflineRegionDownloadState);
35
36 OfflineRegionStatus getStatus() const;
37
38private:
39 void activateDownload();
40 void continueDownload();
41 void deactivateDownload();
42
43 /*
44 * Ensure that the resource is stored in the database, requesting it if necessary.
45 * While the request is in progress, it is recorded in `requests`. If the download
46 * is deactivated, all in progress requests are cancelled.
47 */
48 void ensureResource(const Resource&, std::function<void (Response)> = {});
49
50 void onMapboxTileCountLimitExceeded();
51
52 int64_t id;
53 OfflineRegionDefinition definition;
54 OfflineDatabase& offlineDatabase;
55 FileSource& onlineFileSource;
56 OfflineRegionStatus status;
57 std::unique_ptr<OfflineRegionObserver> observer;
58
59 std::list<std::unique_ptr<AsyncRequest>> requests;
60 std::unordered_set<std::string> requiredSourceURLs;
61 std::deque<Resource> resourcesRemaining;
62 std::list<std::tuple<Resource, Response>> buffer;
63
64 void queueResource(Resource);
65 void queueTiles(style::SourceType, uint16_t tileSize, const Tileset&);
66};
67
68} // namespace mbgl
69

source code of qtlocation/src/3rdparty/mapbox-gl-native/platform/default/mbgl/storage/offline_download.hpp