Commit 87d4f5f8 authored by Simon Morlat's avatar Simon Morlat
Browse files

imlement java synchronization of LinphoneFriend with LinphoneCore

parent bc078d65
......@@ -656,3 +656,7 @@ void linphone_core_write_friends_config(LinphoneCore* lc)
linphone_friend_write_to_config_file(lc->config,NULL,i); /* set the end */
}
LinphoneCore *linphone_friend_get_core(const LinphoneFriend *fr){
return fr->lc;
}
......@@ -2222,6 +2222,16 @@ extern "C" jint Java_org_linphone_core_LinphoneFriendImpl_getStatus(JNIEnv* env
,jlong ptr) {
return (jint)linphone_friend_get_status((LinphoneFriend*)ptr);
}
extern "C" jobject Java_org_linphone_core_LinphoneFriendImpl_getCore(JNIEnv* env
,jobject thiz
,jlong ptr) {
LinphoneCore *lc=linphone_friend_get_core((LinphoneFriend*)ptr);
if (lc!=NULL){
LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
return lcData->core;
}
return NULL;
}
/*
* Class: org_linphone_core_LinphoneFriendImpl
......
......@@ -392,6 +392,11 @@ LINPHONE_PUBLIC LinphoneFriend *linphone_core_find_friend(const LinphoneCore *lc
*/
LINPHONE_PUBLIC LinphoneFriend *linphone_core_get_friend_by_ref_key(const LinphoneCore *lc, const char *key);
/**
* Returns the LinphoneCore object managing this friend, if any.
*/
LINPHONE_PUBLIC LinphoneCore *linphone_friend_get_core(const LinphoneFriend *fr);
/**
* @}
*/
......
......@@ -34,8 +34,9 @@ class LinphoneFriendImpl implements LinphoneFriend, Serializable {
private native void setPresenceModel(long nativePtr, long presencePtr);
private native void edit(long nativePtr);
private native void done(long nativePtr);
private native void delete(long ptr);
private native Object getCore(long ptr);
boolean ownPtr = false;
protected LinphoneFriendImpl() {
nativePtr = newLinphoneFriend(null);
......@@ -57,13 +58,17 @@ class LinphoneFriendImpl implements LinphoneFriend, Serializable {
return new LinphoneAddressImpl(getAddress(nativePtr),LinphoneAddressImpl.WrapMode.FromConst);
}
public void setIncSubscribePolicy(SubscribePolicy policy) {
setIncSubscribePolicy(nativePtr,policy.mValue);
synchronized(getSyncObject()){
setIncSubscribePolicy(nativePtr,policy.mValue);
}
}
public SubscribePolicy getIncSubscribePolicy() {
return SubscribePolicy.fromInt(getIncSubscribePolicy(nativePtr)) ;
}
public void enableSubscribes(boolean enable) {
enableSubscribes(nativePtr, enable);
synchronized(getSyncObject()){
enableSubscribes(nativePtr, enable);
}
}
public boolean isSubscribesEnabled() {
return isSubscribesEnabled(nativePtr);
......@@ -75,12 +80,27 @@ class LinphoneFriendImpl implements LinphoneFriend, Serializable {
return (PresenceModel)getPresenceModel(nativePtr);
}
public void edit() {
edit(nativePtr);
synchronized(getSyncObject()){
edit(nativePtr);
}
}
public void done() {
done(nativePtr);
synchronized(getSyncObject()){
done(nativePtr);
}
}
public long getNativePtr() {
return nativePtr;
}
/*
* Returns a java object to synchronize this friend with.
* Indeed some operation must be synchronized with the LinphoneCore object.
* If the friend is not associated with a LinphoneCore object, it returns itself in order to avoid writing code for case where no synchronization is necessary.
*/
private Object getSyncObject(){
Object core=getCore(nativePtr);
if (core!=null) return core;
else return this;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment