From 53d4d1b7f8bcd5b604011dafef37224c1751bfc4 Mon Sep 17 00:00:00 2001 From: Simon Morlat Date: Wed, 22 May 2013 17:01:06 +0200 Subject: [PATCH] add transfer_state_changed callback to JNI/java info api wrapping in progress --- .../core/tutorials/TutorialBuddyStatus.java | 7 +++ .../core/tutorials/TutorialChatRoom.java | 7 +++ .../core/tutorials/TutorialHelloWorld.java | 7 +++ .../core/tutorials/TutorialRegistration.java | 7 +++ coreapi/linphonecore_jni.cc | 45 +++++++++++++++++- .../org/linphone/core/LinphoneCall.java | 6 +++ .../org/linphone/core/LinphoneContent.java | 46 ++++++++++++++++++ .../org/linphone/core/LinphoneCore.java | 14 ++++++ .../linphone/core/LinphoneCoreListener.java | 7 +++ .../linphone/core/LinphoneInfoMessage.java | 36 ++++++++++++++ .../org/linphone/core/LinphoneCallImpl.java | 5 ++ .../linphone/core/LinphoneContentImpl.java | 46 ++++++++++++++++++ .../org/linphone/core/LinphoneCoreImpl.java | 11 +++++ .../core/LinphoneInfoMessageImpl.java | 47 +++++++++++++++++++ 14 files changed, 290 insertions(+), 1 deletion(-) create mode 100644 java/common/org/linphone/core/LinphoneContent.java create mode 100644 java/common/org/linphone/core/LinphoneInfoMessage.java create mode 100644 java/impl/org/linphone/core/LinphoneContentImpl.java create mode 100644 java/impl/org/linphone/core/LinphoneInfoMessageImpl.java diff --git a/coreapi/help/java/org/linphone/core/tutorials/TutorialBuddyStatus.java b/coreapi/help/java/org/linphone/core/tutorials/TutorialBuddyStatus.java index dc1341d80..5bd39d03b 100644 --- a/coreapi/help/java/org/linphone/core/tutorials/TutorialBuddyStatus.java +++ b/coreapi/help/java/org/linphone/core/tutorials/TutorialBuddyStatus.java @@ -241,5 +241,12 @@ public class TutorialBuddyStatus implements LinphoneCoreListener { } + @Override + public void transferState(LinphoneCore lc, LinphoneCall call, + State new_call_state) { + // TODO Auto-generated method stub + + } + } diff --git a/coreapi/help/java/org/linphone/core/tutorials/TutorialChatRoom.java b/coreapi/help/java/org/linphone/core/tutorials/TutorialChatRoom.java index 024927468..0c5edda7e 100644 --- a/coreapi/help/java/org/linphone/core/tutorials/TutorialChatRoom.java +++ b/coreapi/help/java/org/linphone/core/tutorials/TutorialChatRoom.java @@ -163,5 +163,12 @@ public class TutorialChatRoom implements LinphoneCoreListener, LinphoneChatMessa write("Sent message [" + msg.getText() + "] new state is " + state.toString()); } + @Override + public void transferState(LinphoneCore lc, LinphoneCall call, + State new_call_state) { + // TODO Auto-generated method stub + + } + } diff --git a/coreapi/help/java/org/linphone/core/tutorials/TutorialHelloWorld.java b/coreapi/help/java/org/linphone/core/tutorials/TutorialHelloWorld.java index d6b61cf8b..bf5421d6d 100644 --- a/coreapi/help/java/org/linphone/core/tutorials/TutorialHelloWorld.java +++ b/coreapi/help/java/org/linphone/core/tutorials/TutorialHelloWorld.java @@ -167,5 +167,12 @@ public class TutorialHelloWorld implements LinphoneCoreListener { } + @Override + public void transferState(LinphoneCore lc, LinphoneCall call, + State new_call_state) { + // TODO Auto-generated method stub + + } + } diff --git a/coreapi/help/java/org/linphone/core/tutorials/TutorialRegistration.java b/coreapi/help/java/org/linphone/core/tutorials/TutorialRegistration.java index fa18d51f8..89e53f5c5 100644 --- a/coreapi/help/java/org/linphone/core/tutorials/TutorialRegistration.java +++ b/coreapi/help/java/org/linphone/core/tutorials/TutorialRegistration.java @@ -198,6 +198,13 @@ public class TutorialRegistration implements LinphoneCoreListener { } + @Override + public void transferState(LinphoneCore lc, LinphoneCall call, + State new_call_state) { + // TODO Auto-generated method stub + + } + } diff --git a/coreapi/linphonecore_jni.cc b/coreapi/linphonecore_jni.cc index 1ff08e0a3..0701f1f37 100644 --- a/coreapi/linphonecore_jni.cc +++ b/coreapi/linphonecore_jni.cc @@ -139,6 +139,7 @@ public: vTable.new_subscription_request = new_subscription_request; vTable.notify_presence_recv = notify_presence_recv; vTable.call_stats_updated = callStatsUpdated; + vTable.transfer_state_changed = transferStateChanged; listenerClass = (jclass)env->NewGlobalRef(env->GetObjectClass( alistener)); @@ -160,6 +161,8 @@ public: callStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCall$State")); callStateFromIntId = env->GetStaticMethodID(callStateClass,"fromInt","(I)Lorg/linphone/core/LinphoneCall$State;"); + transferStateId = env->GetMethodID(listenerClass,"transferState","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCall;Lorg/linphone/core/LinphoneCall$State;)V"); + /*callStatsUpdated(LinphoneCore lc, LinphoneCall call, LinphoneCallStats stats);*/ callStatsUpdatedId = env->GetMethodID(listenerClass, "callStatsUpdated", "(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCall;Lorg/linphone/core/LinphoneCallStats;)V"); @@ -240,6 +243,7 @@ public: jmethodID messageReceivedId; jmethodID dtmfReceivedId; jmethodID callStatsUpdatedId; + jmethodID transferStateId; jclass globalStateClass; jmethodID globalStateId; @@ -499,7 +503,22 @@ public: env->CallVoidMethod(callobj, lcData->callSetVideoStatsId, statsobj); env->CallVoidMethod(lcData->listener, lcData->callStatsUpdatedId, lcData->core, callobj, statsobj); } - + static void transferStateChanged(LinphoneCore *lc, LinphoneCall *call, LinphoneCallState remote_call_state){ + JNIEnv *env = 0; + jint result = jvm->AttachCurrentThread(&env,NULL); + jobject jcall; + if (result != 0) { + ms_error("cannot attach VM\n"); + return; + } + LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc); + env->CallVoidMethod(lcData->listener + ,lcData->transferStateId + ,lcData->core + ,(jcall=lcData->getCall(env,call)) + ,env->CallStaticObjectMethod(lcData->callStateClass,lcData->callStateFromIntId,(jint)remote_call_state) + ); + } }; extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_newLinphoneCore(JNIEnv* env @@ -545,6 +564,19 @@ extern "C" void Java_org_linphone_core_LinphoneCoreImpl_delete(JNIEnv* env delete lcData; } +/* + * Class: org_linphone_core_LinphoneCoreImpl + * Method: createInfoMessage + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_org_linphone_core_LinphoneCoreImpl_createInfoMessage(JNIEnv *, jobject jobj, jlong lcptr){ + return (jlong) linphone_core_create_info_message((LinphoneCore*)lcptr); +} + +JNIEXPORT jint JNICALL Java_org_linphone_core_LinphoneCoreImpl_sendInfoMessage(JNIEnv *env, jobject jobj, jlong lcptr, jlong infoptr, jlong addrptr){ + return linphone_core_send_info_message((LinphoneCore*)lcptr,(LinphoneInfoMessage*)infoptr,(LinphoneAddress*)addrptr); +} + extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPrimaryContact(JNIEnv* env, jobject thiz, jlong lc, jstring jdisplayname, jstring jusername) { const char* displayname = env->GetStringUTFChars(jdisplayname, NULL); const char* username = env->GetStringUTFChars(jusername, NULL); @@ -1694,6 +1726,17 @@ extern "C" jint Java_org_linphone_core_LinphoneCallImpl_getState( JNIEnv* env ,jlong ptr) { return (jint)linphone_call_get_state((LinphoneCall*)ptr); } + +/* + * Class: org_linphone_core_LinphoneCallImpl + * Method: getTransferState + * Signature: (J)I + */ +JNIEXPORT jint JNICALL Java_org_linphone_core_LinphoneCallImpl_getTransferState(JNIEnv *, jobject jobj, jlong callptr){ + LinphoneCall *call=(LinphoneCall*)callptr; + return linphone_call_get_transfer_state(call); +} + extern "C" void Java_org_linphone_core_LinphoneCallImpl_enableEchoCancellation( JNIEnv* env ,jobject thiz ,jlong ptr diff --git a/java/common/org/linphone/core/LinphoneCall.java b/java/common/org/linphone/core/LinphoneCall.java index 893572e2e..3328b2959 100644 --- a/java/common/org/linphone/core/LinphoneCall.java +++ b/java/common/org/linphone/core/LinphoneCall.java @@ -292,4 +292,10 @@ public interface LinphoneCall { * Stop call recording. */ void stopRecording(); + + /** + * If a call transfer has been initiated for this call, returns the call state of the new call performed at the remote end as a result of the transfer request. + * @return the call state of the new call performed by the referee to the refer target. + */ + State getTransferState(); } diff --git a/java/common/org/linphone/core/LinphoneContent.java b/java/common/org/linphone/core/LinphoneContent.java new file mode 100644 index 000000000..b3811006f --- /dev/null +++ b/java/common/org/linphone/core/LinphoneContent.java @@ -0,0 +1,46 @@ +package org.linphone.core; + +/** + * LinphoneContent interface describes a SIP message content (body). + * It can be used together with the LinphoneInfoMessage, in order to add content attachment to the INFO message. + * @author smorlat + * + */ +public interface LinphoneContent { + /** + * Get the type of the content, for example "application" + * @return the type + */ + String getType(); + /** + * Get the subtype of the content, for example "html" + * @return the subtype + */ + String getSubtype(); + /** + * Get the data as a string. + * @return the data + */ + String getDataAsString(); + /** + * Get the data size. + * @return the data size. + */ + int getSize(); + + /** + * Set the content type, for example "application" + * @param type the content's primary type + */ + void setType(String type); + /** + * Set the subtype, for example "text" + * @param subtype the subtype + */ + void setSubtype(String subtype); + /** + * Set the data, supplied as String. + * @param data the data + */ + void setStringData(String data); +} diff --git a/java/common/org/linphone/core/LinphoneCore.java b/java/common/org/linphone/core/LinphoneCore.java index d76acad9a..c3c26e946 100644 --- a/java/common/org/linphone/core/LinphoneCore.java +++ b/java/common/org/linphone/core/LinphoneCore.java @@ -1259,5 +1259,19 @@ public interface LinphoneCore { * the external ip address is not available return null. */ public String getUpnpExternalIpaddress(); + + /** + * Create an empty INFO message. + * It can later be sent using {@link LinphoneCore.sendInfoMessage() }. + * @return the new info message. + */ + public LinphoneInfoMessage createInfoMessage(); + + /** + * Send an INFO message to specified destination. + * @param info the info message + * @param dest the destination sip address. + */ + public void sendInfoMessage(LinphoneInfoMessage info, LinphoneAddress dest); } diff --git a/java/common/org/linphone/core/LinphoneCoreListener.java b/java/common/org/linphone/core/LinphoneCoreListener.java index 740bdc29c..d8487c69a 100644 --- a/java/common/org/linphone/core/LinphoneCoreListener.java +++ b/java/common/org/linphone/core/LinphoneCoreListener.java @@ -117,6 +117,13 @@ public interface LinphoneCoreListener { */ void notifyReceived(LinphoneCore lc, LinphoneCall call, LinphoneAddress from, byte[] event); + /** + * Notifies progress of a call transfer. + * @param lc the LinphoneCore + * @param call the call through which the transfer was sent. + * @param new_call_state the state of the call resulting of the transfer, at the other party. + **/ + void transferState(LinphoneCore lc, LinphoneCall call, LinphoneCall.State new_call_state); /**< @Deprecated Notifies the application that it should show up * @return */ diff --git a/java/common/org/linphone/core/LinphoneInfoMessage.java b/java/common/org/linphone/core/LinphoneInfoMessage.java new file mode 100644 index 000000000..93ee6a7ec --- /dev/null +++ b/java/common/org/linphone/core/LinphoneInfoMessage.java @@ -0,0 +1,36 @@ +package org.linphone.core; + +/** + * The LinphoneInfoMessage represents an informational message (INFO) to be transmitted or received by the LinphoneCore. + * @author smorlat + * + */ +public interface LinphoneInfoMessage { + /** + * Assign a content to the info message. This is optional. + * @param content + */ + void setContent(LinphoneContent content); + /** + * Get the actual content of the info message. It may be null. + * @return a LinphoneContent object or null + */ + LinphoneContent getContent(); + /** + * Add a specific header to the info message + * @param name the header's name + * @param value the header's value + */ + void addHeader(String name, String value); + /** + * Retrieve a header's value based on its name. + * @param name the header's name + * @return the header's value + */ + String getHeader(String name); + /** + * Get the origin of the info message as a string URI. + * @return origin of the message. + */ + String getFrom(); +} diff --git a/java/impl/org/linphone/core/LinphoneCallImpl.java b/java/impl/org/linphone/core/LinphoneCallImpl.java index 041acaef2..afe0afc00 100644 --- a/java/impl/org/linphone/core/LinphoneCallImpl.java +++ b/java/impl/org/linphone/core/LinphoneCallImpl.java @@ -207,4 +207,9 @@ class LinphoneCallImpl implements LinphoneCall { public void stopRecording() { stopRecording(nativePtr); } + private native int getTransferState(long nativePtr); + @Override + public State getTransferState() { + return State.fromInt(getTransferState(nativePtr)); + } } diff --git a/java/impl/org/linphone/core/LinphoneContentImpl.java b/java/impl/org/linphone/core/LinphoneContentImpl.java new file mode 100644 index 000000000..f74711042 --- /dev/null +++ b/java/impl/org/linphone/core/LinphoneContentImpl.java @@ -0,0 +1,46 @@ +package org.linphone.core; + +public class LinphoneContentImpl implements LinphoneContent { + private String mType, mSubtype, mData; + public LinphoneContentImpl(String type, String subtype, String data){ + mType=type; + mSubtype=subtype; + mData=data; + } + + @Override + public String getType() { + return mType; + } + + @Override + public String getSubtype() { + return mSubtype; + } + + @Override + public String getDataAsString() { + return mData; + } + + @Override + public int getSize() { + return mData.length(); + } + + @Override + public void setType(String type) { + mType=type; + } + + @Override + public void setSubtype(String subtype) { + mSubtype=subtype; + } + + @Override + public void setStringData(String data) { + mData=data; + } + +} diff --git a/java/impl/org/linphone/core/LinphoneCoreImpl.java b/java/impl/org/linphone/core/LinphoneCoreImpl.java index f9a7abf39..a414baf7a 100644 --- a/java/impl/org/linphone/core/LinphoneCoreImpl.java +++ b/java/impl/org/linphone/core/LinphoneCoreImpl.java @@ -948,4 +948,15 @@ class LinphoneCoreImpl implements LinphoneCore { public int getVideoDscp() { return getVideoDscp(nativePtr); } + + private native long createInfoMessage(long nativeptr); + @Override + public LinphoneInfoMessage createInfoMessage() { + return new LinphoneInfoMessageImpl(createInfoMessage(nativePtr)); + } + private native int sendInfoMessage(long corePtr, long infoptr, long destptr); + @Override + public void sendInfoMessage(LinphoneInfoMessage info, LinphoneAddress dest) { + sendInfoMessage(nativePtr,((LinphoneInfoMessageImpl)info).nativePtr, ((LinphoneAddressImpl)dest).nativePtr); + } } diff --git a/java/impl/org/linphone/core/LinphoneInfoMessageImpl.java b/java/impl/org/linphone/core/LinphoneInfoMessageImpl.java new file mode 100644 index 000000000..604fbc961 --- /dev/null +++ b/java/impl/org/linphone/core/LinphoneInfoMessageImpl.java @@ -0,0 +1,47 @@ +package org.linphone.core; + +public class LinphoneInfoMessageImpl implements LinphoneInfoMessage { + protected long nativePtr; + private LinphoneContent mContent; + + private native Object getContent(long nativeptr); + public LinphoneInfoMessageImpl(long ptr){ + nativePtr=ptr; + mContent=(LinphoneContent)getContent(nativePtr); + } + + private native void setContent(long nativePtr, String type, String subtype, String data); + @Override + public void setContent(LinphoneContent content) { + mContent=content; + setContent(nativePtr,mContent.getType(),mContent.getSubtype(),mContent.getDataAsString()); + } + + @Override + public LinphoneContent getContent() { + return mContent; + } + + private native void addHeader(long nativePtr, String name, String value); + @Override + public void addHeader(String name, String value) { + addHeader(nativePtr,name,value); + } + + private native String getHeader(long nativePtr, String name); + @Override + public String getHeader(String name) { + return getHeader(nativePtr,name); + } + + private native String getFrom(long nativePtr); + @Override + public String getFrom() { + return getFrom(nativePtr); + } + + private native void delete(long nativePtr); + protected void finalize(){ + delete(nativePtr); + } +}