diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index 9a7053d07..f89bc5643 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -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); } diff --git a/coreapi/linphonecore.h b/coreapi/linphonecore.h index e3ad83ff7..ac72246ad 100644 --- a/coreapi/linphonecore.h +++ b/coreapi/linphonecore.h @@ -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 diff --git a/coreapi/linphonecore_jni.cc b/coreapi/linphonecore_jni.cc index be72e283f..128da582d 100644 --- a/coreapi/linphonecore_jni.cc +++ b/coreapi/linphonecore_jni.cc @@ -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,"", "(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,"", "(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,"", "(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,"", "(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,"", "(Lorg/linphone/core/LinphoneCoreImpl;J)V"); @@ -270,10 +414,10 @@ public: chatRoomCtrId = env->GetMethodID(chatRoomClass,"", "(J)V"); friendClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneFriendImpl"));; - friendCtrId =env->GetMethodID(friendClass,"", "(J)V"); + friendCtrId = env->GetMethodID(friendClass,"", "(J)V"); addressClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneAddressImpl")); - addressCtrId =env->GetMethodID(addressClass,"", "(J)V"); + addressCtrId = env->GetMethodID(addressClass,"", "(J)V"); callStatsClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCallStatsImpl")); callStatsId = env->GetMethodID(callStatsClass, "", "(JJ)V"); @@ -286,22 +430,8 @@ public: linphoneEventClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneEventImpl")); linphoneEventCtrId = env->GetMethodID(linphoneEventClass,"", "(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 - ,lcData->getCall(env,call) + ,getCall(env,call) ,env->NewObject(lcData->infoMessageClass,lcData->infoMessageCtor,(jlong)copy_info) ); } - jobject getEvent(JNIEnv *env, LinphoneEvent *lev){ - if (lev==NULL) return NULL; - jobject jev=(jobject)linphone_event_get_user_data(lev); - if (jev==NULL){ - jev=env->NewObject(linphoneEventClass,linphoneEventCtrId,(jlong)linphone_event_ref(lev)); - jev=env->NewGlobalRef(jev); - linphone_event_set_user_data(lev,jev); - } - return jev; - } static void subscriptionStateChanged(LinphoneCore *lc, LinphoneEvent *ev, LinphoneSubscriptionState state){ JNIEnv *env = 0; jint result = jvm->AttachCurrentThread(&env,NULL); @@ -747,8 +814,9 @@ public: ms_error("cannot attach VM"); return; } - LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc); - jevent=lcData->getEvent(env,ev); + LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc); + LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table); + jevent=getEvent(env,ev); jstate=env->CallStaticObjectMethod(lcData->subscriptionStateClass,lcData->subscriptionStateFromIntId,(jint)state); env->CallVoidMethod(lcData->listener ,lcData->subscriptionStateId @@ -771,8 +839,9 @@ public: ms_error("cannot attach VM"); return; } - LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc); - jevent=lcData->getEvent(env,ev); + LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc); + LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table); + jevent=getEvent(env,ev); jstate=env->CallStaticObjectMethod(lcData->publishStateClass,lcData->publishStateFromIntId,(jint)state); env->CallVoidMethod(lcData->listener ,lcData->publishStateId @@ -789,8 +858,9 @@ public: ms_error("cannot attach VM"); return; } - LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc); - jevent=lcData->getEvent(env,ev); + LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc); + LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table); + jevent=getEvent(env,ev); env->CallVoidMethod(lcData->listener ,lcData->notifyRecvId ,lcData->core @@ -807,7 +877,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->configuringStateId, lcData->core, env->CallStaticObjectMethod(lcData->configuringStateClass,lcData->configuringStateFromIntId,(jint)status), message ? env->NewStringUTF(message) : NULL); } @@ -820,11 +891,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->fileTransferProgressIndicationId, lcData->core, - (jmsg = lcData->getChatMessage(env, message)), + (jmsg = getChatMessage(env, message)), content ? create_java_linphone_content(env, content) : NULL, progress); } @@ -838,11 +910,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); *size = env->CallIntMethod(lcData->listener, lcData->fileTransferSendId, lcData->core, - (jmsg = lcData->getChatMessage(env, message)), + (jmsg = getChatMessage(env, message)), content ? create_java_linphone_content(env, content) : NULL, buff ? env->NewDirectByteBuffer(buff, asking) : NULL, asking); @@ -856,7 +929,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); jbyteArray jbytes = env->NewByteArray(size); env->SetByteArrayRegion(jbytes, 0, size, (jbyte*)buff); @@ -864,7 +938,7 @@ public: env->CallVoidMethod(lcData->listener, lcData->fileTransferRecvId, lcData->core, - (jmsg = lcData->getChatMessage(env, message)), + (jmsg = getChatMessage(env, message)), content ? create_java_linphone_content(env, content) : NULL, jbytes, size); @@ -872,15 +946,18 @@ public: }; extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_newLinphoneCore(JNIEnv* env - ,jobject thiz + ,jobject thiz ,jobject jlistener ,jstring juserConfig ,jstring jfactoryConfig - ,jobject juserdata){ + ,jobject juserdata){ const char* userConfig = juserConfig?env->GetStringUTFChars(juserConfig, NULL):NULL; const char* factoryConfig = jfactoryConfig?env->GetStringUTFChars(jfactoryConfig, NULL):NULL; - LinphoneCoreData* ldata = new LinphoneCoreData(env,thiz,jlistener,juserdata); + + LinphoneCoreVTable *vTable = linphone_core_v_table_new(); + LinphoneCoreData* ldata = new LinphoneCoreData(env, thiz, vTable, jlistener); + linphone_core_v_table_set_user_data(vTable, ldata); ms_init(); // Initialize mediastreamer2 before loading the plugins @@ -906,23 +983,31 @@ extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_newLinphoneCore(JNIEnv* libmswebrtc_init(); #endif - jlong nativePtr = (jlong)linphone_core_new( &ldata->vTable - ,userConfig - ,factoryConfig - ,ldata); - + jobject core = env->NewGlobalRef(thiz); + jlong nativePtr = (jlong)linphone_core_new(vTable, userConfig, factoryConfig, core); if (userConfig) env->ReleaseStringUTFChars(juserConfig, userConfig); if (factoryConfig) env->ReleaseStringUTFChars(jfactoryConfig, factoryConfig); return nativePtr; } -extern "C" void Java_org_linphone_core_LinphoneCoreImpl_delete(JNIEnv* env - ,jobject thiz - ,jlong lc) { - LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data((LinphoneCore*)lc); +extern "C" void Java_org_linphone_core_LinphoneCoreImpl_delete(JNIEnv* env, jobject thiz, jlong lc) { + jobject core = (jobject)linphone_core_get_user_data((LinphoneCore*)lc); linphone_core_destroy((LinphoneCore*)lc); ms_exit(); - delete lcData; + if (core) { + env->DeleteGlobalRef(core); + } +} + +extern "C" void Java_org_linphone_core_LinphoneCoreImpl_AddListener(JNIEnv* env, jobject thiz, jlong lc, jobject jlistener) { + LinphoneCoreVTable *vTable = linphone_core_v_table_new(); + LinphoneCoreData* ldata = new LinphoneCoreData(env, thiz, vTable, jlistener); + linphone_core_v_table_set_user_data(vTable, ldata); + linphone_core_add_listener((LinphoneCore*)lc, vTable); +} + +extern "C" void Java_org_linphone_core_LinphoneCoreImpl_RemoveListener(JNIEnv* env, jobject thiz, jlong lc) { + //TODO } extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_migrateToMultiTransport(JNIEnv* env @@ -992,15 +1077,14 @@ extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setDefaultProxyConfig( J ,jlong pc) { linphone_core_set_default_proxy((LinphoneCore*)lc,(LinphoneProxyConfig*)pc); } - + extern "C" jobject Java_org_linphone_core_LinphoneCoreImpl_getDefaultProxyConfig(JNIEnv* env ,jobject thiz ,jlong lc) { LinphoneProxyConfig *config=0; - LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data((LinphoneCore*)lc); linphone_core_get_default_proxy((LinphoneCore*)lc,&config); if(config != 0) { - jobject jproxy = lcData->getProxy(env,config,lcData->core); + jobject jproxy = getProxy(env,config,thiz); return jproxy; } else { return NULL; @@ -1012,11 +1096,10 @@ extern "C" jobjectArray Java_org_linphone_core_LinphoneCoreImpl_getProxyConfigLi int proxyCount = ms_list_size(proxies); jclass cls = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneProxyConfigImpl")); jobjectArray jProxies = env->NewObjectArray(proxyCount,cls,NULL); - LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data((LinphoneCore*)lc); for (int i = 0; i < proxyCount; i++ ) { LinphoneProxyConfig* proxy = (LinphoneProxyConfig*)proxies->data; - jobject jproxy = lcData->getProxy(env,proxy,lcData->core); + jobject jproxy = getProxy(env,proxy,thiz); if(jproxy != NULL){ env->SetObjectArrayElement(jProxies, i, jproxy); } @@ -1098,17 +1181,15 @@ extern "C" jobject Java_org_linphone_core_LinphoneCoreImpl_invite(JNIEnv* env ,jlong lc ,jstring juri) { const char* uri = env->GetStringUTFChars(juri, NULL); - LinphoneCoreData *lcd=(LinphoneCoreData*)linphone_core_get_user_data((LinphoneCore*)lc); LinphoneCall* lCall = linphone_core_invite((LinphoneCore*)lc,uri); env->ReleaseStringUTFChars(juri, uri); - return lcd->getCall(env,lCall); + return getCall(env,lCall); } extern "C" jobject Java_org_linphone_core_LinphoneCoreImpl_inviteAddress(JNIEnv* env ,jobject thiz ,jlong lc ,jlong to) { - LinphoneCoreData *lcd=(LinphoneCoreData*)linphone_core_get_user_data((LinphoneCore*)lc); - return lcd->getCall(env, linphone_core_invite_address((LinphoneCore*)lc,(LinphoneAddress*)to)); + return getCall(env, linphone_core_invite_address((LinphoneCore*)lc,(LinphoneAddress*)to)); } extern "C" void Java_org_linphone_core_LinphoneCoreImpl_terminateCall(JNIEnv* env @@ -1458,9 +1539,7 @@ extern "C" jobject Java_org_linphone_core_LinphoneCoreImpl_getCurrentCall(JNIEnv ,jobject thiz ,jlong lc ) { - LinphoneCoreData *lcdata=(LinphoneCoreData*)linphone_core_get_user_data((LinphoneCore*)lc); - - return lcdata->getCall(env,linphone_core_get_current_call((LinphoneCore*)lc)); + return getCall(env,linphone_core_get_current_call((LinphoneCore*)lc)); } extern "C" void Java_org_linphone_core_LinphoneCoreImpl_addFriend(JNIEnv* env ,jobject thiz @@ -2384,9 +2463,8 @@ JNIEXPORT jint JNICALL Java_org_linphone_core_LinphoneCallImpl_getTransferState( JNIEXPORT jobject JNICALL Java_org_linphone_core_LinphoneCallImpl_getTransfererCall(JNIEnv *env, jobject jCall, jlong callptr){ LinphoneCall *call=(LinphoneCall*)callptr; LinphoneCore *lc=linphone_call_get_core(call); - LinphoneCoreData *lcdata=(LinphoneCoreData*)linphone_core_get_user_data(lc); LinphoneCall *ret=linphone_call_get_transferer_call(call); - return lcdata->getCall(env,ret); + return getCall(env,ret); } /* @@ -2397,9 +2475,8 @@ JNIEXPORT jobject JNICALL Java_org_linphone_core_LinphoneCallImpl_getTransfererC JNIEXPORT jobject JNICALL Java_org_linphone_core_LinphoneCallImpl_getTransferTargetCall(JNIEnv *env, jobject jCall, jlong callptr){ LinphoneCall *call=(LinphoneCall*)callptr; LinphoneCore *lc=linphone_call_get_core(call); - LinphoneCoreData *lcdata=(LinphoneCoreData*)linphone_core_get_user_data(lc); LinphoneCall *ret=linphone_call_get_transfer_target_call(call); - return lcdata->getCall(env,ret); + return getCall(env,ret); } extern "C" void Java_org_linphone_core_LinphoneCallImpl_enableEchoCancellation( JNIEnv* env @@ -2429,8 +2506,7 @@ extern "C" jboolean Java_org_linphone_core_LinphoneCallImpl_isEchoLimiterEnabled extern "C" jobject Java_org_linphone_core_LinphoneCallImpl_getReplacedCall( JNIEnv* env ,jobject thiz ,jlong ptr) { - LinphoneCoreData *lcd=(LinphoneCoreData*)linphone_core_get_user_data(linphone_call_get_core((LinphoneCall*)ptr)); - return lcd->getCall(env,linphone_call_get_replaced_call((LinphoneCall*)ptr)); + return getCall(env,linphone_call_get_replaced_call((LinphoneCall*)ptr)); } extern "C" jfloat Java_org_linphone_core_LinphoneCallImpl_getCurrentQuality( JNIEnv* env @@ -2507,8 +2583,8 @@ extern "C" jobject Java_org_linphone_core_LinphoneFriendImpl_getCore(JNIEnv* en ,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; + jobject core = (jobject)linphone_core_get_user_data(lc); + return core; } return NULL; } @@ -2876,12 +2952,14 @@ static void chat_room_impl_callback(LinphoneChatMessage* msg, LinphoneChatMessag jmethodID method = env->GetMethodID(clazz, "onLinphoneChatMessageStateChanged","(Lorg/linphone/core/LinphoneChatMessage;Lorg/linphone/core/LinphoneChatMessage$State;)V"); jobject jmessage=(jobject)linphone_chat_message_get_user_data(msg); LinphoneCore *lc = linphone_chat_room_get_lc(linphone_chat_message_get_chat_room(msg)); - LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc); + + jclass chatMessageStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneChatMessage$State")); + jmethodID chatMessageStateFromIntId = env->GetStaticMethodID(chatMessageStateClass,"fromInt","(I)Lorg/linphone/core/LinphoneChatMessage$State;"); env->CallVoidMethod( listener, method, jmessage, - env->CallStaticObjectMethod(lcData->chatMessageStateClass,lcData->chatMessageStateFromIntId,(jint)state)); + env->CallStaticObjectMethod(chatMessageStateClass,chatMessageStateFromIntId,(jint)state)); if (state == LinphoneChatMessageStateDelivered || state == LinphoneChatMessageStateNotDelivered) { env->DeleteGlobalRef(listener); @@ -2894,8 +2972,8 @@ extern "C" jobject Java_org_linphone_core_LinphoneChatRoomImpl_getCore(JNIEnv* ,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; + jobject core = (jobject)linphone_core_get_user_data(lc); + return core; } extern "C" void Java_org_linphone_core_LinphoneChatRoomImpl_sendMessage2(JNIEnv* env @@ -3134,8 +3212,7 @@ extern "C" void Java_org_linphone_core_LinphoneCallImpl_stopRecording(JNIEnv *en } extern "C" jobject Java_org_linphone_core_LinphoneCoreImpl_inviteAddressWithParams(JNIEnv *env, jobject thiz, jlong lc, jlong addr, jlong params){ - LinphoneCoreData *lcd=(LinphoneCoreData*)linphone_core_get_user_data((LinphoneCore*)lc); - return lcd->getCall(env,linphone_core_invite_address_with_params((LinphoneCore *)lc, (const LinphoneAddress *)addr, (const LinphoneCallParams *)params)); + return getCall(env,linphone_core_invite_address_with_params((LinphoneCore *)lc, (const LinphoneAddress *)addr, (const LinphoneCallParams *)params)); } extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_updateAddressWithParams(JNIEnv *env, jobject thiz, jlong lc, jlong call, jlong params){ @@ -3386,9 +3463,8 @@ extern "C" void Java_org_linphone_core_LinphoneCoreImpl_terminateAllCalls(JNIEnv linphone_core_terminate_all_calls((LinphoneCore *) pCore); } extern "C" jobject Java_org_linphone_core_LinphoneCoreImpl_getCall(JNIEnv *env,jobject thiz,jlong pCore,jint position) { - LinphoneCoreData *lcd=(LinphoneCoreData*)linphone_core_get_user_data((LinphoneCore*)pCore); LinphoneCall* lCall = (LinphoneCall*) ms_list_nth_data(linphone_core_get_calls((LinphoneCore *) pCore),position); - return lcd->getCall(env,lCall); + return getCall(env,lCall); } extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getCallsNb(JNIEnv *env,jobject thiz,jlong pCore) { return (jint)ms_list_size(linphone_core_get_calls((LinphoneCore *) pCore)); @@ -3405,8 +3481,7 @@ extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_transferCallToAnother(JN } extern "C" jobject Java_org_linphone_core_LinphoneCoreImpl_startReferedCall(JNIEnv *env, jobject thiz, jlong lc, jlong callptr, jlong params){ - LinphoneCoreData *lcd=(LinphoneCoreData*)linphone_core_get_user_data((LinphoneCore*)lc); - return lcd->getCall(env,linphone_core_start_refered_call((LinphoneCore *)lc, (LinphoneCall *)callptr, (const LinphoneCallParams *)params)); + return getCall(env,linphone_core_start_refered_call((LinphoneCore *)lc, (LinphoneCall *)callptr, (const LinphoneCallParams *)params)); } extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setZrtpSecretsCache(JNIEnv *env,jobject thiz,jlong pCore, jstring jFile) { @@ -3423,8 +3498,7 @@ extern "C" jobject Java_org_linphone_core_LinphoneCoreImpl_findCallFromUri(JNIEn const char* cUri=env->GetStringUTFChars(jUri, NULL); const LinphoneCall *call=linphone_core_find_call_from_uri((const LinphoneCore *) pCore,cUri); env->ReleaseStringUTFChars(jUri, cUri); - LinphoneCoreData *lcdata=(LinphoneCoreData*)linphone_core_get_user_data((LinphoneCore*)pCore); - return (jobject) lcdata->getCall(env,(LinphoneCall*)call); + return (jobject) getCall(env,(LinphoneCall*)call); } @@ -3794,7 +3868,6 @@ JNIEXPORT jobject JNICALL Java_org_linphone_core_LinphoneCoreImpl_subscribe(JNIE LinphoneEvent *ev; jobject jev=NULL; const char *evname=env->GetStringUTFChars(jevname,NULL); - LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc); if (jtype){ content.type=(char*)env->GetStringUTFChars(jtype,NULL); @@ -3812,7 +3885,7 @@ JNIEXPORT jobject JNICALL Java_org_linphone_core_LinphoneCoreImpl_subscribe(JNIE } env->ReleaseStringUTFChars(jevname,evname); if (ev){ - jev=lcData->getEvent(env,ev); + jev=getEvent(env,ev); } return jev; } @@ -3830,7 +3903,6 @@ JNIEXPORT jobject JNICALL Java_org_linphone_core_LinphoneCoreImpl_publish(JNIEnv LinphoneEvent *ev; jobject jev=NULL; const char *evname=env->GetStringUTFChars(jevname,NULL); - LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc); if (jtype){ content.type=(char*)env->GetStringUTFChars(jtype,NULL); @@ -3848,7 +3920,7 @@ JNIEXPORT jobject JNICALL Java_org_linphone_core_LinphoneCoreImpl_publish(JNIEnv } env->ReleaseStringUTFChars(jevname,evname); if (ev){ - jev=lcData->getEvent(env,ev); + jev=getEvent(env,ev); } return jev; } @@ -4094,8 +4166,8 @@ 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; + jobject core = (jobject)linphone_core_get_user_data(lc); + return core; } /* @@ -4264,7 +4336,6 @@ JNIEXPORT jint JNICALL Java_org_linphone_core_LinphoneEventImpl_getSubscriptionS JNIEXPORT jobject JNICALL Java_org_linphone_core_LinphoneCoreImpl_createSubscribe(JNIEnv *env, jobject thiz, jlong jcore, jlong jaddr, jstring jeventname, jint expires) { LinphoneCore *lc = (LinphoneCore*) jcore; - LinphoneCoreData* lcData = (LinphoneCoreData*) linphone_core_get_user_data(lc); LinphoneAddress *addr = (LinphoneAddress*) jaddr; LinphoneEvent *event; jobject jevent = NULL; @@ -4273,7 +4344,7 @@ JNIEXPORT jobject JNICALL Java_org_linphone_core_LinphoneCoreImpl_createSubscrib event = linphone_core_create_subscribe(lc, addr, event_name, expires); env->ReleaseStringUTFChars(jeventname, event_name); if (event) { - jevent = lcData->getEvent(env, event); + jevent = getEvent(env, event); } return jevent; } @@ -4298,7 +4369,6 @@ JNIEXPORT void JNICALL Java_org_linphone_core_LinphoneEventImpl_sendSubscribe(JN JNIEXPORT jobject JNICALL Java_org_linphone_core_LinphoneCoreImpl_createPublish(JNIEnv *env, jobject thiz, jlong jcore, jlong jaddr, jstring jeventname, jint expires) { LinphoneCore *lc = (LinphoneCore*) jcore; - LinphoneCoreData* lcData = (LinphoneCoreData*) linphone_core_get_user_data(lc); LinphoneAddress *addr = (LinphoneAddress*) jaddr; LinphoneEvent *event; jobject jevent = NULL; @@ -4307,7 +4377,7 @@ JNIEXPORT jobject JNICALL Java_org_linphone_core_LinphoneCoreImpl_createPublish( event = linphone_core_create_publish(lc, addr, event_name, expires); env->ReleaseStringUTFChars(jeventname, event_name); if (event) { - jevent = lcData->getEvent(env, event); + jevent = getEvent(env, event); } return jevent; } diff --git a/coreapi/private.h b/coreapi/private.h index d9d1eeb07..0ce88fee5 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -784,6 +784,7 @@ struct _LinphoneCore LinphoneReason chat_deny_code; const char **supported_formats; LinphoneContent *log_collection_upload_information; + LinphoneCoreVTable *current_vtable; // the latest vtable to call a callback, see linphone_core_get_current_vtable };