diff --git a/coreapi/linphonecore_jni.cc b/coreapi/linphonecore_jni.cc index a7b8a3c52..df3c11c63 100644 --- a/coreapi/linphonecore_jni.cc +++ b/coreapi/linphonecore_jni.cc @@ -299,6 +299,8 @@ public: 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"); + friendListSyncStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneFriendList$State")); + friendListSyncStateFromIntId = env->GetStaticMethodID(friendListSyncStateClass,"fromInt","(I)Lorg/linphone/core/LinphoneFriendList$State;"); addressClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneAddressImpl")); addressCtrId = env->GetMethodID(addressClass,"", "(J)V"); @@ -339,6 +341,7 @@ public: env->DeleteGlobalRef(chatRoomClass); env->DeleteGlobalRef(friendClass); env->DeleteGlobalRef(friendListClass); + env->DeleteGlobalRef(friendListSyncStateClass); env->DeleteGlobalRef(infoMessageClass); env->DeleteGlobalRef(linphoneEventClass); env->DeleteGlobalRef(subscriptionStateClass); @@ -412,6 +415,8 @@ public: jmethodID friendListCtrId; jmethodID friendListCreatedId; jmethodID friendListRemovedId; + jclass friendListSyncStateClass; + jmethodID friendListSyncStateFromIntId; jclass addressClass; jmethodID addressCtrId; @@ -3298,6 +3303,35 @@ static void contact_removed(LinphoneFriendList *list, LinphoneFriend *lf) { env->CallVoidMethod(listener, method, jlist, jfriend); } +static void sync_status_changed(LinphoneFriendList *list, LinphoneFriendListSyncStatus status, const char *message) { + JNIEnv *env = 0; + jint result = jvm->AttachCurrentThread(&env,NULL); + if (result != 0) { + ms_error("cannot attach VM\n"); + return; + } + + LinphoneFriendListCbs *cbs = linphone_friend_list_get_callbacks(list); + jobject listener = (jobject) linphone_friend_list_cbs_get_user_data(cbs); + + if (listener == NULL) { + ms_error("sync_status_changed() notification without listener"); + return ; + } + jclass clazz = (jclass) env->GetObjectClass(listener); + jmethodID method = env->GetMethodID(clazz, "onLinphoneFriendSyncStatusChanged","(Lorg/linphone/core/LinphoneFriendList;Lorg/linphone/core/LinphoneFriendList$State;Ljava/lang/String;)V"); + jobject jlist = getFriendList(env, list); + env->DeleteLocalRef(clazz); + + LinphoneCore *lc = linphone_friend_list_get_core((LinphoneFriendList *)list); + LinphoneJavaBindings *ljb = (LinphoneJavaBindings *)linphone_core_get_user_data(lc); + jstring msg = message ? env->NewStringUTF(message) : NULL; + env->CallVoidMethod(listener, method, jlist, env->CallStaticObjectMethod(ljb->friendListSyncStateClass, ljb->friendListSyncStateFromIntId, (jint)status), msg); + if (msg) { + env->DeleteLocalRef(msg); + } +} + extern "C" void Java_org_linphone_core_LinphoneFriendListImpl_setListener(JNIEnv* env, jobject thiz, jlong ptr, jobject jlistener) { jobject listener = env->NewGlobalRef(jlistener); LinphoneFriendList *list = (LinphoneFriendList *)ptr; @@ -3308,6 +3342,7 @@ extern "C" void Java_org_linphone_core_LinphoneFriendListImpl_setListener(JNIEnv linphone_friend_list_cbs_set_contact_created(cbs, contact_created); linphone_friend_list_cbs_set_contact_updated(cbs, contact_updated); linphone_friend_list_cbs_set_contact_deleted(cbs, contact_removed); + linphone_friend_list_cbs_set_sync_status_changed(cbs, sync_status_changed); } extern "C" void Java_org_linphone_core_LinphoneFriendImpl_setAddress(JNIEnv* env diff --git a/java/common/org/linphone/core/LinphoneFriendList.java b/java/common/org/linphone/core/LinphoneFriendList.java index a65f84b48..23dec80ef 100644 --- a/java/common/org/linphone/core/LinphoneFriendList.java +++ b/java/common/org/linphone/core/LinphoneFriendList.java @@ -18,6 +18,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package org.linphone.core; +import java.util.Vector; + +import org.linphone.core.LinphoneChatMessage.State; + public interface LinphoneFriendList { public void setRLSUri(String uri); public void addFriend(LinphoneFriend friend); @@ -40,5 +44,41 @@ public interface LinphoneFriendList { void onLinphoneFriendUpdated(LinphoneFriendList list, LinphoneFriend newFriend, LinphoneFriend oldFriend); void onLinphoneFriendDeleted(LinphoneFriendList list, LinphoneFriend lf); + + void onLinphoneFriendSyncStatusChanged(LinphoneFriendList list, LinphoneFriendList.State status, String message); + } + public static class State { + static private Vector values = new Vector(); + public final int value() { return mValue; } + + private final int mValue; + private final String mStringValue; + + public final static State SyncStarted = new State(0, "SyncStarted"); + public final static State SyncSuccessful = new State(1, "SyncSuccessful"); + public final static State SyncFailure = new State(2, "SyncFailure"); + + private State(int value,String stringValue) { + mValue = value; + values.addElement(this); + mStringValue = stringValue; + } + + public static State fromInt(int value) { + + for (int i = 0; i < values.size(); i++) { + State state = (State) values.elementAt(i); + if (state.mValue == value) return state; + } + throw new RuntimeException("state not found [" + value + "]"); + } + + public String toString() { + return mStringValue; + } + + public int toInt() { + return mValue; + } } }