Remove coffeecatch

This commit is contained in:
Leith Bade
2015-01-13 20:31:24 +11:00
parent 7cce089d78
commit 1daf2207aa
10 changed files with 62 additions and 3473 deletions

View File

@@ -1,23 +0,0 @@
Copyright (c) 2013, Xavier Roche (http://www.httrack.com/)
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,216 +0,0 @@
diff --git a/coffeecatch.c b/coffeecatch.c
index 448fe0f..f39fcdb 100644
--- a/coffeecatch.c
+++ b/coffeecatch.c
@@ -43,10 +43,7 @@
#include <assert.h>
#include <signal.h>
#include <setjmp.h>
-#if defined(__ANDROID__) && !defined(__BIONIC_HAVE_UCONTEXT_T) && \
- defined(__arm__) && !defined(__BIONIC_HAVE_STRUCT_SIGCONTEXT)
-#include <asm/sigcontext.h>
-#endif
+#include <sys/ucontext.h>
#if (defined(USE_UNWIND) && !defined(USE_CORKSCREW))
#include <unwind.h>
#endif
@@ -88,154 +85,34 @@ static const int native_sig_catch[SIG_CATCH_COUNT + 1]
/* Maximum value of a caught signal. */
#define SIG_NUMBER_MAX 32
-#if (defined(__ANDROID__) && (!defined(__BIONIC_HAVE_UCONTEXT_T)))
-#ifndef ucontext_h_seen
-#define ucontext_h_seen
-
-/* stack_t definition */
-#include <asm/signal.h>
-
-#if defined(__arm__)
-
-/* Taken from richard.quirk's header file. (Android does not have it) */
-
-typedef struct ucontext {
- unsigned long uc_flags;
- struct ucontext *uc_link;
- stack_t uc_stack;
- struct sigcontext uc_mcontext;
- unsigned long uc_sigmask;
-} ucontext_t;
-
-#elif defined(__i386__)
-
-/* Taken from Google Breakpad. */
-
-/* 80-bit floating-point register */
-struct _libc_fpreg {
- unsigned short significand[4];
- unsigned short exponent;
-};
-
-/* Simple floating-point state, see FNSTENV instruction */
-struct _libc_fpstate {
- unsigned long cw;
- unsigned long sw;
- unsigned long tag;
- unsigned long ipoff;
- unsigned long cssel;
- unsigned long dataoff;
- unsigned long datasel;
- struct _libc_fpreg _st[8];
- unsigned long status;
-};
-
-typedef uint32_t greg_t;
-
-typedef struct {
- uint32_t gregs[19];
- struct _libc_fpstate* fpregs;
- uint32_t oldmask;
- uint32_t cr2;
-} mcontext_t;
-
-enum {
- REG_GS = 0,
- REG_FS,
- REG_ES,
- REG_DS,
- REG_EDI,
- REG_ESI,
- REG_EBP,
- REG_ESP,
- REG_EBX,
- REG_EDX,
- REG_ECX,
- REG_EAX,
- REG_TRAPNO,
- REG_ERR,
- REG_EIP,
- REG_CS,
- REG_EFL,
- REG_UESP,
- REG_SS,
-};
-
-typedef struct ucontext {
- uint32_t uc_flags;
- struct ucontext* uc_link;
- stack_t uc_stack;
- mcontext_t uc_mcontext;
-} ucontext_t;
-
-#elif defined(__mips__)
-
-/* Taken from Google Breakpad. */
-
-typedef struct {
- uint32_t regmask;
- uint32_t status;
- uint64_t pc;
- uint64_t gregs[32];
- uint64_t fpregs[32];
- uint32_t acx;
- uint32_t fpc_csr;
- uint32_t fpc_eir;
- uint32_t used_math;
- uint32_t dsp;
- uint64_t mdhi;
- uint64_t mdlo;
- uint32_t hi1;
- uint32_t lo1;
- uint32_t hi2;
- uint32_t lo2;
- uint32_t hi3;
- uint32_t lo3;
-} mcontext_t;
-
-typedef struct ucontext {
- uint32_t uc_flags;
- struct ucontext* uc_link;
- stack_t uc_stack;
- mcontext_t uc_mcontext;
-} ucontext_t;
-
-#else
-#error "Architecture is not supported (unknown ucontext layout)"
-#endif
-
-#endif
-
#ifdef USE_CORKSCREW
typedef struct map_info_t map_info_t;
/* Extracted from Android's include/corkscrew/backtrace.h */
-typedef struct {
- uintptr_t absolute_pc;
- uintptr_t stack_top;
- size_t stack_size;
-} backtrace_frame_t;
-typedef struct {
- uintptr_t relative_pc;
- uintptr_t relative_symbol_addr;
- char* map_name;
- char* symbol_name;
- char* demangled_name;
+typedef struct {
+ uintptr_t absolute_pc;
+ uintptr_t stack_top;
+ size_t stack_size;
+} backtrace_frame_t;
+typedef struct {
+ uintptr_t relative_pc;
+ uintptr_t relative_symbol_addr;
+ char* map_name;
+ char* symbol_name;
+ char* demangled_name;
} backtrace_symbol_t;
/* Extracted from Android's libcorkscrew/arch-arm/backtrace-arm.c */
-typedef ssize_t (*t_unwind_backtrace_signal_arch)
-(siginfo_t* si, void* sc, const map_info_t* lst, backtrace_frame_t* bt,
-size_t ignore_depth, size_t max_depth);
-typedef map_info_t* (*t_acquire_my_map_info_list)();
-typedef void (*t_release_my_map_info_list)(map_info_t* milist);
-typedef void (*t_get_backtrace_symbols)(const backtrace_frame_t* backtrace,
+typedef ssize_t (*t_unwind_backtrace_signal_arch)
+(siginfo_t* si, void* sc, const map_info_t* lst, backtrace_frame_t* bt,
+size_t ignore_depth, size_t max_depth);
+typedef map_info_t* (*t_acquire_my_map_info_list)();
+typedef void (*t_release_my_map_info_list)(map_info_t* milist);
+typedef void (*t_get_backtrace_symbols)(const backtrace_frame_t* backtrace,
size_t frames,
backtrace_symbol_t* symbols);
typedef void (*t_free_backtrace_symbols)(backtrace_symbol_t* symbols,
size_t frames);
#endif
-#endif
-
/* Process-wide crash handler structure. */
typedef struct native_code_global_struct {
/* Initialized. */
@@ -341,7 +218,7 @@ static ssize_t coffeecatch_backtrace_signal(siginfo_t* si, void* sc,
&& acquire_my_map_info_list != NULL
&& release_my_map_info_list != NULL) {
map_info_t*const info = acquire_my_map_info_list();
- const ssize_t size =
+ const ssize_t size =
unwind_backtrace_signal_arch(si, sc, info, frames, ignore_depth,
max_depth);
release_my_map_info_list(info);
@@ -1073,12 +950,12 @@ static uintptr_t coffeecatch_get_pc_from_ucontext(const ucontext_t *uc) {
return uc->uc_mcontext.regs->nip;
#elif (defined(__hppa__))
return uc->uc_mcontext.sc_iaoq[0] & ~0x3UL;
-#elif (defined(__sparc__) && defined (__arch64__))
- return uc->uc_mcontext.mc_gregs[MC_PC];
-#elif (defined(__sparc__) && !defined (__arch64__))
- return uc->uc_mcontext.gregs[REG_PC];
-#elif (defined(__mips__))
- return uc->uc_mcontext.gregs[31];
+#elif (defined(__sparc__) && defined (__arch64__))
+ return uc->uc_mcontext.mc_gregs[MC_PC];
+#elif (defined(__sparc__) && !defined (__arch64__))
+ return uc->uc_mcontext.gregs[REG_PC];
+#elif (defined(__mips__))
+ return uc->uc_mcontext.gregs[31];
#else
#error "Architecture is unknown, please report me!"
#endif

View File

@@ -1,185 +0,0 @@
/* CoffeeCatch, a tiny native signal handler/catcher for JNI code.
* (especially for Android/Dalvik)
*
* Copyright (c) 2013, Xavier Roche (http://www.httrack.com/)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef COFFEECATCH_JNI_H
#define COFFEECATCH_JNI_H
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <sys/types.h>
#include <jni.h>
#include <assert.h>
#include <coffeecatch/coffeecatch.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct t_bt_fun {
JNIEnv* env;
jclass cls;
jclass cls_ste;
jmethodID cons_ste;
jobjectArray elements;
size_t size;
size_t index;
} t_bt_fun;
static char* bt_print(const char *function, uintptr_t offset) {
if (function != NULL) {
char buffer[256];
snprintf(buffer, sizeof(buffer), "%s:%p", function, (void*) offset);
return strdup(buffer);
} else {
return "<unknown>";
}
}
static char* bt_addr(uintptr_t addr) {
char buffer[32];
snprintf(buffer, sizeof(buffer), "%p", (void*) addr);
return strdup(buffer);
}
#define IS_VALID_CLASS_CHAR(C) ( \
((C) >= 'a' && (C) <= 'z') \
|| ((C) >= 'A' && (C) <= 'Z') \
|| ((C) >= '0' && (C) <= '9') \
|| (C) == '_' \
)
static char* bt_module(const char *module) {
if (module != NULL) {
size_t i;
char *copy;
if (*module == '/') {
module++;
}
copy = strdup(module);
/* Pseudo-java-class. */
for(i = 0; copy[i] != '\0'; i++) {
if (copy[i] == '/') {
copy[i] = '.';
} else if (!IS_VALID_CLASS_CHAR(copy[i])) {
copy[i] = '_';
}
}
return copy;
} else {
return "<unknown>";
}
}
static void bt_fun(void *arg, const char *module, uintptr_t addr,
const char *function, uintptr_t offset) {
t_bt_fun *const t = (t_bt_fun*) arg;
JNIEnv*const env = t->env;
jstring declaringClass = (*env)->NewStringUTF(env, bt_module(module));
jstring methodName = (*env)->NewStringUTF(env, bt_addr(addr));
jstring fileName = (*env)->NewStringUTF(env, bt_print(function, offset));
const int lineNumber = function != NULL ? 0 : -2; /* "-2" is "inside JNI code" */
jobject trace = (*env)->NewObject(env, t->cls_ste, t->cons_ste,
declaringClass, methodName, fileName,
lineNumber);
if (t->index < t->size) {
(*t->env)->SetObjectArrayElement(t->env, t->elements, t->index++, trace);
}
}
void coffeecatch_throw_exception(JNIEnv* env) {
jclass cls = (*env)->FindClass(env, "java/lang/Error");
jclass cls_ste = (*env)->FindClass(env, "java/lang/StackTraceElement");
jmethodID cons = (*env)->GetMethodID(env, cls, "<init>", "(Ljava/lang/String;)V");
jmethodID cons_cause = (*env)->GetMethodID(env, cls, "<init>", "(Ljava/lang/String;Ljava/lang/Throwable;)V");
jmethodID cons_ste = (*env)->GetMethodID(env, cls_ste, "<init>",
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I)V");
jmethodID meth_sste = (*env)->GetMethodID(env, cls, "setStackTrace",
"([Ljava/lang/StackTraceElement;)V");
/* Exception message. */
const char*const message = coffeecatch_get_message();
jstring str = (*env)->NewStringUTF(env, strdup(message));
/* Final exception. */
jthrowable exception;
/* Add pseudo-stack trace. */
const ssize_t bt_size = coffeecatch_get_backtrace_size();
assert(cls != NULL);
assert(cls_ste != NULL);
assert(cons != NULL);
assert(cons_cause != NULL);
assert(cons_ste != NULL);
assert(meth_sste != NULL);
assert(message != NULL);
assert(str != NULL);
/* Can we produce a stack trace ? */
if (bt_size > 0) {
/* Create secondary exception. */
jthrowable cause = (jthrowable) (*env)->NewObject(env, cls, cons, str);
/* Stack trace. */
jobjectArray elements =
(*env)->NewObjectArray(env, bt_size, cls_ste, NULL);
if (elements != NULL) {
t_bt_fun t;
t.env = env;
t.cls = cls;
t.cls_ste = cls_ste;
t.cons_ste = cons_ste;
t.elements = elements;
t.index = 0;
t.size = bt_size;
coffeecatch_get_backtrace_info(bt_fun, &t);
(*env)->CallVoidMethod(env, cause, meth_sste, elements);
}
/* Primary exception */
exception = (jthrowable) (*env)->NewObject(env, cls, cons_cause, str, cause);
} else {
/* Simple exception */
exception = (jthrowable) (*env)->NewObject(env, cls, cons, str);
}
/* Throw exception. */
if (exception != NULL) {
(*env)->Throw(env, exception);
} else {
(*env)->ThrowNew(env, cls, strdup(message));
}
}
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -12,8 +12,6 @@
#include <android/native_window_jni.h>
#include <sys/system_properties.h>
#include <coffeecatch/coffeejni.h>
#include <mbgl/android/jni.hpp>
#include <mbgl/android/native_map_view.hpp>
#include <mbgl/map/map.hpp>
@@ -23,16 +21,6 @@
#pragma clang diagnostic ignored "-Wunused-parameter"
#define CPP_TRY_JNI(ENV, CODE) \
try { \
CODE; \
} \
catch (std::exception e) { \
std::string msg("Unhandled C++ exception: "); \
msg.append(e.what()); \
throw_error(ENV, msg.c_str()); \
}
namespace mbgl {
namespace android {
@@ -185,12 +173,7 @@ nativeCreate(JNIEnv *env, jobject obj, jstring cachePath_, jstring dataPath_, js
cachePath = std_string_from_jstring(env, cachePath_);
dataPath = std_string_from_jstring(env, dataPath_);
apkPath = std_string_from_jstring(env, apkPath_);
NativeMapView *nativeMapView = nullptr;
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView = new NativeMapView(env, obj)));
if (nativeMapView == nullptr) {
throw_error(env, "Unable to create NativeMapView.");
return 0;
}
NativeMapView *nativeMapView = new NativeMapView(env, obj);
jlong mapViewPtr = reinterpret_cast<jlong>(nativeMapView);
return mapViewPtr;
}
@@ -207,9 +190,7 @@ void JNICALL nativeInitializeDisplay(JNIEnv *env, jobject obj, jlong nativeMapVi
mbgl::Log::Debug(mbgl::Event::JNI, "nativeInitializeDisplay");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
bool ret = false;
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, ret = nativeMapView->initializeDisplay()));
if (!ret) {
if (!nativeMapView->initializeDisplay()) {
throw_error(env, "Unable to initialize GL display.");
}
}
@@ -218,16 +199,14 @@ void JNICALL nativeTerminateDisplay(JNIEnv *env, jobject obj, jlong nativeMapVie
mbgl::Log::Debug(mbgl::Event::JNI, "nativeTerminateDisplay");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->terminateDisplay()));
nativeMapView->terminateDisplay();
}
void JNICALL nativeInitializeContext(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeInitializeContext");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
bool ret = false;
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, ret = nativeMapView->initializeContext()));
if (!ret) {
if (!nativeMapView->initializeContext()) {
throw_error(env, "Unable to initialize GL context.");
}
}
@@ -236,7 +215,7 @@ void JNICALL nativeTerminateContext(JNIEnv *env, jobject obj, jlong nativeMapVie
mbgl::Log::Debug(mbgl::Event::JNI, "nativeTerminateContext");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->terminateContext()));
nativeMapView->terminateContext();
}
void JNICALL
@@ -244,10 +223,8 @@ nativeCreateSurface(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jobject su
mbgl::Log::Debug(mbgl::Event::JNI, "nativeCreateSurface");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
bool ret = false;
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, ret = nativeMapView->createSurface(
ANativeWindow_fromSurface(env, surface))));
if (!ret) {
if (!nativeMapView->createSurface(ANativeWindow_fromSurface(env, surface))) {
throw_error(env, "Unable to create GL surface.");
}
}
@@ -256,79 +233,77 @@ void JNICALL nativeDestroySurface(JNIEnv *env, jobject obj, jlong nativeMapViewP
mbgl::Log::Debug(mbgl::Event::JNI, "nativeDestroySurface");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->destroySurface()));
nativeMapView->destroySurface();
}
void JNICALL nativeStart(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeStart");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->start()));
nativeMapView->start();
}
void JNICALL nativeStop(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeStop");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->stop()));
nativeMapView->stop();
}
void JNICALL nativePause(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativePause");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->pause()));
nativeMapView->pause();
}
void JNICALL nativeResume(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeResume");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->resume()));
nativeMapView->resume();
}
void JNICALL nativeRun(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeRun");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().run()));
nativeMapView->getMap().run();
}
void JNICALL nativeRerender(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeRerender");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().rerender()));
nativeMapView->getMap().rerender();
}
void JNICALL nativeUpdate(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeUpdate");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().update()));
nativeMapView->getMap().update();
}
void JNICALL nativeTerminate(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeTerminate");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().terminate()));
nativeMapView->getMap().terminate();
}
jboolean JNICALL nativeNeedsSwap(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeNeedsSwap");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
jboolean ret = false;
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, ret = nativeMapView->getMap().needsSwap()));
return ret;
return nativeMapView->getMap().needsSwap();
}
void JNICALL nativeSwapped(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeSwapped");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, (nativeMapView->getMap().swapped())));
nativeMapView->getMap().swapped();
}
void JNICALL nativeResize(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jint width, jint height,
@@ -340,7 +315,7 @@ void JNICALL nativeResize(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jint
assert(width <= UINT16_MAX);
assert(height <= UINT16_MAX);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().resize(width, height, ratio)));
nativeMapView->getMap().resize(width, height, ratio);
}
void JNICALL nativeResize(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jint width, jint height,
@@ -356,8 +331,7 @@ void JNICALL nativeResize(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jint
assert(fbWidth <= UINT16_MAX);
assert(fbHeight <= UINT16_MAX);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().resize(width, height, ratio,
fbWidth, fbHeight)));
nativeMapView->getMap().resize(width, height, ratio, fbWidth, fbHeight);
}
void JNICALL
@@ -365,18 +339,14 @@ nativeSetAppliedClasses(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jobjec
mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetAppliedClasses");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().setAppliedClasses(
std_vector_string_from_jobject(env, classes))));
nativeMapView->getMap().setAppliedClasses(std_vector_string_from_jobject(env, classes));
}
jobject JNICALL nativeGetAppliedClasses(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeGetAppliedClasses");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
jobject ret = nullptr;
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, ret = std_vector_string_to_jobject(
env, nativeMapView->getMap().getAppliedClasses())));
return ret;
return std_vector_string_to_jobject(env, nativeMapView->getMap().getAppliedClasses());
}
void JNICALL nativeSetDefaultTransitionDuration(JNIEnv *env, jobject obj, jlong nativeMapViewPtr,
@@ -385,26 +355,21 @@ void JNICALL nativeSetDefaultTransitionDuration(JNIEnv *env, jobject obj, jlong
assert(nativeMapViewPtr != 0);
assert(milliseconds >= 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
COFFEE_TRY_JNI(
env, CPP_TRY_JNI(env, nativeMapView->getMap().setDefaultTransitionDuration(milliseconds)));
nativeMapView->getMap().setDefaultTransitionDuration(milliseconds);
}
jlong JNICALL nativeGetDefaultTransitionDuration(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeGetDefaultTransitionDuration");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
jlong ret = 0;
COFFEE_TRY_JNI(env,
CPP_TRY_JNI(env, ret = nativeMapView->getMap().getDefaultTransitionDuration()));
return ret;
return nativeMapView->getMap().getDefaultTransitionDuration();
}
void JNICALL nativeSetStyleURL(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jstring url) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetStyleURL");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().setStyleURL(
std_string_from_jstring(env, url))));
nativeMapView->getMap().setStyleURL(std_string_from_jstring(env, url));
}
void JNICALL nativeSetStyleJSON(JNIEnv *env, jobject obj, jlong nativeMapViewPtr,
@@ -412,19 +377,15 @@ void JNICALL nativeSetStyleJSON(JNIEnv *env, jobject obj, jlong nativeMapViewPtr
mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetStyleJSON");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().setStyleJSON(
std_string_from_jstring(env, newStyleJson),
std_string_from_jstring(env, base))));
nativeMapView->getMap().setStyleJSON(std_string_from_jstring(env, newStyleJson),
std_string_from_jstring(env, base));
}
jstring JNICALL nativeGetStyleJSON(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeGetStyleJSON");
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().getStyleJSON())));
return ret;
return std_string_to_jstring(env, nativeMapView->getMap().getStyleJSON());
}
void JNICALL
@@ -432,26 +393,21 @@ nativeSetAccessToken(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jstring a
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->getFileSource().setAccessToken(
std_string_from_jstring(env, accessToken))));
nativeMapView->getFileSource().setAccessToken(std_string_from_jstring(env, accessToken));
}
jstring JNICALL nativeGetAccessToken(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeGetAccessToken");
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->getFileSource().getAccessToken())));
return ret;
return std_string_to_jstring(env, nativeMapView->getFileSource().getAccessToken());
}
void JNICALL nativeCancelTransitions(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeCancelTransitions");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().cancelTransitions()));
nativeMapView->getMap().cancelTransitions();
}
void JNICALL nativeMoveBy(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jdouble dx, jdouble dy,
@@ -459,7 +415,7 @@ void JNICALL nativeMoveBy(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jdou
mbgl::Log::Debug(mbgl::Event::JNI, "nativeMoveBy");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().moveBy(dx, dy, duration)));
nativeMapView->getMap().moveBy(dx, dy, duration);
}
void JNICALL nativeSetLonLat(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jobject lonLat,
@@ -480,7 +436,7 @@ void JNICALL nativeSetLonLat(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, j
return;
}
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().setLonLat(lon, lat, duration)));
nativeMapView->getMap().setLonLat(lon, lat, duration);
}
jobject JNICALL nativeGetLonLat(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
@@ -488,7 +444,7 @@ jobject JNICALL nativeGetLonLat(JNIEnv *env, jobject obj, jlong nativeMapViewPtr
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
double lon = 0.0, lat = 0.0;
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().getLonLat(lon, lat)));
nativeMapView->getMap().getLonLat(lon, lat);
jobject ret = env->NewObject(lonLatClass, lonLatConstructorId, lon, lat);
if (ret == nullptr) {
@@ -503,21 +459,21 @@ void JNICALL nativeStartPanning(JNIEnv *env, jobject obj, jlong nativeMapViewPtr
mbgl::Log::Debug(mbgl::Event::JNI, "nativeStartPanning");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().startPanning()));
nativeMapView->getMap().startPanning();
}
void JNICALL nativeStopPanning(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeStopPanning");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().stopPanning()));
nativeMapView->getMap().stopPanning();
}
void JNICALL nativeResetPosition(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeResetPosition");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().resetPosition()));
nativeMapView->getMap().resetPosition();
}
void JNICALL nativeScaleBy(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jdouble ds, jdouble cx,
@@ -525,7 +481,7 @@ void JNICALL nativeScaleBy(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jdo
mbgl::Log::Debug(mbgl::Event::JNI, "nativeScaleBy");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().scaleBy(ds, cx, cy, duration)));
nativeMapView->getMap().scaleBy(ds, cx, cy, duration);
}
void JNICALL nativeSetScale(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jdouble scale,
@@ -533,17 +489,14 @@ void JNICALL nativeSetScale(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jd
mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetScale");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
COFFEE_TRY_JNI(env,
CPP_TRY_JNI(env, nativeMapView->getMap().setScale(scale, cx, cy, duration)));
nativeMapView->getMap().setScale(scale, cx, cy, duration);
}
jdouble JNICALL nativeGetScale(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeGetScale");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
jdouble ret = 0.0;
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, ret = nativeMapView->getMap().getScale()));
return ret;
return nativeMapView->getMap().getScale();
}
void JNICALL
@@ -551,16 +504,14 @@ nativeSetZoom(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jdouble zoom, jd
mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetZoom");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().setZoom(zoom, duration)));
nativeMapView->getMap().setZoom(zoom, duration);
}
jdouble JNICALL nativeGetZoom(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeGetZoom");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
jdouble ret = 0.0;
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, ret = nativeMapView->getMap().getZoom()));
return ret;
return nativeMapView->getMap().getZoom();
}
void JNICALL nativeSetLonLatZoom(JNIEnv *env, jobject obj, jlong nativeMapViewPtr,
@@ -587,8 +538,7 @@ void JNICALL nativeSetLonLatZoom(JNIEnv *env, jobject obj, jlong nativeMapViewPt
return;
}
COFFEE_TRY_JNI(
env, CPP_TRY_JNI(env, nativeMapView->getMap().setLonLatZoom(lon, lat, zoom, duration)));
nativeMapView->getMap().setLonLatZoom(lon, lat, zoom, duration);
}
jobject JNICALL nativeGetLonLatZoom(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
@@ -596,7 +546,7 @@ jobject JNICALL nativeGetLonLatZoom(JNIEnv *env, jobject obj, jlong nativeMapVie
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
double lon = 0.0, lat = 0.0, zoom = 0.0;
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().getLonLatZoom(lon, lat, zoom)));
nativeMapView->getMap().getLonLatZoom(lon, lat, zoom);
jobject ret = env->NewObject(lonLatZoomClass, lonLatZoomConstructorId, lon, lat, zoom);
if (ret == nullptr) {
@@ -611,39 +561,35 @@ void JNICALL nativeResetZoom(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeResetZoom");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().resetZoom()));
nativeMapView->getMap().resetZoom();
}
void JNICALL nativeStartScaling(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeStartScaling");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().startScaling()));
nativeMapView->getMap().startScaling();
}
void JNICALL nativeStopScaling(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeStopScaling");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().stopScaling()));
return nativeMapView->getMap().stopScaling();
}
jdouble JNICALL nativeGetMinZoom(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeGetMinZoom");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
jdouble ret = 0.0;
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, ret = nativeMapView->getMap().getMinZoom()));
return ret;
return nativeMapView->getMap().getMinZoom();
}
jdouble JNICALL nativeGetMaxZoom(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeGetMaxZoom");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
jdouble ret = 0.0;
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, ret = nativeMapView->getMap().getMaxZoom()));
return ret;
return nativeMapView->getMap().getMaxZoom();
}
void JNICALL nativeRotateBy(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jdouble sx,
@@ -651,8 +597,7 @@ void JNICALL nativeRotateBy(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jd
mbgl::Log::Debug(mbgl::Event::JNI, "nativeRotateBy");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
COFFEE_TRY_JNI(env,
CPP_TRY_JNI(env, nativeMapView->getMap().rotateBy(sx, sy, ex, ey, duration)));
nativeMapView->getMap().rotateBy(sx, sy, ex, ey, duration);
}
void JNICALL nativeSetBearing(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jdouble degrees,
@@ -660,7 +605,7 @@ void JNICALL nativeSetBearing(JNIEnv *env, jobject obj, jlong nativeMapViewPtr,
mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetBearing");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().setBearing(degrees, duration)));
nativeMapView->getMap().setBearing(degrees, duration);
}
void JNICALL nativeSetBearing(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jdouble degrees,
@@ -668,62 +613,58 @@ void JNICALL nativeSetBearing(JNIEnv *env, jobject obj, jlong nativeMapViewPtr,
mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetBearing");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().setBearing(degrees, cx, cy)));
nativeMapView->getMap().setBearing(degrees, cx, cy);
}
jdouble JNICALL nativeGetBearing(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeGetBearing");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
jdouble ret = 0.0;
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, ret = nativeMapView->getMap().getBearing()));
return ret;
return nativeMapView->getMap().getBearing();
}
void JNICALL nativeResetNorth(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeResetNorth");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().resetNorth()));
nativeMapView->getMap().resetNorth();
}
void JNICALL nativeStartRotating(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeStartRotating");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().startRotating()));
nativeMapView->getMap().startRotating();
}
void JNICALL nativeStopRotating(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeStopRotating");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().stopRotating()));
nativeMapView->getMap().stopRotating();
}
void JNICALL nativeSetDebug(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jboolean debug) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetDebug");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().setDebug(debug);
nativeMapView->enableFps(debug)));
nativeMapView->getMap().setDebug(debug);
nativeMapView->enableFps(debug);
}
void JNICALL nativeToggleDebug(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeToggleDebug");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, nativeMapView->getMap().toggleDebug();
nativeMapView->enableFps(nativeMapView->getMap().getDebug())));
nativeMapView->getMap().toggleDebug();
nativeMapView->enableFps(nativeMapView->getMap().getDebug());
}
jboolean JNICALL nativeGetDebug(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeGetDebug");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
jboolean ret = false;
COFFEE_TRY_JNI(env, CPP_TRY_JNI(env, ret = nativeMapView->getMap().getDebug()));
return ret;
return nativeMapView->getMap().getDebug();
}
void JNICALL
@@ -731,7 +672,7 @@ nativeSetReachability(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jboolean
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->getFileSource().setReachability(status)));
nativeMapView->getFileSource().setReachability(status);
}
}

