summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/mbgl/storage/default_file_source.hpp2
-rw-r--r--include/mbgl/storage/file_source.hpp6
-rw-r--r--include/mbgl/storage/resource.hpp43
-rw-r--r--include/mbgl/tile/tile_necessity.hpp15
4 files changed, 55 insertions, 11 deletions
diff --git a/include/mbgl/storage/default_file_source.hpp b/include/mbgl/storage/default_file_source.hpp
index 91e442cf85..b9c8de5052 100644
--- a/include/mbgl/storage/default_file_source.hpp
+++ b/include/mbgl/storage/default_file_source.hpp
@@ -34,7 +34,7 @@ public:
uint64_t maximumCacheSize = util::DEFAULT_MAX_CACHE_SIZE);
~DefaultFileSource() override;
- bool supportsOptionalRequests() const override {
+ bool supportsCacheOnlyRequests() const override {
return true;
}
diff --git a/include/mbgl/storage/file_source.hpp b/include/mbgl/storage/file_source.hpp
index 404c683fdb..0709a1c245 100644
--- a/include/mbgl/storage/file_source.hpp
+++ b/include/mbgl/storage/file_source.hpp
@@ -24,11 +24,11 @@ public:
// not be executed.
virtual std::unique_ptr<AsyncRequest> request(const Resource&, Callback) = 0;
- // When a file source supports optional requests, it must return true.
- // Optional requests are requests that aren't as urgent, but could be useful, e.g.
+ // When a file source supports consulting a local cache only, it must return true.
+ // Cache-only requests are requests that aren't as urgent, but could be useful, e.g.
// to cover part of the map while loading. The FileSource should only do cheap actions to
// retrieve the data, e.g. load it from a cache, but not from the internet.
- virtual bool supportsOptionalRequests() const {
+ virtual bool supportsCacheOnlyRequests() const {
return false;
}
};
diff --git a/include/mbgl/storage/resource.hpp b/include/mbgl/storage/resource.hpp
index 5d44f4869f..318fa389f4 100644
--- a/include/mbgl/storage/resource.hpp
+++ b/include/mbgl/storage/resource.hpp
@@ -4,6 +4,8 @@
#include <mbgl/util/optional.hpp>
#include <mbgl/util/font_stack.hpp>
#include <mbgl/util/tileset.hpp>
+#include <mbgl/util/util.hpp>
+#include <mbgl/util/traits.hpp>
#include <string>
@@ -30,18 +32,28 @@ public:
int8_t z;
};
- enum Necessity : bool {
- Optional = false,
- Required = true,
+ enum class LoadingMethod : uint8_t {
+ None = 0b00,
+ Cache = 0b01,
+ Network = 0b10,
+
+ CacheOnly = Cache,
+ NetworkOnly = Network,
+ All = Cache | Network,
};
- Resource(Kind kind_, std::string url_, optional<TileData> tileData_ = {}, Necessity necessity_ = Required)
+ Resource(Kind kind_,
+ std::string url_,
+ optional<TileData> tileData_ = {},
+ LoadingMethod loadingMethod_ = LoadingMethod::All)
: kind(kind_),
- necessity(necessity_),
+ loadingMethod(loadingMethod_),
url(std::move(url_)),
tileData(std::move(tileData_)) {
}
+ bool hasLoadingMethod(LoadingMethod method);
+
static Resource style(const std::string& url);
static Resource source(const std::string& url);
static Resource tile(const std::string& urlTemplate,
@@ -50,7 +62,7 @@ public:
int32_t y,
int8_t z,
Tileset::Scheme scheme,
- Necessity = Required);
+ LoadingMethod = LoadingMethod::All);
static Resource glyphs(const std::string& urlTemplate,
const FontStack& fontStack,
const std::pair<uint16_t, uint16_t>& glyphRange);
@@ -59,7 +71,7 @@ public:
static Resource image(const std::string& url);
Kind kind;
- Necessity necessity;
+ LoadingMethod loadingMethod;
std::string url;
// Includes auxiliary data if this is a tile request.
@@ -71,4 +83,21 @@ public:
std::shared_ptr<const std::string> priorData;
};
+
+MBGL_CONSTEXPR Resource::LoadingMethod operator|(Resource::LoadingMethod a, Resource::LoadingMethod b) {
+ return Resource::LoadingMethod(mbgl::underlying_type(a) | mbgl::underlying_type(b));
+}
+
+MBGL_CONSTEXPR Resource::LoadingMethod& operator|=(Resource::LoadingMethod& a, Resource::LoadingMethod b) {
+ return (a = a | b);
+}
+
+MBGL_CONSTEXPR Resource::LoadingMethod operator&(Resource::LoadingMethod a, Resource::LoadingMethod b) {
+ return Resource::LoadingMethod(mbgl::underlying_type(a) & mbgl::underlying_type(b));
+}
+
+inline bool Resource::hasLoadingMethod(Resource::LoadingMethod method) {
+ return (loadingMethod & method) != Resource::LoadingMethod::None;
+}
+
} // namespace mbgl
diff --git a/include/mbgl/tile/tile_necessity.hpp b/include/mbgl/tile/tile_necessity.hpp
new file mode 100644
index 0000000000..e51bf51d10
--- /dev/null
+++ b/include/mbgl/tile/tile_necessity.hpp
@@ -0,0 +1,15 @@
+#pragma once
+
+namespace mbgl {
+
+// Tiles can have two states: optional or required.
+// - optional means that only low-cost actions should be taken to obtain the data
+// (e.g. load from cache, but accept stale data)
+// - required means that every effort should be taken to obtain the data (e.g. load
+// from internet and keep the data fresh if it expires)
+enum class TileNecessity : bool {
+ Optional = false,
+ Required = true,
+};
+
+} // namespace mbgl