| 27 | }; |
| 28 | |
| 29 | class JavaEnv { |
| 30 | public: |
| 31 | JavaEnv(); |
| 32 | |
| 33 | static void setExceptionHandlerForCurrentThread(JNIExceptionHandler* exceptionHandler); |
| 34 | static JNIExceptionHandler* getExceptionHandlerForCurrentThread(); |
| 35 | |
| 36 | static JNIEnv* getUnsafeEnv(); |
| 37 | |
| 38 | template<typename Fun> |
| 39 | static auto accessEnv(Fun&& f) { |
| 40 | f(*getUnsafeEnv()); |
| 41 | checkException(); |
| 42 | } |
| 43 | |
| 44 | template<typename Fun> |
| 45 | static auto accessEnvRet(Fun&& f) { |
| 46 | auto result = f(*getUnsafeEnv()); |
| 47 | checkException(); |
| 48 | return result; |
| 49 | } |
| 50 | |
| 51 | template<typename Fun> |
| 52 | static auto accessEnvRetRef(Fun&& f) -> ::djinni::LocalRef<decltype(f(*getUnsafeEnv()))> { |
| 53 | auto result = f(*getUnsafeEnv()); |
| 54 | if (result == nullptr) { |
| 55 | checkException(); |
| 56 | } |
| 57 | return ::djinni::LocalRef<decltype(f(*getUnsafeEnv()))>(result); |
| 58 | } |
| 59 | |
| 60 | static bool checkException(); |
| 61 | |
| 62 | static JavaCache& getCache(); |
| 63 | |
| 64 | static ::djinni::GlobalRef<jobject> newGlobalRef(jobject obj); |
| 65 | static ::djinni::GlobalRef<jclass> newGlobalRef(jclass cls); |
| 66 | static ::djinni::LocalRef<jobject> newLocalRef(jobject obj); |
| 67 | |
| 68 | static bool instanceOf(jobject object, const JavaClass& cls); |
| 69 | static bool isSameObject(jobject object, jobject otherObject); |
| 70 | }; |
| 71 | |
| 72 | } // namespace ValdiAndroid |
no outgoing calls