| Index: jni/Utils.h |
| diff --git a/jni/Utils.h b/jni/Utils.h |
| index dd3d600dee7e0e77e54029c020b563354d06e641..4827ef27749e6577ee493b0c7e3cd2dbb7b58035 100644 |
| --- a/jni/Utils.h |
| +++ b/jni/Utils.h |
| @@ -1,6 +1,6 @@ |
| /* |
| * This file is part of Adblock Plus <http://adblockplus.org/>, |
| - * Copyright (C) 2006-2013 Eyeo GmbH |
| + * Copyright (C) 2006-2014 Eyeo GmbH |
| * |
| * Adblock Plus is free software: you can redistribute it and/or modify |
| * it under the terms of the GNU General Public License version 3 as |
| @@ -33,11 +33,6 @@ |
| #define ABP_JNI_VERSION JNI_VERSION_1_6 |
| -namespace AdblockPlus |
| -{ |
| -namespace Android |
| -{ |
| - |
| void JniThrowException(JNIEnv* env, const std::string& message); |
| void JniThrowException(JNIEnv* env, const std::exception& e); |
| @@ -48,12 +43,12 @@ class JNIEnvAcquire |
| { |
| public: |
| JNIEnvAcquire(JavaVM* javaVM) : |
|
Felix Dahlke
2014/03/28 11:27:18
Colon on next line s'il vous plaît.
|
| - m_JavaVM(javaVM), m_JNIEnv(0), m_AttachStatus(0) |
| + javaVM(javaVM), jniEnv(0), attachmentStatus(0) |
| { |
| - m_AttachStatus = javaVM->GetEnv((void **)&m_JNIEnv, ABP_JNI_VERSION); |
| - if (m_AttachStatus == JNI_EDETACHED) |
| + attachmentStatus = javaVM->GetEnv((void **)&jniEnv, ABP_JNI_VERSION); |
|
Felix Dahlke
2014/03/28 11:27:18
Same as JniCallbacks.h, non-trivial non-template f
|
| + if (attachmentStatus == JNI_EDETACHED) |
| { |
| - if (javaVM->AttachCurrentThread(&m_JNIEnv, 0)) |
| + if (javaVM->AttachCurrentThread(&jniEnv, 0)) |
| { |
| // This one is FATAL, we can't recover from this (because without a JVM we're dead), so |
| // throwing a runtime_exception in a ctor can be tolerated here IMHO |
| @@ -64,26 +59,26 @@ public: |
| ~JNIEnvAcquire() |
| { |
| - if (m_AttachStatus == JNI_EDETACHED) |
| + if (attachmentStatus == JNI_EDETACHED) |
| { |
| - m_JavaVM->DetachCurrentThread(); |
| + javaVM->DetachCurrentThread(); |
| } |
| } |
| inline JNIEnv* operator*() |
| { |
| - return m_JNIEnv; |
| + return jniEnv; |
| } |
| inline JNIEnv* operator->() |
| { |
| - return m_JNIEnv; |
| + return jniEnv; |
| } |
| private: |
| - JavaVM* m_JavaVM; |
| - JNIEnv* m_JNIEnv; |
| - int m_AttachStatus; |
| + JavaVM* javaVM; |
| + JNIEnv* jniEnv; |
| + int attachmentStatus; |
| }; |
| template<typename T> |
| @@ -92,15 +87,15 @@ class JniGlobalReference |
| public: |
| JniGlobalReference(JNIEnv* env, T reference) |
| { |
| - env->GetJavaVM(&m_JavaVM); |
| - m_Reference = static_cast<T>(env->NewGlobalRef(static_cast<jobject>(reference))); |
| + env->GetJavaVM(&javaVM); |
| + reference = static_cast<T>(env->NewGlobalRef(static_cast<jobject>(reference))); |
| } |
| ~JniGlobalReference() |
| { |
| - JNIEnvAcquire env(m_JavaVM); |
| + JNIEnvAcquire env(javaVM); |
| - env->DeleteGlobalRef(static_cast<jobject>(m_Reference)); |
| + env->DeleteGlobalRef(static_cast<jobject>(reference)); |
| } |
| JniGlobalReference(const JniGlobalReference& other); |
| @@ -108,32 +103,32 @@ public: |
| inline T get() |
| { |
| - return m_Reference; |
| + return reference; |
| } |
| - typedef std::tr1::shared_ptr<JniGlobalReference<T> > PTR; |
| + typedef std::tr1::shared_ptr<JniGlobalReference<T> > Ptr; |
| private: |
| - T m_Reference; |
| - JavaVM* m_JavaVM; |
| + T reference; |
| + JavaVM* javaVM; |
| }; |
| -inline void* JniLong2Ptr(jlong value) |
| +inline void* JniLongToPtr(jlong value) |
| { |
| return reinterpret_cast<void*>((size_t)value); |
| } |
| -inline jlong JniPtr2Long(void* ptr) |
| +inline jlong JniPtrToLong(void* ptr) |
| { |
| return (jlong)reinterpret_cast<size_t>(ptr); |
| } |
| -// TODO(rje): It's feeling a bit dirty casting to shared_ptr<T: JsValue> directly, so maybe |
| +// TODO: It's feeling a bit dirty casting to shared_ptr<T: JsValue> directly, so maybe |
| // implement a special cast functions that first reinterpret_casts to shared_ptr<JsValue> and then |
| // dynamic_casts to shared_ptr<T: JsValue> ... also as the same inheritance is mirrored on the Java |
| // side (and Java will throw a class cast exception on error) this shouldn't be an issue (TM) |
| template<typename T> |
| -inline T* JniLong2TypePtr(jlong value) |
| +inline T* JniLongToTypePtr(jlong value) |
| { |
| return reinterpret_cast<T*>((size_t)value); |
| } |
| @@ -146,8 +141,7 @@ void JniAddObjectToList(JNIEnv* env, jobject list, jobject value); |
| inline std::string JniGetStringField(JNIEnv* env, jclass clazz, jobject jObj, const char* name) |
| { |
| - return AdblockPlus::Android::JniJava2StdString(env, |
| - reinterpret_cast<jstring>(env->GetObjectField(jObj, env->GetFieldID(clazz, name, "Ljava/lang/String;")))); |
| + return JniJava2StdString(env, reinterpret_cast<jstring>(env->GetObjectField(jObj, env->GetFieldID(clazz, name, "Ljava/lang/String;")))); |
| } |
| inline bool JniGetBooleanField(JNIEnv* env, jclass clazz, jobject jObj, const char* name) |
| @@ -169,40 +163,37 @@ inline jobject NewJniFilter(JNIEnv* env, const AdblockPlus::FilterPtr& filter) |
| { |
| jclass clazz = env->FindClass(PKG("Filter")); |
| jmethodID method = env->GetMethodID(clazz, "<init>", "(J)V"); |
| - return env->NewObject(clazz, method, JniPtr2Long(new AdblockPlus::FilterPtr(filter))); |
| + return env->NewObject(clazz, method, JniPtrToLong(new AdblockPlus::FilterPtr(filter))); |
| } |
| inline jobject NewJniSubscription(JNIEnv* env, const AdblockPlus::SubscriptionPtr& subscription) |
| { |
| jclass clazz = env->FindClass(PKG("Subscription")); |
| jmethodID method = env->GetMethodID(clazz, "<init>", "(J)V"); |
| - return env->NewObject(clazz, method, JniPtr2Long(new AdblockPlus::SubscriptionPtr(subscription))); |
| + return env->NewObject(clazz, method, JniPtrToLong(new AdblockPlus::SubscriptionPtr(subscription))); |
| } |
| -} // namespace Android |
| -} // namespace AdblockPlus |
| - |
| #define TRY try |
| #define CATCH_AND_THROW(jEnv) \ |
| catch (const std::exception& except) \ |
| { \ |
| - AdblockPlus::Android::JniThrowException(jEnv, except); \ |
| + JniThrowException(jEnv, except); \ |
| } \ |
| catch (...) \ |
| { \ |
| - AdblockPlus::Android::JniThrowException(jEnv); \ |
| + JniThrowException(jEnv); \ |
| } |
| #define CATCH_THROW_AND_RETURN(jEnv, retVal) \ |
| catch (const std::exception& except) \ |
| { \ |
| - AdblockPlus::Android::JniThrowException(jEnv, except); \ |
| + JniThrowException(jEnv, except); \ |
| return retVal; \ |
| } \ |
| catch (...) \ |
| { \ |
| - AdblockPlus::Android::JniThrowException(jEnv); \ |
| + JniThrowException(jEnv); \ |
| return retVal; \ |
| } |