diff options
author | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2019-03-19 16:57:36 +0200 |
---|---|---|
committer | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2019-03-20 21:30:08 +0200 |
commit | d5868d3da822f2bf3297229bd879e76853108a63 (patch) | |
tree | b3d28aab92b938cf541f917f1027d2bbd06d9780 /include/mbgl/storage | |
parent | d1762d7111b39d45430bd7bb75ea60b7a5d85bd2 (diff) | |
download | qtlocation-mapboxgl-d5868d3da822f2bf3297229bd879e76853108a63.tar.gz |
[core] Remove file source from public Map ctor
Diffstat (limited to 'include/mbgl/storage')
-rw-r--r-- | include/mbgl/storage/default_file_source.hpp | 2 | ||||
-rw-r--r-- | include/mbgl/storage/file_source.hpp | 12 | ||||
-rw-r--r-- | include/mbgl/storage/resource_options.hpp | 116 |
3 files changed, 129 insertions, 1 deletions
diff --git a/include/mbgl/storage/default_file_source.hpp b/include/mbgl/storage/default_file_source.hpp index 5f6999e99f..8f88964acf 100644 --- a/include/mbgl/storage/default_file_source.hpp +++ b/include/mbgl/storage/default_file_source.hpp @@ -28,7 +28,7 @@ public: * of megabytes). */ DefaultFileSource(const std::string& cachePath, - const std::string& assetRoot, + const std::string& assetPath, uint64_t maximumCacheSize = util::DEFAULT_MAX_CACHE_SIZE); DefaultFileSource(const std::string& cachePath, std::unique_ptr<FileSource>&& assetFileSource, diff --git a/include/mbgl/storage/file_source.hpp b/include/mbgl/storage/file_source.hpp index 0709a1c245..868dbf7347 100644 --- a/include/mbgl/storage/file_source.hpp +++ b/include/mbgl/storage/file_source.hpp @@ -1,16 +1,21 @@ #pragma once +#include <mbgl/actor/actor_ref.hpp> #include <mbgl/storage/response.hpp> #include <mbgl/storage/resource.hpp> #include <mbgl/util/noncopyable.hpp> #include <mbgl/util/async_request.hpp> +#include <mbgl/util/optional.hpp> #include <functional> #include <memory> namespace mbgl { +class ResourceOptions; +class ResourceTransform; + class FileSource : private util::noncopyable { public: virtual ~FileSource() = default; @@ -31,6 +36,13 @@ public: virtual bool supportsCacheOnlyRequests() const { return false; } + + // Factory for creating a platform-specific file source. + static std::shared_ptr<FileSource> createPlatformFileSource(const ResourceOptions&); + + // Singleton for obtaining the shared platform-specific file source. A single instance of a file source is provided + // for each unique combination of a Mapbox API base URL, access token, cache path and platform context. + static std::shared_ptr<FileSource> getSharedFileSource(const ResourceOptions&); }; } // namespace mbgl diff --git a/include/mbgl/storage/resource_options.hpp b/include/mbgl/storage/resource_options.hpp new file mode 100644 index 0000000000..0a4669ea15 --- /dev/null +++ b/include/mbgl/storage/resource_options.hpp @@ -0,0 +1,116 @@ +#pragma once + +#include <memory> +#include <string> + +namespace mbgl { + +/** + * @brief Holds values for resource options. + */ +class ResourceOptions final { +public: + /** + * @brief Constructs a ResourceOptions object with default values. + */ + ResourceOptions(); + ~ResourceOptions(); + + /** + * @brief Sets the Mapbox access token - see https://docs.mapbox.com/help/how-mapbox-works/access-tokens/ for details. + * + * @param token Mapbox access token. + * @return reference to ResourceOptions for chaining options together. + */ + ResourceOptions& withAccessToken(std::string token); + + /** + * @brief Gets the previously set (or default) Mapbox access token. + * + * @return const std::string& Mapbox access token. + */ + const std::string& accessToken() const; + + /** + * @brief Sets the API base URL. Default is https://api.mapbox.com for Mapbox. + * + * @param baseURL API base URL. + * @return reference to ResourceOptions for chaining options together. + */ + ResourceOptions& withBaseURL(std::string baseURL); + + /** + * @brief Gets the previously set (or default) API base URL. + * + * @return const std::string& API base URL. + */ + const std::string& baseURL() const; + + /** + * @brief Sets the cache path. + * + * @param path Cache path. + * @return reference to ResourceOptions for chaining options together. + */ + ResourceOptions& withCachePath(std::string path); + + /** + * @brief Gets the previously set (or default) cache path. + * + * @return cache path + */ + const std::string& cachePath() const; + + /** + * @brief Sets the asset path, which is the root directory from where + * the asset:// scheme gets resolved in a style. + * + * @param path Asset path. + * @return reference to ResourceOptions for chaining options together. + */ + ResourceOptions& withAssetPath(std::string path); + + /** + * @brief Gets the previously set (or default) asset path. + * + * @return asset path + */ + const std::string& assetPath() const; + + /** + * @brief Sets the maximum cache size. + * + * @param size Cache maximum size in bytes. + * @return reference to ResourceOptions for chaining options together. + */ + ResourceOptions& withMaximumCacheSize(uint64_t size); + + /** + * @brief Gets the previously set (or default) maximum allowed cache size. + * + * @return maximum allowed cache database size in bytes. + */ + uint64_t maximumCacheSize() const; + + /** + * @brief Sets the platform context. A platform context is usually an object + * that assists the creation of a file source. + * + * @param context Platform context. + * @return reference to ResourceOptions for chaining options together. + */ + ResourceOptions& withPlatformContext(void* context); + + /** + * @brief Gets the previously set (or default) platform context. + * + * @return Platform context. + */ + void* platformContext() const; + +private: + class Impl; + std::shared_ptr<Impl> impl_; +}; + +} // namespace mbgl |