From 8373a0fa6063507e55b12167e53b63a2217d5b1e Mon Sep 17 00:00:00 2001 From: Brenton Bostick Date: Thu, 2 Feb 2023 14:00:39 -0500 Subject: [PATCH] add GETENV macro --- java/jni/ZT_jniutils.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) 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);