8#ifndef META_OCEAN_PLATFORM_ANDROID_SCOPED_JNI_LOCAL_OBJECT_H
9#define META_OCEAN_PLATFORM_ANDROID_SCOPED_JNI_LOCAL_OBJECT_H
22#if defined(OCEAN_DEBUG) || defined(OCEAN_ENABLE_JNI_REFERENCE_VERIFICATION)
23 #define OCEAN_VERIFY_JNI_REFERENCE_THREAD
36template <
typename T>
class ScopedJNILocalObject;
39template <
typename T>
class ScopedJNIGlobalObject;
159 inline const T&
object()
const;
172 explicit inline operator bool()
const;
222 *
this = std::move(
object);
227 jniEnvironment_(&jniEnvironment),
230#ifdef OCEAN_VERIFY_JNI_REFERENCE_THREAD
241 ocean_assert(scopedJNIEnvironment.
isValid());
243 if (!scopedJNIEnvironment.
isValid())
261 if (object_ ==
nullptr)
263 jniEnvironment_ =
nullptr;
267 ocean_assert(jniEnvironment_ !=
nullptr);
269 if (verifyCreatingThread())
271 jniEnvironment_->DeleteLocalRef(object_);
274 jniEnvironment_ =
nullptr;
276 verificationJavaVM_ =
nullptr;
282 if (verificationJavaVM_ ==
nullptr)
288 JNIEnv* callingJNIEnvironment =
nullptr;
290 if (verificationJavaVM_->GetEnv((
void**)(&callingJNIEnvironment), JNI_VERSION_1_6) != JNI_OK)
296 ocean_assert(
false &&
"The thread has been detached, the local reference does not exist anymore!");
301 if (callingJNIEnvironment != jniEnvironment_)
306 ocean_assert(
false &&
"The local reference must be released on the thread which has created it!");
317 return object_ !=
nullptr;
329 ocean_assert(isValid());
347 jniEnvironment_ =
object.jniEnvironment_;
348 object_ =
object.object_;
350 verificationJavaVM_ =
object.verificationJavaVM_;
352 object.jniEnvironment_ =
nullptr;
353 object.object_ = T();
354 object.verificationJavaVM_ =
nullptr;
static void writeToDebugOutput(const std::string &message)
Writes a message to the most suitable debug output of the current platform.
The namespace covering the entire Ocean framework.
Definition Accessor.h:15