From a142ea2981912ab3e6aaad772ad9bf48b8adf007 Mon Sep 17 00:00:00 2001 From: Christophe Deschamps Date: Thu, 24 Dec 2015 00:33:36 +0100 Subject: [PATCH 1/3] find friend by URI added to JNI --- coreapi/linphonecore_jni.cc | 9 +++++++-- java/common/org/linphone/core/LinphoneFriendList.java | 1 + java/impl/org/linphone/core/LinphoneCoreImpl.java | 2 ++ .../impl/org/linphone/core/LinphoneFriendListImpl.java | 10 ++++++++++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/coreapi/linphonecore_jni.cc b/coreapi/linphonecore_jni.cc index 1f770163a..b8e5e71f4 100644 --- a/coreapi/linphonecore_jni.cc +++ b/coreapi/linphonecore_jni.cc @@ -3007,8 +3007,13 @@ extern "C" void Java_org_linphone_core_LinphoneFriendListImpl_updateSubscription linphone_friend_list_update_subscriptions((LinphoneFriendList*)friendListptr,(LinphoneProxyConfig*)proxyConfigPtr,jonlyWhenRegistered); } - - +extern "C" jlong Java_org_linphone_core_LinphoneFriendListImpl_findFriendByUri(JNIEnv* env + ,jobject thiz + ,jlong friendListptr + ,jstring juri) { + const char* uri = env->GetStringUTFChars(juri, NULL); + return (jlong)linphone_friend_list_find_friend_by_uri((LinphoneFriendList*)friendListptr,uri); +} extern "C" jlong Java_org_linphone_core_LinphoneFriendImpl_getAddress(JNIEnv* env ,jobject thiz diff --git a/java/common/org/linphone/core/LinphoneFriendList.java b/java/common/org/linphone/core/LinphoneFriendList.java index daeca4801..29621eb0a 100644 --- a/java/common/org/linphone/core/LinphoneFriendList.java +++ b/java/common/org/linphone/core/LinphoneFriendList.java @@ -23,5 +23,6 @@ public interface LinphoneFriendList { public void setRLSUri(String uri); public void addFriend(LinphoneFriend friend); public void updateSubscriptions(LinphoneProxyConfig proxyConfig,boolean onlyWhenRegistered); + public LinphoneFriend findFriendByUri(String uri); long getNativePtr(); } diff --git a/java/impl/org/linphone/core/LinphoneCoreImpl.java b/java/impl/org/linphone/core/LinphoneCoreImpl.java index 582bf6bd4..19ed24b32 100644 --- a/java/impl/org/linphone/core/LinphoneCoreImpl.java +++ b/java/impl/org/linphone/core/LinphoneCoreImpl.java @@ -25,6 +25,8 @@ import java.io.IOException; import org.linphone.core.LinphoneCall.State; import org.linphone.core.LinphoneCoreListener; +import org.linphone.core.LinphoneProxyConfigImpl; + import org.linphone.mediastream.Log; import org.linphone.mediastream.Version; import org.linphone.mediastream.video.AndroidVideoWindowImpl; diff --git a/java/impl/org/linphone/core/LinphoneFriendListImpl.java b/java/impl/org/linphone/core/LinphoneFriendListImpl.java index 15832f786..19eb2687c 100644 --- a/java/impl/org/linphone/core/LinphoneFriendListImpl.java +++ b/java/impl/org/linphone/core/LinphoneFriendListImpl.java @@ -30,6 +30,8 @@ class LinphoneFriendListImpl implements LinphoneFriendList, Serializable { private native void addFriend(long nativePtr,long friendPtr); private native void updateSubscriptions(long nativePtr,long proxyConfigPtr,boolean onlyWhenRegistered); private native Object getCore(long ptr); + private native LinphoneFriend findFriendByUri(long nativePtr,String uri); + protected LinphoneFriendListImpl(LinphoneCoreImpl core) { @@ -56,6 +58,14 @@ class LinphoneFriendListImpl implements LinphoneFriendList, Serializable { updateSubscriptions(nativePtr, ((LinphoneProxyConfigImpl)proxyConfig).nativePtr,onlyWhenRegistered); } } + + @Override + public LinphoneFriend findFriendByUri(String uri) { + synchronized(getSyncObject()){ + return findFriendByUri(nativePtr,uri); + } + } + /*reserved for JNI */ protected LinphoneFriendListImpl(long aNativePtr) { From a589056381bb25d718d4c2f586a8cc69dc40f0e9 Mon Sep 17 00:00:00 2001 From: Christophe Deschamps Date: Mon, 28 Dec 2015 09:26:32 +0100 Subject: [PATCH 2/3] Fix memory leak --- coreapi/linphonecore_jni.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/coreapi/linphonecore_jni.cc b/coreapi/linphonecore_jni.cc index b8e5e71f4..078d1b506 100644 --- a/coreapi/linphonecore_jni.cc +++ b/coreapi/linphonecore_jni.cc @@ -2990,6 +2990,7 @@ extern "C" void Java_org_linphone_core_LinphoneFriendListImpl_setRLSUri(JNIEnv* ,jstring jrlsUri) { const char* uri = env->GetStringUTFChars(jrlsUri, NULL); linphone_friend_list_set_rls_uri((LinphoneFriendList*)ptr,uri); + env->ReleaseStringUTFChars(jrlsUri, uri); } extern "C" void Java_org_linphone_core_LinphoneFriendListImpl_addFriend(JNIEnv* env @@ -3012,7 +3013,10 @@ extern "C" jlong Java_org_linphone_core_LinphoneFriendListImpl_findFriendByUri(J ,jlong friendListptr ,jstring juri) { const char* uri = env->GetStringUTFChars(juri, NULL); - return (jlong)linphone_friend_list_find_friend_by_uri((LinphoneFriendList*)friendListptr,uri); + LinphoneFriend* lResult; + lResult = linphone_friend_list_find_friend_by_uri((LinphoneFriendList*)friendListptr,uri); + env->ReleaseStringUTFChars(juri, uri); + return (jlong)lResult; } extern "C" jlong Java_org_linphone_core_LinphoneFriendImpl_getAddress(JNIEnv* env From 293376d648c109db432341f49fbf86f3eb13d2f5 Mon Sep 17 00:00:00 2001 From: Christophe Deschamps Date: Tue, 29 Dec 2015 22:35:58 +0100 Subject: [PATCH 3/3] Fixes crash upon file transfer - jni wrapper --- coreapi/linphonecore_jni.cc | 812 ++++++++++++++++++++++-------------- 1 file changed, 502 insertions(+), 310 deletions(-) diff --git a/coreapi/linphonecore_jni.cc b/coreapi/linphonecore_jni.cc index 078d1b506..f93cb1843 100644 --- a/coreapi/linphonecore_jni.cc +++ b/coreapi/linphonecore_jni.cc @@ -196,177 +196,36 @@ extern "C" void Java_org_linphone_core_LinphoneCoreFactoryImpl_setLogCollectionP } // LinphoneCore -/* - * returns the java LinphoneProxyConfig associated with a C LinphoneProxyConfig. -**/ -jobject getProxy(JNIEnv *env, LinphoneProxyConfig *proxy, jobject core){ - jobject jobj=0; - - if (proxy!=NULL){ - jclass proxyClass = (jclass)env->FindClass("org/linphone/core/LinphoneProxyConfigImpl"); - jmethodID proxyCtrId = env->GetMethodID(proxyClass,"", "(Lorg/linphone/core/LinphoneCoreImpl;J)V"); - - void *up=linphone_proxy_config_get_user_data(proxy); - - if (up==NULL){ - jobj=env->NewObject(proxyClass,proxyCtrId,core,(jlong)proxy); - linphone_proxy_config_set_user_data(proxy,(void*)env->NewWeakGlobalRef(jobj)); - linphone_proxy_config_ref(proxy); - }else{ - //promote the weak ref to local ref - jobj=env->NewLocalRef((jobject)up); - if (jobj == NULL){ - //the weak ref was dead - jobj=env->NewObject(proxyClass,proxyCtrId,core,(jlong)proxy); - linphone_proxy_config_set_user_data(proxy,(void*)env->NewWeakGlobalRef(jobj)); - } - } - env->DeleteLocalRef(proxyClass); - } - return jobj; -} - -jobject getCall(JNIEnv *env, LinphoneCall *call){ - jobject jobj=0; - - if (call!=NULL){ - jclass callClass = (jclass)env->FindClass("org/linphone/core/LinphoneCallImpl"); - jmethodID callCtrId = env->GetMethodID(callClass,"", "(J)V"); - - void *up=linphone_call_get_user_pointer(call); - - if (up==NULL){ - jobj=env->NewObject(callClass,callCtrId,(jlong)call); - jobj=env->NewGlobalRef(jobj); - linphone_call_set_user_pointer(call,(void*)jobj); - linphone_call_ref(call); - }else{ - jobj=(jobject)up; - } - env->DeleteLocalRef(callClass); - } - return jobj; -} - -jobject getChatMessage(JNIEnv *env, LinphoneChatMessage *msg){ - jobject jobj = 0; - - if (msg != NULL){ - jclass chatMessageClass = (jclass)env->FindClass("org/linphone/core/LinphoneChatMessageImpl"); - jmethodID chatMessageCtrId = env->GetMethodID(chatMessageClass,"", "(J)V"); - - void *up = linphone_chat_message_get_user_data(msg); - - if (up == NULL) { - jobj = env->NewObject(chatMessageClass,chatMessageCtrId,(jlong)linphone_chat_message_ref(msg)); - jobj = env->NewGlobalRef(jobj); - linphone_chat_message_set_user_data(msg,(void*)jobj); - } else { - jobj = (jobject)up; - } - env->DeleteLocalRef(chatMessageClass); - } - return jobj; -} - -jobject getFriend(JNIEnv *env, LinphoneFriend *lfriend){ - jobject jobj=0; - - if (lfriend != NULL){ - jclass friendClass = (jclass)env->FindClass("org/linphone/core/LinphoneFriendImpl"); - jmethodID friendCtrId = env->GetMethodID(friendClass,"", "(J)V"); - - void *up=linphone_friend_get_user_data(lfriend); - - if (up == NULL){ - jobj=env->NewObject(friendClass,friendCtrId,(jlong)lfriend); - linphone_friend_set_user_data(lfriend,(void*)env->NewWeakGlobalRef(jobj)); - linphone_friend_ref(lfriend); - }else{ - - jobj=env->NewLocalRef((jobject)up); - if (jobj == NULL){ - jobj=env->NewObject(friendClass,friendCtrId,(jlong)lfriend); - linphone_friend_set_user_data(lfriend,(void*)env->NewWeakGlobalRef(jobj)); - } - } - env->DeleteLocalRef(friendClass); - } - return jobj; -} - -jobject getEvent(JNIEnv *env, LinphoneEvent *lev){ - if (lev==NULL) return NULL; - jobject jev=(jobject)linphone_event_get_user_data(lev); - if (jev==NULL){ - jclass linphoneEventClass = (jclass)env->FindClass("org/linphone/core/LinphoneEventImpl"); - jmethodID linphoneEventCtrId = env->GetMethodID(linphoneEventClass,"", "(J)V"); - - jev=env->NewObject(linphoneEventClass,linphoneEventCtrId,(jlong)linphone_event_ref(lev)); - jev=env->NewGlobalRef(jev); - linphone_event_set_user_data(lev,jev); - - env->DeleteLocalRef(linphoneEventClass); - } - return jev; -} - -class LinphoneCoreData { +class LinphoneJavaBindings { public: - LinphoneCoreData(JNIEnv *env, jobject lc, LinphoneCoreVTable *vTable, jobject alistener) { - core = env->NewGlobalRef(lc); - listener = env->NewGlobalRef(alistener); - - memset(vTable, 0, sizeof(LinphoneCoreVTable)); - - listenerClass = (jclass)env->NewGlobalRef(env->GetObjectClass(alistener)); - + LinphoneJavaBindings(JNIEnv *env) { + listenerClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCoreListener")); + /*displayStatus(LinphoneCore lc,String message);*/ displayStatusId = env->GetMethodID(listenerClass,"displayStatus","(Lorg/linphone/core/LinphoneCore;Ljava/lang/String;)V"); - if (displayStatusId) { - vTable->display_status = displayStatusCb; - } /*void generalState(LinphoneCore lc,int state); */ globalStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCore$GlobalState")); globalStateFromIntId = env->GetStaticMethodID(globalStateClass,"fromInt","(I)Lorg/linphone/core/LinphoneCore$GlobalState;"); globalStateId = env->GetMethodID(listenerClass,"globalState","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCore$GlobalState;Ljava/lang/String;)V"); - if (globalStateId) { - vTable->global_state_changed = globalStateChange; - } /*registrationState(LinphoneCore lc, LinphoneProxyConfig cfg, LinphoneCore.RegistrationState cstate, String smessage);*/ registrationStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCore$RegistrationState")); registrationStateFromIntId = env->GetStaticMethodID(registrationStateClass,"fromInt","(I)Lorg/linphone/core/LinphoneCore$RegistrationState;"); registrationStateId = env->GetMethodID(listenerClass,"registrationState","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneProxyConfig;Lorg/linphone/core/LinphoneCore$RegistrationState;Ljava/lang/String;)V"); - if (registrationStateId) { - vTable->registration_state_changed = registrationStateChange; - } /*callState(LinphoneCore lc, LinphoneCall call, LinphoneCall.State cstate,String message);*/ callStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCall$State")); callStateFromIntId = env->GetStaticMethodID(callStateClass,"fromInt","(I)Lorg/linphone/core/LinphoneCall$State;"); callStateId = env->GetMethodID(listenerClass,"callState","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCall;Lorg/linphone/core/LinphoneCall$State;Ljava/lang/String;)V"); - if (callStateId) { - vTable->call_state_changed = callStateChange; - } transferStateId = env->GetMethodID(listenerClass,"transferState","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCall;Lorg/linphone/core/LinphoneCall$State;)V"); - if (transferStateId) { - vTable->transfer_state_changed = transferStateChanged; - } /*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"); - if (callStatsUpdatedId) { - vTable->call_stats_updated = callStatsUpdated; - } /*callEncryption(LinphoneCore lc, LinphoneCall call, boolean encrypted,String auth_token);*/ callEncryptionChangedId = env->GetMethodID(listenerClass,"callEncryptionChanged","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCall;ZLjava/lang/String;)V"); - if (callEncryptionChangedId) { - vTable->call_encryption_changed = callEncryptionChange; - } /*void ecCalibrationStatus(LinphoneCore.EcCalibratorStatus status, int delay_ms, Object data);*/ ecCalibratorStatusClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCore$EcCalibratorStatus")); @@ -375,92 +234,44 @@ public: /*void newSubscriptionRequest(LinphoneCore lc, LinphoneFriend lf, String url)*/ newSubscriptionRequestId = env->GetMethodID(listenerClass,"newSubscriptionRequest","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneFriend;Ljava/lang/String;)V"); - if (newSubscriptionRequestId) { - vTable->new_subscription_requested = new_subscription_requested; - } authInfoRequestedId = env->GetMethodID(listenerClass,"authInfoRequested","(Lorg/linphone/core/LinphoneCore;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"); - if (authInfoRequestedId) { - vTable->auth_info_requested = authInfoRequested; - } /*void notifyPresenceReceived(LinphoneCore lc, LinphoneFriend lf);*/ notifyPresenceReceivedId = env->GetMethodID(listenerClass,"notifyPresenceReceived","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneFriend;)V"); - if (notifyPresenceReceivedId) { - vTable->notify_presence_received = notify_presence_received; - } messageReceivedId = env->GetMethodID(listenerClass,"messageReceived","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneChatRoom;Lorg/linphone/core/LinphoneChatMessage;)V"); - if (messageReceivedId) { - vTable->message_received = message_received; - } isComposingReceivedId = env->GetMethodID(listenerClass,"isComposingReceived","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneChatRoom;)V"); - if (isComposingReceivedId) { - vTable->is_composing_received = is_composing_received; - } dtmfReceivedId = env->GetMethodID(listenerClass,"dtmfReceived","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCall;I)V"); - if (dtmfReceivedId) { - vTable->dtmf_received = dtmf_received; - } infoReceivedId = env->GetMethodID(listenerClass,"infoReceived", "(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCall;Lorg/linphone/core/LinphoneInfoMessage;)V"); - if (infoReceivedId) { - vTable->info_received = infoReceived; - } subscriptionStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/SubscriptionState")); subscriptionStateFromIntId = env->GetStaticMethodID(subscriptionStateClass,"fromInt","(I)Lorg/linphone/core/SubscriptionState;"); subscriptionStateId = env->GetMethodID(listenerClass,"subscriptionStateChanged", "(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneEvent;Lorg/linphone/core/SubscriptionState;)V"); - if (subscriptionStateId) { - vTable->subscription_state_changed = subscriptionStateChanged; - } publishStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/PublishState")); publishStateFromIntId = env->GetStaticMethodID(publishStateClass,"fromInt","(I)Lorg/linphone/core/PublishState;"); publishStateId = env->GetMethodID(listenerClass,"publishStateChanged", "(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneEvent;Lorg/linphone/core/PublishState;)V"); - if (publishStateId) { - vTable->publish_state_changed = publishStateChanged; - } notifyRecvId = env->GetMethodID(listenerClass,"notifyReceived", "(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneEvent;Ljava/lang/String;Lorg/linphone/core/LinphoneContent;)V"); - if (notifyRecvId) { - vTable->notify_received = notifyReceived; - } configuringStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCore$RemoteProvisioningState")); configuringStateFromIntId = env->GetStaticMethodID(configuringStateClass,"fromInt","(I)Lorg/linphone/core/LinphoneCore$RemoteProvisioningState;"); configuringStateId = env->GetMethodID(listenerClass,"configuringStatus","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCore$RemoteProvisioningState;Ljava/lang/String;)V"); - if (configuringStateId) { - vTable->configuring_status = configuringStatus; - } fileTransferProgressIndicationId = env->GetMethodID(listenerClass, "fileTransferProgressIndication", "(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneChatMessage;Lorg/linphone/core/LinphoneContent;I)V"); - if (fileTransferProgressIndicationId) { - vTable->file_transfer_progress_indication = fileTransferProgressIndication; - } fileTransferSendId = env->GetMethodID(listenerClass, "fileTransferSend", "(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneChatMessage;Lorg/linphone/core/LinphoneContent;Ljava/nio/ByteBuffer;I)I"); - if (fileTransferSendId) { - vTable->file_transfer_send = fileTransferSend; - } fileTransferRecvId = env->GetMethodID(listenerClass, "fileTransferRecv", "(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneChatMessage;Lorg/linphone/core/LinphoneContent;[BI)V"); - if (fileTransferRecvId) { - vTable->file_transfer_recv = fileTransferRecv; - } logCollectionUploadStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCore$LogCollectionUploadState")); logCollectionUploadStateFromIntId = env->GetStaticMethodID(logCollectionUploadStateClass, "fromInt", "(I)Lorg/linphone/core/LinphoneCore$LogCollectionUploadState;"); logCollectionUploadProgressId = env->GetMethodID(listenerClass, "uploadProgressIndication", "(Lorg/linphone/core/LinphoneCore;II)V"); - if (logCollectionUploadProgressId) { - vTable->log_collection_upload_progress_indication = logCollectionUploadProgressIndication; - } logCollectionUploadStateId = env->GetMethodID(listenerClass, "uploadStateChanged", "(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCore$LogCollectionUploadState;Ljava/lang/String;)V"); - if (logCollectionUploadStateId) { - vTable->log_collection_upload_state_changed = logCollectionUploadStateChange; - } chatMessageStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneChatMessage$State")); chatMessageStateFromIntId = env->GetStaticMethodID(chatMessageStateClass,"fromInt","(I)Lorg/linphone/core/LinphoneChatMessage$State;"); @@ -499,12 +310,18 @@ public: subscriptionDirClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/SubscriptionDir")); subscriptionDirFromIntId = env->GetStaticMethodID(subscriptionDirClass,"fromInt","(I)Lorg/linphone/core/SubscriptionDir;"); } + + void setCore(jobject c) { + core = c; + } + + jobject getCore() { + return core; + } - ~LinphoneCoreData() { + ~LinphoneJavaBindings() { JNIEnv *env = 0; jvm->AttachCurrentThread(&env,NULL); - env->DeleteGlobalRef(core); - env->DeleteGlobalRef(listener); env->DeleteGlobalRef(listenerClass); env->DeleteGlobalRef(globalStateClass); env->DeleteGlobalRef(configuringStateClass); @@ -522,8 +339,8 @@ public: env->DeleteGlobalRef(subscriptionDirClass); env->DeleteGlobalRef(logCollectionUploadStateClass); } + jobject core; - jobject listener; jclass listenerClass; jmethodID displayStatusId; @@ -611,6 +428,227 @@ public: jmethodID logCollectionUploadStateId; jmethodID logCollectionUploadStateFromIntId; jmethodID logCollectionUploadProgressId; +}; + +/* + * returns the java LinphoneProxyConfig associated with a C LinphoneProxyConfig. +**/ +jobject getProxy(JNIEnv *env, LinphoneProxyConfig *proxy, jobject core){ + jobject jobj=0; + + if (proxy!=NULL){ + LinphoneCore *lc = linphone_proxy_config_get_core(proxy); + LinphoneJavaBindings *ljb = (LinphoneJavaBindings *)linphone_core_get_user_data(lc); + + void *up=linphone_proxy_config_get_user_data(proxy); + + if (up==NULL){ + jobj=env->NewObject(ljb->proxyClass, ljb->proxyCtrId, core, (jlong)proxy); + linphone_proxy_config_set_user_data(proxy,(void*)env->NewWeakGlobalRef(jobj)); + linphone_proxy_config_ref(proxy); + }else{ + //promote the weak ref to local ref + jobj=env->NewLocalRef((jobject)up); + if (jobj == NULL){ + //the weak ref was dead + jobj=env->NewObject(ljb->proxyClass, ljb->proxyCtrId, core, (jlong)proxy); + linphone_proxy_config_set_user_data(proxy,(void*)env->NewWeakGlobalRef(jobj)); + } + } + } + return jobj; +} + +jobject getCall(JNIEnv *env, LinphoneCall *call){ + jobject jobj=0; + + if (call!=NULL){ + LinphoneCore *lc = linphone_call_get_core(call); + LinphoneJavaBindings *ljb = (LinphoneJavaBindings *)linphone_core_get_user_data(lc); + + void *up=linphone_call_get_user_pointer(call); + + if (up==NULL){ + jobj=env->NewObject(ljb->callClass, ljb->callCtrId, (jlong)call); + jobj=env->NewGlobalRef(jobj); + linphone_call_set_user_pointer(call,(void*)jobj); + linphone_call_ref(call); + }else{ + jobj=(jobject)up; + } + } + return jobj; +} + +jobject getChatMessage(JNIEnv *env, LinphoneChatMessage *msg){ + jobject jobj = 0; + + if (msg != NULL){ + LinphoneChatRoom *room = linphone_chat_message_get_chat_room(msg); + LinphoneCore *lc = linphone_chat_room_get_core(room); + LinphoneJavaBindings *ljb = (LinphoneJavaBindings *)linphone_core_get_user_data(lc); + + void *up = linphone_chat_message_get_user_data(msg); + + if (up == NULL) { + jobj = env->NewObject(ljb->chatMessageClass, ljb->chatMessageCtrId, (jlong)linphone_chat_message_ref(msg)); + jobj = env->NewGlobalRef(jobj); + linphone_chat_message_set_user_data(msg,(void*)jobj); + } else { + jobj = (jobject)up; + } + } + return jobj; +} + +jobject getFriend(JNIEnv *env, LinphoneFriend *lfriend){ + jobject jobj=0; + + if (lfriend != NULL){ + LinphoneCore *lc = linphone_friend_get_core(lfriend); + LinphoneJavaBindings *ljb = (LinphoneJavaBindings *)linphone_core_get_user_data(lc); + + void *up=linphone_friend_get_user_data(lfriend); + + if (up == NULL){ + jobj=env->NewObject(ljb->friendClass, ljb->friendCtrId, (jlong)lfriend); + linphone_friend_set_user_data(lfriend,(void*)env->NewWeakGlobalRef(jobj)); + linphone_friend_ref(lfriend); + }else{ + + jobj=env->NewLocalRef((jobject)up); + if (jobj == NULL){ + jobj=env->NewObject(ljb->friendClass, ljb->friendCtrId, (jlong)lfriend); + linphone_friend_set_user_data(lfriend,(void*)env->NewWeakGlobalRef(jobj)); + } + } + } + return jobj; +} + +jobject getEvent(JNIEnv *env, LinphoneEvent *lev){ + if (lev==NULL) return NULL; + jobject jev=(jobject)linphone_event_get_user_data(lev); + if (jev==NULL){ + LinphoneCore *lc = linphone_event_get_core(lev); + LinphoneJavaBindings *ljb = (LinphoneJavaBindings *)linphone_core_get_user_data(lc); + + jev=env->NewObject(ljb->linphoneEventClass, ljb->linphoneEventCtrId, (jlong)linphone_event_ref(lev)); + jev=env->NewGlobalRef(jev); + linphone_event_set_user_data(lev,jev); + } + return jev; +} + +class LinphoneCoreData { +public: + LinphoneCoreData(JNIEnv *env, jobject lc, LinphoneCoreVTable *vTable, jobject alistener, LinphoneJavaBindings *ljb) { + core = env->NewGlobalRef(lc); + listener = env->NewGlobalRef(alistener); + + memset(vTable, 0, sizeof(LinphoneCoreVTable)); + + if (ljb->displayStatusId) { + vTable->display_status = displayStatusCb; + } + + if (ljb->globalStateId) { + vTable->global_state_changed = globalStateChange; + } + + if (ljb->registrationStateId) { + vTable->registration_state_changed = registrationStateChange; + } + + if (ljb->callStateId) { + vTable->call_state_changed = callStateChange; + } + + if (ljb->transferStateId) { + vTable->transfer_state_changed = transferStateChanged; + } + + if (ljb->callStatsUpdatedId) { + vTable->call_stats_updated = callStatsUpdated; + } + + if (ljb->callEncryptionChangedId) { + vTable->call_encryption_changed = callEncryptionChange; + } + + if (ljb->newSubscriptionRequestId) { + vTable->new_subscription_requested = new_subscription_requested; + } + + if (ljb->authInfoRequestedId) { + vTable->auth_info_requested = authInfoRequested; + } + + if (ljb->notifyPresenceReceivedId) { + vTable->notify_presence_received = notify_presence_received; + } + + if (ljb->messageReceivedId) { + vTable->message_received = message_received; + } + + if (ljb->isComposingReceivedId) { + vTable->is_composing_received = is_composing_received; + } + + if (ljb->dtmfReceivedId) { + vTable->dtmf_received = dtmf_received; + } + + if (ljb->infoReceivedId) { + vTable->info_received = infoReceived; + } + + if (ljb->subscriptionStateId) { + vTable->subscription_state_changed = subscriptionStateChanged; + } + + if (ljb->publishStateId) { + vTable->publish_state_changed = publishStateChanged; + } + + if (ljb->notifyRecvId) { + vTable->notify_received = notifyReceived; + } + + if (ljb->configuringStateId) { + vTable->configuring_status = configuringStatus; + } + + if (ljb->fileTransferProgressIndicationId) { + vTable->file_transfer_progress_indication = fileTransferProgressIndication; + } + + if (ljb->fileTransferSendId) { + vTable->file_transfer_send = fileTransferSend; + } + + if (ljb->fileTransferRecvId) { + vTable->file_transfer_recv = fileTransferRecv; + } + + if (ljb->logCollectionUploadProgressId) { + vTable->log_collection_upload_progress_indication = logCollectionUploadProgressIndication; + } + if (ljb->logCollectionUploadStateId) { + vTable->log_collection_upload_state_changed = logCollectionUploadStateChange; + } + } + + ~LinphoneCoreData() { + JNIEnv *env = 0; + jvm->AttachCurrentThread(&env,NULL); + env->DeleteGlobalRef(core); + env->DeleteGlobalRef(listener); + } + + jobject core; + jobject listener; LinphoneCoreVTable vTable; @@ -621,10 +659,12 @@ public: ms_error("cannot attach VM"); return; } + + LinphoneJavaBindings *ljb = (LinphoneJavaBindings *)linphone_core_get_user_data(lc); LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc); LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table); jstring msg = message ? env->NewStringUTF(message) : NULL; - env->CallVoidMethod(lcData->listener,lcData->displayStatusId,lcData->core,msg); + env->CallVoidMethod(lcData->listener,ljb->displayStatusId,lcData->core,msg); handle_possible_java_exception(env, lcData->listener); if (msg) { env->DeleteLocalRef(msg); @@ -637,13 +677,15 @@ public: ms_error("cannot attach VM"); return; } + + LinphoneJavaBindings *ljb = (LinphoneJavaBindings *)linphone_core_get_user_data(lc); LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc); LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table); jstring r = realm ? env->NewStringUTF(realm) : NULL; jstring u = username ? env->NewStringUTF(username) : NULL; jstring d = domain ? env->NewStringUTF(domain) : NULL; env->CallVoidMethod(lcData->listener, - lcData->authInfoRequestedId, + ljb->authInfoRequestedId, lcData->core, r, u, @@ -675,6 +717,8 @@ public: ms_error("cannot attach VM"); return; } + + LinphoneJavaBindings *ljb = (LinphoneJavaBindings *)linphone_core_get_user_data(lc); LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc); LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table); @@ -684,9 +728,9 @@ public: jstring msg = message ? env->NewStringUTF(message) : NULL; env->CallVoidMethod(lcData->listener - ,lcData->globalStateId + ,ljb->globalStateId ,lcData->core - ,env->CallStaticObjectMethod(lcData->globalStateClass,lcData->globalStateFromIntId,(jint)gstate), + ,env->CallStaticObjectMethod(ljb->globalStateClass,ljb->globalStateFromIntId,(jint)gstate), msg); handle_possible_java_exception(env, lcData->listener); if (msg) { @@ -701,14 +745,16 @@ public: ms_error("cannot attach VM"); return; } + + LinphoneJavaBindings *ljb = (LinphoneJavaBindings *)linphone_core_get_user_data(lc); LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc); LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table); jstring msg = message ? env->NewStringUTF(message) : NULL; env->CallVoidMethod(lcData->listener - ,lcData->registrationStateId + ,ljb->registrationStateId ,lcData->core ,(jproxy=getProxy(env,proxy,lcData->core)) - ,env->CallStaticObjectMethod(lcData->registrationStateClass,lcData->registrationStateFromIntId,(jint)state), + ,env->CallStaticObjectMethod(ljb->registrationStateClass,ljb->registrationStateFromIntId,(jint)state), msg); handle_possible_java_exception(env, lcData->listener); if (msg) { @@ -724,14 +770,16 @@ public: ms_error("cannot attach VM"); return; } + + LinphoneJavaBindings *ljb = (LinphoneJavaBindings *)linphone_core_get_user_data(lc); LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc); LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table); jstring msg = message ? env->NewStringUTF(message) : NULL; env->CallVoidMethod(lcData->listener - ,lcData->callStateId + ,ljb->callStateId ,lcData->core ,(jcall=getCall(env,call)) - ,env->CallStaticObjectMethod(lcData->callStateClass,lcData->callStateFromIntId,(jint)state), + ,env->CallStaticObjectMethod(ljb->callStateClass,ljb->callStateFromIntId,(jint)state), msg); handle_possible_java_exception(env, lcData->listener); if (state==LinphoneCallReleased) { @@ -749,10 +797,12 @@ public: ms_error("cannot attach VM"); return; } + + LinphoneJavaBindings *ljb = (LinphoneJavaBindings *)linphone_core_get_user_data(lc); LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc); LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table); env->CallVoidMethod(lcData->listener - ,lcData->callEncryptionChangedId + ,ljb->callEncryptionChangedId ,lcData->core ,getCall(env,call) ,encrypted @@ -766,10 +816,12 @@ public: ms_error("cannot attach VM"); return; } + + LinphoneJavaBindings *ljb = (LinphoneJavaBindings *)linphone_core_get_user_data(lc); LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc); LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table); env->CallVoidMethod(lcData->listener - ,lcData->notifyPresenceReceivedId + ,ljb->notifyPresenceReceivedId ,lcData->core ,getFriend(env,my_friend)); handle_possible_java_exception(env, lcData->listener); @@ -781,10 +833,12 @@ public: ms_error("cannot attach VM"); return; } + + LinphoneJavaBindings *ljb = (LinphoneJavaBindings *)linphone_core_get_user_data(lc); LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc); LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table); env->CallVoidMethod(lcData->listener - ,lcData->newSubscriptionRequestId + ,ljb->newSubscriptionRequestId ,lcData->core ,getFriend(env,my_friend) ,url ? env->NewStringUTF(url) : NULL); @@ -797,10 +851,12 @@ public: ms_error("cannot attach VM"); return; } + + LinphoneJavaBindings *ljb = (LinphoneJavaBindings *)linphone_core_get_user_data(lc); LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc); LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table); env->CallVoidMethod(lcData->listener - ,lcData->dtmfReceivedId + ,ljb->dtmfReceivedId ,lcData->core ,getCall(env,call) ,dtmf); @@ -814,13 +870,15 @@ public: ms_error("cannot attach VM"); return; } + + LinphoneJavaBindings *ljb = (LinphoneJavaBindings *)linphone_core_get_user_data(lc); LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc); LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table); /*note: we call linphone_chat_message_ref() because the application does not acquire the object when invoked from a callback*/ env->CallVoidMethod(lcData->listener - ,lcData->messageReceivedId + ,ljb->messageReceivedId ,lcData->core - ,env->NewObject(lcData->chatRoomClass,lcData->chatRoomCtrId,(jlong)room) + ,env->NewObject(ljb->chatRoomClass,ljb->chatRoomCtrId,(jlong)room) ,(jmsg = getChatMessage(env, msg))); handle_possible_java_exception(env, lcData->listener); } @@ -831,12 +889,14 @@ public: ms_error("cannot attach VM"); return; } + + LinphoneJavaBindings *ljb = (LinphoneJavaBindings *)linphone_core_get_user_data(lc); LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc); LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table); env->CallVoidMethod(lcData->listener - ,lcData->isComposingReceivedId + ,ljb->isComposingReceivedId ,lcData->core - ,env->NewObject(lcData->chatRoomClass,lcData->chatRoomCtrId,(jlong)room)); + ,env->NewObject(ljb->chatRoomClass,ljb->chatRoomCtrId,(jlong)room)); handle_possible_java_exception(env, lcData->listener); } static void ecCalibrationStatus(LinphoneCore *lc, LinphoneEcCalibratorStatus status, int delay_ms, void *data) { @@ -847,13 +907,14 @@ public: return; } + LinphoneJavaBindings *ljb = (LinphoneJavaBindings *)linphone_core_get_user_data(lc); LinphoneCoreVTable *table = (LinphoneCoreVTable*) data; - if (table) { + if (table && ljb) { LinphoneCoreData* lcData = (LinphoneCoreData*) linphone_core_v_table_get_user_data(table); - if (lcData->ecCalibrationStatusId) { - jobject state = env->CallStaticObjectMethod(lcData->ecCalibratorStatusClass, lcData->ecCalibratorStatusFromIntId, (jint)status); + if (ljb->ecCalibrationStatusId) { + jobject state = env->CallStaticObjectMethod(ljb->ecCalibratorStatusClass, ljb->ecCalibratorStatusFromIntId, (jint)status); env->CallVoidMethod(lcData->listener - ,lcData->ecCalibrationStatusId + ,ljb->ecCalibrationStatusId ,lcData->core ,state ,delay_ms @@ -875,15 +936,17 @@ public: ms_error("cannot attach VM"); return; } + + LinphoneJavaBindings *ljb = (LinphoneJavaBindings *)linphone_core_get_user_data(lc); LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc); LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table); - statsobj = env->NewObject(lcData->callStatsClass, lcData->callStatsId, (jlong)call, (jlong)stats); + statsobj = env->NewObject(ljb->callStatsClass, ljb->callStatsId, (jlong)call, (jlong)stats); callobj = getCall(env, call); if (stats->type == LINPHONE_CALL_STATS_AUDIO) - env->CallVoidMethod(callobj, lcData->callSetAudioStatsId, statsobj); + env->CallVoidMethod(callobj, ljb->callSetAudioStatsId, statsobj); else - env->CallVoidMethod(callobj, lcData->callSetVideoStatsId, statsobj); - env->CallVoidMethod(lcData->listener, lcData->callStatsUpdatedId, lcData->core, callobj, statsobj); + env->CallVoidMethod(callobj, ljb->callSetVideoStatsId, statsobj); + env->CallVoidMethod(lcData->listener, ljb->callStatsUpdatedId, lcData->core, callobj, statsobj); handle_possible_java_exception(env, lcData->listener); if (statsobj) env->DeleteLocalRef(statsobj); } @@ -895,13 +958,15 @@ public: ms_error("cannot attach VM"); return; } + + LinphoneJavaBindings *ljb = (LinphoneJavaBindings *)linphone_core_get_user_data(lc); LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc); LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table); env->CallVoidMethod(lcData->listener - ,lcData->transferStateId + ,ljb->transferStateId ,lcData->core ,(jcall=getCall(env,call)) - ,env->CallStaticObjectMethod(lcData->callStateClass,lcData->callStateFromIntId,(jint)remote_call_state) + ,env->CallStaticObjectMethod(ljb->callStateClass,ljb->callStateFromIntId,(jint)remote_call_state) ); handle_possible_java_exception(env, lcData->listener); } @@ -912,14 +977,16 @@ public: ms_error("cannot attach VM"); return; } + + LinphoneJavaBindings *ljb = (LinphoneJavaBindings *)linphone_core_get_user_data(lc); LinphoneInfoMessage *copy_info=linphone_info_message_copy(info); LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc); LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table); env->CallVoidMethod(lcData->listener - ,lcData->infoReceivedId + ,ljb->infoReceivedId ,lcData->core ,getCall(env,call) - ,env->NewObject(lcData->infoMessageClass,lcData->infoMessageCtor,(jlong)copy_info) + ,env->NewObject(ljb->infoMessageClass,ljb->infoMessageCtor,(jlong)copy_info) ); handle_possible_java_exception(env, lcData->listener); } @@ -932,12 +999,14 @@ public: ms_error("cannot attach VM"); return; } + + LinphoneJavaBindings *ljb = (LinphoneJavaBindings *)linphone_core_get_user_data(lc); LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc); LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table); jevent=getEvent(env,ev); - jstate=env->CallStaticObjectMethod(lcData->subscriptionStateClass,lcData->subscriptionStateFromIntId,(jint)state); + jstate=env->CallStaticObjectMethod(ljb->subscriptionStateClass,ljb->subscriptionStateFromIntId,(jint)state); env->CallVoidMethod(lcData->listener - ,lcData->subscriptionStateId + ,ljb->subscriptionStateId ,lcData->core ,jevent ,jstate @@ -958,12 +1027,14 @@ public: ms_error("cannot attach VM"); return; } + + LinphoneJavaBindings *ljb = (LinphoneJavaBindings *)linphone_core_get_user_data(lc); LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc); LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table); jevent=getEvent(env,ev); - jstate=env->CallStaticObjectMethod(lcData->publishStateClass,lcData->publishStateFromIntId,(jint)state); + jstate=env->CallStaticObjectMethod(ljb->publishStateClass,ljb->publishStateFromIntId,(jint)state); env->CallVoidMethod(lcData->listener - ,lcData->publishStateId + ,ljb->publishStateId ,lcData->core ,jevent ,jstate @@ -978,11 +1049,13 @@ public: ms_error("cannot attach VM"); return; } + + LinphoneJavaBindings *ljb = (LinphoneJavaBindings *)linphone_core_get_user_data(lc); LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc); LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table); jevent=getEvent(env,ev); env->CallVoidMethod(lcData->listener - ,lcData->notifyRecvId + ,ljb->notifyRecvId ,lcData->core ,jevent ,env->NewStringUTF(evname) @@ -998,9 +1071,11 @@ public: ms_error("cannot attach VM"); return; } + + LinphoneJavaBindings *ljb = (LinphoneJavaBindings *)linphone_core_get_user_data(lc); LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc); LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table); - env->CallVoidMethod(lcData->listener, lcData->configuringStateId, lcData->core, env->CallStaticObjectMethod(lcData->configuringStateClass,lcData->configuringStateFromIntId,(jint)status), message ? env->NewStringUTF(message) : NULL); + env->CallVoidMethod(lcData->listener, ljb->configuringStateId, lcData->core, env->CallStaticObjectMethod(ljb->configuringStateClass,ljb->configuringStateFromIntId,(jint)status), message ? env->NewStringUTF(message) : NULL); handle_possible_java_exception(env, lcData->listener); } @@ -1013,11 +1088,13 @@ public: ms_error("cannot attach VM"); return; } + + LinphoneJavaBindings *ljb = (LinphoneJavaBindings *)linphone_core_get_user_data(lc); LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc); LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table); jobject jcontent = content ? create_java_linphone_content(env, content) : NULL; env->CallVoidMethod(lcData->listener, - lcData->fileTransferProgressIndicationId, + ljb->fileTransferProgressIndicationId, lcData->core, (jmsg = getChatMessage(env, message)), jcontent, @@ -1037,12 +1114,14 @@ public: ms_error("cannot attach VM"); return; } + + LinphoneJavaBindings *ljb = (LinphoneJavaBindings *)linphone_core_get_user_data(lc); LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc); LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table); jobject jcontent = content ? create_java_linphone_content(env, content) : NULL; jobject jbuffer = buff ? env->NewDirectByteBuffer(buff, asking) : NULL; *size = env->CallIntMethod(lcData->listener, - lcData->fileTransferSendId, + ljb->fileTransferSendId, lcData->core, (jmsg = getChatMessage(env, message)), jcontent, @@ -1065,6 +1144,8 @@ public: ms_error("cannot attach VM"); return; } + + LinphoneJavaBindings *ljb = (LinphoneJavaBindings *)linphone_core_get_user_data(lc); LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc); LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table); @@ -1073,7 +1154,7 @@ public: jobject jcontent = content ? create_java_linphone_content(env, content) : NULL; env->CallVoidMethod(lcData->listener, - lcData->fileTransferRecvId, + ljb->fileTransferRecvId, lcData->core, (jmsg = getChatMessage(env, message)), jcontent, @@ -1091,10 +1172,12 @@ public: ms_error("cannot attach VM"); return; } + + LinphoneJavaBindings *ljb = (LinphoneJavaBindings *)linphone_core_get_user_data(lc); LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc); LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table); env->CallVoidMethod(lcData->listener - ,lcData->logCollectionUploadProgressId + ,ljb->logCollectionUploadProgressId ,lcData->core ,(jlong)offset ,(jlong)total); @@ -1107,13 +1190,15 @@ public: ms_error("cannot attach VM"); return; } + + LinphoneJavaBindings *ljb = (LinphoneJavaBindings *)linphone_core_get_user_data(lc); LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc); LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table); jstring msg = info ? env->NewStringUTF(info) : NULL; env->CallVoidMethod(lcData->listener - ,lcData->logCollectionUploadStateId + ,ljb->logCollectionUploadStateId ,lcData->core - ,env->CallStaticObjectMethod(lcData->logCollectionUploadStateClass,lcData->logCollectionUploadStateFromIntId,(jint)state), + ,env->CallStaticObjectMethod(ljb->logCollectionUploadStateClass,ljb->logCollectionUploadStateFromIntId,(jint)state), msg); handle_possible_java_exception(env, lcData->listener); if (msg) { @@ -1142,8 +1227,10 @@ extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_newLinphoneCore(JNIEnv* const char* userConfig = juserConfig?env->GetStringUTFChars(juserConfig, NULL):NULL; const char* factoryConfig = jfactoryConfig?env->GetStringUTFChars(jfactoryConfig, NULL):NULL; + LinphoneJavaBindings *ljb = new LinphoneJavaBindings(env); + LinphoneCoreVTable *vTable = linphone_core_v_table_new(); - LinphoneCoreData* ldata = new LinphoneCoreData(env, thiz, vTable, jlistener); + LinphoneCoreData* ldata = new LinphoneCoreData(env, thiz, vTable, jlistener, ljb); linphone_core_v_table_set_user_data(vTable, ldata); ms_init(); // Initialize mediastreamer2 before loading the plugins @@ -1174,7 +1261,9 @@ extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_newLinphoneCore(JNIEnv* #endif jobject core = env->NewGlobalRef(thiz); - jlong nativePtr = (jlong)linphone_core_new(vTable, userConfig, factoryConfig, core); + ljb->setCore(core); + LinphoneCore *lc = linphone_core_new(vTable, userConfig, factoryConfig, ljb); + jlong nativePtr = (jlong)lc; if (userConfig) env->ReleaseStringUTFChars(juserConfig, userConfig); if (factoryConfig) env->ReleaseStringUTFChars(jfactoryConfig, factoryConfig); @@ -1182,7 +1271,7 @@ extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_newLinphoneCore(JNIEnv* } extern "C" void Java_org_linphone_core_LinphoneCoreImpl_delete(JNIEnv* env, jobject thiz, jlong native_ptr) { LinphoneCore *lc=(LinphoneCore*)native_ptr; - jobject core = (jobject)linphone_core_get_user_data(lc); + LinphoneJavaBindings *ljb = (LinphoneJavaBindings *)linphone_core_get_user_data(lc); jobject multicast_lock = lc->multicast_lock; jobject multicast_lock_class = lc->multicast_lock_class; @@ -1197,14 +1286,19 @@ extern "C" void Java_org_linphone_core_LinphoneCoreImpl_delete(JNIEnv* env, jobj if (multicast_lock) env->DeleteGlobalRef(multicast_lock); if (multicast_lock_class) env->DeleteGlobalRef(multicast_lock_class); - if (core) { - env->DeleteGlobalRef(core); + if (ljb) { + jobject core = ljb->getCore(); + if (core) { + env->DeleteGlobalRef(core); + } + delete ljb; } } extern "C" void Java_org_linphone_core_LinphoneCoreImpl_addListener(JNIEnv* env, jobject thiz, jlong lc, jobject jlistener) { + LinphoneJavaBindings *ljb = (LinphoneJavaBindings *) linphone_core_get_user_data((LinphoneCore *)lc); LinphoneCoreVTable *vTable = linphone_core_v_table_new(); - LinphoneCoreData* ldata = new LinphoneCoreData(env, thiz, vTable, jlistener); + LinphoneCoreData* ldata = new LinphoneCoreData(env, thiz, vTable, jlistener, ljb); linphone_core_v_table_set_user_data(vTable, ldata); linphone_core_add_listener((LinphoneCore*)lc, vTable); } @@ -1340,8 +1434,8 @@ extern "C" jobject Java_org_linphone_core_LinphoneCoreImpl_getDefaultProxyConfig extern "C" jobjectArray Java_org_linphone_core_LinphoneCoreImpl_getProxyConfigList(JNIEnv* env, jobject thiz, jlong lc) { const MSList* proxies = linphone_core_get_proxy_config_list((LinphoneCore*)lc); int proxyCount = ms_list_size(proxies); - jclass cls = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneProxyConfigImpl")); - jobjectArray jProxies = env->NewObjectArray(proxyCount,cls,NULL); + LinphoneJavaBindings *ljb = (LinphoneJavaBindings *)linphone_core_get_user_data((LinphoneCore *)lc); + jobjectArray jProxies = env->NewObjectArray(proxyCount,ljb->proxyClass,NULL); for (int i = 0; i < proxyCount; i++ ) { LinphoneProxyConfig* proxy = (LinphoneProxyConfig*)proxies->data; @@ -1351,7 +1445,7 @@ extern "C" jobjectArray Java_org_linphone_core_LinphoneCoreImpl_getProxyConfigLi } proxies = proxies->next; } - env->DeleteGlobalRef(cls); + return jProxies; } @@ -1859,8 +1953,8 @@ extern "C" jobjectArray Java_org_linphone_core_LinphoneCoreImpl_getFriendList(JN ,jlong lc) { const MSList* friends = linphone_core_get_friend_list((LinphoneCore*)lc); int friendsSize = ms_list_size(friends); - jclass cls = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneFriendImpl")); - jobjectArray jFriends = env->NewObjectArray(friendsSize,cls,NULL); + LinphoneJavaBindings *ljb = (LinphoneJavaBindings *)linphone_core_get_user_data((LinphoneCore *)lc); + jobjectArray jFriends = env->NewObjectArray(friendsSize,ljb->friendClass,NULL); for (int i = 0; i < friendsSize; i++) { LinphoneFriend* lfriend = (LinphoneFriend*)friends->data; @@ -1870,8 +1964,7 @@ extern "C" jobjectArray Java_org_linphone_core_LinphoneCoreImpl_getFriendList(JN } friends = friends->next; } - - env->DeleteGlobalRef(cls); + return jFriends; } extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPresenceInfo(JNIEnv* env @@ -2048,8 +2141,9 @@ extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_startEchoCalibration(JNI ,jobject thiz ,jlong lc ,jobject data) { + LinphoneJavaBindings *ljb = (LinphoneJavaBindings *) linphone_core_get_user_data((LinphoneCore *)lc); LinphoneCoreVTable *vTable = linphone_core_v_table_new(); - LinphoneCoreData* ldata = new LinphoneCoreData(env, thiz, vTable, data); + LinphoneCoreData* ldata = new LinphoneCoreData(env, thiz, vTable, data, ljb); linphone_core_v_table_set_user_data(vTable, ldata); return (jint)linphone_core_start_echo_calibration((LinphoneCore*)lc, ldata->ecCalibrationStatus, NULL, NULL, vTable); @@ -2990,7 +3084,18 @@ extern "C" void Java_org_linphone_core_LinphoneFriendListImpl_setRLSUri(JNIEnv* ,jstring jrlsUri) { const char* uri = env->GetStringUTFChars(jrlsUri, NULL); linphone_friend_list_set_rls_uri((LinphoneFriendList*)ptr,uri); - env->ReleaseStringUTFChars(jrlsUri, uri); + env->ReleaseStringUTFChars(jrlsUri, uri); +} + +extern "C" jlong Java_org_linphone_core_LinphoneFriendListImpl_findFriendByUri(JNIEnv* env + ,jobject thiz + ,jlong friendListptr + ,jstring juri) { + const char* uri = env->GetStringUTFChars(juri, NULL); + LinphoneFriend* lResult; + lResult = linphone_friend_list_find_friend_by_uri((LinphoneFriendList*)friendListptr,uri); + env->ReleaseStringUTFChars(juri, uri); + return (jlong)lResult; } extern "C" void Java_org_linphone_core_LinphoneFriendListImpl_addFriend(JNIEnv* env @@ -3008,16 +3113,8 @@ extern "C" void Java_org_linphone_core_LinphoneFriendListImpl_updateSubscription linphone_friend_list_update_subscriptions((LinphoneFriendList*)friendListptr,(LinphoneProxyConfig*)proxyConfigPtr,jonlyWhenRegistered); } -extern "C" jlong Java_org_linphone_core_LinphoneFriendListImpl_findFriendByUri(JNIEnv* env - ,jobject thiz - ,jlong friendListptr - ,jstring juri) { - const char* uri = env->GetStringUTFChars(juri, NULL); - LinphoneFriend* lResult; - lResult = linphone_friend_list_find_friend_by_uri((LinphoneFriendList*)friendListptr,uri); - env->ReleaseStringUTFChars(juri, uri); - return (jlong)lResult; -} + + extern "C" jlong Java_org_linphone_core_LinphoneFriendImpl_getAddress(JNIEnv* env ,jobject thiz @@ -3056,7 +3153,8 @@ extern "C" jobject Java_org_linphone_core_LinphoneFriendImpl_getCore(JNIEnv* en ,jlong ptr) { LinphoneCore *lc=linphone_friend_get_core((LinphoneFriend*)ptr); if (lc!=NULL){ - jobject core = (jobject)linphone_core_get_user_data(lc); + LinphoneJavaBindings *ljb = (LinphoneJavaBindings *)linphone_core_get_user_data(lc); + jobject core = ljb->getCore(); return core; } return NULL; @@ -3255,10 +3353,25 @@ extern "C" void Java_org_linphone_core_LinphoneChatRoomImpl_markAsRead(JNIEnv* extern "C" jlong Java_org_linphone_core_LinphoneChatRoomImpl_createFileTransferMessage(JNIEnv* env, jobject thiz, jlong ptr, jstring jname, jstring jtype, jstring jsubtype, jint data_size) { - LinphoneContent content = {0}; + LinphoneCore *lc = linphone_chat_room_get_core((LinphoneChatRoom*) ptr); + LinphoneContent * content = linphone_core_create_content(lc); LinphoneChatMessage *message = NULL; + const char *tmp; - message = linphone_chat_room_create_file_transfer_message((LinphoneChatRoom *)ptr, &content); + linphone_content_set_type(content, tmp = env->GetStringUTFChars(jtype, NULL)); + env->ReleaseStringUTFChars(jtype, tmp); + + linphone_content_set_subtype(content, tmp = env->GetStringUTFChars(jsubtype, NULL)); + env->ReleaseStringUTFChars(jsubtype, tmp); + + linphone_content_set_name(content, tmp = env->GetStringUTFChars(jname, NULL)); + env->ReleaseStringUTFChars(jname, tmp); + + linphone_content_set_size(content, data_size); + + message = linphone_chat_room_create_file_transfer_message((LinphoneChatRoom *)ptr, content); + + linphone_content_unref(content); return (jlong) message; } @@ -3445,15 +3558,15 @@ static void message_state_changed(LinphoneChatMessage* msg, LinphoneChatMessageS jobject jmessage = getChatMessage(env, msg); env->DeleteLocalRef(clazz); - jclass chatMessageStateClass = (jclass)env->FindClass("org/linphone/core/LinphoneChatMessage$State"); - jmethodID chatMessageStateFromIntId = env->GetStaticMethodID(chatMessageStateClass, "fromInt","(I)Lorg/linphone/core/LinphoneChatMessage$State;"); - env->CallVoidMethod(listener, method, jmessage, env->CallStaticObjectMethod(chatMessageStateClass, chatMessageStateFromIntId, (jint)state)); + LinphoneChatRoom *room = linphone_chat_message_get_chat_room(msg); + LinphoneCore *lc = linphone_chat_room_get_core(room); + LinphoneJavaBindings *ljb = (LinphoneJavaBindings *)linphone_core_get_user_data(lc); + env->CallVoidMethod(listener, method, jmessage, env->CallStaticObjectMethod(ljb->chatMessageStateClass, ljb->chatMessageStateFromIntId, (jint)state)); if (state == LinphoneChatMessageStateDelivered || state == LinphoneChatMessageStateNotDelivered) { env->DeleteGlobalRef(listener); msg->message_state_changed_user_data = NULL; } - env->DeleteLocalRef(chatMessageStateClass); } static void file_transfer_progress_indication(LinphoneChatMessage *msg, const LinphoneContent* content, size_t offset, size_t total) { @@ -3587,18 +3700,18 @@ static void chat_room_impl_callback(LinphoneChatMessage* msg, LinphoneChatMessag jmethodID method = env->GetMethodID(clazz, "onLinphoneChatMessageStateChanged","(Lorg/linphone/core/LinphoneChatMessage;Lorg/linphone/core/LinphoneChatMessage$State;)V"); jobject jmessage=(jobject)linphone_chat_message_get_user_data(msg); - jclass chatMessageStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneChatMessage$State")); - jmethodID chatMessageStateFromIntId = env->GetStaticMethodID(chatMessageStateClass,"fromInt","(I)Lorg/linphone/core/LinphoneChatMessage$State;"); + LinphoneChatRoom *room = linphone_chat_message_get_chat_room(msg); + LinphoneCore *lc = linphone_chat_room_get_core(room); + LinphoneJavaBindings *ljb = (LinphoneJavaBindings *)linphone_core_get_user_data(lc); env->CallVoidMethod( listener, method, jmessage, - env->CallStaticObjectMethod(chatMessageStateClass,chatMessageStateFromIntId,(jint)state)); + env->CallStaticObjectMethod(ljb->chatMessageStateClass,ljb->chatMessageStateFromIntId,(jint)state)); if (state == LinphoneChatMessageStateDelivered || state == LinphoneChatMessageStateNotDelivered) { env->DeleteGlobalRef(listener); env->DeleteGlobalRef(jmessage); - env->DeleteGlobalRef(chatMessageStateClass); linphone_chat_message_set_user_data(msg,NULL); } } @@ -3607,7 +3720,8 @@ extern "C" jobject Java_org_linphone_core_LinphoneChatRoomImpl_getCore(JNIEnv* ,jobject thiz ,jlong chatroom_ptr){ LinphoneCore *lc=linphone_chat_room_get_core((LinphoneChatRoom*)chatroom_ptr); - jobject core = (jobject)linphone_core_get_user_data(lc); + LinphoneJavaBindings *ljb = (LinphoneJavaBindings *)linphone_core_get_user_data(lc); + jobject core = ljb->getCore(); return core; } @@ -4402,6 +4516,7 @@ extern "C" jobjectArray Java_org_linphone_core_LinphoneCoreImpl_tunnelGetServers const MSList *servers = linphone_tunnel_get_servers(tunnel); const MSList *it; int i; + tunnelConfigArray = env->NewObjectArray(ms_list_size(servers), tunnelConfigClass, NULL); for(it = servers, i=0; it != NULL; it = it->next, i++) { LinphoneTunnelConfig *conf = (LinphoneTunnelConfig *)it->data; @@ -4632,6 +4747,34 @@ extern "C" jstring Java_org_linphone_core_LinphoneCoreImpl_getUpnpExternalIpaddr return jvalue; } +static LinphoneContent *create_content_from_java_args(JNIEnv *env, LinphoneCore *lc, jstring jtype, jstring jsubtype, jbyteArray jdata, jstring jencoding, jstring jname){ + LinphoneContent *content = NULL; + if (jtype){ + content = linphone_core_create_content(lc); + void *data = (void*)env->GetByteArrayElements(jdata,NULL); + const char *tmp; + + linphone_content_set_type(content, tmp = env->GetStringUTFChars(jtype, NULL)); + env->ReleaseStringUTFChars(jtype, tmp); + + linphone_content_set_subtype(content, tmp = env->GetStringUTFChars(jsubtype, NULL)); + env->ReleaseStringUTFChars(jsubtype, tmp); + + if (jname){ + linphone_content_set_name(content, tmp = env->GetStringUTFChars(jname, NULL)); + env->ReleaseStringUTFChars(jname, tmp); + } + + if (jencoding){ + linphone_content_set_encoding(content, tmp = env->GetStringUTFChars(jencoding,NULL)); + env->ReleaseStringUTFChars(jencoding, tmp); + } + + linphone_content_set_buffer(content, data, env->GetArrayLength(jdata)); + env->ReleaseByteArrayElements(jdata,(jbyte*)data,JNI_ABORT); + } + return content; +} /* * Class: org_linphone_core_LinphoneCoreImpl @@ -4642,15 +4785,14 @@ JNIEXPORT jobject JNICALL Java_org_linphone_core_LinphoneCoreImpl_subscribe(JNIE jstring jevname, jint expires, jstring jtype, jstring jsubtype, jbyteArray jdata, jstring jencoding){ LinphoneCore *lc=(LinphoneCore*)coreptr; LinphoneAddress *addr=(LinphoneAddress*)addrptr; - LinphoneContent content={0}; + LinphoneContent * content = create_content_from_java_args(env, (LinphoneCore*)coreptr, jtype, jsubtype, jdata, jencoding, NULL); LinphoneEvent *ev; jobject jev=NULL; const char *evname=env->GetStringUTFChars(jevname,NULL); - ev=linphone_core_subscribe(lc,addr,evname,expires,linphone_content_get_type(&content) ? &content : NULL); - if (jtype){ - env->ReleaseByteArrayElements(jdata,(jbyte*)linphone_content_get_user_data(&content),JNI_ABORT); - } + + ev=linphone_core_subscribe(lc,addr,evname,expires, content); + if (content) linphone_content_unref(content); env->ReleaseStringUTFChars(jevname,evname); if (ev){ jev=getEvent(env,ev); @@ -4667,17 +4809,13 @@ JNIEXPORT jobject JNICALL Java_org_linphone_core_LinphoneCoreImpl_publish(JNIEnv jstring jtype, jstring jsubtype, jbyteArray jdata, jstring jencoding){ LinphoneCore *lc=(LinphoneCore*)coreptr; LinphoneAddress *addr=(LinphoneAddress*)addrptr; - LinphoneContent content={0}; + LinphoneContent * content = create_content_from_java_args(env, (LinphoneCore*)coreptr, jtype, jsubtype, jdata, jencoding, NULL); LinphoneEvent *ev; jobject jev=NULL; const char *evname=env->GetStringUTFChars(jevname,NULL); - ev=linphone_core_subscribe(lc,addr,evname,expires,linphone_content_get_type(&content) ? &content : NULL); - - if (jtype){ - env->ReleaseByteArrayElements(jdata,(jbyte*)linphone_content_get_user_data(&content),JNI_ABORT); - - } + ev=linphone_core_publish(lc,addr,evname,expires, content); + if (content) linphone_content_unref(content); env->ReleaseStringUTFChars(jevname,evname); if (ev){ jev=getEvent(env,ev); @@ -4819,24 +4957,35 @@ static jobject create_java_linphone_content(JNIEnv *env, const LinphoneContent * jstring jtype, jsubtype, jencoding, jname; jbyteArray jdata = NULL; jint jsize = 0; + const char *tmp; + void *data; contentClass = (jclass)env->FindClass("org/linphone/core/LinphoneContentImpl"); ctor = env->GetMethodID(contentClass,"", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[BLjava/lang/String;I)V"); jtype = env->NewStringUTF(linphone_content_get_type(icontent)); jsubtype = env->NewStringUTF(linphone_content_get_subtype(icontent)); - jencoding = linphone_content_get_encoding(icontent) ? env->NewStringUTF(linphone_content_get_encoding(icontent)) : NULL; - jname = linphone_content_get_name(icontent) ? env->NewStringUTF(linphone_content_get_name(icontent)) : NULL; + jencoding = ((tmp = linphone_content_get_encoding(icontent))) ? env->NewStringUTF(tmp) : NULL; + jname = ((tmp = linphone_content_get_name(icontent))) ? env->NewStringUTF(tmp) : NULL; jsize = (jint) linphone_content_get_size(icontent); - if (linphone_content_get_user_data(icontent)){ + data = linphone_content_get_buffer(icontent); + if (data){ jdata = env->NewByteArray(linphone_content_get_size(icontent)); - env->SetByteArrayRegion(jdata, 0, linphone_content_get_size(icontent), (jbyte*)linphone_content_get_user_data(icontent)); + env->SetByteArrayRegion(jdata, 0, linphone_content_get_size(icontent), (jbyte*)data); } jobject jobj = env->NewObject(contentClass, ctor, jname, jtype, jsubtype, jdata, jencoding, jsize); env->DeleteLocalRef(contentClass); + env->DeleteLocalRef(jtype); + env->DeleteLocalRef(jsubtype); + if (jencoding) { + env->DeleteLocalRef(jencoding); + } + if (jname) { + env->DeleteLocalRef(jname); + } return jobj; } @@ -4906,9 +5055,22 @@ JNIEXPORT jobject JNICALL Java_org_linphone_core_LinphoneInfoMessageImpl_getCont * Signature: (JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V */ JNIEXPORT void JNICALL Java_org_linphone_core_LinphoneInfoMessageImpl_setContent(JNIEnv *env, jobject jobj, jlong infoptr, jstring jtype, jstring jsubtype, jstring jdata){ - LinphoneContent content={0}; - - linphone_info_message_set_content((LinphoneInfoMessage*)infoptr,&content); + LinphoneInfoMessage *infomsg = (LinphoneInfoMessage*) infoptr; + LinphoneContent * content = linphone_content_new(); + const char *tmp; + + linphone_content_set_type(content, tmp = env->GetStringUTFChars(jtype,NULL)); + env->ReleaseStringUTFChars(jtype, tmp); + + linphone_content_set_type(content, tmp = env->GetStringUTFChars(jsubtype,NULL)); + env->ReleaseStringUTFChars(jsubtype, tmp); + + + linphone_content_set_string_buffer(content, tmp = env->GetStringUTFChars(jdata,NULL)); + env->ReleaseStringUTFChars(jdata, tmp); + + linphone_info_message_set_content((LinphoneInfoMessage*)infoptr, content); + linphone_content_unref(content); } /* @@ -4966,7 +5128,8 @@ JNIEXPORT void JNICALL Java_org_linphone_core_LinphoneCoreFactoryImpl__1setLogHa JNIEXPORT jobject JNICALL Java_org_linphone_core_LinphoneEventImpl_getCore(JNIEnv *env, jobject jobj, jlong evptr){ LinphoneCore *lc=linphone_event_get_core((LinphoneEvent*)evptr); - jobject core = (jobject)linphone_core_get_user_data(lc); + LinphoneJavaBindings *ljb = (LinphoneJavaBindings *)linphone_core_get_user_data(lc); + jobject core = ljb->getCore(); return core; } @@ -5007,13 +5170,16 @@ JNIEXPORT jint JNICALL Java_org_linphone_core_LinphoneEventImpl_denySubscription * Signature: (JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;)I */ JNIEXPORT jint JNICALL Java_org_linphone_core_LinphoneEventImpl_notify(JNIEnv *env, jobject jobj, jlong evptr, jstring jtype, jstring jsubtype, jbyteArray jdata, jstring jencoding){ - LinphoneContent content={0}; + LinphoneContent * content = create_content_from_java_args(env, linphone_event_get_core((LinphoneEvent *)evptr), + jtype, jsubtype, jdata, jencoding, NULL); LinphoneEvent *ev=(LinphoneEvent*)evptr; jint err; + err=linphone_event_notify(ev, content); - err=linphone_event_notify(ev,linphone_content_get_type(&content) ? &content : NULL); - + if (content){ + linphone_content_unref(content); + } return err; } @@ -5023,12 +5189,14 @@ JNIEXPORT jint JNICALL Java_org_linphone_core_LinphoneEventImpl_notify(JNIEnv *e * Signature: (JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;)I */ JNIEXPORT jint JNICALL Java_org_linphone_core_LinphoneEventImpl_updateSubscribe(JNIEnv *env, jobject jobj, jlong evptr, jstring jtype, jstring jsubtype, jbyteArray jdata, jstring jencoding){ - LinphoneContent content={0}; + LinphoneContent * content = create_content_from_java_args(env, linphone_event_get_core((LinphoneEvent *)evptr), + jtype, jsubtype, jdata, jencoding, NULL); LinphoneEvent *ev=(LinphoneEvent*)evptr; jint err; - err=linphone_event_update_subscribe(ev,linphone_content_get_type(&content) ? &content : NULL); + err=linphone_event_update_subscribe(ev, content); + if (content) linphone_content_unref(content); return err; } @@ -5038,12 +5206,14 @@ JNIEXPORT jint JNICALL Java_org_linphone_core_LinphoneEventImpl_updateSubscribe( * Signature: (JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;)I */ JNIEXPORT jint JNICALL Java_org_linphone_core_LinphoneEventImpl_updatePublish(JNIEnv *env, jobject jobj, jlong evptr, jstring jtype, jstring jsubtype, jbyteArray jdata, jstring jencoding){ - LinphoneContent content={0}; + LinphoneContent * content = create_content_from_java_args(env, linphone_event_get_core((LinphoneEvent *)evptr), + jtype, jsubtype, jdata, jencoding, NULL); LinphoneEvent *ev=(LinphoneEvent*)evptr; jint err; + + err=linphone_event_update_publish(ev, content); - err=linphone_event_update_publish(ev,linphone_content_get_type(&content) ? &content : NULL); - + if (content) linphone_content_unref(content); return err; } @@ -5108,9 +5278,12 @@ JNIEXPORT jobject JNICALL Java_org_linphone_core_LinphoneCoreImpl_createSubscrib return jevent; } -JNIEXPORT void JNICALL Java_org_linphone_core_LinphoneEventImpl_sendSubscribe(JNIEnv *env, jobject thiz, jlong jevent, jstring jtype, jstring jsubtype, jbyteArray jdata, jstring jencoding) { - LinphoneContent content = {0}; - linphone_event_send_subscribe((LinphoneEvent*) jevent, linphone_content_get_type(&content)? &content : NULL); +JNIEXPORT void JNICALL Java_org_linphone_core_LinphoneEventImpl_sendSubscribe(JNIEnv *env, jobject thiz, jlong eventptr, jstring jtype, jstring jsubtype, jbyteArray jdata, jstring jencoding) { + LinphoneContent *content = create_content_from_java_args(env, linphone_event_get_core((LinphoneEvent*)eventptr), + jtype, jsubtype, jdata, jencoding, NULL); + + linphone_event_send_subscribe((LinphoneEvent*) eventptr, content); + if (content) linphone_content_unref(content); } JNIEXPORT jobject JNICALL Java_org_linphone_core_LinphoneCoreImpl_createPublish(JNIEnv *env, jobject thiz, jlong jcore, jlong jaddr, jstring jeventname, jint expires) { @@ -5128,11 +5301,11 @@ JNIEXPORT jobject JNICALL Java_org_linphone_core_LinphoneCoreImpl_createPublish( return jevent; } -JNIEXPORT void JNICALL Java_org_linphone_core_LinphoneEventImpl_sendPublish(JNIEnv *env, jobject thiz, jlong jevent, jstring jtype, jstring jsubtype, jbyteArray jdata, jstring jencoding) { - LinphoneContent content = {0}; - linphone_event_send_publish((LinphoneEvent*) jevent, linphone_content_get_type(&content)? &content : NULL); - - +JNIEXPORT void JNICALL Java_org_linphone_core_LinphoneEventImpl_sendPublish(JNIEnv *env, jobject thiz, jlong eventptr, jstring jtype, jstring jsubtype, jbyteArray jdata, jstring jencoding) { + LinphoneContent *content = create_content_from_java_args(env, linphone_event_get_core((LinphoneEvent*)eventptr), + jtype, jsubtype, jdata, jencoding, NULL); + linphone_event_send_publish((LinphoneEvent*) eventptr, content); + if (content) linphone_content_unref(content); } JNIEXPORT void JNICALL Java_org_linphone_core_LinphoneEventImpl_addCustomHeader(JNIEnv *env, jobject thiz, jlong jevent, jstring jname, jstring jvalue) { @@ -6537,4 +6710,23 @@ JNIEXPORT jint JNICALL Java_org_linphone_core_LinphoneCoreImpl_getSipTransportTi return linphone_core_get_sip_transport_timeout((LinphoneCore*)pcore); } +/* + * Class: org_linphone_core_LinphoneCoreImpl + * Method: setNortpTimeout + * Signature: (JI)V + */ +JNIEXPORT void JNICALL Java_org_linphone_core_LinphoneCoreImpl_setNortpTimeout(JNIEnv *env, jobject obj, jlong core, jint timeout){ + linphone_core_set_nortp_timeout((LinphoneCore*)core, timeout); +} + +/* + * Class: org_linphone_core_LinphoneCoreImpl + * Method: getNortpTimeout + * Signature: (J)I + */ +JNIEXPORT jint JNICALL Java_org_linphone_core_LinphoneCoreImpl_getNortpTimeout(JNIEnv *env, jobject obj, jlong core){ + return linphone_core_get_nortp_timeout((LinphoneCore*)core); +} + +