diff --git a/coreapi/linphonecore_jni.cc b/coreapi/linphonecore_jni.cc index 6ce4611af..02cd5325d 100644 --- a/coreapi/linphonecore_jni.cc +++ b/coreapi/linphonecore_jni.cc @@ -294,6 +294,11 @@ public: friendClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneFriendImpl"));; friendCtrId = env->GetMethodID(friendClass,"", "(J)V"); + + friendListClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneFriendListImpl"));; + friendListCtrId = env->GetMethodID(friendListClass,"", "(J)V"); + friendListCreatedId = env->GetMethodID(listenerClass, "friendListCreated", "(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneFriendList;)V"); + friendListRemovedId = env->GetMethodID(listenerClass, "friendListRemoved", "(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneFriendList;)V"); addressClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneAddressImpl")); addressCtrId = env->GetMethodID(addressClass,"", "(J)V"); @@ -333,6 +338,7 @@ public: env->DeleteGlobalRef(chatMessageClass); env->DeleteGlobalRef(chatRoomClass); env->DeleteGlobalRef(friendClass); + env->DeleteGlobalRef(friendListClass); env->DeleteGlobalRef(infoMessageClass); env->DeleteGlobalRef(linphoneEventClass); env->DeleteGlobalRef(subscriptionStateClass); @@ -402,6 +408,11 @@ public: jclass friendClass; jmethodID friendCtrId; + jclass friendListClass; + jmethodID friendListCtrId; + jmethodID friendListCreatedId; + jmethodID friendListRemovedId; + jclass addressClass; jmethodID addressCtrId; @@ -526,6 +537,31 @@ jobject getFriend(JNIEnv *env, LinphoneFriend *lfriend){ return jobj; } +jobject getFriendList(JNIEnv *env, LinphoneFriendList *lfriendList){ + jobject jobj=0; + + if (lfriendList != NULL){ + LinphoneCore *lc = linphone_friend_list_get_core(lfriendList); + LinphoneJavaBindings *ljb = (LinphoneJavaBindings *)linphone_core_get_user_data(lc); + + void *up=linphone_friend_list_get_user_data(lfriendList); + + if (up == NULL){ + jobj=env->NewObject(ljb->friendListClass, ljb->friendListCtrId, (jlong)lfriendList); + linphone_friend_list_set_user_data(lfriendList,(void*)env->NewWeakGlobalRef(jobj)); + linphone_friend_list_ref(lfriendList); + }else{ + + jobj=env->NewLocalRef((jobject)up); + if (jobj == NULL){ + jobj=env->NewObject(ljb->friendListClass, ljb->friendListCtrId, (jlong)lfriendList); + linphone_friend_list_set_user_data(lfriendList,(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); @@ -638,6 +674,13 @@ public: if (ljb->logCollectionUploadStateId) { vTable->log_collection_upload_state_changed = logCollectionUploadStateChange; } + + if (ljb->friendListCreatedId) { + vTable->friend_list_created = friendListCreated; + } + if (ljb->friendListRemovedId) { + vTable->friend_list_removed = friendListRemoved; + } } ~LinphoneCoreData() { @@ -1208,6 +1251,40 @@ public: env->DeleteLocalRef(msg); } } + static void friendListCreated(LinphoneCore *lc, LinphoneFriendList *list) { + JNIEnv *env = 0; + jint result = jvm->AttachCurrentThread(&env,NULL); + if (result != 0) { + 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 + ,ljb->friendListCreatedId + ,lcData->core + ,getFriendList(env, list)); + handle_possible_java_exception(env, lcData->listener); + } + static void friendListRemoved(LinphoneCore *lc, LinphoneFriendList *list) { + JNIEnv *env = 0; + jint result = jvm->AttachCurrentThread(&env,NULL); + if (result != 0) { + 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 + ,ljb->friendListRemovedId + ,lcData->core + ,getFriendList(env, list)); + handle_possible_java_exception(env, lcData->listener); + } private: static inline void handle_possible_java_exception(JNIEnv *env, jobject listener) diff --git a/java/common/org/linphone/core/LinphoneCoreListener.java b/java/common/org/linphone/core/LinphoneCoreListener.java index b7457a777..0d96e6a0c 100644 --- a/java/common/org/linphone/core/LinphoneCoreListener.java +++ b/java/common/org/linphone/core/LinphoneCoreListener.java @@ -226,5 +226,19 @@ public interface LinphoneCoreListener { * @param info Additional information: error message in case of error state, URL of uploaded file in case of success. */ void uploadStateChanged(LinphoneCore lc, LinphoneCore.LogCollectionUploadState state, String info); + + /** + * Callback prototype for reporting LinphoneFriendList creation. + * @param lc LinphoneCore object + * @param list LinphoneFriendList object + */ + void friendListCreated(LinphoneCore lc, LinphoneFriendList list); + + /** + * Callback prototype for reporting LinphoneFriendList removal. + * @param lc LinphoneCore object + * @param list LinphoneFriendList object + */ + void friendListRemoved(LinphoneCore lc, LinphoneFriendList list); } diff --git a/java/common/org/linphone/core/LinphoneCoreListenerBase.java b/java/common/org/linphone/core/LinphoneCoreListenerBase.java index a7db59c11..772719ad3 100644 --- a/java/common/org/linphone/core/LinphoneCoreListenerBase.java +++ b/java/common/org/linphone/core/LinphoneCoreListenerBase.java @@ -198,4 +198,15 @@ public class LinphoneCoreListenerBase implements LinphoneCoreListener { } + @Override + public void friendListCreated(LinphoneCore lc, LinphoneFriendList list) { + // TODO Auto-generated method stub + + } + + @Override + public void friendListRemoved(LinphoneCore lc, LinphoneFriendList list) { + // TODO Auto-generated method stub + + } }