One way to do this is to use a pointer to a member function and change the signature of the integration function.
See below for a general idea:
functionwrapper.h
Declare a function wrapper class.
class FunctionWrapper { public: typedef double (FunctionWrapper::*Function1VariablePtr)(double x); FunctionWrapper(JNIEnv*, jclass); double compute(double x); };
integrate.h
Eliminate the previous pointer to the typedef function and change the signature of the method to include the wrapper object and a pointer to its member function.
#include "functionwrapper.h" extern "C" { double DLL_MACRO integrate(FunctionWrapper*, FunctionWrapper::Function1VariablePtr, double min, double max); }
integrate.cpp
Change a function call to a member function call.
#include "integrate.h" double integrate(FunctionWrapper* wrapper, FunctionWrapper::Function1VariablePtr function, double min, double max) {
refund amount; }
JNI code "bridge":
Define a shell code and define a function that performs the actual call. Call the integrate function directly from the JNI function:
#include "functionwrapper.h" FunctionWrapper::FunctionWrapper(JNIEnv *jnienv, jclass jc) : m_jnienv(jnienv), m_jc(jc) { m_method= jnienv->GetStaticMethodID(jc, "Function1D","(D)D"); } double FunctionWrapper:compute(double x) { return m_jnienv->CallStaticDoubleMethod(m_jc, m_method, x);; } // C++ "bridge" code to from/to Java: JNIEXPORT jdouble JNICALL Java_IntegrateJApp_JIntegrate(JNIEnv *jnienv, jclass jc, jdouble xmin, jdouble xmax) { FunctionWrapper wrapper(jnienv, jc); return integrate(&wrapper, &FunctionWrapper::compute, 2, 3); }