The Java Native Interface (JNI) is a native language support, which allows Java code (running on JVM) to interoperate with applications and libraries written in C and C++. JNI provides a one-way access to call C/C++ functions from Java. Therefore it helps to use ApertusVR's features from Java codes, which is indispensably important, when programming on Android.
ApertusVR uses the JNI language support as a plugin, which helps distribute the events, and implements wrapper functionality for ApertusVR entities. The JNI-plugin consists of three layers:
The C++ layer (apeJNIPlugin shared library)
Java static native functions (ApertusJNI.java)
Wrapper classes (ape<CppClassName>.java)
This layer is an ordinary ape::IPlugin implementation, which gather the events into its event queue, then when somebody calls the appropriate function in Java (
ApertusJNI.processEventDoubleQueue()), the plugin fires the events on the Java side, using the JNI's callback possibilities.
This is a static Java class, which contains the Java "headers" of the C++ JNI functions, and everything else needed to use the plugin in Java.
For each subclass of
ape::Entity in ApertusVR, there is a corresponding Java class (the
ape::Entity is also included), which provides an interface to access, query, and modify an object on the C++ side. These wrapper classes contains only a
String, and a
apeEntity.Type member variables, which makes it available to identify the entity related to the interface object. Then it calls the
static nativefunctions in ApertusJNI, to access the entity in C++.