Helper function added to handle Java exceptions in native code
authorTobias Brunner <tobias@strongswan.org>
Tue, 7 Aug 2012 11:40:47 +0000 (13:40 +0200)
committerTobias Brunner <tobias@strongswan.org>
Mon, 13 Aug 2012 09:00:25 +0000 (11:00 +0200)
src/frontends/android/jni/libandroidbridge/android_jni.h

index 77c33f7..427c641 100644 (file)
@@ -24,6 +24,7 @@
 #define ANDROID_JNI_H_
 
 #include <jni.h>
+#include <library.h>
 
 #define JNI_PACKAGE org_strongswan_android_logic
 #define JNI_PACKAGE_STRING "org/strongswan/android/logic"
@@ -62,4 +63,21 @@ void androidjni_attach_thread(JNIEnv **env);
  */
 void androidjni_detach_thread();
 
+/**
+ * Handle exceptions thrown by a JNI call
+ *
+ * @param env          JNIEnv
+ * @return                     TRUE if an exception was thrown
+ */
+static inline bool androidjni_exception_occurred(JNIEnv *env)
+{
+       if ((*env)->ExceptionOccurred(env))
+       {       /* clear any exception, otherwise the VM is terminated */
+               (*env)->ExceptionDescribe(env);
+               (*env)->ExceptionClear(env);
+               return TRUE;
+       }
+       return FALSE;
+}
+
 #endif /** ANDROID_JNI_H_ @}*/