Make file request overridable by platform implementations
refs #579: Android can now rename AssetRequest to FileRequest and implement it differently
This commit is contained in:
@@ -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)' ],
|
||||
|
||||
@@ -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': [
|
||||
|
||||
@@ -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)' ],
|
||||
|
||||
@@ -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)' }],
|
||||
}
|
||||
}]
|
||||
],
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -24,4 +24,4 @@ private:
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
'dependencies': [
|
||||
'../mapboxgl.gyp:mbgl-standalone',
|
||||
'../mapboxgl.gyp:mbgl-linux',
|
||||
'../mapboxgl.gyp:bundle_styles',
|
||||
'../mapboxgl.gyp:copy_certificate_bundle',
|
||||
],
|
||||
'copies': [{
|
||||
|
||||
@@ -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().
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user