diff --git a/java/jni/ZT_jniutils.h b/java/jni/ZT_jniutils.h index 6b911c5ef..a948d61c7 100644 --- a/java/jni/ZT_jniutils.h +++ b/java/jni/ZT_jniutils.h @@ -51,6 +51,32 @@ #define LOGE(...) fprintf(stdout, __VA_ARGS__) #endif +// +// Call GetEnv and assert if there is an error +// +#define GETENV(env, vm) \ + do { \ + jint getEnvRet; \ + assert(vm); \ + if ((getEnvRet = vm->GetEnv(reinterpret_cast(&env), JNI_VERSION_1_6)) != JNI_OK) { \ + LOGE("Error calling GetEnv: %d", getEnvRet); \ + assert(false && "Error calling GetEnv"); \ + } \ + } while (false) + +// +// Call GetJavaVM and assert if there is an error +// +#define GETJAVAVM(env, vm) \ + do { \ + jint getJavaVMRet; \ + if ((getJavaVMRet = env->GetJavaVM(&vm)) != 0) { \ + LOGE("Error calling GetJavaVM: %d", getJavaVMRet); \ + assert(false && "Error calling GetJavaVM"); \ + } \ + } while (false) + + jobject createResultObject(JNIEnv *env, ZT_ResultCode code); jobject createVirtualNetworkStatus(JNIEnv *env, ZT_VirtualNetworkStatus status); jobject createVirtualNetworkType(JNIEnv *env, ZT_VirtualNetworkType type);