summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2015-01-29 18:30:46 +0100
committerKonstantin Käfer <mail@kkaefer.com>2015-02-04 10:49:09 +0100
commit29baacf3a5bb773d94d08d16b81c3cda45a44eb6 (patch)
tree1dc3ca456151138ee5e8b7cf88b3afcecc3df1db /include
parent3d51e116a84ee168975bcee8377e9156f77e2731 (diff)
downloadqtlocation-mapboxgl-29baacf3a5bb773d94d08d16b81c3cda45a44eb6.tar.gz
refactor makefile
Diffstat (limited to 'include')
-rw-r--r--include/mbgl/android/jni.hpp6
-rw-r--r--include/mbgl/android/native_map_view.hpp8
-rw-r--r--include/mbgl/platform/platform.hpp3
-rw-r--r--include/mbgl/storage/asset_request_baton.hpp38
-rw-r--r--include/mbgl/storage/default/http_context.hpp61
-rw-r--r--include/mbgl/storage/default/request.hpp4
-rw-r--r--include/mbgl/storage/default/shared_request_base.hpp3
-rw-r--r--include/mbgl/storage/default/thread_context.hpp78
-rw-r--r--include/mbgl/storage/default_file_source.hpp (renamed from include/mbgl/storage/default/default_file_source.hpp)0
9 files changed, 104 insertions, 97 deletions
diff --git a/include/mbgl/android/jni.hpp b/include/mbgl/android/jni.hpp
index 5f71f697d0..698c024731 100644
--- a/include/mbgl/android/jni.hpp
+++ b/include/mbgl/android/jni.hpp
@@ -2,7 +2,11 @@
#define MBGL_ANDROID_JNI
#include <string>
-#include <jni.h>
+
+// Forward definition of JNI types
+typedef class _jclass* jclass;
+typedef struct _jmethodID* jmethodID;
+typedef struct _jfieldID* jfieldID;
namespace mbgl {
namespace android {
diff --git a/include/mbgl/android/native_map_view.hpp b/include/mbgl/android/native_map_view.hpp
index c1bd085e9d..bfe544c2b0 100644
--- a/include/mbgl/android/native_map_view.hpp
+++ b/include/mbgl/android/native_map_view.hpp
@@ -4,7 +4,8 @@
#include <mbgl/map/map.hpp>
#include <mbgl/map/view.hpp>
#include <mbgl/util/noncopyable.hpp>
-#include <mbgl/storage/caching_http_file_source.hpp>
+#include <mbgl/storage/default/sqlite_cache.hpp>
+#include <mbgl/storage/default_file_source.hpp>
#include <string>
#include <jni.h>
@@ -28,7 +29,7 @@ public:
void notifyMapChange(mbgl::MapChange change, std::chrono::steady_clock::duration delay = std::chrono::steady_clock::duration::zero()) override;
mbgl::Map &getMap();
- mbgl::CachingHTTPFileSource &getFileSource();
+ mbgl::DefaultFileSource &getFileSource();
void initializeDisplay();
void terminateDisplay();
@@ -61,7 +62,8 @@ private:
ANativeWindow *window = nullptr;
- mbgl::CachingHTTPFileSource fileSource;
+ mbgl::SQLiteCache fileCache;
+ mbgl::DefaultFileSource fileSource;
mbgl::Map map;
EGLDisplay display = EGL_NO_DISPLAY;
diff --git a/include/mbgl/platform/platform.hpp b/include/mbgl/platform/platform.hpp
index 7a6762cbcf..ea630c0956 100644
--- a/include/mbgl/platform/platform.hpp
+++ b/include/mbgl/platform/platform.hpp
@@ -20,6 +20,9 @@ std::string lowercase(const std::string &string);
// Returns the path to the root folder of the application.
const std::string &applicationRoot();
+// Returns the path to the asset location.
+const std::string &assetRoot();
+
// Shows an alpha image with the specified dimensions in a named window.
void show_debug_image(std::string name, const char *data, size_t width, size_t height);
diff --git a/include/mbgl/storage/asset_request_baton.hpp b/include/mbgl/storage/asset_request_baton.hpp
deleted file mode 100644
index 2cbb6c51c0..0000000000
--- a/include/mbgl/storage/asset_request_baton.hpp
+++ /dev/null
@@ -1,38 +0,0 @@
-#ifndef MBGL_STORAGE_ASSET_REQUEST_BATON
-#define MBGL_STORAGE_ASSET_REQUEST_BATON
-
-#include <mbgl/util/uv.hpp>
-#include <thread>
-
-#include <uv.h>
-
-namespace mbgl {
-
-class AssetRequest;
-
-struct AssetRequestBaton {
- AssetRequestBaton(AssetRequest *request_, const std::string &path, uv_loop_t *loop);
-
- const std::thread::id threadId;
- AssetRequest *request = nullptr;
- std::unique_ptr<uv::async> asyncRun;
- std::string path;
- bool canceled = false;
-
- void cancel();
- 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:
-
- // Called to load the asset. Platform-specific implementation.
- static void run(AssetRequestBaton *ptr);
-
-};
-
-
-}
-
-
-#endif
diff --git a/include/mbgl/storage/default/http_context.hpp b/include/mbgl/storage/default/http_context.hpp
index 18f17ef0cb..6b9518dab3 100644
--- a/include/mbgl/storage/default/http_context.hpp
+++ b/include/mbgl/storage/default/http_context.hpp
@@ -1,17 +1,9 @@
#ifndef MBGL_STORAGE_DEFAULT_HTTP_CONTEXT
#define MBGL_STORAGE_DEFAULT_HTTP_CONTEXT
+#include "thread_context.hpp"
#include <mbgl/storage/network_status.hpp>
-#include <mbgl/util/noncopyable.hpp>
-#include <mbgl/util/std.hpp>
-#include <mbgl/util/util.hpp>
-#include <mbgl/util/uv.hpp>
-#include <uv.h>
-#include <pthread.h>
-
-#include <map>
-#include <cassert>
#include <set>
namespace mbgl {
@@ -23,18 +15,7 @@ class HTTPRequest;
// triggers immediate retries on all requests waiting for network status changes.
template <typename Context>
-class HTTPContext : private util::noncopyable {
-protected:
- MBGL_STORE_THREAD(tid)
- using Map = std::map<uv_loop_t *, std::unique_ptr<Context>>;
-
-public:
- static Context *Get(uv_loop_t *loop);
-
-private:
- static pthread_key_t key;
- static pthread_once_t once;
-
+class HTTPContext : public ThreadContext<Context> {
public:
HTTPContext(uv_loop_t *loop);
~HTTPContext();
@@ -43,8 +24,6 @@ public:
void removeRequest(HTTPRequest *baton);
public:
- uv_loop_t *loop;
-
// Will be fired when the network status becomes reachable.
uv_async_t *reachability = nullptr;
@@ -54,35 +33,15 @@ public:
};
template <typename Context>
-Context *HTTPContext<Context>::Get(uv_loop_t *loop) {
- pthread_once(&once, []() {
- pthread_key_create(&key, [](void *ptr) {
- assert(ptr);
- delete reinterpret_cast<Map *>(ptr);
- });
- });
- auto contexts = reinterpret_cast<Map *>(pthread_getspecific(key));
- if (!contexts) {
- contexts = new Map();
- pthread_setspecific(key, contexts);
- }
-
- // Now find a HTTPContext that matches the requested loop.
- auto it = contexts->find(loop);
- if (it == contexts->end()) {
- auto result = contexts->emplace(loop, util::make_unique<Context>(loop));
- assert(result.second); // Make sure it was actually inserted.
- return result.first->second.get();
- } else {
- return it->second.get();
- }
-}
-
-template <typename Context>
-HTTPContext<Context>::HTTPContext(uv_loop_t *loop_) : loop(loop_) {
+HTTPContext<Context>::HTTPContext(uv_loop_t *loop_)
+ : ThreadContext<Context>(loop_) {
reachability = new uv_async_t;
reachability->data = this;
- uv_async_init(loop, reachability, [](uv_async_t *async, int) {
+#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10
+ uv_async_init(loop_, reachability, [](uv_async_t *async, int) {
+#else
+ uv_async_init(loop_, reachability, [](uv_async_t *async) {
+#endif
for (auto request : reinterpret_cast<Context *>(async->data)->requests) {
request->retryImmediately();
}
@@ -94,7 +53,7 @@ HTTPContext<Context>::HTTPContext(uv_loop_t *loop_) : loop(loop_) {
template <typename Context>
HTTPContext<Context>::~HTTPContext() {
- MBGL_VERIFY_THREAD(tid);
+ MBGL_VERIFY_THREAD(HTTPContext<Context>::tid);
assert(requests.empty());
diff --git a/include/mbgl/storage/default/request.hpp b/include/mbgl/storage/default/request.hpp
index 528a49f748..81ed14a568 100644
--- a/include/mbgl/storage/default/request.hpp
+++ b/include/mbgl/storage/default/request.hpp
@@ -33,8 +33,8 @@ public:
void cancel();
private:
- static void notifyCallback(uv_async_t *async, int);
- static void cancelCallback(uv_async_t *async, int);
+ static void notifyCallback(uv_async_t *async);
+ static void cancelCallback(uv_async_t *async);
private:
uv_async_t *notify_async = nullptr;
diff --git a/include/mbgl/storage/default/shared_request_base.hpp b/include/mbgl/storage/default/shared_request_base.hpp
index 8591d66ba3..a0f3e8d4e3 100644
--- a/include/mbgl/storage/default/shared_request_base.hpp
+++ b/include/mbgl/storage/default/shared_request_base.hpp
@@ -3,11 +3,10 @@
#include <mbgl/storage/resource.hpp>
#include <mbgl/storage/file_cache.hpp>
+#include <mbgl/storage/default_file_source.hpp>
#include <mbgl/util/util.hpp>
#include <mbgl/util/noncopyable.hpp>
-#include "default_file_source.hpp"
-
#include <string>
#include <set>
#include <cassert>
diff --git a/include/mbgl/storage/default/thread_context.hpp b/include/mbgl/storage/default/thread_context.hpp
new file mode 100644
index 0000000000..763c83a25b
--- /dev/null
+++ b/include/mbgl/storage/default/thread_context.hpp
@@ -0,0 +1,78 @@
+#ifndef MBGL_STORAGE_DEFAULT_THREAD_CONTEXT
+#define MBGL_STORAGE_DEFAULT_THREAD_CONTEXT
+
+#include <mbgl/util/noncopyable.hpp>
+#include <mbgl/util/std.hpp>
+#include <mbgl/util/util.hpp>
+#include <mbgl/util/uv.hpp>
+
+#include <uv.h>
+#include <pthread.h>
+
+#include <map>
+#include <cassert>
+
+namespace mbgl {
+
+// This is a template class that provides a per-thread and per-loop Context object. It can be used
+// by implementations to store global state.
+
+template <typename Context>
+class ThreadContext : private util::noncopyable {
+protected:
+ MBGL_STORE_THREAD(tid)
+ using Map = std::map<uv_loop_t *, std::unique_ptr<Context>>;
+
+public:
+ static Context *Get(uv_loop_t *loop);
+
+private:
+ static pthread_key_t key;
+ static pthread_once_t once;
+
+public:
+ ThreadContext(uv_loop_t *loop);
+ ~ThreadContext();
+
+public:
+ uv_loop_t *loop;
+};
+
+template <typename Context>
+Context *ThreadContext<Context>::Get(uv_loop_t *loop) {
+ pthread_once(&once, []() {
+ pthread_key_create(&key, [](void *ptr) {
+ assert(ptr);
+ delete reinterpret_cast<Map *>(ptr);
+ });
+ });
+ auto contexts = reinterpret_cast<Map *>(pthread_getspecific(key));
+ if (!contexts) {
+ contexts = new Map();
+ pthread_setspecific(key, contexts);
+ }
+
+ // Now find a ThreadContext that matches the requested loop.
+ auto it = contexts->find(loop);
+ if (it == contexts->end()) {
+ auto result = contexts->emplace(loop, util::make_unique<Context>(loop));
+ assert(result.second); // Make sure it was actually inserted.
+ return result.first->second.get();
+ } else {
+ return it->second.get();
+ }
+}
+
+template <typename Context>
+ThreadContext<Context>::ThreadContext(uv_loop_t *loop_) : loop(loop_) {
+}
+
+template <typename Context>
+ThreadContext<Context>::~ThreadContext() {
+ MBGL_VERIFY_THREAD(tid);
+}
+
+
+}
+
+#endif
diff --git a/include/mbgl/storage/default/default_file_source.hpp b/include/mbgl/storage/default_file_source.hpp
index 21048e99e5..21048e99e5 100644
--- a/include/mbgl/storage/default/default_file_source.hpp
+++ b/include/mbgl/storage/default_file_source.hpp