Fix commit
This commit is contained in:
@@ -418,7 +418,7 @@ void JNICALL nativeSetAccessToken(JNIEnv* env, jobject obj, jlong nativeMapViewP
|
||||
mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetAccessToken");
|
||||
assert(nativeMapViewPtr != 0);
|
||||
NativeMapView* nativeMapView = reinterpret_cast<NativeMapView*>(nativeMapViewPtr);
|
||||
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().setAccessToken(std_string_from_jstring(env, accessToken))));
|
||||
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getFileSource().setAccessToken(std_string_from_jstring(env, accessToken))));
|
||||
}
|
||||
|
||||
jstring JNICALL nativeGetAccessToken(JNIEnv* env, jobject obj, jlong nativeMapViewPtr) {
|
||||
@@ -426,7 +426,7 @@ jstring JNICALL nativeGetAccessToken(JNIEnv* env, jobject obj, jlong nativeMapVi
|
||||
assert(nativeMapViewPtr != 0);
|
||||
NativeMapView* nativeMapView = reinterpret_cast<NativeMapView*>(nativeMapViewPtr);
|
||||
jstring ret = nullptr;
|
||||
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, ret = std_string_to_jstring(env, nativeMapView->getMap().getAccessToken())));
|
||||
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, ret = std_string_to_jstring(env, nativeMapView->getFileSource().getAccessToken())));
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -699,7 +699,7 @@ void JNICALL nativeSetReachability(JNIEnv* env, jobject obj, jlong nativeMapView
|
||||
mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetReachability");
|
||||
assert(nativeMapViewPtr != 0);
|
||||
NativeMapView* nativeMapView = reinterpret_cast<NativeMapView*>(nativeMapViewPtr);
|
||||
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().setReachability(status)));
|
||||
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getFileSource().setReachability(status)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <mbgl/platform/platform.hpp>
|
||||
#include <mbgl/platform/event.hpp>
|
||||
#include <mbgl/platform/log.hpp>
|
||||
#include <mbgl/platform/gl.hpp>
|
||||
#include <mbgl/util/std.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
@@ -39,7 +39,6 @@
|
||||
'../platform/default/image_reader.cpp',
|
||||
'../platform/default/png_reader.cpp',
|
||||
'../platform/default/jpeg_reader.cpp',
|
||||
'../platform/default/caching_http_file_source.cpp',
|
||||
],
|
||||
'include_dirs': [
|
||||
'../include',
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <mbgl/map/map.hpp>
|
||||
#include <mbgl/map/view.hpp>
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
#include <mbgl/platform/default/caching_http_file_source.hpp>
|
||||
#include <mbgl/storage/caching_http_file_source.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <jni.h>
|
||||
@@ -44,6 +44,10 @@ public:
|
||||
return map;
|
||||
}
|
||||
|
||||
mbgl::CachingHTTPFileSource& getFileSource() {
|
||||
return fileSource;
|
||||
}
|
||||
|
||||
bool initializeDisplay();
|
||||
void terminateDisplay();
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#ifndef MBGL_STORAGE_ASSET_REQUEST_BATON
|
||||
#define MBGL_STORAGE_ASSET_REQUEST_BATON
|
||||
|
||||
#include <mbgl/storage/asset_request.hpp>
|
||||
#include <mbgl/util/uv.hpp>
|
||||
#include <thread>
|
||||
|
||||
@@ -9,6 +8,8 @@
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
class AssetRequest;
|
||||
|
||||
struct AssetRequestBaton {
|
||||
AssetRequestBaton(AssetRequest *request_, const std::string &path, uv_loop_t *loop);
|
||||
|
||||
@@ -19,7 +20,8 @@ struct AssetRequestBaton {
|
||||
bool canceled = false;
|
||||
|
||||
void cancel();
|
||||
static void notify_error(AssetRequestBaton *ptr, const int code, const char *message);
|
||||
static void notifyError(AssetRequestBaton *ptr, const int code, const char *message);
|
||||
static void notifySuccess(AssetRequestBaton *ptr, const std::string body);
|
||||
static void cleanup(AssetRequestBaton *ptr);
|
||||
|
||||
// IMPLEMENT THIS PLATFORM SPECIFIC FUNCTION:
|
||||
|
||||
@@ -29,6 +29,9 @@ public:
|
||||
// Set the Mapbox API access token
|
||||
void setAccessToken(std::string);
|
||||
|
||||
// Get the Mapbox API access token
|
||||
std::string getAccessToken() const;
|
||||
|
||||
std::unique_ptr<Request> request(ResourceType type, const std::string &url);
|
||||
|
||||
void prepare(std::function<void()> fn);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include <mbgl/mbgl.hpp>
|
||||
#include <mbgl/android/jni.hpp>
|
||||
#include <mbgl/storage/asset_request_baton.hpp>
|
||||
#include <mbgl/storage/asset_request.hpp>
|
||||
#include <mbgl/storage/response.hpp>
|
||||
#include <mbgl/util/std.hpp>
|
||||
|
||||
@@ -29,7 +29,7 @@ void AssetRequestBaton::run(AssetRequestBaton *ptr) {
|
||||
const int messageSize = zip_error_to_str(nullptr, 0, error, errno);
|
||||
const std::unique_ptr<char[]> message = mbgl::util::make_unique<char[]>(messageSize);
|
||||
zip_error_to_str(message.get(), 0, error, errno);
|
||||
notify_error(ptr, 500, message.get());
|
||||
notifyError(ptr, 500, message.get());
|
||||
cleanup(ptr);
|
||||
return;
|
||||
}
|
||||
@@ -40,7 +40,7 @@ void AssetRequestBaton::run(AssetRequestBaton *ptr) {
|
||||
// Opening the asset failed or was canceled. We already have an open file handle
|
||||
// though, which we'll have to close.
|
||||
zip_error_get(apk, &error, nullptr);
|
||||
notify_error(ptr, error == ZIP_ER_NOENT ? 404 : 500, zip_strerror(apk));
|
||||
notifyError(ptr, error == ZIP_ER_NOENT ? 404 : 500, zip_strerror(apk));
|
||||
zip_close(apk);
|
||||
apk = nullptr;
|
||||
cleanup(ptr);
|
||||
@@ -51,7 +51,7 @@ void AssetRequestBaton::run(AssetRequestBaton *ptr) {
|
||||
if ((zip_stat(apk, apkFilePath.c_str(), ZIP_FL_NOCASE, &stat) != 0) || ptr->canceled || !ptr->request) {
|
||||
// Stating failed or was canceled. We already have an open file handle
|
||||
// though, which we'll have to close.
|
||||
notify_error(ptr, 500, zip_strerror(apk));
|
||||
notifyError(ptr, 500, zip_strerror(apk));
|
||||
zip_fclose(apkFile);
|
||||
apkFile = nullptr;
|
||||
zip_close(apk);
|
||||
@@ -65,7 +65,7 @@ void AssetRequestBaton::run(AssetRequestBaton *ptr) {
|
||||
if (static_cast<zip_uint64_t>(zip_fread(apkFile, reinterpret_cast<void *>(data.get()), stat.size)) != stat.size || ptr->canceled || !ptr->request) {
|
||||
// Reading failed or was canceled. We already have an open file handle
|
||||
// though, which we'll have to close.
|
||||
notify_error(ptr, 500, zip_file_strerror(apkFile));
|
||||
notifyError(ptr, 500, zip_file_strerror(apkFile));
|
||||
zip_fclose(apkFile);
|
||||
apkFile = nullptr;
|
||||
zip_close(apk);
|
||||
@@ -74,13 +74,8 @@ void AssetRequestBaton::run(AssetRequestBaton *ptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (ptr->request) {
|
||||
ptr->request->response = std::unique_ptr<Response>(new Response);
|
||||
ptr->request->response->code = 200;
|
||||
std::string body(data.get(), stat.size);
|
||||
ptr->request->response->data = body;
|
||||
ptr->request->notify();
|
||||
}
|
||||
std::string body(data.get(), stat.size);
|
||||
notifySuccess(ptr, body);
|
||||
|
||||
if (zip_fclose(apkFile) != 0) {
|
||||
// Closing the asset failed. But there isn't anything we can do.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <mbgl/mbgl.hpp>
|
||||
#include <mbgl/storage/asset_request_baton.hpp>
|
||||
#include <mbgl/storage/asset_request.hpp>
|
||||
#include <mbgl/storage/response.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
@@ -15,7 +15,7 @@ void AssetRequestBaton::run(AssetRequestBaton *ptr) {
|
||||
}
|
||||
|
||||
// Just return a 500 error until implemented properly
|
||||
notify_error(ptr, 500, "Assets not implemented on this platform.");
|
||||
notifyError(ptr, 500, "Assets not implemented on this platform.");
|
||||
cleanup(ptr);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ void AssetRequestBaton::cancel() {
|
||||
canceled = true;
|
||||
}
|
||||
|
||||
void AssetRequestBaton::notify_error(AssetRequestBaton *ptr, const int code, const char *message) {
|
||||
void AssetRequestBaton::notifyError(AssetRequestBaton *ptr, const int code, const char *message) {
|
||||
assert(std::this_thread::get_id() == ptr->threadId);
|
||||
|
||||
if (ptr->request && !ptr->canceled) {
|
||||
@@ -33,6 +33,17 @@ void AssetRequestBaton::notify_error(AssetRequestBaton *ptr, const int code, con
|
||||
}
|
||||
}
|
||||
|
||||
void AssetRequestBaton::notifySuccess(AssetRequestBaton *ptr, const std::string body) {
|
||||
assert(std::this_thread::get_id() == ptr->threadId);
|
||||
|
||||
if (ptr->request && !ptr->canceled) {
|
||||
ptr->request->response = std::unique_ptr<Response>(new Response);
|
||||
ptr->request->response->code = 200;
|
||||
ptr->request->response->data = body;
|
||||
ptr->request->notify();
|
||||
}
|
||||
}
|
||||
|
||||
void AssetRequestBaton::cleanup(AssetRequestBaton *ptr) {
|
||||
assert(std::this_thread::get_id() == ptr->threadId);
|
||||
|
||||
@@ -64,8 +64,12 @@ void CachingHTTPFileSource::setAccessToken(std::string value) {
|
||||
accessToken.swap(value);
|
||||
}
|
||||
|
||||
std::string CachingHTTPFileSource::getAccessToken() const {
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
std::unique_ptr<Request> CachingHTTPFileSource::request(ResourceType type, const std::string& url_) {
|
||||
assert(tstd::this_thread::get_id() == threadId);
|
||||
assert(std::this_thread::get_id() == threadId);
|
||||
|
||||
std::string url = url_;
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace mbgl {
|
||||
FileRequestBaton::FileRequestBaton(FileRequest *request_, const std::string &path, uv_loop_t *loop)
|
||||
: threadId(std::this_thread::get_id()), request(request_) {
|
||||
req.data = this;
|
||||
uv_fs_open(loop, &req, path.c_str(), O_RDONLY, S_IRUSR, file_opened);
|
||||
uv_fs_open(loop, &req, path.c_str(), O_RDONLY, S_IRUSR, fileOpened);
|
||||
}
|
||||
|
||||
FileRequestBaton::~FileRequestBaton() {
|
||||
@@ -25,7 +25,7 @@ void FileRequestBaton::cancel() {
|
||||
uv_cancel((uv_req_t *)&req);
|
||||
}
|
||||
|
||||
void FileRequestBaton::notify_error(uv_fs_t *req) {
|
||||
void FileRequestBaton::notifyError(uv_fs_t *req) {
|
||||
FileRequestBaton *ptr = reinterpret_cast<FileRequestBaton *>(req->data);
|
||||
assert(std::this_thread::get_id() == ptr->threadId);
|
||||
|
||||
@@ -41,13 +41,13 @@ void FileRequestBaton::notify_error(uv_fs_t *req) {
|
||||
}
|
||||
}
|
||||
|
||||
void FileRequestBaton::file_opened(uv_fs_t *req) {
|
||||
void FileRequestBaton::fileOpened(uv_fs_t *req) {
|
||||
FileRequestBaton *ptr = reinterpret_cast<FileRequestBaton *>(req->data);
|
||||
assert(std::this_thread::get_id() == ptr->threadId);
|
||||
|
||||
if (req->result < 0) {
|
||||
// Opening failed or was canceled. There isn't much left we can do.
|
||||
notify_error(req);
|
||||
notifyError(req);
|
||||
cleanup(req);
|
||||
} else {
|
||||
const uv_file fd = uv_file(req->result);
|
||||
@@ -58,25 +58,25 @@ void FileRequestBaton::file_opened(uv_fs_t *req) {
|
||||
if (ptr->canceled || !ptr->request) {
|
||||
// Either the FileRequest object has been destructed, or the
|
||||
// request was canceled.
|
||||
uv_fs_close(req->loop, req, fd, file_closed);
|
||||
uv_fs_close(req->loop, req, fd, fileClosed);
|
||||
} else {
|
||||
ptr->fd = fd;
|
||||
uv_fs_fstat(req->loop, req, fd, file_stated);
|
||||
uv_fs_fstat(req->loop, req, fd, fileStated);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FileRequestBaton::file_stated(uv_fs_t *req) {
|
||||
void FileRequestBaton::fileStated(uv_fs_t *req) {
|
||||
FileRequestBaton *ptr = reinterpret_cast<FileRequestBaton *>(req->data);
|
||||
assert(std::this_thread::get_id() == ptr->threadId);
|
||||
|
||||
if (req->result != 0 || ptr->canceled || !ptr->request) {
|
||||
// Stating failed or was canceled. We already have an open file handle
|
||||
// though, which we'll have to close.
|
||||
notify_error(req);
|
||||
notifyError(req);
|
||||
|
||||
uv_fs_req_cleanup(req);
|
||||
uv_fs_close(req->loop, req, ptr->fd, file_closed);
|
||||
uv_fs_close(req->loop, req, ptr->fd, fileClosed);
|
||||
} else {
|
||||
#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10
|
||||
const uv_statbuf_t *stat = static_cast<const uv_statbuf_t *>(req->ptr);
|
||||
@@ -98,29 +98,29 @@ void FileRequestBaton::file_stated(uv_fs_t *req) {
|
||||
}
|
||||
|
||||
uv_fs_req_cleanup(req);
|
||||
uv_fs_close(req->loop, req, ptr->fd, file_closed);
|
||||
uv_fs_close(req->loop, req, ptr->fd, fileClosed);
|
||||
} else {
|
||||
const unsigned int size = (unsigned int)(stat->st_size);
|
||||
ptr->body.resize(size);
|
||||
ptr->buffer = uv_buf_init(const_cast<char *>(ptr->body.data()), size);
|
||||
uv_fs_req_cleanup(req);
|
||||
#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10
|
||||
uv_fs_read(req->loop, req, ptr->fd, ptr->buffer.base, ptr->buffer.len, -1, file_read);
|
||||
uv_fs_read(req->loop, req, ptr->fd, ptr->buffer.base, ptr->buffer.len, -1, fileRead);
|
||||
#else
|
||||
uv_fs_read(req->loop, req, ptr->fd, &ptr->buffer, 1, 0, file_read);
|
||||
uv_fs_read(req->loop, req, ptr->fd, &ptr->buffer, 1, 0, fileRead);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FileRequestBaton::file_read(uv_fs_t *req) {
|
||||
void FileRequestBaton::fileRead(uv_fs_t *req) {
|
||||
FileRequestBaton *ptr = reinterpret_cast<FileRequestBaton *>(req->data);
|
||||
assert(std::this_thread::get_id() == ptr->threadId);
|
||||
|
||||
if (req->result < 0 || ptr->canceled || !ptr->request) {
|
||||
// Reading failed or was canceled. We already have an open file handle
|
||||
// though, which we'll have to close.
|
||||
notify_error(req);
|
||||
notifyError(req);
|
||||
} else {
|
||||
// File was successfully read.
|
||||
if (ptr->request) {
|
||||
@@ -132,10 +132,10 @@ void FileRequestBaton::file_read(uv_fs_t *req) {
|
||||
}
|
||||
|
||||
uv_fs_req_cleanup(req);
|
||||
uv_fs_close(req->loop, req, ptr->fd, file_closed);
|
||||
uv_fs_close(req->loop, req, ptr->fd, fileClosed);
|
||||
}
|
||||
|
||||
void FileRequestBaton::file_closed(uv_fs_t *req) {
|
||||
void FileRequestBaton::fileClosed(uv_fs_t *req) {
|
||||
assert(std::this_thread::get_id() == reinterpret_cast<FileRequestBaton *>(req->data)->threadId);
|
||||
|
||||
if (req->result < 0) {
|
||||
|
||||
@@ -13,11 +13,11 @@ struct FileRequestBaton {
|
||||
~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 fileOpened(uv_fs_t *req);
|
||||
static void fileStated(uv_fs_t *req);
|
||||
static void fileRead(uv_fs_t *req);
|
||||
static void fileClosed(uv_fs_t *req);
|
||||
static void notifyError(uv_fs_t *req);
|
||||
static void cleanup(uv_fs_t *req);
|
||||
|
||||
const std::thread::id threadId;
|
||||
|
||||
Reference in New Issue
Block a user