3 Copyright (C) 2010 Belledonne Communications, Grenoble, France
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #include "linphonecore.h"
22 #include <android/log.h>
23 extern "C" void libmsilbc_init();
26 extern "C" void ms_andsnd_set_jvm(JavaVM *jvm) ;
27 extern "C" void ms_andvid_set_jvm(JavaVM *jvm) ;
32 static void linphone_android_log_handler(OrtpLogLevel lev, const char *fmt, va_list args){
35 case ORTP_DEBUG: prio = ANDROID_LOG_DEBUG; break;
36 case ORTP_MESSAGE: prio = ANDROID_LOG_INFO; break;
37 case ORTP_WARNING: prio = ANDROID_LOG_WARN; break;
38 case ORTP_ERROR: prio = ANDROID_LOG_ERROR; break;
39 case ORTP_FATAL: prio = ANDROID_LOG_FATAL; break;
40 default: prio = ANDROID_LOG_DEFAULT; break;
42 __android_log_vprint(prio, LOG_DOMAIN, fmt, args);
46 JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *ajvm, void *reserved)
49 ms_andsnd_set_jvm(ajvm);
51 ms_andvid_set_jvm(ajvm);
52 #endif /*VIDEO_ENABLED*/
55 return JNI_VERSION_1_2;
60 extern "C" void Java_org_linphone_core_LinphoneCoreFactoryImpl_setDebugMode(JNIEnv* env
64 linphone_core_enable_logs_with_cb(linphone_android_log_handler);
66 linphone_core_disable_logs();
71 class LinphoneCoreData {
73 LinphoneCoreData(JNIEnv* env, jobject lc,jobject alistener, jobject auserdata) {
75 core = env->NewGlobalRef(lc);
76 listener = env->NewGlobalRef(alistener);
77 userdata = auserdata?env->NewGlobalRef(auserdata):0;
78 memset(&vTable,0,sizeof(vTable));
79 vTable.show = showInterfaceCb;
80 vTable.auth_info_requested = authInfoRequested;
81 vTable.display_status = displayStatusCb;
82 vTable.display_message = displayMessageCb;
83 vTable.display_warning = displayMessageCb;
84 vTable.global_state_changed = globalStateChange;
85 vTable.registration_state_changed = registrationStateChange;
86 vTable.call_state_changed = callStateChange;
87 vTable.text_received = text_received;
88 vTable.new_subscription_request = new_subscription_request;
89 vTable.notify_presence_recv = notify_presence_recv;
91 listernerClass = (jclass)env->NewGlobalRef(env->GetObjectClass( alistener));
92 /*displayStatus(LinphoneCore lc,String message);*/
93 displayStatusId = env->GetMethodID(listernerClass,"displayStatus","(Lorg/linphone/core/LinphoneCore;Ljava/lang/String;)V");
94 /*void generalState(LinphoneCore lc,int state); */
95 globalStateId = env->GetMethodID(listernerClass,"globalState","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCore$GlobalState;Ljava/lang/String;)V");
96 globalStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCore$GlobalState"));
97 globalStateFromIntId = env->GetStaticMethodID(globalStateClass,"fromInt","(I)Lorg/linphone/core/LinphoneCore$GlobalState;");
98 /*registrationState(LinphoneCore lc, LinphoneProxyConfig cfg, LinphoneCore.RegistrationState cstate, String smessage);*/
99 registrationStateId = env->GetMethodID(listernerClass,"registrationState","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneProxyConfig;Lorg/linphone/core/LinphoneCore$RegistrationState;Ljava/lang/String;)V");
100 registrationStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCore$RegistrationState"));
101 registrationStateFromIntId = env->GetStaticMethodID(registrationStateClass,"fromInt","(I)Lorg/linphone/core/LinphoneCore$RegistrationState;");
102 /*callState(LinphoneCore lc, LinphoneCall call, LinphoneCall.State cstate,String message);*/
103 callStateId = env->GetMethodID(listernerClass,"callState","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCall;Lorg/linphone/core/LinphoneCall$State;Ljava/lang/String;)V");
104 callStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCall$State"));
105 callStateFromIntId = env->GetStaticMethodID(callStateClass,"fromInt","(I)Lorg/linphone/core/LinphoneCall$State;");
107 /*void newSubscriptionRequest(LinphoneCore lc, LinphoneFriend lf, String url)*/
108 newSubscriptionRequestId = env->GetMethodID(listernerClass,"newSubscriptionRequest","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneFriend;Ljava/lang/String;)V");
110 /*void notifyPresenceReceived(LinphoneCore lc, LinphoneFriend lf);*/
111 notifyPresenceReceivedId = env->GetMethodID(listernerClass,"notifyPresenceReceived","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneFriend;)V");
113 /*void textReceived(LinphoneCore lc, LinphoneChatRoom cr,LinphoneAddress from,String message);*/
114 textReceivedId = env->GetMethodID(listernerClass,"textReceived","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneChatRoom;Lorg/linphone/core/LinphoneAddress;Ljava/lang/String;)V");
116 proxyClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneProxyConfigImpl"));
117 proxyCtrId = env->GetMethodID(proxyClass,"<init>", "(J)V");
119 callClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCallImpl"));
120 callCtrId = env->GetMethodID(callClass,"<init>", "(J)V");
122 chatRoomClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneChatRoomImpl"));
123 chatRoomCtrId = env->GetMethodID(chatRoomClass,"<init>", "(J)V");
125 friendClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneFriendImpl"));;
126 friendCtrId =env->GetMethodID(friendClass,"<init>", "(J)V");
128 addressClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneAddressImpl"));
129 addressCtrId =env->GetMethodID(addressClass,"<init>", "(J)V");
133 ~LinphoneCoreData() {
135 jvm->AttachCurrentThread(&env,NULL);
136 env->DeleteGlobalRef(core);
137 env->DeleteGlobalRef(listener);
138 if (userdata) env->DeleteGlobalRef(userdata);
139 env->DeleteGlobalRef(listernerClass);
140 env->DeleteGlobalRef(globalStateClass);
141 env->DeleteGlobalRef(registrationStateClass);
142 env->DeleteGlobalRef(callStateClass);
143 env->DeleteGlobalRef(proxyClass);
144 env->DeleteGlobalRef(callClass);
145 env->DeleteGlobalRef(chatRoomClass);
146 env->DeleteGlobalRef(friendClass);
153 jclass listernerClass;
154 jmethodID displayStatusId;
155 jmethodID newSubscriptionRequestId;
156 jmethodID notifyPresenceReceivedId;
157 jmethodID textReceivedId;
159 jclass globalStateClass;
160 jmethodID globalStateId;
161 jmethodID globalStateFromIntId;
163 jclass registrationStateClass;
164 jmethodID registrationStateId;
165 jmethodID registrationStateFromIntId;
167 jclass callStateClass;
168 jmethodID callStateId;
169 jmethodID callStateFromIntId;
172 jmethodID proxyCtrId;
177 jclass chatRoomClass;
178 jmethodID chatRoomCtrId;
181 jmethodID friendCtrId;
184 jmethodID addressCtrId;
186 LinphoneCoreVTable vTable;
188 static void showInterfaceCb(LinphoneCore *lc) {
191 static void byeReceivedCb(LinphoneCore *lc, const char *from) {
194 static void displayStatusCb(LinphoneCore *lc, const char *message) {
196 jint result = jvm->AttachCurrentThread(&env,NULL);
198 ms_error("cannot attach VM\n");
201 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
202 env->CallVoidMethod(lcData->listener,lcData->displayStatusId,lcData->core,env->NewStringUTF(message));
204 static void displayMessageCb(LinphoneCore *lc, const char *message) {
207 static void authInfoRequested(LinphoneCore *lc, const char *realm, const char *username) {
210 static void globalStateChange(LinphoneCore *lc, LinphoneGlobalState gstate,const char* message) {
212 jint result = jvm->AttachCurrentThread(&env,NULL);
214 ms_error("cannot attach VM\n");
217 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
218 env->CallVoidMethod(lcData->listener
219 ,lcData->globalStateId
221 ,env->CallStaticObjectMethod(lcData->globalStateClass,lcData->globalStateFromIntId,(jint)gstate),
222 message ? env->NewStringUTF(message) : NULL);
224 static void registrationStateChange(LinphoneCore *lc, LinphoneProxyConfig* proxy,LinphoneRegistrationState state,const char* message) {
226 jint result = jvm->AttachCurrentThread(&env,NULL);
228 ms_error("cannot attach VM\n");
231 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
232 env->CallVoidMethod(lcData->listener
233 ,lcData->registrationStateId
235 ,env->NewObject(lcData->proxyClass,lcData->proxyCtrId,(jlong)proxy)
236 ,env->CallStaticObjectMethod(lcData->registrationStateClass,lcData->registrationStateFromIntId,(jint)state),
237 message ? env->NewStringUTF(message) : NULL);
239 static void callStateChange(LinphoneCore *lc, LinphoneCall* call,LinphoneCallState state,const char* message) {
241 jint result = jvm->AttachCurrentThread(&env,NULL);
243 ms_error("cannot attach VM\n");
246 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
247 env->CallVoidMethod(lcData->listener
250 ,env->NewObject(lcData->callClass,lcData->callCtrId,(jlong)call)
251 ,env->CallStaticObjectMethod(lcData->callStateClass,lcData->callStateFromIntId,(jint)state),
252 message ? env->NewStringUTF(message) : NULL);
254 static void notify_presence_recv (LinphoneCore *lc, LinphoneFriend *my_friend) {
256 jint result = jvm->AttachCurrentThread(&env,NULL);
258 ms_error("cannot attach VM\n");
261 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
262 env->CallVoidMethod(lcData->listener
263 ,lcData->notifyPresenceReceivedId
265 ,env->NewObject(lcData->friendClass,lcData->friendCtrId,(jlong)my_friend));
267 static void new_subscription_request (LinphoneCore *lc, LinphoneFriend *my_friend, const char* url) {
269 jint result = jvm->AttachCurrentThread(&env,NULL);
271 ms_error("cannot attach VM\n");
274 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
275 env->CallVoidMethod(lcData->listener
276 ,lcData->newSubscriptionRequestId
278 ,env->NewObject(lcData->friendClass,lcData->friendCtrId,(jlong)my_friend)
279 ,url ? env->NewStringUTF(url) : NULL);
281 static void text_received(LinphoneCore *lc, LinphoneChatRoom *room, const LinphoneAddress *from, const char *message) {
283 jint result = jvm->AttachCurrentThread(&env,NULL);
285 ms_error("cannot attach VM\n");
288 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
289 env->CallVoidMethod(lcData->listener
290 ,lcData->textReceivedId
292 ,env->NewObject(lcData->chatRoomClass,lcData->chatRoomCtrId,(jlong)room)
293 ,env->NewObject(lcData->addressClass,lcData->addressCtrId,(jlong)from)
294 ,message ? env->NewStringUTF(message) : NULL);
299 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_newLinphoneCore(JNIEnv* env
303 ,jstring jfactoryConfig
306 const char* userConfig = juserConfig?env->GetStringUTFChars(juserConfig, NULL):NULL;
307 const char* factoryConfig = jfactoryConfig?env->GetStringUTFChars(jfactoryConfig, NULL):NULL;
308 LinphoneCoreData* ldata = new LinphoneCoreData(env,thiz,jlistener,juserdata);
310 ms_andsnd_set_jvm(jvm);
314 libmsilbc_init(); // requires an fpu
316 jlong nativePtr = (jlong)linphone_core_new( &ldata->vTable
320 //clear auth info list
321 linphone_core_clear_all_auth_info((LinphoneCore*) nativePtr);
322 //clear existing proxy config
323 linphone_core_clear_proxy_config((LinphoneCore*) nativePtr);
325 if (userConfig) env->ReleaseStringUTFChars(juserConfig, userConfig);
326 if (factoryConfig) env->ReleaseStringUTFChars(jfactoryConfig, factoryConfig);
329 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_delete(JNIEnv* env
332 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data((LinphoneCore*)lc);
333 linphone_core_destroy((LinphoneCore*)lc);
337 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_clearProxyConfigs(JNIEnv* env, jobject thiz,jlong lc) {
338 linphone_core_clear_proxy_config((LinphoneCore*)lc);
341 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setDefaultProxyConfig( JNIEnv* env
345 linphone_core_set_default_proxy((LinphoneCore*)lc,(LinphoneProxyConfig*)pc);
347 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_getDefaultProxyConfig( JNIEnv* env
350 LinphoneProxyConfig *config=0;
351 linphone_core_get_default_proxy((LinphoneCore*)lc,&config);
352 return (jlong)config;
355 extern "C" int Java_org_linphone_core_LinphoneCoreImpl_addProxyConfig( JNIEnv* env
360 LinphoneProxyConfig* proxy = (LinphoneProxyConfig*)pc;
361 linphone_proxy_config_set_user_data(proxy, env->NewGlobalRef(jproxyCfg));
363 return linphone_core_add_proxy_config((LinphoneCore*)lc,(LinphoneProxyConfig*)pc);
366 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_clearAuthInfos(JNIEnv* env, jobject thiz,jlong lc) {
367 linphone_core_clear_all_auth_info((LinphoneCore*)lc);
370 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_addAuthInfo( JNIEnv* env
374 linphone_core_add_auth_info((LinphoneCore*)lc,(LinphoneAuthInfo*)pc);
376 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_iterate( JNIEnv* env
379 linphone_core_iterate((LinphoneCore*)lc);
381 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_invite( JNIEnv* env
385 const char* uri = env->GetStringUTFChars(juri, NULL);
386 LinphoneCall* lCall = linphone_core_invite((LinphoneCore*)lc,uri);
387 env->ReleaseStringUTFChars(juri, uri);
390 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_inviteAddress( JNIEnv* env
394 return (jlong) linphone_core_invite_address((LinphoneCore*)lc,(LinphoneAddress*)to);
397 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_terminateCall( JNIEnv* env
401 linphone_core_terminate_call((LinphoneCore*)lc,(LinphoneCall*)call);
404 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_getRemoteAddress( JNIEnv* env
407 return (jlong)linphone_core_get_current_call_remote_address((LinphoneCore*)lc);
409 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isInCall( JNIEnv* env
413 return linphone_core_in_call((LinphoneCore*)lc);
415 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isInComingInvitePending( JNIEnv* env
419 return linphone_core_inc_invite_pending((LinphoneCore*)lc);
421 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_acceptCall( JNIEnv* env
426 linphone_core_accept_call((LinphoneCore*)lc,(LinphoneCall*)call);
429 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_getCallLog( JNIEnv* env
433 return (jlong)ms_list_nth_data(linphone_core_get_call_logs((LinphoneCore*)lc),position);
435 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getNumberOfCallLogs( JNIEnv* env
438 return ms_list_size(linphone_core_get_call_logs((LinphoneCore*)lc));
440 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setNetworkStateReachable( JNIEnv* env
443 ,jboolean isReachable) {
444 linphone_core_set_network_reachable((LinphoneCore*)lc,isReachable);
447 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPlaybackGain( JNIEnv* env
451 linphone_core_set_playback_gain_db((LinphoneCore*)lc,gain);
454 extern "C" float Java_org_linphone_core_LinphoneCoreImpl_getPlaybackGain( JNIEnv* env
457 return linphone_core_get_playback_gain_db((LinphoneCore*)lc);
460 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_muteMic( JNIEnv* env
464 linphone_core_mute_mic((LinphoneCore*)lc,isMuted);
467 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_interpretUrl( JNIEnv* env
471 const char* url = env->GetStringUTFChars(jurl, NULL);
472 jlong result = (jlong)linphone_core_interpret_url((LinphoneCore*)lc,url);
473 env->ReleaseStringUTFChars(jurl, url);
476 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_sendDtmf( JNIEnv* env
480 linphone_core_send_dtmf((LinphoneCore*)lc,dtmf);
482 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_playDtmf( JNIEnv* env
487 linphone_core_play_dtmf((LinphoneCore*)lc,dtmf,duration);
489 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_stopDtmf( JNIEnv* env
492 linphone_core_stop_dtmf((LinphoneCore*)lc);
495 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_clearCallLogs(JNIEnv* env
498 linphone_core_clear_call_logs((LinphoneCore*)lc);
500 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isMicMuted( JNIEnv* env
503 return linphone_core_is_mic_muted((LinphoneCore*)lc);
505 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_findPayloadType(JNIEnv* env
510 const char* mime = env->GetStringUTFChars(jmime, NULL);
511 jlong result = (jlong)linphone_core_find_payload_type((LinphoneCore*)lc,mime,rate);
512 env->ReleaseStringUTFChars(jmime, mime);
515 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_enablePayloadType(JNIEnv* env
520 return linphone_core_enable_payload_type((LinphoneCore*)lc,(PayloadType*)pt,enable);
522 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_enableEchoCancellation(JNIEnv* env
526 linphone_core_enable_echo_cancellation((LinphoneCore*)lc,enable);
528 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isEchoCancellationEnabled(JNIEnv* env
532 return linphone_core_echo_cancellation_enabled((LinphoneCore*)lc);
535 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_getCurrentCall(JNIEnv* env
539 return (jlong)linphone_core_get_current_call((LinphoneCore*)lc);
541 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_addFriend(JNIEnv* env
546 linphone_core_add_friend((LinphoneCore*)lc,(LinphoneFriend*)aFriend);
548 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPresenceInfo(JNIEnv* env
552 ,jstring jalternative_contact
554 const char* alternative_contact = jalternative_contact?env->GetStringUTFChars(jalternative_contact, NULL):NULL;
555 linphone_core_set_presence_info((LinphoneCore*)lc,minute_away,alternative_contact,(LinphoneOnlineStatus)status);
556 if (alternative_contact) env->ReleaseStringUTFChars(jalternative_contact, alternative_contact);
559 extern "C" long Java_org_linphone_core_LinphoneCoreImpl_createChatRoom(JNIEnv* env
564 const char* to = env->GetStringUTFChars(jto, NULL);
565 LinphoneChatRoom* lResult = linphone_core_create_chat_room((LinphoneCore*)lc,to);
566 env->ReleaseStringUTFChars(jto, to);
567 return (long)lResult;
570 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_enableVideo(JNIEnv* env
573 ,jboolean vcap_enabled
574 ,jboolean display_enabled) {
575 linphone_core_enable_video((LinphoneCore*)lc, vcap_enabled,display_enabled);
578 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isVideoEnabled(JNIEnv* env
581 return linphone_core_video_enabled((LinphoneCore*)lc);
586 extern "C" jlong Java_org_linphone_core_LinphoneProxyConfigImpl_newLinphoneProxyConfig(JNIEnv* env,jobject thiz) {
587 LinphoneProxyConfig* proxy = linphone_proxy_config_new();
588 return (jlong) proxy;
591 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_delete(JNIEnv* env,jobject thiz,jlong ptr) {
592 linphone_proxy_config_destroy((LinphoneProxyConfig*)ptr);
594 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setIdentity(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jidentity) {
595 const char* identity = env->GetStringUTFChars(jidentity, NULL);
596 linphone_proxy_config_set_identity((LinphoneProxyConfig*)proxyCfg,identity);
597 env->ReleaseStringUTFChars(jidentity, identity);
599 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getIdentity(JNIEnv* env,jobject thiz,jlong proxyCfg) {
600 const char* identity = linphone_proxy_config_get_identity((LinphoneProxyConfig*)proxyCfg);
602 return env->NewStringUTF(identity);
607 extern "C" int Java_org_linphone_core_LinphoneProxyConfigImpl_setProxy(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jproxy) {
608 const char* proxy = env->GetStringUTFChars(jproxy, NULL);
609 int err=linphone_proxy_config_set_server_addr((LinphoneProxyConfig*)proxyCfg,proxy);
610 env->ReleaseStringUTFChars(jproxy, proxy);
613 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getProxy(JNIEnv* env,jobject thiz,jlong proxyCfg) {
614 const char* proxy = linphone_proxy_config_get_addr((LinphoneProxyConfig*)proxyCfg);
616 return env->NewStringUTF(proxy);
621 extern "C" int Java_org_linphone_core_LinphoneProxyConfigImpl_setRoute(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jroute) {
622 if (jroute != NULL) {
623 const char* route = env->GetStringUTFChars(jroute, NULL);
624 int err=linphone_proxy_config_set_route((LinphoneProxyConfig*)proxyCfg,route);
625 env->ReleaseStringUTFChars(jroute, route);
628 return linphone_proxy_config_set_route((LinphoneProxyConfig*)proxyCfg,NULL);
631 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getRoute(JNIEnv* env,jobject thiz,jlong proxyCfg) {
632 const char* route = linphone_proxy_config_get_route((LinphoneProxyConfig*)proxyCfg);
634 return env->NewStringUTF(route);
640 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_enableRegister(JNIEnv* env,jobject thiz,jlong proxyCfg,jboolean enableRegister) {
641 linphone_proxy_config_enable_register((LinphoneProxyConfig*)proxyCfg,enableRegister);
643 extern "C" jboolean Java_org_linphone_core_LinphoneProxyConfigImpl_isRegistered(JNIEnv* env,jobject thiz,jlong proxyCfg) {
644 return linphone_proxy_config_is_registered((LinphoneProxyConfig*)proxyCfg);
646 extern "C" jboolean Java_org_linphone_core_LinphoneProxyConfigImpl_isRegisterEnabled(JNIEnv* env,jobject thiz,jlong proxyCfg) {
647 return linphone_proxy_config_register_enabled((LinphoneProxyConfig*)proxyCfg);
649 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_edit(JNIEnv* env,jobject thiz,jlong proxyCfg) {
650 linphone_proxy_config_edit((LinphoneProxyConfig*)proxyCfg);
652 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_done(JNIEnv* env,jobject thiz,jlong proxyCfg) {
653 linphone_proxy_config_done((LinphoneProxyConfig*)proxyCfg);
655 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_normalizePhoneNumber(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jnumber) {
657 ms_error("cannot normalized null number");
659 const char* number = env->GetStringUTFChars(jnumber, NULL);
660 int len = env->GetStringLength(jnumber);
662 ms_warning("cannot normalize empty number");
665 char targetBuff[2*len];// returned number can be greater than origin (specially in case of prefix insertion
666 linphone_proxy_config_normalize_number((LinphoneProxyConfig*)proxyCfg,number,targetBuff,sizeof(targetBuff));
667 jstring normalizedNumber = env->NewStringUTF(targetBuff);
668 env->ReleaseStringUTFChars(jnumber, number);
669 return normalizedNumber;
671 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getDomain(JNIEnv* env
674 const char* domain = linphone_proxy_config_get_domain((LinphoneProxyConfig*)proxyCfg);
676 return env->NewStringUTF(domain);
681 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setDialEscapePlus(JNIEnv* env,jobject thiz,jlong proxyCfg,jboolean value) {
682 linphone_proxy_config_set_dial_escape_plus((LinphoneProxyConfig*)proxyCfg,value);
685 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setDialPrefix(JNIEnv* env
689 const char* prefix = env->GetStringUTFChars(jprefix, NULL);
690 linphone_proxy_config_set_dial_prefix((LinphoneProxyConfig*)proxyCfg,prefix);
691 env->ReleaseStringUTFChars(jprefix, prefix);
697 extern "C" jlong Java_org_linphone_core_LinphoneAuthInfoImpl_newLinphoneAuthInfo(JNIEnv* env
705 const char* username = env->GetStringUTFChars(jusername, NULL);
706 const char* password = env->GetStringUTFChars(jpassword, NULL);
707 jlong auth = (jlong)linphone_auth_info_new(username,NULL,password,NULL,NULL);
709 env->ReleaseStringUTFChars(jusername, username);
710 env->ReleaseStringUTFChars(jpassword, password);
714 extern "C" void Java_org_linphone_core_LinphoneAuthInfoImpl_delete(JNIEnv* env
717 linphone_auth_info_destroy((LinphoneAuthInfo*)ptr);
722 extern "C" jlong Java_org_linphone_core_LinphoneAddressImpl_newLinphoneAddressImpl(JNIEnv* env
725 ,jstring jdisplayName) {
726 const char* uri = env->GetStringUTFChars(juri, NULL);
727 LinphoneAddress* address = linphone_address_new(uri);
728 if (jdisplayName && address) {
729 const char* displayName = env->GetStringUTFChars(jdisplayName, NULL);
730 linphone_address_set_display_name(address,displayName);
731 env->ReleaseStringUTFChars(jdisplayName, displayName);
733 env->ReleaseStringUTFChars(juri, uri);
735 return (jlong) address;
737 extern "C" void Java_org_linphone_core_LinphoneAddressImpl_delete(JNIEnv* env
740 linphone_address_destroy((LinphoneAddress*)ptr);
743 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_getDisplayName(JNIEnv* env
746 const char* displayName = linphone_address_get_display_name((LinphoneAddress*)ptr);
748 return env->NewStringUTF(displayName);
753 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_getUserName(JNIEnv* env
756 const char* userName = linphone_address_get_username((LinphoneAddress*)ptr);
758 return env->NewStringUTF(userName);
763 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_getDomain(JNIEnv* env
766 const char* domain = linphone_address_get_domain((LinphoneAddress*)ptr);
768 return env->NewStringUTF(domain);
774 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_toString(JNIEnv* env
777 char* uri = linphone_address_as_string((LinphoneAddress*)ptr);
778 jstring juri =env->NewStringUTF(uri);
782 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_toUri(JNIEnv* env
785 char* uri = linphone_address_as_string_uri_only((LinphoneAddress*)ptr);
786 jstring juri =env->NewStringUTF(uri);
790 extern "C" void Java_org_linphone_core_LinphoneAddressImpl_setDisplayName(JNIEnv* env
793 ,jstring jdisplayName) {
794 const char* displayName = jdisplayName!= NULL?env->GetStringUTFChars(jdisplayName, NULL):NULL;
795 linphone_address_set_display_name((LinphoneAddress*)address,displayName);
796 if (displayName != NULL) env->ReleaseStringUTFChars(jdisplayName, displayName);
801 extern "C" jlong Java_org_linphone_core_LinphoneCallLogImpl_getFrom(JNIEnv* env
804 return (jlong)((LinphoneCallLog*)ptr)->from;
806 extern "C" jlong Java_org_linphone_core_LinphoneCallLogImpl_getTo(JNIEnv* env
809 return (jlong)((LinphoneCallLog*)ptr)->to;
811 extern "C" jboolean Java_org_linphone_core_LinphoneCallLogImpl_isIncoming(JNIEnv* env
814 return ((LinphoneCallLog*)ptr)->dir==LinphoneCallIncoming?JNI_TRUE:JNI_FALSE;
817 extern "C" jstring Java_org_linphone_core_PayloadTypeImpl_toString(JNIEnv* env
821 PayloadType* pt = (PayloadType*)ptr;
822 char* value = ms_strdup_printf("[%s] clock [%s], bitrate [%s]"
823 ,payload_type_get_mime(pt)
824 ,payload_type_get_rate(pt)
825 ,payload_type_get_bitrate(pt));
826 jstring jvalue =env->NewStringUTF(value);
831 extern "C" void Java_org_linphone_core_LinphoneCallImpl_ref(JNIEnv* env
834 linphone_call_ref((LinphoneCall*)ptr);
837 extern "C" void Java_org_linphone_core_LinphoneCallImpl_unref(JNIEnv* env
840 linphone_call_unref((LinphoneCall*)ptr);
843 extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_getCallLog( JNIEnv* env
846 return (jlong)linphone_call_get_call_log((LinphoneCall*)ptr);
849 extern "C" jboolean Java_org_linphone_core_LinphoneCallImpl_isIncoming( JNIEnv* env
852 return linphone_call_get_dir((LinphoneCall*)ptr)==LinphoneCallIncoming?JNI_TRUE:JNI_FALSE;
855 extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_getRemoteAddress( JNIEnv* env
858 return (jlong)linphone_call_get_remote_address((LinphoneCall*)ptr);
861 extern "C" jint Java_org_linphone_core_LinphoneCallImpl_getState( JNIEnv* env
864 return (jint)linphone_call_get_state((LinphoneCall*)ptr);
868 extern "C" long Java_org_linphone_core_LinphoneFriendImpl_newLinphoneFriend(JNIEnv* env
870 ,jstring jFriendUri) {
871 LinphoneFriend* lResult;
874 const char* friendUri = env->GetStringUTFChars(jFriendUri, NULL);
875 lResult= linphone_friend_new_with_addr(friendUri);
876 env->ReleaseStringUTFChars(jFriendUri, friendUri);
878 lResult = linphone_friend_new();
880 return (long)lResult;
882 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_setAddress(JNIEnv* env
885 ,jlong linphoneAddress) {
886 linphone_friend_set_addr((LinphoneFriend*)ptr,(LinphoneAddress*)linphoneAddress);
888 extern "C" long Java_org_linphone_core_LinphoneFriendImpl_getAddress(JNIEnv* env
891 return (long)linphone_friend_get_address((LinphoneFriend*)ptr);
893 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_setIncSubscribePolicy(JNIEnv* env
897 linphone_friend_set_inc_subscribe_policy((LinphoneFriend*)ptr,(LinphoneSubscribePolicy)policy);
899 extern "C" jint Java_org_linphone_core_LinphoneFriendImpl_getIncSubscribePolicy(JNIEnv* env
902 return linphone_friend_get_inc_subscribe_policy((LinphoneFriend*)ptr);
904 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_enableSubscribes(JNIEnv* env
908 linphone_friend_enable_subscribes((LinphoneFriend*)ptr,value);
910 extern "C" jboolean Java_org_linphone_core_LinphoneFriendImpl_isSubscribesEnabled(JNIEnv* env
913 return linphone_friend_subscribes_enabled((LinphoneFriend*)ptr);
915 extern "C" jboolean Java_org_linphone_core_LinphoneFriendImpl_getStatus(JNIEnv* env
918 return linphone_friend_get_status((LinphoneFriend*)ptr);
920 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_edit(JNIEnv* env
923 return linphone_friend_edit((LinphoneFriend*)ptr);
925 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_done(JNIEnv* env
928 linphone_friend_done((LinphoneFriend*)ptr);
931 extern "C" long Java_org_linphone_core_LinphoneChatRoomImpl_getPeerAddress(JNIEnv* env
934 return (long) linphone_chat_room_get_peer_address((LinphoneChatRoom*)ptr);
936 extern "C" void Java_org_linphone_core_LinphoneChatRoomImpl_sendMessage(JNIEnv* env
940 const char* message = env->GetStringUTFChars(jmessage, NULL);
941 linphone_chat_room_send_message((LinphoneChatRoom*)ptr,message);
942 env->ReleaseStringUTFChars(jmessage, message);
946 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setVideoWindowId(JNIEnv* env
950 linphone_core_set_native_video_window_id((LinphoneCore*)lc,(unsigned long)obj);
954 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setFirewallPolicy(JNIEnv *env, jobject thiz, jlong lc, int enum_value){
955 linphone_core_set_firewall_policy((LinphoneCore*)lc,(LinphoneFirewallPolicy)enum_value);
958 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getFirewallPolicy(JNIEnv *env, jobject thiz, jlong lc){
959 return linphone_core_get_firewall_policy((LinphoneCore*)lc);
962 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setStunServer(JNIEnv *env, jobject thiz, jlong lc, jstring jserver){
963 const char* server = NULL;
964 if (jserver) server=env->GetStringUTFChars(jserver, NULL);
965 linphone_core_set_stun_server((LinphoneCore*)lc,server);
966 if (server) env->ReleaseStringUTFChars(jserver,server);
969 extern "C" jstring Java_org_linphone_core_LinphoneCoreImpl_getStunServer(JNIEnv *env, jobject thiz, jlong lc){
970 const char *ret= linphone_core_get_stun_server((LinphoneCore*)lc);
971 if (ret==NULL) return NULL;
972 jstring jvalue =env->NewStringUTF(ret);
976 extern "C" void Java_org_linphone_core_LinphoneCallParamsImpl_enableVideo(JNIEnv *env, jobject thiz, jlong lcp, jboolean b){
977 linphone_call_params_enable_video((LinphoneCallParams*)lcp, b);
980 extern "C" jboolean Java_org_linphone_core_LinphoneCallParamsImpl_getVideoEnabled(JNIEnv *env, jobject thiz, jlong lcp){
981 return linphone_call_params_video_enabled((LinphoneCallParams*)lcp);
983 extern "C" jlong Java_org_linphone_core_LinphoneCallParamsImpl_copy(JNIEnv *env, jobject thiz, jlong lcp){
984 return (jlong) linphone_call_params_copy((LinphoneCallParams*)lcp);
986 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_createDefaultCallParams(JNIEnv *env, jobject thiz, jlong lc){
987 return (jlong) linphone_core_create_default_call_parameters((LinphoneCore*)lc);
990 extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_getCurrentParams(JNIEnv *env, jobject thiz, jlong lc){
991 return (jlong) linphone_call_get_current_params((LinphoneCall*)lc);
994 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_inviteAddressWithParams(JNIEnv *env, jobject thiz, jlong lc, jlong addr, jlong params){
995 return (jlong) linphone_core_invite_address_with_params((LinphoneCore *)lc, (const LinphoneAddress *)addr, (const LinphoneCallParams *)params);
998 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_updateAddressWithParams(JNIEnv *env, jobject thiz, jlong lc, jlong call, jlong params){
999 return (jint) linphone_core_update_call((LinphoneCore *)lc, (LinphoneCall *)call, (LinphoneCallParams *)params);
1002 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_updateCall(JNIEnv *env, jobject thiz, jlong lc, jlong call, jlong params){
1003 return (jint) linphone_core_update_call((LinphoneCore *)lc, (LinphoneCall *)call, (LinphoneCallParams *)params);