diff options
author | Mike Morris <michael.patrick.morris@gmail.com> | 2014-11-25 14:18:47 -0500 |
---|---|---|
committer | Mike Morris <michael.patrick.morris@gmail.com> | 2014-12-03 12:25:11 -0500 |
commit | dac76a0f9269a580706e52b730a98f9b1430bcdf (patch) | |
tree | b7c592b648a443ef456479ddd2e21fe66d22abad /include | |
parent | d3ab8951530b760afb19e685078b1480babc2209 (diff) | |
download | qtlocation-mapboxgl-dac76a0f9269a580706e52b730a98f9b1430bcdf.tar.gz |
break out FileSource as an abstract class
add CachingHTTPFileSource implementation
Diffstat (limited to 'include')
-rw-r--r-- | include/mbgl/map/map.hpp | 4 | ||||
-rw-r--r-- | include/mbgl/platform/default/caching_http_file_source.hpp | 52 | ||||
-rw-r--r-- | include/mbgl/storage/file_source.hpp | 37 |
3 files changed, 61 insertions, 32 deletions
diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index e97c63138c..718efbf149 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -32,7 +32,7 @@ class Map : private util::noncopyable { typedef void (*stop_callback)(void *); public: - explicit Map(View &view); + explicit Map(View&, FileSource&); ~Map(); // Start the map render thread. It is asynchronous. @@ -177,7 +177,7 @@ private: Transform transform; TransformState state; - util::ptr<FileSource> fileSource; + FileSource& fileSource; util::ptr<Style> style; GlyphAtlas glyphAtlas; diff --git a/include/mbgl/platform/default/caching_http_file_source.hpp b/include/mbgl/platform/default/caching_http_file_source.hpp new file mode 100644 index 0000000000..058bdc7c3e --- /dev/null +++ b/include/mbgl/platform/default/caching_http_file_source.hpp @@ -0,0 +1,52 @@ +#ifndef MBGL_STORAGE_CACHING_HTTP_FILE_SOURCE +#define MBGL_STORAGE_CACHING_HTTP_FILE_SOURCE + +#include <mbgl/storage/file_source.hpp> + +#include <unordered_map> + +typedef struct uv_messenger_s uv_messenger_t; + +namespace mbgl { + +class BaseRequest; +class SQLiteStore; + +class CachingHTTPFileSource : public FileSource { +public: + CachingHTTPFileSource(uv_loop_t*, const std::string &path_); + CachingHTTPFileSource(const std::string &path_); + ~CachingHTTPFileSource(); + + // Stores and checks the libuv loop for requests + void setLoop(uv_loop_t*); + bool hasLoop(); + + // Stores and retrieves the base path/URL for relative requests + void setBase(const std::string &value); + const std::string &getBase() const; + + std::unique_ptr<Request> request(ResourceType type, const std::string &url); + + void prepare(std::function<void()> fn); + + void retryAllPending(); + +private: + unsigned long thread_id; + + // Path to the cache database. + std::string path; + + // Stores a URL that is used as a base for loading resources with relative path. + std::string base; + + std::unordered_map<std::string, std::weak_ptr<BaseRequest>> pending; + util::ptr<SQLiteStore> store; + uv_loop_t *loop = nullptr; + uv_messenger_t *queue = nullptr; +}; + +} + +#endif diff --git a/include/mbgl/storage/file_source.hpp b/include/mbgl/storage/file_source.hpp index 3839ae22e1..9c5182397d 100644 --- a/include/mbgl/storage/file_source.hpp +++ b/include/mbgl/storage/file_source.hpp @@ -1,48 +1,25 @@ #ifndef MBGL_STORAGE_FILE_SOURCE #define MBGL_STORAGE_FILE_SOURCE +#include <mbgl/util/noncopyable.hpp> #include <mbgl/storage/resource_type.hpp> #include <mbgl/storage/request.hpp> -#include <mbgl/util/noncopyable.hpp> #include <string> -#include <unordered_map> #include <functional> typedef struct uv_loop_s uv_loop_t; -typedef struct uv_messenger_s uv_messenger_t; namespace mbgl { -class BaseRequest; -class SQLiteStore; - class FileSource : public util::noncopyable { -private: public: - FileSource(uv_loop_t *loop, const std::string &path); - ~FileSource(); - - // Stores and retrieves the base path/URL for relative requests - void setBase(const std::string &value); - const std::string &getBase() const; - - std::unique_ptr<Request> request(ResourceType type, const std::string &url); - - void prepare(std::function<void()> fn); - - void retryAllPending(); - -private: - const unsigned long thread_id; - - // Stores a URL that is used as a base for loading resources with relative path. - std::string base; - - std::unordered_map<std::string, std::weak_ptr<BaseRequest>> pending; - util::ptr<SQLiteStore> store; - uv_loop_t *loop = nullptr; - uv_messenger_t *queue = nullptr; + virtual void setLoop(uv_loop_t*) = 0; + virtual bool hasLoop() = 0; + virtual void setBase(const std::string &value) = 0; + virtual std::unique_ptr<Request> request(ResourceType type, const std::string &url) = 0; + virtual void prepare(std::function<void()> fn) = 0; + virtual void retryAllPending() = 0; }; } |