diff --git a/coreapi/chat.c b/coreapi/chat.c index c20cfef9e..9e2ce9a69 100644 --- a/coreapi/chat.c +++ b/coreapi/chat.c @@ -387,11 +387,19 @@ bool_t linphone_chat_room_is_remote_composing(const LinphoneChatRoom *cr) { /** * Returns back pointer to LinphoneCore object. + * @deprecated use linphone_chat_room_get_core() **/ LinphoneCore* linphone_chat_room_get_lc(LinphoneChatRoom *cr){ return cr->lc; } +/** + * Returns back pointer to LinphoneCore object. +**/ +LinphoneCore* linphone_chat_room_get_core(LinphoneChatRoom *cr){ + return cr->lc; +} + /** * Assign a user pointer to the chat room. **/ diff --git a/coreapi/linphonecore.h b/coreapi/linphonecore.h index debf48461..c35776c1d 100644 --- a/coreapi/linphonecore.h +++ b/coreapi/linphonecore.h @@ -1158,6 +1158,7 @@ LINPHONE_PUBLIC bool_t linphone_chat_room_is_remote_composing(const LinphoneChat LINPHONE_PUBLIC int linphone_chat_room_get_unread_messages_count(LinphoneChatRoom *cr); LINPHONE_PUBLIC LinphoneCore* linphone_chat_room_get_lc(LinphoneChatRoom *cr); +LINPHONE_PUBLIC LinphoneCore* linphone_chat_room_get_core(LinphoneChatRoom *cr); LINPHONE_PUBLIC void linphone_chat_room_set_user_data(LinphoneChatRoom *cr, void * ud); LINPHONE_PUBLIC void * linphone_chat_room_get_user_data(LinphoneChatRoom *cr); LINPHONE_PUBLIC MSList* linphone_core_get_chat_rooms(LinphoneCore *lc); diff --git a/coreapi/linphonecore_jni.cc b/coreapi/linphonecore_jni.cc index a24d2c589..919c813a9 100644 --- a/coreapi/linphonecore_jni.cc +++ b/coreapi/linphonecore_jni.cc @@ -2630,6 +2630,15 @@ static void chat_room_impl_callback(LinphoneChatMessage* msg, LinphoneChatMessag linphone_chat_message_set_user_data(msg,NULL); } } + +extern "C" jobject Java_org_linphone_core_LinphoneChatRoomImpl_getCore(JNIEnv* env + ,jobject thiz + ,jlong chatroom_ptr){ + LinphoneCore *lc=linphone_chat_room_get_core((LinphoneChatRoom*)chatroom_ptr); + LinphoneCoreData *lcd=(LinphoneCoreData*)linphone_core_get_user_data(lc); + return lcd->core; +} + extern "C" void Java_org_linphone_core_LinphoneChatRoomImpl_sendMessage2(JNIEnv* env ,jobject thiz ,jlong chatroom_ptr @@ -3669,6 +3678,12 @@ 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); + LinphoneCoreData *lcd=(LinphoneCoreData*)linphone_core_get_user_data(lc); + return lcd->core; +} + /* * Class: org_linphone_core_LinphoneEventImpl * Method: getEventName diff --git a/java/common/org/linphone/core/LinphoneChatRoom.java b/java/common/org/linphone/core/LinphoneChatRoom.java index e84538269..c1e635c0a 100644 --- a/java/common/org/linphone/core/LinphoneChatRoom.java +++ b/java/common/org/linphone/core/LinphoneChatRoom.java @@ -114,4 +114,9 @@ public interface LinphoneChatRoom { * @return LinphoneChatMessage object */ LinphoneChatMessage createLinphoneChatMessage(String message, String url, State state, long timestamp, boolean isRead, boolean isIncoming); + /** + * Returns a back pointer to the core managing the chat room. + * @return the LinphoneCore + */ + LinphoneCore getCore(); } diff --git a/java/common/org/linphone/core/LinphoneEvent.java b/java/common/org/linphone/core/LinphoneEvent.java index dcdfcfc48..cca9a3f2d 100644 --- a/java/common/org/linphone/core/LinphoneEvent.java +++ b/java/common/org/linphone/core/LinphoneEvent.java @@ -100,4 +100,10 @@ public interface LinphoneEvent { * @param body the new data to be published */ void sendPublish(LinphoneContent body); + + /** + * Get a back pointer to the LinphoneCore object managing this LinphoneEvent. + * @return + */ + LinphoneCore getCore(); } diff --git a/java/impl/org/linphone/core/LinphoneChatRoomImpl.java b/java/impl/org/linphone/core/LinphoneChatRoomImpl.java index 7901272c9..003cdd076 100644 --- a/java/impl/org/linphone/core/LinphoneChatRoomImpl.java +++ b/java/impl/org/linphone/core/LinphoneChatRoomImpl.java @@ -119,4 +119,9 @@ class LinphoneChatRoomImpl implements LinphoneChatRoom { return new LinphoneChatMessageImpl(createLinphoneChatMessage2( nativePtr, message, url, state.value(), timestamp / 1000, isRead, isIncoming)); } + private native Object getCore(long nativePtr); + @Override + public LinphoneCore getCore() { + return (LinphoneCore)getCore(nativePtr); + } } diff --git a/java/impl/org/linphone/core/LinphoneCoreImpl.java b/java/impl/org/linphone/core/LinphoneCoreImpl.java index 8cd5fe79e..bf43810a3 100644 --- a/java/impl/org/linphone/core/LinphoneCoreImpl.java +++ b/java/impl/org/linphone/core/LinphoneCoreImpl.java @@ -610,13 +610,13 @@ class LinphoneCoreImpl implements LinphoneCore { public synchronized void enableEchoLimiter(boolean val) { enableEchoLimiter(nativePtr,val); } - public void setVideoDevice(int id) { + public synchronized void setVideoDevice(int id) { Log.i("Setting camera id :", id); if (setVideoDevice(nativePtr, id) != 0) { Log.e("Failed to set video device to id:", id); } } - public int getVideoDevice() { + public synchronized int getVideoDevice() { return getVideoDevice(nativePtr); } @@ -847,7 +847,7 @@ class LinphoneCoreImpl implements LinphoneCore { private native void tunnelSetHttpProxy(long nativePtr, String proxy_host, int port, String username, String password); @Override - public void tunnelSetHttpProxy(String proxy_host, int port, + public synchronized void tunnelSetHttpProxy(String proxy_host, int port, String username, String password) { tunnelSetHttpProxy(nativePtr, proxy_host, port, username, password); } @@ -1185,17 +1185,17 @@ class LinphoneCoreImpl implements LinphoneCore { } @Override - public void stopRinging() { + public synchronized void stopRinging() { stopRinging(nativePtr); } private native void setPayloadTypeBitrate(long coreptr, long payload_ptr, int bitrate); @Override - public void setPayloadTypeBitrate(PayloadType pt, int bitrate) { + public synchronized void setPayloadTypeBitrate(PayloadType pt, int bitrate) { setPayloadTypeBitrate(nativePtr, ((PayloadTypeImpl)pt).nativePtr, bitrate); } private native int getPayloadTypeBitrate(long coreptr, long payload_ptr); @Override - public int getPayloadTypeBitrate(PayloadType pt) { + public synchronized int getPayloadTypeBitrate(PayloadType pt) { return getPayloadTypeBitrate(nativePtr, ((PayloadTypeImpl)pt).nativePtr); } diff --git a/java/impl/org/linphone/core/LinphoneEventImpl.java b/java/impl/org/linphone/core/LinphoneEventImpl.java index 2b4c1a71b..ca9c2151c 100644 --- a/java/impl/org/linphone/core/LinphoneEventImpl.java +++ b/java/impl/org/linphone/core/LinphoneEventImpl.java @@ -11,71 +11,83 @@ public class LinphoneEventImpl implements LinphoneEvent { private native String getEventName(long nativeptr); @Override - public String getEventName() { + public synchronized String getEventName() { return getEventName(mNativePtr); } private native int acceptSubscription(long nativeptr); @Override - public void acceptSubscription() { - acceptSubscription(mNativePtr); + public synchronized void acceptSubscription() { + synchronized(getCore()){ + acceptSubscription(mNativePtr); + } } private native int denySubscription(long nativeptr, int reason); @Override - public void denySubscription(Reason reason) { - denySubscription(mNativePtr,reason.mValue); + public synchronized void denySubscription(Reason reason) { + synchronized(getCore()){ + denySubscription(mNativePtr,reason.mValue); + } } private native int notify(long nativeptr, String type, String subtype, byte data[], String encoding); @Override - public void notify(LinphoneContent content) { - notify(mNativePtr,content.getType(),content.getSubtype(),content.getData(),content.getEncoding()); + public synchronized void notify(LinphoneContent content) { + synchronized(getCore()){ + notify(mNativePtr,content.getType(),content.getSubtype(),content.getData(),content.getEncoding()); + } } private native int updateSubscribe(long nativePtr, String type, String subtype, byte data[], String encoding); @Override - public void updateSubscribe(LinphoneContent content) { - updateSubscribe(mNativePtr,content.getType(), content.getSubtype(),content.getData(),content.getEncoding()); + public synchronized void updateSubscribe(LinphoneContent content) { + synchronized(getCore()){ + updateSubscribe(mNativePtr,content.getType(), content.getSubtype(),content.getData(),content.getEncoding()); + } } private native int updatePublish(long nativePtr, String type, String subtype, byte data[], String encoding); @Override - public void updatePublish(LinphoneContent content) { - updatePublish(mNativePtr,content.getType(), content.getSubtype(),content.getData(),content.getEncoding()); + public synchronized void updatePublish(LinphoneContent content) { + synchronized(getCore()){ + updatePublish(mNativePtr,content.getType(), content.getSubtype(),content.getData(),content.getEncoding()); + } } private native int terminate(long nativePtr); @Override - public void terminate() { - terminate(mNativePtr); + public synchronized void terminate() { + synchronized(getCore()){ + terminate(mNativePtr); + } } private native int getReason(long nativePtr); @Override - public Reason getReason() { + public synchronized Reason getReason() { return Reason.fromInt(getReason(mNativePtr)); } @Override - public void setUserContext(Object obj) { + public synchronized void setUserContext(Object obj) { mUserContext=obj; } @Override - public Object getUserContext() { + public synchronized Object getUserContext() { return mUserContext; } private native int getSubscriptionDir(long nativeptr); @Override - public SubscriptionDir getSubscriptionDir() { + public synchronized SubscriptionDir getSubscriptionDir() { return SubscriptionDir.fromInt(getSubscriptionDir(mNativePtr)); } private native int getSubscriptionState(long nativeptr); @Override - public SubscriptionState getSubscriptionState() { + public synchronized SubscriptionState getSubscriptionState() { try { return SubscriptionState.fromInt(getSubscriptionState(mNativePtr)); } catch (LinphoneCoreException e) { @@ -91,37 +103,47 @@ public class LinphoneEventImpl implements LinphoneEvent { private native void addCustomHeader(long ptr, String name, String value); @Override - public void addCustomHeader(String name, String value) { + public synchronized void addCustomHeader(String name, String value) { addCustomHeader(mNativePtr, name, value); } private native String getCustomHeader(long ptr, String name); @Override - public String getCustomHeader(String name) { + public synchronized String getCustomHeader(String name) { return getCustomHeader(mNativePtr, name); } private native void sendSubscribe(long ptr, String type, String subtype, byte data [], String encoding); @Override - public void sendSubscribe(LinphoneContent body) { - if (body != null) - sendSubscribe(mNativePtr, body.getType(), body.getSubtype(), body.getData(), body.getEncoding()); - else - sendSubscribe(mNativePtr, null, null, null, null); + public synchronized void sendSubscribe(LinphoneContent body) { + synchronized(getCore()){ + if (body != null) + sendSubscribe(mNativePtr, body.getType(), body.getSubtype(), body.getData(), body.getEncoding()); + else + sendSubscribe(mNativePtr, null, null, null, null); + } } private native void sendPublish(long ptr, String type, String subtype, byte data [], String encoding); @Override - public void sendPublish(LinphoneContent body) { - if (body != null) - sendPublish(mNativePtr, body.getType(), body.getSubtype(), body.getData(), body.getEncoding()); - else - sendPublish(mNativePtr, null, null, null, null); + public synchronized void sendPublish(LinphoneContent body) { + synchronized(getCore()){ + if (body != null) + sendPublish(mNativePtr, body.getType(), body.getSubtype(), body.getData(), body.getEncoding()); + else + sendPublish(mNativePtr, null, null, null, null); + } } private native long getErrorInfo(long nativePtr); @Override - public ErrorInfo getErrorInfo() { + public synchronized ErrorInfo getErrorInfo() { return new ErrorInfoImpl(getErrorInfo(mNativePtr)); } + private native Object getCore(long nativePtr); + @Override + public synchronized LinphoneCore getCore() { + return (LinphoneCore)getCore(mNativePtr); + } + }