Background
I have a native function in JAVA
package mypackage;
public class MyWrapper {
private native int
wrapFilterRawRequest(String config, String rawRequest);
public void
processRequest( String configPath,String rawRequest){
int status = 0;
status = new MyWrapper().wrapFilterRawRequest(configPath, rawRequest);
status2 = new MyWrapper().wrapFilterRawRequest(configPath, rawRequest);
}
static{
System.loadLibrary("mylibrary");
}
}
and a JNI Wrapper in C for the same
int processRequest(char *conf, char *req)
{
int status = 0;
// Do something here
return status;
}
JNIEXPORT jint JNICALL Java_mypackage_MyWrapper_wrapFilterRawRequest
(JNIEnv *env, jobject obj, jstring config, jstring rawRequest)
{
jint status = 0;
const char *conf, *req;
char *conf_copy, *req_copy;
conf = (env)->GetStringUTFChars(config, NULL);
req = (env)->GetStringUTFChars(rawRequest, NULL);
copy_str(&conf_copy, conf);
copy_str(&req_copy, req);
(env)->ReleaseStringUTFChars(config, conf);
(env)->ReleaseStringUTFChars(rawRequest, req);
status = processRequest(conf_copy , req_copy );
return status;
}
Problem
When I call the native function twice in JAVA it gives me an error because it is equivalent to calling the C function processRequest(char*, char*) twice in a row, which is not supported by my application. I want to be able to call it standalone every time, similar to how it is when you run an executable twice. (The program works when it is called twice, but not when the same function is called twice in the same application). I want JNI to re-initialize everything when it makes the native call. How can I do this?