[android] Use jni.hpp in http_request_android.cpp

This commit is contained in:
John Firebaugh
2016-02-28 20:30:58 -08:00
parent 9e0be736fc
commit 235f4ee6f6
8 changed files with 224 additions and 402 deletions

View File

@@ -0,0 +1,31 @@
#pragma once
#include <jni/jni.hpp>
namespace mbgl {
namespace android {
class JNIEnvDeleter {
private:
jni::JavaVM* vm = nullptr;
bool detach = false;
public:
JNIEnvDeleter() = default;
JNIEnvDeleter(jni::JavaVM& v, bool d)
: vm(&v), detach(d) {}
void operator()(jni::JNIEnv* p) const {
if (p && detach) {
assert(vm);
vm->DetachCurrentThread();
}
}
};
using UniqueEnv = std::unique_ptr<jni::JNIEnv, JNIEnvDeleter>;
UniqueEnv AttachEnv();
}
}