Handles all Java binding-related static data.
More...
#include <objectpool.h>
Handles all Java binding-related static data.
Definition at line 34 of file objectpool.h.
◆ BeatmupJavaObjectPool()
BeatmupJavaObjectPool::BeatmupJavaObjectPool |
( |
| ) |
|
|
inline |
Definition at line 148 of file objectpool.h.
struct BeatmupJavaObjectPool::@20 javaContext
◆ queryJavaContext()
bool BeatmupJavaObjectPool::queryJavaContext |
( |
JNIEnv * |
newEnv | ) |
|
|
inlineprivate |
Java context check.
Definition at line 47 of file objectpool.h.
50 std::lock_guard<std::mutex> lock(
access);
52 jclass cls = newEnv->FindClass(
"Beatmup/Object");
53 javaContext.handleFieldId = newEnv->GetFieldID(cls,
"handle",
"J");
54 newEnv->DeleteLocalRef(cls);
std::mutex access
structure access control
◆ getObject() [1/2]
template<class Object >
Object* BeatmupJavaObjectPool::getObject |
( |
JNIEnv * |
jenv, |
|
|
jlong |
handle |
|
) |
| |
|
inline |
Retrieves native object by its handle.
Definition at line 68 of file objectpool.h.
74 return static_cast<Object*
>( (
void*)
handle );
static const jlong INVALID_HANDLE
JNIEnv jobject jlong handle
◆ getObject() [2/2]
template<class Object >
Object* BeatmupJavaObjectPool::getObject |
( |
JNIEnv * |
jenv, |
|
|
jobject |
obj |
|
) |
| |
|
inline |
Retrieves native object from its Java prototype.
Definition at line 80 of file objectpool.h.
86 LOG_I(
"Hitting object #%lld from Java", ptr);
90 return static_cast<Object*
>( (
void*)
jenv->GetLongField(obj,
javaContext.handleFieldId) );
bool queryJavaContext(JNIEnv *newEnv)
Java context check.
◆ nullifyHandle()
void BeatmupJavaObjectPool::nullifyHandle |
( |
JNIEnv * |
jenv, |
|
|
jobject |
obj |
|
) |
| |
|
inline |
Sets a handle of a java object to null.
Definition at line 97 of file objectpool.h.
◆ addJavaReference()
Creates new global reference on a Java object to avoid garbage collecting.
Definition at line 105 of file objectpool.h.
106 std::lock_guard<std::mutex> lock(
access);
std::multimap< const Beatmup::Object *, jobject > javaRefs
Java global references representing dependencies of internal objects on external Java objects.
◆ removeJavaReference()
void BeatmupJavaObjectPool::removeJavaReference |
( |
JNIEnv * |
jenv, |
|
|
const Beatmup::Object * |
bobj |
|
) |
| |
|
inline |
Removes a Java reference.
Definition at line 114 of file objectpool.h.
115 std::lock_guard<std::mutex> lock(
access);
118 jenv->DeleteGlobalRef(ref->second);
◆ removeAllJavaReferences()
void BeatmupJavaObjectPool::removeAllJavaReferences |
( |
JNIEnv * |
jenv, |
|
|
const Beatmup::Object * |
bobj |
|
) |
| |
|
inline |
Removes all Java references to depending objects.
Definition at line 127 of file objectpool.h.
128 std::lock_guard<std::mutex> lock(
access);
133 jenv->DeleteGlobalRef(ref->second);
◆ getJavaReference()
Returns a reference to the Java object which a given object depends on.
Definition at line 142 of file objectpool.h.
◆ throwToJava() [1/2]
static void BeatmupJavaObjectPool::throwToJava |
( |
JNIEnv * |
jenv, |
|
|
const char * |
exceptionClass, |
|
|
const char * |
message |
|
) |
| |
|
inlinestatic |
Throws a specific exception.
Definition at line 156 of file objectpool.h.
157 jclass exClass =
jenv->FindClass(exceptionClass);
158 jmethodID constructor =
jenv->GetMethodID(exClass,
"<init>",
"(Ljava/lang/String;)V");
159 jobject exception =
jenv->NewObject(exClass, constructor,
jenv->NewStringUTF(message));
160 jenv->Throw((jthrowable) exception);
161 jenv->DeleteLocalRef(exClass);
◆ throwToJava() [2/2]
static void BeatmupJavaObjectPool::throwToJava |
( |
JNIEnv * |
jenv, |
|
|
const char * |
message |
|
) |
| |
|
inlinestatic |
Throws a general exception.
Definition at line 168 of file objectpool.h.
static void throwToJava(JNIEnv *jenv, const char *exceptionClass, const char *message)
Throws a specific exception.
◆ rethrowToJava()
static void BeatmupJavaObjectPool::rethrowToJava |
( |
JNIEnv * |
jenv, |
|
|
std::exception & |
ex |
|
) |
| |
|
inlinestatic |
Rethrows a core-caused exception.
Definition at line 176 of file objectpool.h.
◆ javaRefs
Java global references representing dependencies of internal objects on external Java objects.
Definition at line 36 of file objectpool.h.
◆ env
JNIEnv* BeatmupJavaObjectPool::env |
◆ handleFieldId
jfieldID BeatmupJavaObjectPool::handleFieldId |
struct { ... } BeatmupJavaObjectPool::javaContext |
◆ access
std::mutex BeatmupJavaObjectPool::access |
|
private |
◆ INVALID_HANDLE
return BeatmupJavaObjectPool::INVALID_HANDLE = std::numeric_limits<jlong>::min() |
|
static |
◆ factory
The documentation for this class was generated from the following files: