Treffer: Template-Generated JNI.
Weitere Informationen
This article presents a sourcecode for converting Java Native Interface (JNI) data types to C++ data types. JNI was designed to facilitate cross-platform development between Java and languages such as C++. However, writing JNI code can be tedious. JNI usually provides conversion of Java data types to and from C++ data types by transforming arguments passed from Java to the appropriate C++ types, then converting results of the C++ functions to Java types. In this fashion, function calls to the actual C++ libraries can resume with the appropriate arguments and the Java side can receive results meaningful to its environment. In middleware terms, this process is called data marshalling. My first approach was to combine template-based Boost function holders with JNI helpers. The framework presented removes the manual JNI coding in most circumstances. Thus, developers on either side can concentrate more on problem-oriented tasks. In comparison to a similar framework provided by Sun, it has a runtime type conversion and checking. It is type-safe as long as you test passing right arguments from the Java side. Moreover, it gives access to the C++ functions and methods while breaking dependencies on a particular compiler-mangling scheme.