AVPKit
com::avpkit::ferry::JNIHelper Class Reference

The JNIHelper object contains a series of methods designed to assist functions when running inside a Java JVM. More...

#include <JNIHelper.h>

Public Types

typedef void(* CallbackFunc) (JavaVM *jvm, void *closure)
 

Public Member Functions

VS_API_FERRY JavaVM * getVM ()
 
VS_API_FERRY void setVM (JavaVM *jvm)
 
VS_API_FERRY void * getPointer (jobject pointerRef)
 
VS_API_FERRY void * setPointer (jobject pointerRef, void *newVal)
 
VS_API_FERRY jobject newLocalRef (jobject ref)
 
VS_API_FERRY void deleteLocalRef (jobject ref)
 
VS_API_FERRY jobject newGlobalRef (jobject ref)
 
VS_API_FERRY void deleteGlobalRef (jobject ref)
 
VS_API_FERRY jweak newWeakGlobalRef (jobject ref)
 
VS_API_FERRY void deleteWeakGlobalRef (jweak ref)
 
VS_API_FERRY jint getJNIVersion ()
 
VS_API_FERRY JNIEnv * getEnv ()
 
VS_API_FERRY void registerInitializationCallback (CallbackFunc, void *closure)
 
VS_API_FERRY void registerTerminationCallback (CallbackFunc, void *closure)
 
VS_API_FERRY void throwOutOfMemoryError ()
 
VS_API_FERRY int32_t isInterrupted ()
 
VS_API_FERRY bool isInterruptedException (jthrowable exception)
 
VS_API_FERRY void interrupt ()
 

Static Public Member Functions

static VS_API_FERRY JNIHelpergetHelper ()
 
static JavaVM * sGetVM ()
 
static void sSetVM (JavaVM *jvm)
 
static jint sGetJNIVersion ()
 
static JNIEnv * sGetEnv ()
 
static void * sGetPointer (jobject pointerRef)
 
static void * sSetPointer (jobject pointerRef, void *newVal)
 
static jobject sNewLocalRef (jobject ref)
 
static void sDeleteLocalRef (jobject ref)
 
static jobject sNewGlobalRef (jobject ref)
 
static void sDeleteGlobalRef (jobject ref)
 
static jweak sNewWeakGlobalRef (jobject ref)
 
static void sDeleteWeakGlobalRef (jweak ref)
 
static void sRegisterInitializationCallback (CallbackFunc func, void *closure)
 
static void sRegisterTerminationCallback (CallbackFunc func, void *closure)
 
static VS_API_FERRY void shutdownHelper ()
 

Detailed Description

The JNIHelper object contains a series of methods designed to assist functions when running inside a Java JVM.

There is only one JNIHelper object per shared library loaded.

Definition at line 36 of file JNIHelper.h.

Member Function Documentation

◆ throwOutOfMemoryError()

void com::avpkit::ferry::JNIHelper::throwOutOfMemoryError ( )

Be VERY careful in this function; it gets call when we're low on memory so you check any allocations of memory, as they are incredibly likely to fail – and will do so on the most inconvenient OS more often than others.

Definition at line 514 of file JNIHelper.cpp.

515  {
522  JNIEnv *env = this->getEnv();
523  if (!env)
524  return;
525  // exception already pending?
526  if (env->ExceptionCheck())
527  return;
528  jclass cls=0;
529 
530  // let's set up a singleton out of memory error for potential
531  // reuse later
532  cls = env->FindClass("java/lang/OutOfMemoryError");
533  // couldn't find the class?
534  if (cls) {
535  int retval = env->ThrowNew(cls, "out of native memory");
536  env->DeleteLocalRef(cls);
537  if (retval == 0) // success
538  return;
539  }
540 
541  if (!mOutOfMemoryErrorSingleton)
542  return;
543  env->Throw(mOutOfMemoryErrorSingleton);
544  }

The documentation for this class was generated from the following files: