Commit 76c56b7e authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

callback notif text delivered JNI

parent 0eb64837
......@@ -119,6 +119,13 @@ void linphone_core_text_received(LinphoneCore *lc, const char *from, const char
ms_free(cleanfrom);
}
LinphoneCore* linphone_chat_room_get_lc(LinphoneChatRoom *cr){
return cr->lc;
}
LinphoneChatRoom* linphone_chat_message_get_chat_room(LinphoneChatMessage *msg){
return msg->chat_room;
}
void linphone_chat_room_set_user_data(LinphoneChatRoom *cr, void * ud){
cr->user_data=ud;
......@@ -169,4 +176,4 @@ void linphone_chat_message_set_user_data(LinphoneChatMessage* message,void* ud)
*/
void* linphone_chat_message_get_user_data(const LinphoneChatMessage* message) {
return message->message_userdata;
}
\ No newline at end of file
}
......@@ -669,7 +669,8 @@ typedef void (*LinphoneChatMessageStateChangeCb)(LinphoneChatMessage* msg,Linpho
* @param ud user data for the status cb.
*/
void linphone_chat_room_send_message2(LinphoneChatRoom *cr, LinphoneChatMessage* msg,LinphoneChatMessageStateChangeCb status_cb,void* ud);
LinphoneCore* linphone_chat_room_get_lc(LinphoneChatRoom *cr);
LinphoneChatRoom* linphone_chat_message_get_chat_room(LinphoneChatMessage *msg);
void linphone_chat_room_set_user_data(LinphoneChatRoom *cr, void * ud);
void * linphone_chat_room_get_user_data(LinphoneChatRoom *cr);
......
......@@ -132,6 +132,9 @@ public:
callStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCall$State"));
callStateFromIntId = env->GetStaticMethodID(callStateClass,"fromInt","(I)Lorg/linphone/core/LinphoneCall$State;");
chatMessageStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneChatMessage$State"));
chatMessageStateFromIntId = env->GetStaticMethodID(chatMessageStateClass,"fromInt","(I)Lorg/linphone/core/LinphoneChatMessage$State;");
/*callEncryption(LinphoneCore lc, LinphoneCall call, boolean encrypted,String auth_token);*/
callEncryptionChangedId=env->GetMethodID(listenerClass,"callEncryptionChanged","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCall;ZLjava/lang/String;)V");
......@@ -176,6 +179,7 @@ public:
env->DeleteGlobalRef(globalStateClass);
env->DeleteGlobalRef(registrationStateClass);
env->DeleteGlobalRef(callStateClass);
env->DeleteGlobalRef(chatMessageStateClass);
env->DeleteGlobalRef(proxyClass);
env->DeleteGlobalRef(callClass);
env->DeleteGlobalRef(chatRoomClass);
......@@ -204,6 +208,9 @@ public:
jmethodID callStateId;
jmethodID callStateFromIntId;
jclass chatMessageStateClass;
jmethodID chatMessageStateFromIntId;
jmethodID callEncryptionChangedId;
jclass ecCalibratorStatusClass;
......@@ -1358,16 +1365,64 @@ extern "C" long Java_org_linphone_core_LinphoneChatRoomImpl_getPeerAddress(JNIEn
,jlong ptr) {
return (long) linphone_chat_room_get_peer_address((LinphoneChatRoom*)ptr);
}
extern "C" void Java_org_linphone_core_LinphoneChatRoomImpl_sendMessage(JNIEnv* env
extern "C" jlong Java_org_linphone_core_LinphoneChatRoomImpl_createLinphoneChatMessage(JNIEnv* env
,jobject thiz
,jlong ptr
,jstring jmessage) {
const char* message = env->GetStringUTFChars(jmessage, NULL);
linphone_chat_room_send_message((LinphoneChatRoom*)ptr,message);
LinphoneChatMessage *chatMessage = linphone_chat_room_create_message((LinphoneChatRoom *)ptr, message);
env->ReleaseStringUTFChars(jmessage, message);
return (jlong) chatMessage;
}
extern "C" void Java_org_linphone_core_LinphoneChatMessageImpl_setUserData(JNIEnv* env
,jobject thiz
,jlong ptr
) {
jobject ud = env->NewGlobalRef(thiz);
linphone_chat_message_set_user_data((LinphoneChatMessage*)ptr,(void*) ud);
}
extern "C" void Java_org_linphone_core_LinphoneChatRoomImpl_sendMessage(JNIEnv* env
,jobject thiz
,jlong ptr
,jstring jmessage) {
const char* message = env->GetStringUTFChars(jmessage, NULL);
linphone_chat_room_send_message((LinphoneChatRoom*)ptr, message);
env->ReleaseStringUTFChars(jmessage, message);
}
static void chat_room_impl_callback(LinphoneChatMessage* msg, LinphoneChatMessageState state, void* ud) {
JNIEnv *env = 0;
jint result = jvm->AttachCurrentThread(&env,NULL);
if (result != 0) {
ms_error("cannot attach VM\n");
return;
}
jobject listener = (jobject) ud;
jclass clazz = (jclass) env->GetObjectClass(listener);
jmethodID method = env->GetMethodID(clazz, "onLinphoneChatMessageStateChanged","(Lorg/linphone/core/LinphoneChatMessage;Lorg/linphone/core/LinphoneChatMessage$State;)V");
LinphoneCore *lc = linphone_chat_room_get_lc(linphone_chat_message_get_chat_room(msg));
LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
env->CallVoidMethod(
listener,
method,
(jobject)linphone_chat_message_get_user_data(msg),
env->CallStaticObjectMethod(lcData->chatMessageStateClass,lcData->chatMessageStateFromIntId,(jint)state));
if (state == LinphoneChatMessageStateDelivered || state == LinphoneChatMessageStateNotDelivered) {
env->DeleteGlobalRef(listener);
}
}
extern "C" void Java_org_linphone_core_LinphoneChatRoomImpl_sendMessage2(JNIEnv* env
,jobject thiz
,jlong ptr
,jlong jmessage
,jobject jlistener) {
jobject listener = env->NewGlobalRef(jlistener);
linphone_chat_room_send_message2((LinphoneChatRoom*)ptr, (LinphoneChatMessage*)jmessage, chat_room_impl_callback, (void*)listener);
}
extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setVideoWindowId(JNIEnv* env
,jobject thiz
,jlong lc
......
......@@ -8,6 +8,7 @@ public interface LinphoneChatMessage {
void onLinphoneChatMessageStateChanged(LinphoneChatMessage msg, State state);
}
static class State {
@SuppressWarnings("rawtypes")
static private Vector values = new Vector();
private final int mValue;
public final int value() {return mValue;}
......@@ -30,6 +31,7 @@ public interface LinphoneChatMessage {
*/
public final static State NotDelivered = new State(3,"NotDelivered");
@SuppressWarnings("unchecked")
private State(int value,String stringValue) {
mValue = value;
values.addElement(this);
......@@ -47,7 +49,14 @@ public interface LinphoneChatMessage {
public String toString() {
return mStringValue;
}
public int toInt() {
return mValue;
}
}
long getNativePtr();
Object getUserData();
void setUserData();
}
......@@ -39,11 +39,19 @@ public interface LinphoneChatRoom {
* Send a message to peer member of this chat room.
* @param chat message
*/
void sendMessage(LinphoneChatMessage msg, LinphoneChatMessage.StateListener listener);
void sendMessage(LinphoneChatMessage message, LinphoneChatMessage.StateListener listener);
/**
* DEPRECATED
* @param opaque
* @param message
*/
void sendMessage(Object opaque, String message);
/**
* Create a LinphoneChatMessage
* @param chatRoom chat room associated to the message
* @param message message to send
* @return LinphoneChatMessage object
*/
LinphoneChatMessage createLinphoneChatMessage(String message);
}
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