diff options
author | Leith Bade <leith@mapbox.com> | 2014-12-04 08:02:57 +1100 |
---|---|---|
committer | Leith Bade <leith@mapbox.com> | 2014-12-04 08:02:57 +1100 |
commit | 991a74774e1e835ff2277b3997d60f09245593dd (patch) | |
tree | f881149caec5f1e1a55a4e9900548f8a5e92bf0b /include | |
parent | 58833dd56a29d14afb7b40d8484328941d3d5020 (diff) | |
parent | 21b4f8c501d67ed8ecf6dedbdd55064a5c8f823c (diff) | |
download | qtlocation-mapboxgl-991a74774e1e835ff2277b3997d60f09245593dd.tar.gz |
Merge branch 'master' of github.com:mapbox/mapbox-gl-native into android-mason
Conflicts:
gyp/mbgl-ios.gypi
gyp/mbgl-linux.gypi
gyp/mbgl-osx.gypi
platform/default/caching_http_file_source.cpp
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 | ||||
-rw-r--r-- | include/mbgl/util/uv_detail.hpp | 20 |
4 files changed, 73 insertions, 40 deletions
diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index 2f81a2bd81..f222036bfa 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -34,7 +34,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. @@ -197,7 +197,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; }; } diff --git a/include/mbgl/util/uv_detail.hpp b/include/mbgl/util/uv_detail.hpp index 61a972c44f..055993db3e 100644 --- a/include/mbgl/util/uv_detail.hpp +++ b/include/mbgl/util/uv_detail.hpp @@ -14,8 +14,10 @@ namespace uv { template <class T> -void close(T* handle) { - uv_close(reinterpret_cast<uv_handle_t*>(handle), nullptr); +void close(std::unique_ptr<T> ptr) { + uv_close(reinterpret_cast<uv_handle_t*>(ptr.release()), [](uv_handle_t* handle) { + delete reinterpret_cast<T*>(handle); + }); } class thread : public mbgl::util::noncopyable { @@ -75,19 +77,21 @@ private: class async : public mbgl::util::noncopyable { public: inline async(uv_loop_t* loop, std::function<void ()> fn_) - : fn(fn_) { - a.data = this; - if (uv_async_init(loop, &a, async_cb) != 0) { + : a(new uv_async_t) + , fn(fn_) + { + a->data = this; + if (uv_async_init(loop, a.get(), async_cb) != 0) { throw std::runtime_error("failed to initialize async"); } } inline ~async() { - close(&a); + close(std::move(a)); } inline void send() { - if (uv_async_send(&a) != 0) { + if (uv_async_send(a.get()) != 0) { throw std::runtime_error("failed to async send"); } } @@ -101,7 +105,7 @@ private: reinterpret_cast<async*>(a->data)->fn(); } - uv_async_t a; + std::unique_ptr<uv_async_t> a; std::function<void ()> fn; }; |