Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

call method from JAVA (jni)

 
bharani rao
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi.
i have a cpp program which has the functionalities of a sip phone.
we are using pjsip stack

the program runs fine with all functionalities in sip phone and in command prompt mode.

now we have to integrate with java using jni to have a interface for the sip phone.

we have succeeded in initializing the stack( registering with the server), placing call, answering call, hanging up a call and releasing( unregistering).

so,
while we place call, the following method in cpp gets automatically called at the reciever end.



the above method has some coding on what to do with the incoming call and some interactive things like




now we are struck up with this part for the past 1 week.
all we need to do is to have the above interactive part to be called from the java program.
for that we need to write a method for that part in java.
but the problem is that the method is automatically called when we place a call ( when some one recieves a call).so we donot need to write a native method for that in java.



it would be easier if we write a native method for the above method in java(because all the things will be called once the method is called, so do the interactive part of the method).

but we want it to be run from java.
kindly help...

thanks in advance..






 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The C++ code can simply use the JNI to call a Java method. I'm not sure what problem you're having. This page in the JNI guide shows how to call a Java method from C++.
 
Rob Spoor
Sheriff
Pie
Posts: 20550
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I get the problem correctly, the native C++ code is raising events outside Java, and you want the Java code to handle those events. Am I right?

This C++ function should have a reference to the JVM (JNIEnv*) and the object on which to call the method. It can then use functions like GetMethodID and CallVoidMethod to call that method from Java. You will need to convert the parameters to the C++ function to something Java understands though.

In pseudo code:
As you see this would require ways to convert the C++ data types to Java data types and vice versa, and you're going from native code to Java code back to native code.
 
bharani rao
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

let me make it even more clear.
now when we run the java program in eclipse we get the gui and we can initialize the stack,place call, hang call and release the queue(unregister from server)

so when we place a call the automatically will get called which have

this code...

so we get "type a to answer the call" in the eclipse output window.
what we want is, instead of typing a in eclipse output window we want to press a button in the gui which does the function of typing a in the output eclipse window.

hope i'm more clear now.

thanks in advance
 
bharani rao
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry rob,

at the time i posted my second reply your reply was not there. that is why i posted the reply making more clear idea..

i suppose you got it right.. as far as i'm concerned what you is said is exactly what i want. but who knows, if my team lead accepts this or not....

anyways thank you very much for the exact answer....

i may reply again if that procedure is not accepted.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic