From aa2a82ceae9e1d000a273e3792357d2863aff1f6 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Thu, 24 Dec 2015 14:55:44 +0100 Subject: [PATCH] Added JNI wrapper for friends/vcards import/export methods + setFriendsDatabasePath --- coreapi/linphonecore_jni.cc | 27 +++++++++++++++---- .../org/linphone/core/LinphoneCore.java | 16 +++++++++++ .../org/linphone/core/LinphoneCoreImpl.java | 17 ++++++++++++ 3 files changed, 55 insertions(+), 5 deletions(-) diff --git a/coreapi/linphonecore_jni.cc b/coreapi/linphonecore_jni.cc index 24df9fde4..4b2d3ec26 100644 --- a/coreapi/linphonecore_jni.cc +++ b/coreapi/linphonecore_jni.cc @@ -1355,16 +1355,21 @@ extern "C" void Java_org_linphone_core_LinphoneCoreImpl_stopRinging(JNIEnv* env, linphone_core_stop_ringing((LinphoneCore*)lc); } -extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setChatDatabasePath(JNIEnv* env, jobject thiz, jlong lc, jstring jpath) { +extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setChatDatabasePath(JNIEnv* env, jobject thiz, jlong lc, jstring jpath) { const char* path = env->GetStringUTFChars(jpath, NULL); linphone_core_set_chat_database_path((LinphoneCore*)lc, path); env->ReleaseStringUTFChars(jpath, path); } -extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setCallLogsDatabasePath( JNIEnv* env, jobject thiz, jlong lc, jstring jpath) { - const char* path = env->GetStringUTFChars(jpath, NULL); - linphone_core_set_call_logs_database_path((LinphoneCore*)lc, path); - env->ReleaseStringUTFChars(jpath, path); +extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setCallLogsDatabasePath( JNIEnv* env, jobject thiz, jlong lc, jstring jpath) { + const char* path = env->GetStringUTFChars(jpath, NULL); + linphone_core_set_call_logs_database_path((LinphoneCore*)lc, path); + env->ReleaseStringUTFChars(jpath, path); +} +extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setFriendsDatabasePath( JNIEnv* env, jobject thiz, jlong lc, jstring jpath) { + const char* path = env->GetStringUTFChars(jpath, NULL); + linphone_core_set_friends_database_path((LinphoneCore*)lc, path); + env->ReleaseStringUTFChars(jpath, path); } extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPrimaryContact2(JNIEnv* env, jobject thiz, jlong lc, jstring jcontact) { @@ -1940,6 +1945,18 @@ extern "C" void Java_org_linphone_core_LinphoneCoreImpl_addFriend(JNIEnv* env linphone_core_add_friend((LinphoneCore*)lc,(LinphoneFriend*)aFriend); } +extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_importFriendsFromVCardFile(JNIEnv* env, jobject thiz, jlong lc, jstring jpath) { + const char* path = env->GetStringUTFChars(jpath, NULL); + return linphone_core_import_friends_from_vcard4_file((LinphoneCore*)lc, path); + env->ReleaseStringUTFChars(jpath, path); +} + +extern "C" void Java_org_linphone_core_LinphoneCoreImpl_exportFriendsToVCardFile(JNIEnv* env, jobject thiz, jlong lc, jstring jpath) { + const char* path = env->GetStringUTFChars(jpath, NULL); + linphone_core_export_friends_as_vcard4_file((LinphoneCore*)lc, path); + env->ReleaseStringUTFChars(jpath, path); +} + extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setFriendList(JNIEnv* env ,jobject thiz ,jlong lc diff --git a/java/common/org/linphone/core/LinphoneCore.java b/java/common/org/linphone/core/LinphoneCore.java index bb36434da..f1ab3af41 100644 --- a/java/common/org/linphone/core/LinphoneCore.java +++ b/java/common/org/linphone/core/LinphoneCore.java @@ -1906,6 +1906,12 @@ public interface LinphoneCore { */ public void setCallLogsDatabasePath(String path); + /** + * Sets the path to the database where the friends will be stored (if enabled) + * @param path the database where the friends will be stored. + */ + public void setFriendsDatabasePath(String path); + /** * Gets the chat rooms * @return an array of LinphoneChatRoom @@ -2241,4 +2247,14 @@ public interface LinphoneCore { */ public int getNortpTimeout(); + /** + * Imports LinphoneFriends from a vCard 4 file + * @return the number of friend imported + **/ + public int importFriendsFromVCardFile(String file); + + /** + * Exports LinphoneFriends to a vCard 4 file + **/ + public void exportFriendsToVCardFile(String file); } diff --git a/java/impl/org/linphone/core/LinphoneCoreImpl.java b/java/impl/org/linphone/core/LinphoneCoreImpl.java index 46f6d6352..88af94b15 100644 --- a/java/impl/org/linphone/core/LinphoneCoreImpl.java +++ b/java/impl/org/linphone/core/LinphoneCoreImpl.java @@ -165,6 +165,7 @@ class LinphoneCoreImpl implements LinphoneCore { private native String getPrimaryContactDisplayName(long nativePtr); private native void setChatDatabasePath(long nativePtr, String path); private native void setCallLogsDatabasePath(long nativePtr, String path); + private native void setFriendsDatabasePath(long nativePtr, String path); private native long[] getChatRooms(long nativePtr); private native int migrateToMultiTransport(long nativePtr); private native void migrateCallLogs(long nativePtr); @@ -1196,6 +1197,10 @@ class LinphoneCoreImpl implements LinphoneCore { public synchronized void setCallLogsDatabasePath(String path) { setCallLogsDatabasePath(nativePtr, path); } + + public synchronized void setFriendsDatabasePath(String path) { + setFriendsDatabasePath(nativePtr, path); + } public synchronized LinphoneChatRoom[] getChatRooms() { long[] typesPtr = getChatRooms(nativePtr); @@ -1599,4 +1604,16 @@ class LinphoneCoreImpl implements LinphoneCore { public int getNortpTimeout(){ return getNortpTimeout(nativePtr); } + + private native int importFriendsFromVCardFile(long nativePtr, String file); + @Override + public int importFriendsFromVCardFile(String file) { + return importFriendsFromVCardFile(nativePtr, file); + } + + private native void exportFriendsToVCardFile(long nativePtr, String file); + @Override + public void exportFriendsToVCardFile(String file) { + exportFriendsToVCardFile(nativePtr, file); + } }