View File

@@ -10,8 +10,6 @@
'sources': [
'./cpp/native_map_view.cpp',
'./cpp/jni.cpp',
'./cpp/coffeecatch.c',
'./cpp/coffeejni.c',
],
'cflags_cc': [
'-I<(boost_root)/include',

View File

@@ -1,226 +0,0 @@
/* CoffeeCatch, a tiny native signal handler/catcher for JNI code.
* (especially for Android/Dalvik)
*
* Copyright (c) 2013, Xavier Roche (http://www.httrack.com/)
* All rights reserved.
* See the "License" section below for the licensing terms.
*
* Description:
*
* Allows to "gracefully" recover from a signal (segv, sibus...) as if it was
* a Java exception. It will not gracefully recover from allocator/mutexes
* corruption etc., however, but at least "most" gentle crashes (null pointer
* dereferencing, integer division, stack overflow etc.) should be handled
* without too much troubles.
*
* The handler is thread-safe, but client must have exclusive control on the
* signal handlers (ie. the library is installing its own signal handlers on
* top of the existing ones).
*
* You must build all your libraries with `-funwind-tables', to get proper
* unwinding information on all binaries. On ARM, you may also use the
* `--no-merge-exidx-entries` linker switch, to solve certain issues with
* unwinding (the switch is possibly not needed anymore).
* On Android, this can be achieved by using this line in the Android.mk file
* in each library block:
* LOCAL_CFLAGS := -funwind-tables -Wl,--no-merge-exidx-entries
*
* Example:
*
* COFFEE_TRY() {
* call_some_native_function()
* } COFFEE_CATCH() {
* const char*const message = coffeecatch_get_message();
* jclass cls = (*env)->FindClass(env, "java/lang/RuntimeException");
* (*env)->ThrowNew(env, cls, strdup(message));
* } COFFEE_END();
*
* Implementation notes:
*
* Currently the library is installing both alternate stack and signal
* handlers for known signals (SIGABRT, SIGILL, SIGTRAP, SIGBUS, SIGFPE,
* SIGSEGV, SIGSTKFLT), and is using sigsetjmp()/siglongjmp() to return to
* "userland" (compared to signal handler context). As a security, an alarm
* is started as soon as a fatal signal is detected (ie. not something the
* JVM will handle) to kill the process after a grace period. Be sure your
* program will exit quickly after the error is caught, or call alarm(0)
* to cancel the pending time-bomb.
* The signal handlers had to be written with caution, because the virtual
* machine might be using signals (including SEGV) to handle JIT compiler,
* and some clever optimizations (such as NullPointerException handling)
* We are using several signal-unsafe functions, namely:
* - siglongjmp() to return to userland
* - pthread_getspecific() to get thread-specific setup
*
* License:
*
* Copyright (c) 2013, Xavier Roche (http://www.httrack.com/)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef COFFEECATCH_H
#define COFFEECATCH_H
#include <stdint.h>
#include <sys/types.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* Setup crash handler to enter in a protected section. If a recognized signal
* is received in this section, the execution will be diverted to the
* COFFEE_CATCH() block.
*
* Note: you MUST use the following pattern when using this macro:
* COFFEE_TRY() {
* .. protected section without exit point
* } COFFEE_CATCH() {
* .. handler section without exit point
* } COFFEE_END();
*
* You can not exit the protected section block, or the handler section block,
* using statements such as "return", because the cleanup code would not be
* executed.
*
* It is advised to enclose this complete try/catch/end block in a dedicated
* function declared extern or __attribute__ ((noinline)).
*
* Example:
*
* void my_native_function(JNIEnv* env, jobject object, jint *retcode) {
* COFFEE_TRY() {
* *retcode = call_dangerous_function(env, object);
* } COFFEE_CATCH() {
* const char*const message = coffeecatch_get_message();
* jclass cls = (*env)->FindClass(env, "java/lang/RuntimeException");
* (*env)->ThrowNew(env, cls, strdup(message));
* *retcode = -1;
* } COFFEE_END();
* }
*
* In addition, the following restrictions MUST be followed:
* - the function must be declared extern, or with the special attribute
* __attribute__ ((noinline)).
* - you must not use local variables before the complete try/catch/end block,
* or define them as "volatile".
* - your function should not ignore the crash silently, as the library will
* ensure the process is killed after a grace period (typically 30s) to
* prevent any deadlock that may occur if the crash was caught inside a
* non-signal-safe function, for example (such as malloc()).
*
COFFEE_TRY()
**/
/**
* Declare the signal handler block. This block will be executed if a signal
* was received, and recognized, in the previous COFFEE_TRY() {} section.
* You may call audit functions in this block, such as coffeecatch_get_signal()
* or coffeecatch_get_message().
*
COFFEE_CATCH()
**/
/**
* Declare the end of the COFFEE_TRY()/COFFEE_CATCH() section.
* Diagnostic functions must not be called beyond this point.
*
COFFEE_END()
**/
/**
* Get the signal associated with the crash.
* This function can only be called inside a COFFEE_CATCH() block.
*/
extern int coffeecatch_get_signal(void);
/**
* Get the full error message associated with the crash.
* This function can only be called inside a COFFEE_CATCH() block, and the
* returned pointer is only valid within this block. (you may want to copy
* the string in a static buffer, or use strdup())
*/
const char* coffeecatch_get_message(void);
/**
* Raise an abort() signal in the current thread. If the current code section
* is protected, the 'exp', 'file' and 'line' information are stored for
* further audit.
*/
extern void coffeecatch_abort(const char* exp, const char* file, int line);
/**
* Assertion check. If the expression is false, an abort() signal is raised
* using coffeecatch_abort().
*/
#define coffeecatch_assert(EXP) (void)( (EXP) || (coffeecatch_abort(#EXP, __FILE__, __LINE__), 0) )
/**
* Get the backtrace size, or 0 upon error.
* This function can only be called inside a COFFEE_CATCH() block.
*/
extern size_t coffeecatch_get_backtrace_size(void);
/**
* Get the backtrace pointer, or 0 upon error.
* This function can only be called inside a COFFEE_CATCH() block.
*/
extern uintptr_t coffeecatch_get_backtrace(ssize_t index);
/**
* Enumerate the backtrace with information.
* This function can only be called inside a COFFEE_CATCH() block.
*/
extern void coffeecatch_get_backtrace_info(void (*fun)(void *arg,
const char *module,
uintptr_t addr,
const char *function,
uintptr_t offset), void *arg);
/**
* Cancel any pending alarm() triggered after a signal was caught.
* Calling this function is dangerous, because it exposes the process to
* a possible deadlock if the signal was caught due to internal low-level
* library error (mutex being in a locked state, for example).
*/
extern int coffeecatch_cancel_pending_alarm(void);
/** Internal functions & definitions, not to be used directly. **/
#include <setjmp.h>
extern int coffeecatch_setup(void);
extern sigjmp_buf* coffeecatch_get_ctx(void);
extern void coffeecatch_cleanup(void);
#define COFFEE_TRY() \
if (coffeecatch_setup() == 0 \
&& sigsetjmp(*coffeecatch_get_ctx(), 1) == 0)
#define COFFEE_CATCH() else
#define COFFEE_END() coffeecatch_cleanup()
/** End of internal functions & definitions. **/
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -1,133 +0,0 @@
/* CoffeeCatch, a tiny native signal handler/catcher for JNI code.
* (especially for Android/Dalvik)
*
* Copyright (c) 2013, Xavier Roche (http://www.httrack.com/)
* All rights reserved.
* See the "License" section below for the licensing terms.
*
* Description:
*
* Allows to "gracefully" recover from a signal (segv, sibus...) as if it was
* a Java exception. It will not gracefully recover from allocator/mutexes
* corruption etc., however, but at least "most" gentle crashes (null pointer
* dereferencing, integer division, stack overflow etc.) should be handled
* without too much troubles.
*
* The handler is thread-safe, but client must have exclusive control on the
* signal handlers (ie. the library is installing its own signal handlers on
* top of the existing ones).
*
* You must build all your libraries with `-funwind-tables', to get proper
* unwinding information on all binaries. On ARM, you may also use the
* `--no-merge-exidx-entries` linker switch, to solve certain issues with
* unwinding (the switch is possibly not needed anymore).
* On Android, this can be achieved by using this line in the Android.mk file
* in each library block:
* LOCAL_CFLAGS := -funwind-tables -Wl,--no-merge-exidx-entries
*
* Example:
* COFFEE_TRY_JNI(env, *retcode = call_dangerous_function(env, object));
*
* Implementation notes:
*
* Currently the library is installing both alternate stack and signal
* handlers for known signals (SIGABRT, SIGILL, SIGTRAP, SIGBUS, SIGFPE,
* SIGSEGV, SIGSTKFLT), and is using sigsetjmp()/siglongjmp() to return to
* "userland" (compared to signal handler context). As a security, an alarm
* is started as soon as a fatal signal is detected (ie. not something the
* JVM will handle) to kill the process after a grace period. Be sure your
* program will exit quickly after the error is caught, or call alarm(0)
* to cancel the pending time-bomb.
* The signal handlers had to be written with caution, because the virtual
* machine might be using signals (including SEGV) to handle JIT compiler,
* and some clever optimizations (such as NullPointerException handling)
* We are using several signal-unsafe functions, namely:
* - siglongjmp() to return to userland
* - pthread_getspecific() to get thread-specific setup
*
* License:
*
* Copyright (c) 2013, Xavier Roche (http://www.httrack.com/)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef COFFEECATCH_JNI_H
#define COFFEECATCH_JNI_H
#include <jni.h>
#include <coffeecatch/coffeecatch.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* Setup crash handler to enter in a protected section. If a recognized signal
* is received in this section, an appropriate native Java Error will be
* raised.
*
* You can not exit the protected section block CODE_TO_BE_EXECUTED, using
* statements such as "return", because the cleanup code would not be
* executed.
*
* It is advised to enclose the complete CODE_TO_BE_EXECUTED block in a
* dedicated function declared extern or __attribute__ ((noinline)).
*
* You must build all your libraries with `-funwind-tables', to get proper
* unwinding information on all binaries. On Android, this can be achieved
* by using this line in the Android.mk file in each library block:
* LOCAL_CFLAGS := -funwind-tables
*
* Example:
*
* void my_native_function(JNIEnv* env, jobject object, jint *retcode) {
* COFFEE_TRY_JNI(env, *retcode = call_dangerous_function(env, object));
* }
*
* In addition, the following restrictions MUST be followed:
* - the function must be declared extern, or with the special attribute
* __attribute__ ((noinline)).
* - you must not use local variables before the COFFEE_TRY_JNI block,
* or define them as "volatile".
*
COFFEE_TRY_JNI(JNIEnv* env, CODE_TO_BE_EXECUTED)
*/
/** Internal functions & definitions, not to be used directly. **/
extern void coffeecatch_throw_exception(JNIEnv* env);
#define COFFEE_TRY_JNI(ENV, CODE) \
do { \
COFFEE_TRY() { \
CODE; \
} COFFEE_CATCH() { \
coffeecatch_throw_exception(ENV); \
} COFFEE_END(); \
} while(0)
/** End of internal functions & definitions. **/
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -33,10 +33,6 @@
#include <uv.h>
#ifdef __ANDROID__
#include <coffeecatch/coffeecatch.h>
#endif
// Check libuv library version.
const static bool uvVersionCheck = []() {
const unsigned int version = uv_version();
@@ -267,10 +263,6 @@ void Map::resume() {
}
void Map::run() {
#ifdef __ANDROID__
COFFEE_TRY() {
#endif
if (mode == Mode::None) {
#ifndef NDEBUG
mapThread = mainThread;
@@ -309,12 +301,6 @@ void Map::run() {
mode = Mode::None;
fileSource.clearLoop();
}
#ifdef __ANDROID__
} COFFEE_CATCH() {
Log::Error(Event::Crash, "Map::run() crash:\n%s", coffeecatch_get_message());
abort();
}
#endif
}
void Map::checkForPause() {