I use JNI in my Java code to call native C code. This works fine and I'm doing some processing in the C code. The C code registers an event listener so that I'm notified every time a new result is ready in the C part.
Now I want to return the results to the Java code like that:
void notifyGazeEvent()
{
jclass cls = (*env)->GetObjectClass(env, obj);
jmethodID mid = (*env)->GetMethodID(env, cls, "newGazeEvent", "(I)V");
if (mid == 0)
{
return;
}
printf("In C, about to enter Java");
(*env)->CallVoidMethod(env, obj, mid, 1);
}
The problem now is: I don't know where to get the JNIEnv object and the jObject object from. This is passed when I first call the C code:
JNIEXPORT void JNICALL
Java_a_b_C_doCalculation(JNIEnv *env, jobject obj)
{
// here I register all the handlers etc,
}
But I don't know how I can pass the references until my method that does the callback to Java.