B
bart59
Hello,
I am using JNI,
I've got for exemple a first JNI function called to initiate the dll.
It returns the pointer to the mainClass, so that the JNI CallBack loop
Function can call it:
/** Create the MainInterface and initalise the h323 connection
return the MainInterface Pointer to reuse it later in other JNI
functions**/
JNIEXPORT jint JNICALL
Java_ca_sess_voicesess_terminal_JNIWrapper_create
(JNIEnv *env, jobject obj,jstring options)
{
//get the options as a PString
const char* option = env->GetStringUTFChars(options,NULL);
PString poptions = option;
//makes an instance of PProc()
PProc* g_PProcess = new PProc();
//make an instance of an endpoint
MainInterface * mainInterface;
mainInterface = new MainInterface( env, obj, poptions );
env->ReleaseStringUTFChars(options,option);
return ( ( jint ) mainInterface );
}
/**
*CallBack loop, to Get the message ( fifo pile )
**/
JNIEXPORT jstring JNICALL
Java_ca_sess_voicesess_terminal_JNIWrapper_getMsgQueue
(JNIEnv *env, jobject obj,jint mainInterfacePtr){
enum CallMode {
IdleCallMode,
MakingCallMode,
HangingUpMode,
IncomingCallWait,
IncomingLineCall,
Active323CallMode,
ActiveLineCallMode,
NoGatekeeperMode,
ApplicationShuttingDown,
IncomingCallIntrusion
};
MainInterface* myMainInterface =
(MainInterface*)mainInterfacePtr;
PString * queuePtr = new PString();
queuePtr = (*myMainInterface).GetMsgFromQueue();
while((queuePtr==NULL) &&
!((*myMainInterface).GetCallMode()==ApplicationShuttingDown)){
queuePtr = ((*myMainInterface).GetMsgFromQueue());
#ifdef _WIN32
Sleep(1000);
#endif
#ifndef _WIN32
sleep(1);
#endif
}
if(((*myMainInterface).GetCallMode()!=ApplicationShuttingDown)){
(*myMainInterface).ShowOutputs("Return OK, trying to display the
pointer data");
(*myMainInterface).ShowOutputs(PString("FIFO Msg:") + queuePtr[0]);
return env->NewStringUTF(queuePtr[0]);
}
else {
return env->NewStringUTF("1end");
}
By the waym I don know if it is the best method to have a callback
from the dll:
is there better method, faster/more secure?
-> Today I've got a PROBLEM with my program: sometimes it's freezing
all the java side (but the dll is still working...), doesn't seem to
be a problem from swing (I use InvokeLater etc...), nor from the dll,
because it is still runnning, however, if I don't use the callBack JNI
function from Java, the problem seems to stop (it is difficult to
evaluate because it occurs only sometimes, it is not systematic...)
Thanks for your help !
Bart
I am using JNI,
I've got for exemple a first JNI function called to initiate the dll.
It returns the pointer to the mainClass, so that the JNI CallBack loop
Function can call it:
/** Create the MainInterface and initalise the h323 connection
return the MainInterface Pointer to reuse it later in other JNI
functions**/
JNIEXPORT jint JNICALL
Java_ca_sess_voicesess_terminal_JNIWrapper_create
(JNIEnv *env, jobject obj,jstring options)
{
//get the options as a PString
const char* option = env->GetStringUTFChars(options,NULL);
PString poptions = option;
//makes an instance of PProc()
PProc* g_PProcess = new PProc();
//make an instance of an endpoint
MainInterface * mainInterface;
mainInterface = new MainInterface( env, obj, poptions );
env->ReleaseStringUTFChars(options,option);
return ( ( jint ) mainInterface );
}
/**
*CallBack loop, to Get the message ( fifo pile )
**/
JNIEXPORT jstring JNICALL
Java_ca_sess_voicesess_terminal_JNIWrapper_getMsgQueue
(JNIEnv *env, jobject obj,jint mainInterfacePtr){
enum CallMode {
IdleCallMode,
MakingCallMode,
HangingUpMode,
IncomingCallWait,
IncomingLineCall,
Active323CallMode,
ActiveLineCallMode,
NoGatekeeperMode,
ApplicationShuttingDown,
IncomingCallIntrusion
};
MainInterface* myMainInterface =
(MainInterface*)mainInterfacePtr;
PString * queuePtr = new PString();
queuePtr = (*myMainInterface).GetMsgFromQueue();
while((queuePtr==NULL) &&
!((*myMainInterface).GetCallMode()==ApplicationShuttingDown)){
queuePtr = ((*myMainInterface).GetMsgFromQueue());
#ifdef _WIN32
Sleep(1000);
#endif
#ifndef _WIN32
sleep(1);
#endif
}
if(((*myMainInterface).GetCallMode()!=ApplicationShuttingDown)){
(*myMainInterface).ShowOutputs("Return OK, trying to display the
pointer data");
(*myMainInterface).ShowOutputs(PString("FIFO Msg:") + queuePtr[0]);
return env->NewStringUTF(queuePtr[0]);
}
else {
return env->NewStringUTF("1end");
}
By the waym I don know if it is the best method to have a callback
from the dll:
is there better method, faster/more secure?
-> Today I've got a PROBLEM with my program: sometimes it's freezing
all the java side (but the dll is still working...), doesn't seem to
be a problem from swing (I use InvokeLater etc...), nor from the dll,
because it is still runnning, however, if I don't use the callBack JNI
function from Java, the problem seems to stop (it is difficult to
evaluate because it occurs only sometimes, it is not systematic...)
Thanks for your help !
Bart