Commit 3f53d5f0 authored by Sylvain Berfini's avatar Sylvain Berfini

Reworked jni layer to be able to set multiple vtables for callbacks in android app

parent 1bb6ebed
......@@ -7025,16 +7025,34 @@ LinphoneCoreVTable *linphone_core_v_table_new() {
return ms_new0(LinphoneCoreVTable,1);
}
void linphone_core_v_table_set_user_data(LinphoneCoreVTable *table, void *data) {
if (table->user_data) {
ms_free(table->user_data);
}
table->user_data = data;
}
void* linphone_core_v_table_get_user_data(LinphoneCoreVTable *table) {
return table->user_data;
}
void linphone_core_v_table_destroy(LinphoneCoreVTable* table) {
if (table->user_data) {
ms_free(table->user_data);
}
ms_free(table);
}
LinphoneCoreVTable *linphone_core_get_current_vtable(LinphoneCore *lc) {
return lc->current_vtable;
}
#define NOTIFY_IF_EXIST(function_name) \
MSList* iterator; \
ms_message ("Linphone core [%p] notifying [%s]",lc,#function_name);\
for (iterator=lc->vtables; iterator!=NULL; iterator=iterator->next) \
if (((LinphoneCoreVTable*)(iterator->data))->function_name)\
if ((lc->current_vtable=((LinphoneCoreVTable*)(iterator->data)))->function_name)\
((LinphoneCoreVTable*)(iterator->data))->function_name
void linphone_core_notify_global_state_changed(LinphoneCore *lc, LinphoneGlobalState gstate, const char *message) {
NOTIFY_IF_EXIST(global_state_changed)(lc,gstate,message);
}
......
......@@ -1558,7 +1558,7 @@ typedef enum _LinphoneCoreLogCollectionUploadState {
* @param gstate the global state
* @param message informational message.
*/
typedef void (*LinphoneCoreGlobalStateChangedCb )(LinphoneCore *lc, LinphoneGlobalState gstate, const char *message);
typedef void (*LinphoneCoreGlobalStateChangedCb)(LinphoneCore *lc, LinphoneGlobalState gstate, const char *message);
/**
* Call state notification callback.
* @param lc the LinphoneCore
......@@ -1809,6 +1809,7 @@ typedef struct _LinphoneCoreVTable{
LinphoneCoreNetworkReachableCb network_reachable; /**< Callback to report IP network status (I.E up/down )*/
LinphoneCoreLogCollectionUploadStateChangedCb log_collection_upload_state_changed; /**< Callback to upload collected logs */
LinphoneCoreLogCollectionUploadProgressIndicationCb log_collection_upload_progress_indication; /**< Callback to indicate log collection upload progress */
void *user_data;
} LinphoneCoreVTable;
/**
......@@ -1817,6 +1818,28 @@ typedef struct _LinphoneCoreVTable{
*/
LINPHONE_PUBLIC LinphoneCoreVTable *linphone_core_v_table_new();
/**
* Sets a user data pointer in the vtable.
* @param table the vtable
* @param data the user data to attach
*/
LINPHONE_PUBLIC void linphone_core_v_table_set_user_data(LinphoneCoreVTable *table, void *data);
/**
* Gets a user data pointer in the vtable.
* @param table the vtable
* @returns the data attached to the vtable
*/
LINPHONE_PUBLIC void* linphone_core_v_table_get_user_data(LinphoneCoreVTable *table);
/**
* Gets the current VTable.
* This is meant only to be called from a callback to be able to get the user_data associated with the vtable that called the callback.
* @param lc the linphonecore
* @returns the vtable that called the last callback
*/
LINPHONE_PUBLIC LinphoneCoreVTable *linphone_core_get_current_vtable(LinphoneCore *lc);
/**
* Destroy a vtable.
* @param vtable to be destroyed
......
......@@ -163,70 +163,154 @@ extern "C" void Java_org_linphone_core_LinphoneCoreFactoryImpl_setDebugMode(JNIE
}
// LinphoneCore
/*
* returns the java LinphoneProxyConfig associated with a C LinphoneProxyConfig.
**/
jobject getProxy(JNIEnv *env, LinphoneProxyConfig *proxy, jobject core){
jobject jobj=0;
if (proxy!=NULL){
jclass proxyClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneProxyConfigImpl"));
jmethodID proxyCtrId = env->GetMethodID(proxyClass,"<init>", "(Lorg/linphone/core/LinphoneCoreImpl;J)V");
void *up=linphone_proxy_config_get_user_data(proxy);
if (up==NULL){
jobj=env->NewObject(proxyClass,proxyCtrId,core,(jlong)proxy);
linphone_proxy_config_set_user_data(proxy,(void*)env->NewWeakGlobalRef(jobj));
linphone_proxy_config_ref(proxy);
}else{
//promote the weak ref to local ref
jobj=env->NewLocalRef((jobject)up);
if (jobj == NULL){
//the weak ref was dead
jobj=env->NewObject(proxyClass,proxyCtrId,core,(jlong)proxy);
linphone_proxy_config_set_user_data(proxy,(void*)env->NewWeakGlobalRef(jobj));
}
}
env->DeleteGlobalRef(proxyClass);
}
return jobj;
}
jobject getCall(JNIEnv *env, LinphoneCall *call){
jobject jobj=0;
if (call!=NULL){
jclass callClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCallImpl"));
jmethodID callCtrId = env->GetMethodID(callClass,"<init>", "(J)V");
void *up=linphone_call_get_user_pointer(call);
if (up==NULL){
jobj=env->NewObject(callClass,callCtrId,(jlong)call);
jobj=env->NewGlobalRef(jobj);
linphone_call_set_user_pointer(call,(void*)jobj);
linphone_call_ref(call);
}else{
jobj=(jobject)up;
}
env->DeleteGlobalRef(callClass);
}
return jobj;
}
jobject getChatMessage(JNIEnv *env, LinphoneChatMessage *msg){
jobject jobj = 0;
if (msg != NULL){
jclass chatMessageClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneChatMessageImpl"));
jmethodID chatMessageCtrId = env->GetMethodID(chatMessageClass,"<init>", "(J)V");
void *up = linphone_chat_message_get_user_data(msg);
if (up == NULL) {
jobj = env->NewObject(chatMessageClass,chatMessageCtrId,(jlong)linphone_chat_message_ref(msg));
jobj = env->NewGlobalRef(jobj);
linphone_chat_message_set_user_data(msg,(void*)jobj);
} else {
jobj = (jobject)up;
}
env->DeleteGlobalRef(chatMessageClass);
}
return jobj;
}
jobject getEvent(JNIEnv *env, LinphoneEvent *lev){
if (lev==NULL) return NULL;
jobject jev=(jobject)linphone_event_get_user_data(lev);
if (jev==NULL){
jclass linphoneEventClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneEventImpl"));
jmethodID linphoneEventCtrId = env->GetMethodID(linphoneEventClass,"<init>", "(J)V");
jev=env->NewObject(linphoneEventClass,linphoneEventCtrId,(jlong)linphone_event_ref(lev));
jev=env->NewGlobalRef(jev);
linphone_event_set_user_data(lev,jev);
env->DeleteGlobalRef(linphoneEventClass);
}
return jev;
}
class LinphoneCoreData {
public:
LinphoneCoreData(JNIEnv* env, jobject lc,jobject alistener, jobject auserdata) {
LinphoneCoreData(JNIEnv *env, jobject lc, LinphoneCoreVTable *vTable, jobject alistener) {
core = env->NewGlobalRef(lc);
listener = env->NewGlobalRef(alistener);
userdata = auserdata?env->NewGlobalRef(auserdata):0;
memset(&vTable,0,sizeof(vTable));
vTable.show = showInterfaceCb;
vTable.auth_info_requested = authInfoRequested;
vTable.display_status = displayStatusCb;
vTable.display_message = displayMessageCb;
vTable.display_warning = displayMessageCb;
vTable.global_state_changed = globalStateChange;
vTable.registration_state_changed = registrationStateChange;
vTable.call_state_changed = callStateChange;
vTable.call_encryption_changed = callEncryptionChange;
vTable.text_received = text_received;
vTable.message_received = message_received;
vTable.is_composing_received = is_composing_received;
vTable.dtmf_received = dtmf_received;
vTable.new_subscription_requested = new_subscription_requested;
vTable.notify_presence_received = notify_presence_received;
vTable.call_stats_updated = callStatsUpdated;
vTable.transfer_state_changed = transferStateChanged;
vTable.info_received = infoReceived;
vTable.subscription_state_changed=subscriptionStateChanged;
vTable.notify_received=notifyReceived;
vTable.publish_state_changed=publishStateChanged;
vTable.configuring_status=configuringStatus;
vTable.file_transfer_progress_indication=fileTransferProgressIndication;
vTable.file_transfer_send=fileTransferSend;
vTable.file_transfer_recv=fileTransferRecv;
listenerClass = (jclass)env->NewGlobalRef(env->GetObjectClass( alistener));
memset(vTable, 0, sizeof(LinphoneCoreVTable));
listenerClass = (jclass)env->NewGlobalRef(env->GetObjectClass(alistener));
/*displayStatus(LinphoneCore lc,String message);*/
displayStatusId = env->GetMethodID(listenerClass,"displayStatus","(Lorg/linphone/core/LinphoneCore;Ljava/lang/String;)V");
if (displayStatusId) {
vTable->display_status = displayStatusCb;
}
/*void generalState(LinphoneCore lc,int state); */
globalStateId = env->GetMethodID(listenerClass,"globalState","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCore$GlobalState;Ljava/lang/String;)V");
globalStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCore$GlobalState"));
globalStateFromIntId = env->GetStaticMethodID(globalStateClass,"fromInt","(I)Lorg/linphone/core/LinphoneCore$GlobalState;");
if (globalStateId) {
vTable->global_state_changed = globalStateChange;
}
/*registrationState(LinphoneCore lc, LinphoneProxyConfig cfg, LinphoneCore.RegistrationState cstate, String smessage);*/
registrationStateId = env->GetMethodID(listenerClass,"registrationState","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneProxyConfig;Lorg/linphone/core/LinphoneCore$RegistrationState;Ljava/lang/String;)V");
registrationStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCore$RegistrationState"));
registrationStateFromIntId = env->GetStaticMethodID(registrationStateClass,"fromInt","(I)Lorg/linphone/core/LinphoneCore$RegistrationState;");
if (registrationStateId) {
vTable->registration_state_changed = registrationStateChange;
}
/*callState(LinphoneCore lc, LinphoneCall call, LinphoneCall.State cstate,String message);*/
callStateId = env->GetMethodID(listenerClass,"callState","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCall;Lorg/linphone/core/LinphoneCall$State;Ljava/lang/String;)V");
callStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCall$State"));
callStateFromIntId = env->GetStaticMethodID(callStateClass,"fromInt","(I)Lorg/linphone/core/LinphoneCall$State;");
if (callStateId) {
vTable->call_state_changed = callStateChange;
}
transferStateId = env->GetMethodID(listenerClass,"transferState","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCall;Lorg/linphone/core/LinphoneCall$State;)V");
if (transferStateId) {
vTable->transfer_state_changed = transferStateChanged;
}
/*callStatsUpdated(LinphoneCore lc, LinphoneCall call, LinphoneCallStats stats);*/
callStatsUpdatedId = env->GetMethodID(listenerClass, "callStatsUpdated", "(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCall;Lorg/linphone/core/LinphoneCallStats;)V");
if (callStatsUpdatedId) {
vTable->call_stats_updated = callStatsUpdated;
}
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");
callEncryptionChangedId = env->GetMethodID(listenerClass,"callEncryptionChanged","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCall;ZLjava/lang/String;)V");
if (callEncryptionChangedId) {
vTable->call_encryption_changed = callEncryptionChange;
}
/*void ecCalibrationStatus(LinphoneCore.EcCalibratorStatus status, int delay_ms, Object data);*/
ecCalibrationStatusId = env->GetMethodID(listenerClass,"ecCalibrationStatus","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCore$EcCalibratorStatus;ILjava/lang/Object;)V");
......@@ -235,28 +319,88 @@ public:
/*void newSubscriptionRequest(LinphoneCore lc, LinphoneFriend lf, String url)*/
newSubscriptionRequestId = env->GetMethodID(listenerClass,"newSubscriptionRequest","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneFriend;Ljava/lang/String;)V");
if (newSubscriptionRequestId) {
vTable->new_subscription_requested = new_subscription_requested;
}
authInfoRequestedId = env->GetMethodID(listenerClass,"authInfoRequested","(Lorg/linphone/core/LinphoneCore;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
if (authInfoRequestedId) {
vTable->auth_info_requested = authInfoRequested;
}
/*void notifyPresenceReceived(LinphoneCore lc, LinphoneFriend lf);*/
notifyPresenceReceivedId = env->GetMethodID(listenerClass,"notifyPresenceReceived","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneFriend;)V");
if (notifyPresenceReceivedId) {
vTable->notify_presence_received = notify_presence_received;
}
/*void textReceived(LinphoneCore lc, LinphoneChatRoom cr,LinphoneAddress from,String message);*/
textReceivedId = env->GetMethodID(listenerClass,"textReceived","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneChatRoom;Lorg/linphone/core/LinphoneAddress;Ljava/lang/String;)V");
if (textReceivedId) {
vTable->text_received = text_received;
}
messageReceivedId = env->GetMethodID(listenerClass,"messageReceived","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneChatRoom;Lorg/linphone/core/LinphoneChatMessage;)V");
if (messageReceivedId) {
vTable->message_received = message_received;
}
isComposingReceivedId = env->GetMethodID(listenerClass,"isComposingReceived","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneChatRoom;)V");
if (isComposingReceivedId) {
vTable->is_composing_received = is_composing_received;
}
dtmfReceivedId = env->GetMethodID(listenerClass,"dtmfReceived","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCall;I)V");
infoReceivedId = env->GetMethodID(listenerClass,"infoReceived",
"(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCall;Lorg/linphone/core/LinphoneInfoMessage;)V");
if (dtmfReceivedId) {
vTable->dtmf_received = dtmf_received;
}
infoReceivedId = env->GetMethodID(listenerClass,"infoReceived", "(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCall;Lorg/linphone/core/LinphoneInfoMessage;)V");
if (infoReceivedId) {
vTable->info_received = infoReceived;
}
subscriptionStateId = env->GetMethodID(listenerClass,"subscriptionStateChanged",
"(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneEvent;Lorg/linphone/core/SubscriptionState;)V");
publishStateId = env->GetMethodID(listenerClass,"publishStateChanged",
"(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneEvent;Lorg/linphone/core/PublishState;)V");
notifyRecvId = env->GetMethodID(listenerClass,"notifyReceived",
"(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneEvent;Ljava/lang/String;Lorg/linphone/core/LinphoneContent;)V");
subscriptionStateId = env->GetMethodID(listenerClass,"subscriptionStateChanged", "(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneEvent;Lorg/linphone/core/SubscriptionState;)V");
subscriptionStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/SubscriptionState"));
subscriptionStateFromIntId = env->GetStaticMethodID(subscriptionStateClass,"fromInt","(I)Lorg/linphone/core/SubscriptionState;");
if (subscriptionStateId) {
vTable->subscription_state_changed = subscriptionStateChanged;
}
publishStateId = env->GetMethodID(listenerClass,"publishStateChanged", "(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneEvent;Lorg/linphone/core/PublishState;)V");
publishStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/PublishState"));
publishStateFromIntId = env->GetStaticMethodID(publishStateClass,"fromInt","(I)Lorg/linphone/core/PublishState;");
if (publishStateId) {
vTable->publish_state_changed = publishStateChanged;
}
notifyRecvId = env->GetMethodID(listenerClass,"notifyReceived", "(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneEvent;Ljava/lang/String;Lorg/linphone/core/LinphoneContent;)V");
if (notifyRecvId) {
vTable->notify_received = notifyReceived;
}
configuringStateId = env->GetMethodID(listenerClass,"configuringStatus","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCore$RemoteProvisioningState;Ljava/lang/String;)V");
configuringStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCore$RemoteProvisioningState"));
configuringStateFromIntId = env->GetStaticMethodID(configuringStateClass,"fromInt","(I)Lorg/linphone/core/LinphoneCore$RemoteProvisioningState;");
if (configuringStateId) {
vTable->configuring_status = configuringStatus;
}
fileTransferProgressIndicationId = env->GetMethodID(listenerClass, "fileTransferProgressIndication", "(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneChatMessage;Lorg/linphone/core/LinphoneContent;I)V");
if (fileTransferProgressIndicationId) {
vTable->file_transfer_progress_indication = fileTransferProgressIndication;
}
fileTransferSendId = env->GetMethodID(listenerClass, "fileTransferSend", "(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneChatMessage;Lorg/linphone/core/LinphoneContent;Ljava/nio/ByteBuffer;I)I");
if (fileTransferSendId) {
vTable->file_transfer_send = fileTransferSend;
}
fileTransferRecvId = env->GetMethodID(listenerClass, "fileTransferRecv", "(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneChatMessage;Lorg/linphone/core/LinphoneContent;[BI)V");
if (fileTransferRecvId) {
vTable->file_transfer_recv = fileTransferRecv;
}
proxyClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneProxyConfigImpl"));
proxyCtrId = env->GetMethodID(proxyClass,"<init>", "(Lorg/linphone/core/LinphoneCoreImpl;J)V");
......@@ -270,10 +414,10 @@ public:
chatRoomCtrId = env->GetMethodID(chatRoomClass,"<init>", "(J)V");
friendClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneFriendImpl"));;
friendCtrId =env->GetMethodID(friendClass,"<init>", "(J)V");
friendCtrId = env->GetMethodID(friendClass,"<init>", "(J)V");
addressClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneAddressImpl"));
addressCtrId =env->GetMethodID(addressClass,"<init>", "(J)V");
addressCtrId = env->GetMethodID(addressClass,"<init>", "(J)V");
callStatsClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCallStatsImpl"));
callStatsId = env->GetMethodID(callStatsClass, "<init>", "(JJ)V");
......@@ -286,22 +430,8 @@ public:
linphoneEventClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneEventImpl"));
linphoneEventCtrId = env->GetMethodID(linphoneEventClass,"<init>", "(J)V");
subscriptionStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/SubscriptionState"));
subscriptionStateFromIntId = env->GetStaticMethodID(subscriptionStateClass,"fromInt","(I)Lorg/linphone/core/SubscriptionState;");
publishStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/PublishState"));
publishStateFromIntId = env->GetStaticMethodID(publishStateClass,"fromInt","(I)Lorg/linphone/core/PublishState;");
subscriptionDirClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/SubscriptionDir"));
subscriptionDirFromIntId = env->GetStaticMethodID(subscriptionDirClass,"fromInt","(I)Lorg/linphone/core/SubscriptionDir;");
configuringStateId = env->GetMethodID(listenerClass,"configuringStatus","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCore$RemoteProvisioningState;Ljava/lang/String;)V");
configuringStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCore$RemoteProvisioningState"));
configuringStateFromIntId = env->GetStaticMethodID(configuringStateClass,"fromInt","(I)Lorg/linphone/core/LinphoneCore$RemoteProvisioningState;");
fileTransferProgressIndicationId = env->GetMethodID(listenerClass, "fileTransferProgressIndication", "(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneChatMessage;Lorg/linphone/core/LinphoneContent;I)V");
fileTransferSendId = env->GetMethodID(listenerClass, "fileTransferSend", "(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneChatMessage;Lorg/linphone/core/LinphoneContent;Ljava/nio/ByteBuffer;I)I");
fileTransferRecvId = env->GetMethodID(listenerClass, "fileTransferRecv", "(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneChatMessage;Lorg/linphone/core/LinphoneContent;[BI)V");
}
~LinphoneCoreData() {
......@@ -309,7 +439,6 @@ public:
jvm->AttachCurrentThread(&env,NULL);
env->DeleteGlobalRef(core);
env->DeleteGlobalRef(listener);
if (userdata) env->DeleteGlobalRef(userdata);
env->DeleteGlobalRef(listenerClass);
env->DeleteGlobalRef(globalStateClass);
env->DeleteGlobalRef(configuringStateClass);
......@@ -328,7 +457,6 @@ public:
}
jobject core;
jobject listener;
jobject userdata;
jclass listenerClass;
jmethodID displayStatusId;
......@@ -414,13 +542,7 @@ public:
jmethodID fileTransferRecvId;
LinphoneCoreVTable vTable;
static void showInterfaceCb(LinphoneCore *lc) {
}
static void byeReceivedCb(LinphoneCore *lc, const char *from) {
}
static void displayStatusCb(LinphoneCore *lc, const char *message) {
JNIEnv *env = 0;
jint result = jvm->AttachCurrentThread(&env,NULL);
......@@ -428,11 +550,9 @@ public:
ms_error("cannot attach VM");
return;
}
LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc);
LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table);
env->CallVoidMethod(lcData->listener,lcData->displayStatusId,lcData->core,message ? env->NewStringUTF(message) : NULL);
}
static void displayMessageCb(LinphoneCore *lc, const char *message) {
}
static void authInfoRequested(LinphoneCore *lc, const char *realm, const char *username, const char *domain) {
JNIEnv *env = 0;
......@@ -441,7 +561,8 @@ public:
ms_error("cannot attach VM");
return;
}
LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc);
LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table);
env->CallVoidMethod(lcData->listener,
lcData->authInfoRequestedId,
lcData->core,
......@@ -456,38 +577,14 @@ public:
ms_error("cannot attach VM");
return;
}
LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc);
LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table);
env->CallVoidMethod(lcData->listener
,lcData->globalStateId
,lcData->core
,env->CallStaticObjectMethod(lcData->globalStateClass,lcData->globalStateFromIntId,(jint)gstate),
message ? env->NewStringUTF(message) : NULL);
}
/*
* returns the java LinphoneProxyConfig associated with a C LinphoneProxyConfig.
**/
jobject getProxy(JNIEnv *env , LinphoneProxyConfig *proxy, jobject core){
jobject jobj=0;
if (proxy!=NULL){
void *up=linphone_proxy_config_get_user_data(proxy);
if (up==NULL){
jobj=env->NewObject(proxyClass,proxyCtrId,core,(jlong)proxy);
linphone_proxy_config_set_user_data(proxy,(void*)env->NewWeakGlobalRef(jobj));
linphone_proxy_config_ref(proxy);
}else{
//promote the weak ref to local ref
jobj=env->NewLocalRef((jobject)up);
if (jobj == NULL){
//the weak ref was dead
jobj=env->NewObject(proxyClass,proxyCtrId,core,(jlong)proxy);
linphone_proxy_config_set_user_data(proxy,(void*)env->NewWeakGlobalRef(jobj));
}
}
}
return jobj;
}
static void registrationStateChange(LinphoneCore *lc, LinphoneProxyConfig* proxy,LinphoneRegistrationState state,const char* message) {
JNIEnv *env = 0;
jint result = jvm->AttachCurrentThread(&env,NULL);
......@@ -496,31 +593,15 @@ public:
ms_error("cannot attach VM");
return;
}
LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc);
LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table);
env->CallVoidMethod(lcData->listener
,lcData->registrationStateId
,lcData->core
,(jproxy=lcData->getProxy(env,proxy,lcData->core))
,(jproxy=getProxy(env,proxy,lcData->core))
,env->CallStaticObjectMethod(lcData->registrationStateClass,lcData->registrationStateFromIntId,(jint)state),
message ? env->NewStringUTF(message) : NULL);
}
jobject getCall(JNIEnv *env , LinphoneCall *call){
jobject jobj=0;
if (call!=NULL){
void *up=linphone_call_get_user_pointer(call);
if (up==NULL){
jobj=env->NewObject(callClass,callCtrId,(jlong)call);
jobj=env->NewGlobalRef(jobj);
linphone_call_set_user_pointer(call,(void*)jobj);
linphone_call_ref(call);
}else{
jobj=(jobject)up;
}
}
return jobj;
}
static void callStateChange(LinphoneCore *lc, LinphoneCall* call,LinphoneCallState state,const char* message) {
JNIEnv *env = 0;
......@@ -530,11 +611,12 @@ public:
ms_error("cannot attach VM");
return;
}
LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc);
LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table);
env->CallVoidMethod(lcData->listener
,lcData->callStateId
,lcData->core
,(jcall=lcData->getCall(env,call))
,(jcall=getCall(env,call))
,env->CallStaticObjectMethod(lcData->callStateClass,lcData->callStateFromIntId,(jint)state),
message ? env->NewStringUTF(message) : NULL);
if (state==LinphoneCallReleased){
......@@ -549,11 +631,12 @@ public:
ms_error("cannot attach VM");
return;
}
LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc);
LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table);
env->CallVoidMethod(lcData->listener
,lcData->callEncryptionChangedId
,lcData->core
,lcData->getCall(env,call)
,getCall(env,call)
,encrypted
,authentication_token ? env->NewStringUTF(authentication_token) : NULL);
}
......@@ -564,7 +647,8 @@ public:
ms_error("cannot attach VM");
return;
}
LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc);
LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table);
env->CallVoidMethod(lcData->listener
,lcData->notifyPresenceReceivedId
,lcData->core
......@@ -577,7 +661,8 @@ public:
ms_error("cannot attach VM");
return;
}
LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc);
LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table);
env->CallVoidMethod(lcData->listener
,lcData->newSubscriptionRequestId
,lcData->core
......@@ -591,11 +676,12 @@ public:
ms_error("cannot attach VM");
return;
}
LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc);
LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table);
env->CallVoidMethod(lcData->listener
,lcData->dtmfReceivedId
,lcData->core
,lcData->getCall(env,call)
,getCall(env,call)
,dtmf);
}
static void text_received(LinphoneCore *lc, LinphoneChatRoom *room, const LinphoneAddress *from, const char *message) {
......@@ -605,7 +691,8 @@ public:
ms_error("cannot attach VM");
return;
}
LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc);
LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table);
env->CallVoidMethod(lcData->listener
,lcData->textReceivedId
,lcData->core
......@@ -613,38 +700,23 @@ public:
,env->NewObject(lcData->addressClass,lcData->addressCtrId,(jlong)from)
,message ? env->NewStringUTF(message) : NULL);
}
jobject getChatMessage(JNIEnv *env , LinphoneChatMessage *msg){
jobject jobj = 0;
if (msg != NULL){
void *up = linphone_chat_message_get_user_data(msg);
if (up == NULL) {
jobj = env->NewObject(chatMessageClass,chatMessageCtrId,(jlong)linphone_chat_message_ref(msg));
jobj = env->NewGlobalRef(jobj);
linphone_chat_message_set_user_data(msg,(void*)jobj);
} else {
jobj = (jobject)up;
}
}
return jobj;
}
static void message_received(LinphoneCore *lc, LinphoneChatRoom *room, LinphoneChatMessage *msg) {
JNIEnv *env = 0;
jobject jmsg;
jint result = jvm->AttachCurrentThread(&env,NULL);
if (result != 0) {
ms_error("cannot attach VM");
return;
}
LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
/*note: we call linphone_chat_message_ref() because the application does not acquire the object when invoked from a callback*/
env->CallVoidMethod(lcData->listener
,lcData->messageReceivedId
,lcData->core
,env->NewObject(lcData->chatRoomClass,lcData->chatRoomCtrId,(jlong)room)
,(jmsg = lcData->getChatMessage(env, msg)));
JNIEnv *env = 0;
jobject jmsg;
jint result = jvm->AttachCurrentThread(&env,NULL);
if (result != 0) {
ms_error("cannot attach VM");
return;
}
LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc);
LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table);
/*note: we call linphone_chat_message_ref() because the application does not acquire the object when invoked from a callback*/
env->CallVoidMethod(lcData->listener
,lcData->messageReceivedId
,lcData->core
,env->NewObject(lcData->chatRoomClass,lcData->chatRoomCtrId,(jlong)room)
,(jmsg = getChatMessage(env, msg)));
}
static void is_composing_received(LinphoneCore *lc, LinphoneChatRoom *room) {
JNIEnv *env = 0;
jint result = jvm->AttachCurrentThread(&env,NULL);
......@@ -652,7 +724,8 @@ public:
ms_error("cannot attach VM");
return;
}
LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc);
LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table);
env->CallVoidMethod(lcData->listener
,lcData->isComposingReceivedId
,lcData->core
......@@ -665,7 +738,8 @@ public:
ms_error("cannot attach VM");
return;
}
LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc);
LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table);
env->CallVoidMethod(lcData->listener
,lcData->ecCalibrationStatusId
,lcData->core
......@@ -687,9 +761,10 @@ public:
ms_error("cannot attach VM");
return;
}
LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc);
LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table);
statsobj = env->NewObject(lcData->callStatsClass, lcData->callStatsId, (jlong)call, (jlong)stats);
callobj = lcData->getCall(env, call);
callobj = getCall(env, call);
if (stats->type == LINPHONE_CALL_STATS_AUDIO)
env->CallVoidMethod(callobj, lcData->callSetAudioStatsId, statsobj);
else
......@@ -704,11 +779,12 @@ public:
ms_error("cannot attach VM");
return;
}
LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc);
LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table);
env->CallVoidMethod(lcData->listener
,lcData->transferStateId
,lcData->core
,(jcall=lcData->getCall(env,call))
,(jcall=getCall(env,call))
,env->CallStaticObjectMethod(lcData->callStateClass,lcData->callStateFromIntId,(jint)remote_call_state)
);
}
......@@ -720,24 +796,15 @@ public:
return;
}
LinphoneInfoMessage *copy_info=linphone_info_message_copy(info);
LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc);
LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table);
env->CallVoidMethod(lcData->listener
,lcData->infoReceivedId
,lcData->core</