8#ifndef META_OCEAN_PLATFORM_ANDROID_SCOPED_JNI_GLOBAL_OBJECT_H
9#define META_OCEAN_PLATFORM_ANDROID_SCOPED_JNI_GLOBAL_OBJECT_H
27template <
typename T>
class ScopedJNIGlobalObject;
170 inline const T&
object()
const;
183 explicit inline operator bool()
const;
219 *
this = std::move(
object);
225 if (localObject.object_ ==
nullptr)
230 ocean_assert(localObject.jniEnvironment_ !=
nullptr);
232 if (localObject.jniEnvironment_ ==
nullptr)
240 if (!localObject.verifyCreatingThread())
247 if (object_ ==
nullptr)
253 localObject.release();
259 if (
object ==
nullptr)
264 if (jniEnvironment.GetJavaVM(&javaVM_) != JNI_OK)
266 ocean_assert(
false &&
"Failed to determine the Java virtual machine!");
272 object_ = T(jniEnvironment.NewGlobalRef(
object));
274 if (object_ ==
nullptr)
278 if (jniEnvironment.ExceptionCheck() == JNI_TRUE)
280 jniEnvironment.ExceptionClear();
283 Log::error() <<
"ScopedJNIGlobalObject: Failed to create the global reference!";
292 ocean_assert(scopedJNIEnvironment.
isValid());
294 if (!scopedJNIEnvironment.
isValid())
311 if (object_ ==
nullptr)
316 ocean_assert(javaVM_ !=
nullptr);
318 JNIEnv* jniEnvironment =
nullptr;
320 if (javaVM_->GetEnv((
void**)(&jniEnvironment), JNI_VERSION_1_6) == JNI_OK)
325 jniEnvironment->DeleteGlobalRef(object_);
334 Messenger::writeToDebugOutput(
"ScopedJNIGlobalObject: The global reference is not deleted, the thread is not attached to the virtual machine!");
336 ocean_assert(
false &&
"The global reference is leaked, release this object from a thread which is attached to the virtual machine!");
346 if (object_ ==
nullptr)
351 ocean_assert(javaVM_ !=
nullptr);
353 JNIEnv* jniEnvironment =
nullptr;
355 return javaVM_->GetEnv((
void**)(&jniEnvironment), JNI_VERSION_1_6) == JNI_OK;
361 return object_ !=
nullptr;
373 ocean_assert(isValid());
391 javaVM_ =
object.javaVM_;
392 object_ =
object.object_;
394 object.javaVM_ =
nullptr;
395 object.object_ = T();
static MessageObject error()
Returns the message for error messages.
Definition Messenger.h:1095
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