* src/native/jni.hpp: We typedef the JNI types to the CACAO internal
[cacao.git] / src / native / jni.hpp
index 616cafd3a203c3e5fdd056ac8037ad8d8d0cb6ba..16933eca1c84c6df8932765c60d37a533f4c68bd 100644 (file)
@@ -23,7 +23,7 @@
 */
 
 
-/* jni.h ***********************************************************************
+/* jni.hpp *********************************************************************
 
    ATTENTION: We include this file before we actually define our own
    jni.h.  We do this because otherwise we can get into unresolvable
 
    CLASSPATH_JNI_MD_H and CLASSPATH_JNI_H are defined in config.h.
 
-*******************************************************************************/
-
-#include "config.h"
+   We include both headers (jni.h and jni_md.h) with the absolute path
+   so we can be sure that the preprocessor does not pick up another
+   header from the search path.  Furthermore we include jni_md.h
+   before jni.h as the latter includes the former.
 
-/* We include both headers with the absolute path so we can be sure
-   that the preprocessor does not take another header.  Furthermore we
-   include jni_md.h before jni.h as the latter includes the former. */
+*******************************************************************************/
 
-#include INCLUDE_JNI_MD_H
-#include INCLUDE_JNI_H
 
 #ifndef _JNI_HPP
 #define _JNI_HPP
 
+#include "config.h"
+
 #include <stdbool.h>
 #include <stdint.h>
 
+
+// Define these to override the typedefs in jni.h
+#define _CLASSPATH_VM_JNI_TYPES_DEFINED          1 // GNU Classpath
+#define JNI_TYPES_ALREADY_DEFINED_IN_JNI_MD_H    1 // OpenJDK
+
+// First include jni_md.h so we have the Java primitive types.
+#include INCLUDE_JNI_MD_H
+
+
+// Include the C++ wrapper classes.
+//#include "vm/javaobjects.hpp"
+#include "vm/global.h"
+
+// Typedef the JNI types.
+typedef java_handle_t*              jobject;
+typedef java_handle_t*              jclass;
+typedef java_handle_t*              jstring;
+typedef java_handle_t*              jthrowable;
+typedef java_handle_t*              jweak; // FIXME
+typedef java_handle_array_t*        jarray;
+typedef java_handle_objectarray_t*  jobjectArray;
+typedef java_handle_booleanarray_t* jbooleanArray;
+typedef java_handle_bytearray_t*    jbyteArray;
+typedef java_handle_chararray_t*    jcharArray;
+typedef java_handle_shortarray_t*   jshortArray;
+typedef java_handle_intarray_t*     jintArray;
+typedef java_handle_longarray_t*    jlongArray;
+typedef java_handle_floatarray_t*   jfloatArray;
+typedef java_handle_doublearray_t*  jdoubleArray;
+
+
+// We need some additional stuff for the various JNI headers.
+#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) || defined(WITH_JAVA_RUNTIME_LIBRARY_CLDC1_1)
+
+// These typedefs and defines are copied from GNU Classpath's jni.h
+#define JNI_TRUE true
+#define JNI_FALSE false
+
+typedef struct _Jv_JNIEnv JNIEnv;
+typedef struct _Jv_JavaVM JavaVM;
+
+#elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
+
+// These typedefs are copied from OpenJDK's jni.h
+typedef unsigned char   jboolean;
+typedef unsigned short  jchar;
+typedef short           jshort;
+typedef float           jfloat;
+typedef double          jdouble;
+
+typedef jint            jsize;
+
+typedef union jvalue {
+    jboolean z;
+    jbyte    b;
+    jchar    c;
+    jshort   s;
+    jint     i;
+    jlong    j;
+    jfloat   f;
+    jdouble  d;
+    jobject  l;
+} jvalue;
+
+struct _jfieldID;
+typedef struct _jfieldID *jfieldID;
+
+struct _jmethodID;
+typedef struct _jmethodID *jmethodID;
+
+/* Return values from jobjectRefType */
+typedef enum _jobjectType {
+     JNIInvalidRefType    = 0,
+     JNILocalRefType      = 1,
+     JNIGlobalRefType     = 2,
+     JNIWeakGlobalRefType = 3
+} jobjectRefType;
+
+#endif
+
+
+// Now include jni.h to complete the JNI header.
+#include INCLUDE_JNI_H
+
+
+// Includes.
 #include "vm/global.h"