diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2014-12-17 12:14:32 +0100 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2014-12-17 12:14:32 +0100 |
commit | 936e09651424f111ac2ac64e2e60e2d13b082ebf (patch) | |
tree | 99b7b7bef00ac011805f5a87ea9ddaf06466fed0 | |
parent | 02e43c6d30553a676b912abe1391b82219290333 (diff) | |
download | qtlocation-mapboxgl-936e09651424f111ac2ac64e2e60e2d13b082ebf.tar.gz |
Make file request overridable by platform implementations
refs #579: Android can now rename AssetRequest to FileRequest and implement it differently
-rw-r--r-- | gyp/mbgl-ios.gypi | 2 | ||||
-rw-r--r-- | gyp/mbgl-linux.gypi | 2 | ||||
-rw-r--r-- | gyp/mbgl-osx.gypi | 2 | ||||
-rw-r--r-- | gyp/styles.gypi | 14 | ||||
-rw-r--r-- | include/mbgl/storage/file_request.hpp (renamed from src/mbgl/storage/file_request.hpp) | 2 | ||||
-rw-r--r-- | linux/main.cpp | 2 | ||||
-rw-r--r-- | linux/mapboxgl-app.gyp | 1 | ||||
-rw-r--r-- | platform/default/file_request_libuv.cpp (renamed from src/mbgl/storage/file_request_baton.cpp) | 51 | ||||
-rw-r--r-- | src/mbgl/storage/file_request.cpp | 37 | ||||
-rw-r--r-- | src/mbgl/storage/file_request_baton.hpp | 36 |
10 files changed, 70 insertions, 79 deletions
diff --git a/gyp/mbgl-ios.gypi b/gyp/mbgl-ios.gypi index df6896e1e7..da05619a34 100644 --- a/gyp/mbgl-ios.gypi +++ b/gyp/mbgl-ios.gypi @@ -40,9 +40,11 @@ '../platform/darwin/string_nsstring.mm', '../platform/darwin/http_request_baton_cocoa.mm', '../platform/darwin/image.mm', + '../platform/default/file_request_libuv.cpp', ], 'include_dirs': [ '../include', + '../src', ], 'xcode_settings': { 'OTHER_CPLUSPLUSFLAGS': [ '<@(uv_cflags)' ], diff --git a/gyp/mbgl-linux.gypi b/gyp/mbgl-linux.gypi index fdea368ae2..51df45ecc7 100644 --- a/gyp/mbgl-linux.gypi +++ b/gyp/mbgl-linux.gypi @@ -34,6 +34,7 @@ '../platform/default/shader_cache_tmp.cpp', '../platform/default/log_stderr.cpp', '../platform/default/string_stdlib.cpp', + '../platform/default/file_request_libuv.cpp', '../platform/default/http_request_baton_curl.cpp', '../platform/default/image.cpp', '../platform/default/image_reader.cpp', @@ -42,6 +43,7 @@ ], 'include_dirs': [ '../include', + '../src', ], 'link_settings': { 'libraries': [ diff --git a/gyp/mbgl-osx.gypi b/gyp/mbgl-osx.gypi index 4e8a131da5..cc6db2eb20 100644 --- a/gyp/mbgl-osx.gypi +++ b/gyp/mbgl-osx.gypi @@ -15,9 +15,11 @@ '../platform/darwin/string_nsstring.mm', '../platform/darwin/http_request_baton_cocoa.mm', '../platform/darwin/image.mm', + '../platform/default/file_request_libuv.cpp', ], 'include_dirs': [ '../include', + '../src', ], 'xcode_settings': { 'OTHER_CPLUSPLUSFLAGS': [ '<@(uv_cflags)' ], diff --git a/gyp/styles.gypi b/gyp/styles.gypi index 02cdea6e04..e1cd344fe1 100644 --- a/gyp/styles.gypi +++ b/gyp/styles.gypi @@ -18,9 +18,17 @@ 'type': 'none', 'hard_dependency': 1, 'dependencies': [ 'touch_styles' ], # required for xcode http://openradar.appspot.com/7232149 - 'direct_dependent_settings': { - 'mac_bundle_resources': [ '../styles/styles' ], - } + 'conditions': [ + ['OS == "mac"', { + 'direct_dependent_settings': { + 'mac_bundle_resources': [ '../styles/styles' ], + } + }, { + 'direct_dependent_settings': { + 'copies': [{ 'files': [ '../styles/styles' ], 'destination': '<(PRODUCT_DIR)' }], + } + }] + ], } ] } diff --git a/src/mbgl/storage/file_request.hpp b/include/mbgl/storage/file_request.hpp index 2f883728ff..3de2d5b60d 100644 --- a/src/mbgl/storage/file_request.hpp +++ b/include/mbgl/storage/file_request.hpp @@ -24,4 +24,4 @@ private: } -#endif
\ No newline at end of file +#endif diff --git a/linux/main.cpp b/linux/main.cpp index 42a98d0198..c5b2569ba3 100644 --- a/linux/main.cpp +++ b/linux/main.cpp @@ -83,7 +83,7 @@ int main(int argc, char *argv[]) { // Load style if (style.empty()) - style = std::string("file://") + uv::cwd() + std::string("/../../styles/styles/bright-v6.json"); + style = std::string("file://") + uv::cwd() + std::string("/styles/bright-v6.json"); map.setStyleURL(style); diff --git a/linux/mapboxgl-app.gyp b/linux/mapboxgl-app.gyp index fbeabd74ea..4127b5c278 100644 --- a/linux/mapboxgl-app.gyp +++ b/linux/mapboxgl-app.gyp @@ -48,6 +48,7 @@ 'dependencies': [ '../mapboxgl.gyp:mbgl-standalone', '../mapboxgl.gyp:mbgl-linux', + '../mapboxgl.gyp:bundle_styles', '../mapboxgl.gyp:copy_certificate_bundle', ], 'copies': [{ diff --git a/src/mbgl/storage/file_request_baton.cpp b/platform/default/file_request_libuv.cpp index 0a9c5f6f55..f874bed8d2 100644 --- a/src/mbgl/storage/file_request_baton.cpp +++ b/platform/default/file_request_libuv.cpp @@ -1,12 +1,34 @@ -#include <mbgl/storage/file_request_baton.hpp> #include <mbgl/storage/file_request.hpp> #include <mbgl/storage/response.hpp> #include <mbgl/util/std.hpp> +#include <uv.h> + #include <limits> namespace mbgl { +struct FileRequestBaton { + FileRequestBaton(FileRequest *request_, const std::string &path, uv_loop_t *loop); + ~FileRequestBaton(); + + void cancel(); + static void file_opened(uv_fs_t *req); + static void file_stated(uv_fs_t *req); + static void file_read(uv_fs_t *req); + static void file_closed(uv_fs_t *req); + static void notify_error(uv_fs_t *req); + static void cleanup(uv_fs_t *req); + + const std::thread::id thread_id; + FileRequest *request = nullptr; + uv_fs_t req; + uv_file fd = -1; + bool canceled = false; + std::string body; + uv_buf_t buffer; +}; + FileRequestBaton::FileRequestBaton(FileRequest *request_, const std::string &path, uv_loop_t *loop) : thread_id(std::this_thread::get_id()), request(request_) { req.data = this; @@ -157,4 +179,31 @@ void FileRequestBaton::cleanup(uv_fs_t *req) { delete ptr; } + +FileRequest::FileRequest(const std::string &path_, uv_loop_t *loop) + : BaseRequest(path_), ptr(new FileRequestBaton(this, path, loop)) { +} + +void FileRequest::cancel() { + assert(thread_id == std::this_thread::get_id()); + + if (ptr) { + ptr->cancel(); + + // When deleting a FileRequest object with a uv_fs_* call is in progress, we are making sure + // that the callback doesn't accidentally reference this object again. + ptr->request = nullptr; + ptr = nullptr; + } + + notify(); +} + +FileRequest::~FileRequest() { + assert(thread_id == std::this_thread::get_id()); + cancel(); + + // Note: The FileRequestBaton object is deleted in FileRequestBaton::cleanup(). +} + } diff --git a/src/mbgl/storage/file_request.cpp b/src/mbgl/storage/file_request.cpp deleted file mode 100644 index 9f74c7b414..0000000000 --- a/src/mbgl/storage/file_request.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include <mbgl/storage/file_request.hpp> -#include <mbgl/storage/file_request_baton.hpp> -#include <mbgl/storage/response.hpp> - -#include <uv.h> - -#include <cassert> - -#include <unistd.h> - -namespace mbgl { - -FileRequest::FileRequest(const std::string &path_, uv_loop_t *loop) - : BaseRequest(path_), ptr(new FileRequestBaton(this, path, loop)) { -} - -void FileRequest::cancel() { - assert(thread_id == std::this_thread::get_id()); - - if (ptr) { - ptr->cancel(); - - // When deleting a FileRequest object with a uv_fs_* call is in progress, we are making sure - // that the callback doesn't accidentally reference this object again. - ptr->request = nullptr; - ptr = nullptr; - } - - notify(); -} - -FileRequest::~FileRequest() { - assert(thread_id == std::this_thread::get_id()); - cancel(); -} - -} diff --git a/src/mbgl/storage/file_request_baton.hpp b/src/mbgl/storage/file_request_baton.hpp deleted file mode 100644 index 897c88061d..0000000000 --- a/src/mbgl/storage/file_request_baton.hpp +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef MBGL_STORAGE_FILE_REQUEST_BATON -#define MBGL_STORAGE_FILE_REQUEST_BATON - -#include <mbgl/storage/file_request.hpp> -#include <thread> - -#include <uv.h> - -namespace mbgl { - -struct FileRequestBaton { - FileRequestBaton(FileRequest *request_, const std::string &path, uv_loop_t *loop); - ~FileRequestBaton(); - - void cancel(); - static void file_opened(uv_fs_t *req); - static void file_stated(uv_fs_t *req); - static void file_read(uv_fs_t *req); - static void file_closed(uv_fs_t *req); - static void notify_error(uv_fs_t *req); - static void cleanup(uv_fs_t *req); - - const std::thread::id thread_id; - FileRequest *request = nullptr; - uv_fs_t req; - uv_file fd = -1; - bool canceled = false; - std::string body; - uv_buf_t buffer; -}; - - -} - - -#endif |