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();
24 extern "C" void libmsx264_init();
27 extern "C" void ms_andsnd_set_jvm(JavaVM *jvm) ;
28 extern "C" void ms_andvid_set_jvm(JavaVM *jvm) ;
33 static void linphone_android_log_handler(OrtpLogLevel lev, const char *fmt, va_list args){
36 case ORTP_DEBUG: prio = ANDROID_LOG_DEBUG; break;
37 case ORTP_MESSAGE: prio = ANDROID_LOG_INFO; break;
38 case ORTP_WARNING: prio = ANDROID_LOG_WARN; break;
39 case ORTP_ERROR: prio = ANDROID_LOG_ERROR; break;
40 case ORTP_FATAL: prio = ANDROID_LOG_FATAL; break;
41 default: prio = ANDROID_LOG_DEFAULT; break;
43 __android_log_vprint(prio, LOG_DOMAIN, fmt, args);
47 JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *ajvm, void *reserved)
50 ms_andsnd_set_jvm(ajvm);
52 ms_andvid_set_jvm(ajvm);
53 #endif /*VIDEO_ENABLED*/
56 return JNI_VERSION_1_2;
61 extern "C" void Java_org_linphone_core_LinphoneCoreFactoryImpl_setDebugMode(JNIEnv* env
65 linphone_core_enable_logs_with_cb(linphone_android_log_handler);
67 linphone_core_disable_logs();
72 class LinphoneCoreData {
74 LinphoneCoreData(JNIEnv* env, jobject lc,jobject alistener, jobject auserdata) {
76 core = env->NewGlobalRef(lc);
77 listener = env->NewGlobalRef(alistener);
78 userdata = auserdata?env->NewGlobalRef(auserdata):0;
79 memset(&vTable,0,sizeof(vTable));
80 vTable.show = showInterfaceCb;
81 vTable.auth_info_requested = authInfoRequested;
82 vTable.display_status = displayStatusCb;
83 vTable.display_message = displayMessageCb;
84 vTable.display_warning = displayMessageCb;
85 vTable.global_state_changed = globalStateChange;
86 vTable.registration_state_changed = registrationStateChange;
87 vTable.call_state_changed = callStateChange;
88 vTable.text_received = text_received;
89 vTable.new_subscription_request = new_subscription_request;
90 vTable.notify_presence_recv = notify_presence_recv;
92 listernerClass = (jclass)env->NewGlobalRef(env->GetObjectClass( alistener));
93 /*displayStatus(LinphoneCore lc,String message);*/
94 displayStatusId = env->GetMethodID(listernerClass,"displayStatus","(Lorg/linphone/core/LinphoneCore;Ljava/lang/String;)V");
95 /*void generalState(LinphoneCore lc,int state); */
96 globalStateId = env->GetMethodID(listernerClass,"globalState","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCore$GlobalState;Ljava/lang/String;)V");
97 globalStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCore$GlobalState"));
98 globalStateFromIntId = env->GetStaticMethodID(globalStateClass,"fromInt","(I)Lorg/linphone/core/LinphoneCore$GlobalState;");
99 /*registrationState(LinphoneCore lc, LinphoneProxyConfig cfg, LinphoneCore.RegistrationState cstate, String smessage);*/
100 registrationStateId = env->GetMethodID(listernerClass,"registrationState","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneProxyConfig;Lorg/linphone/core/LinphoneCore$RegistrationState;Ljava/lang/String;)V");
101 registrationStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCore$RegistrationState"));
102 registrationStateFromIntId = env->GetStaticMethodID(registrationStateClass,"fromInt","(I)Lorg/linphone/core/LinphoneCore$RegistrationState;");
103 /*callState(LinphoneCore lc, LinphoneCall call, LinphoneCall.State cstate,String message);*/
104 callStateId = env->GetMethodID(listernerClass,"callState","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCall;Lorg/linphone/core/LinphoneCall$State;Ljava/lang/String;)V");
105 callStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCall$State"));
106 callStateFromIntId = env->GetStaticMethodID(callStateClass,"fromInt","(I)Lorg/linphone/core/LinphoneCall$State;");
108 /*void newSubscriptionRequest(LinphoneCore lc, LinphoneFriend lf, String url)*/
109 newSubscriptionRequestId = env->GetMethodID(listernerClass,"newSubscriptionRequest","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneFriend;Ljava/lang/String;)V");
111 /*void notifyPresenceReceived(LinphoneCore lc, LinphoneFriend lf);*/
112 notifyPresenceReceivedId = env->GetMethodID(listernerClass,"notifyPresenceReceived","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneFriend;)V");
114 /*void textReceived(LinphoneCore lc, LinphoneChatRoom cr,LinphoneAddress from,String message);*/
115 textReceivedId = env->GetMethodID(listernerClass,"textReceived","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneChatRoom;Lorg/linphone/core/LinphoneAddress;Ljava/lang/String;)V");
117 proxyClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneProxyConfigImpl"));
118 proxyCtrId = env->GetMethodID(proxyClass,"<init>", "(J)V");
120 callClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCallImpl"));
121 callCtrId = env->GetMethodID(callClass,"<init>", "(J)V");
123 chatRoomClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneChatRoomImpl"));
124 chatRoomCtrId = env->GetMethodID(chatRoomClass,"<init>", "(J)V");
126 friendClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneFriendImpl"));;
127 friendCtrId =env->GetMethodID(friendClass,"<init>", "(J)V");
129 addressClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneAddressImpl"));
130 addressCtrId =env->GetMethodID(addressClass,"<init>", "(J)V");
134 ~LinphoneCoreData() {
136 jvm->AttachCurrentThread(&env,NULL);
137 env->DeleteGlobalRef(core);
138 env->DeleteGlobalRef(listener);
139 if (userdata) env->DeleteGlobalRef(userdata);
140 env->DeleteGlobalRef(listernerClass);
141 env->DeleteGlobalRef(globalStateClass);
142 env->DeleteGlobalRef(registrationStateClass);
143 env->DeleteGlobalRef(callStateClass);
144 env->DeleteGlobalRef(proxyClass);
145 env->DeleteGlobalRef(callClass);
146 env->DeleteGlobalRef(chatRoomClass);
147 env->DeleteGlobalRef(friendClass);
154 jclass listernerClass;
155 jmethodID displayStatusId;
156 jmethodID newSubscriptionRequestId;
157 jmethodID notifyPresenceReceivedId;
158 jmethodID textReceivedId;
160 jclass globalStateClass;
161 jmethodID globalStateId;
162 jmethodID globalStateFromIntId;
164 jclass registrationStateClass;
165 jmethodID registrationStateId;
166 jmethodID registrationStateFromIntId;
168 jclass callStateClass;
169 jmethodID callStateId;
170 jmethodID callStateFromIntId;
173 jmethodID proxyCtrId;
178 jclass chatRoomClass;
179 jmethodID chatRoomCtrId;
182 jmethodID friendCtrId;
185 jmethodID addressCtrId;
187 LinphoneCoreVTable vTable;
189 static void showInterfaceCb(LinphoneCore *lc) {
192 static void byeReceivedCb(LinphoneCore *lc, const char *from) {
195 static void displayStatusCb(LinphoneCore *lc, const char *message) {
197 jint result = jvm->AttachCurrentThread(&env,NULL);
199 ms_error("cannot attach VM\n");
202 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
203 env->CallVoidMethod(lcData->listener,lcData->displayStatusId,lcData->core,env->NewStringUTF(message));
205 static void displayMessageCb(LinphoneCore *lc, const char *message) {
208 static void authInfoRequested(LinphoneCore *lc, const char *realm, const char *username) {
211 static void globalStateChange(LinphoneCore *lc, LinphoneGlobalState gstate,const char* message) {
213 jint result = jvm->AttachCurrentThread(&env,NULL);
215 ms_error("cannot attach VM\n");
218 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
219 env->CallVoidMethod(lcData->listener
220 ,lcData->globalStateId
222 ,env->CallStaticObjectMethod(lcData->globalStateClass,lcData->globalStateFromIntId,(jint)gstate),
223 message ? env->NewStringUTF(message) : NULL);
225 static void registrationStateChange(LinphoneCore *lc, LinphoneProxyConfig* proxy,LinphoneRegistrationState state,const char* message) {
227 jint result = jvm->AttachCurrentThread(&env,NULL);
229 ms_error("cannot attach VM\n");
232 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
233 env->CallVoidMethod(lcData->listener
234 ,lcData->registrationStateId
236 ,env->NewObject(lcData->proxyClass,lcData->proxyCtrId,(jlong)proxy)
237 ,env->CallStaticObjectMethod(lcData->registrationStateClass,lcData->registrationStateFromIntId,(jint)state),
238 message ? env->NewStringUTF(message) : NULL);
240 static void callStateChange(LinphoneCore *lc, LinphoneCall* call,LinphoneCallState state,const char* message) {
242 jint result = jvm->AttachCurrentThread(&env,NULL);
244 ms_error("cannot attach VM\n");
247 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
248 env->CallVoidMethod(lcData->listener
251 ,env->NewObject(lcData->callClass,lcData->callCtrId,(jlong)call)
252 ,env->CallStaticObjectMethod(lcData->callStateClass,lcData->callStateFromIntId,(jint)state),
253 message ? env->NewStringUTF(message) : NULL);
255 static void notify_presence_recv (LinphoneCore *lc, LinphoneFriend *my_friend) {
257 jint result = jvm->AttachCurrentThread(&env,NULL);
259 ms_error("cannot attach VM\n");
262 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
263 env->CallVoidMethod(lcData->listener
264 ,lcData->notifyPresenceReceivedId
266 ,env->NewObject(lcData->friendClass,lcData->friendCtrId,(jlong)my_friend));
268 static void new_subscription_request (LinphoneCore *lc, LinphoneFriend *my_friend, const char* url) {
270 jint result = jvm->AttachCurrentThread(&env,NULL);
272 ms_error("cannot attach VM\n");
275 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
276 env->CallVoidMethod(lcData->listener
277 ,lcData->newSubscriptionRequestId
279 ,env->NewObject(lcData->friendClass,lcData->friendCtrId,(jlong)my_friend)
280 ,url ? env->NewStringUTF(url) : NULL);
282 static void text_received(LinphoneCore *lc, LinphoneChatRoom *room, const LinphoneAddress *from, const char *message) {
284 jint result = jvm->AttachCurrentThread(&env,NULL);
286 ms_error("cannot attach VM\n");
289 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
290 env->CallVoidMethod(lcData->listener
291 ,lcData->textReceivedId
293 ,env->NewObject(lcData->chatRoomClass,lcData->chatRoomCtrId,(jlong)room)
294 ,env->NewObject(lcData->addressClass,lcData->addressCtrId,(jlong)from)
295 ,message ? env->NewStringUTF(message) : NULL);
300 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_newLinphoneCore(JNIEnv* env
304 ,jstring jfactoryConfig
307 const char* userConfig = juserConfig?env->GetStringUTFChars(juserConfig, NULL):NULL;
308 const char* factoryConfig = jfactoryConfig?env->GetStringUTFChars(jfactoryConfig, NULL):NULL;
309 LinphoneCoreData* ldata = new LinphoneCoreData(env,thiz,jlistener,juserdata);
311 ms_andsnd_set_jvm(jvm);
315 libmsilbc_init(); // requires an fpu
320 jlong nativePtr = (jlong)linphone_core_new( &ldata->vTable
324 //clear auth info list
325 linphone_core_clear_all_auth_info((LinphoneCore*) nativePtr);
326 //clear existing proxy config
327 linphone_core_clear_proxy_config((LinphoneCore*) nativePtr);
329 if (userConfig) env->ReleaseStringUTFChars(juserConfig, userConfig);
330 if (factoryConfig) env->ReleaseStringUTFChars(jfactoryConfig, factoryConfig);
333 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_delete(JNIEnv* env
336 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data((LinphoneCore*)lc);
337 linphone_core_destroy((LinphoneCore*)lc);
341 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_clearProxyConfigs(JNIEnv* env, jobject thiz,jlong lc) {
342 linphone_core_clear_proxy_config((LinphoneCore*)lc);
345 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setDefaultProxyConfig( JNIEnv* env
349 linphone_core_set_default_proxy((LinphoneCore*)lc,(LinphoneProxyConfig*)pc);
351 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_getDefaultProxyConfig( JNIEnv* env
354 LinphoneProxyConfig *config=0;
355 linphone_core_get_default_proxy((LinphoneCore*)lc,&config);
356 return (jlong)config;
359 extern "C" int Java_org_linphone_core_LinphoneCoreImpl_addProxyConfig( JNIEnv* env
364 LinphoneProxyConfig* proxy = (LinphoneProxyConfig*)pc;
365 linphone_proxy_config_set_user_data(proxy, env->NewGlobalRef(jproxyCfg));
367 return linphone_core_add_proxy_config((LinphoneCore*)lc,(LinphoneProxyConfig*)pc);
370 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_clearAuthInfos(JNIEnv* env, jobject thiz,jlong lc) {
371 linphone_core_clear_all_auth_info((LinphoneCore*)lc);
374 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_addAuthInfo( JNIEnv* env
378 linphone_core_add_auth_info((LinphoneCore*)lc,(LinphoneAuthInfo*)pc);
380 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_iterate( JNIEnv* env
383 linphone_core_iterate((LinphoneCore*)lc);
385 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_invite( JNIEnv* env
389 const char* uri = env->GetStringUTFChars(juri, NULL);
390 LinphoneCall* lCall = linphone_core_invite((LinphoneCore*)lc,uri);
391 env->ReleaseStringUTFChars(juri, uri);
394 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_inviteAddress( JNIEnv* env
398 return (jlong) linphone_core_invite_address((LinphoneCore*)lc,(LinphoneAddress*)to);
401 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_terminateCall( JNIEnv* env
405 linphone_core_terminate_call((LinphoneCore*)lc,(LinphoneCall*)call);
408 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_getRemoteAddress( JNIEnv* env
411 return (jlong)linphone_core_get_current_call_remote_address((LinphoneCore*)lc);
413 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isInCall( JNIEnv* env
417 return linphone_core_in_call((LinphoneCore*)lc);
419 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isInComingInvitePending( JNIEnv* env
423 return linphone_core_inc_invite_pending((LinphoneCore*)lc);
425 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_acceptCall( JNIEnv* env
430 linphone_core_accept_call((LinphoneCore*)lc,(LinphoneCall*)call);
433 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_getCallLog( JNIEnv* env
437 return (jlong)ms_list_nth_data(linphone_core_get_call_logs((LinphoneCore*)lc),position);
439 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getNumberOfCallLogs( JNIEnv* env
442 return ms_list_size(linphone_core_get_call_logs((LinphoneCore*)lc));
444 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setNetworkStateReachable( JNIEnv* env
447 ,jboolean isReachable) {
448 linphone_core_set_network_reachable((LinphoneCore*)lc,isReachable);
451 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPlaybackGain( JNIEnv* env
455 linphone_core_set_playback_gain_db((LinphoneCore*)lc,gain);
458 extern "C" float Java_org_linphone_core_LinphoneCoreImpl_getPlaybackGain( JNIEnv* env
461 return linphone_core_get_playback_gain_db((LinphoneCore*)lc);
464 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_muteMic( JNIEnv* env
468 linphone_core_mute_mic((LinphoneCore*)lc,isMuted);
471 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_interpretUrl( JNIEnv* env
475 const char* url = env->GetStringUTFChars(jurl, NULL);
476 jlong result = (jlong)linphone_core_interpret_url((LinphoneCore*)lc,url);
477 env->ReleaseStringUTFChars(jurl, url);
480 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_sendDtmf( JNIEnv* env
484 linphone_core_send_dtmf((LinphoneCore*)lc,dtmf);
486 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_playDtmf( JNIEnv* env
491 linphone_core_play_dtmf((LinphoneCore*)lc,dtmf,duration);
493 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_stopDtmf( JNIEnv* env
496 linphone_core_stop_dtmf((LinphoneCore*)lc);
499 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_clearCallLogs(JNIEnv* env
502 linphone_core_clear_call_logs((LinphoneCore*)lc);
504 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isMicMuted( JNIEnv* env
507 return linphone_core_is_mic_muted((LinphoneCore*)lc);
509 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_findPayloadType(JNIEnv* env
514 const char* mime = env->GetStringUTFChars(jmime, NULL);
515 jlong result = (jlong)linphone_core_find_payload_type((LinphoneCore*)lc,mime,rate);
516 env->ReleaseStringUTFChars(jmime, mime);
519 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_enablePayloadType(JNIEnv* env
524 return linphone_core_enable_payload_type((LinphoneCore*)lc,(PayloadType*)pt,enable);
526 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_enableEchoCancellation(JNIEnv* env
530 linphone_core_enable_echo_cancellation((LinphoneCore*)lc,enable);
532 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isEchoCancellationEnabled(JNIEnv* env
536 return linphone_core_echo_cancellation_enabled((LinphoneCore*)lc);
539 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_getCurrentCall(JNIEnv* env
543 return (jlong)linphone_core_get_current_call((LinphoneCore*)lc);
545 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_addFriend(JNIEnv* env
550 linphone_core_add_friend((LinphoneCore*)lc,(LinphoneFriend*)aFriend);
552 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPresenceInfo(JNIEnv* env
556 ,jstring jalternative_contact
558 const char* alternative_contact = jalternative_contact?env->GetStringUTFChars(jalternative_contact, NULL):NULL;
559 linphone_core_set_presence_info((LinphoneCore*)lc,minute_away,alternative_contact,(LinphoneOnlineStatus)status);
560 if (alternative_contact) env->ReleaseStringUTFChars(jalternative_contact, alternative_contact);
563 extern "C" long Java_org_linphone_core_LinphoneCoreImpl_createChatRoom(JNIEnv* env
568 const char* to = env->GetStringUTFChars(jto, NULL);
569 LinphoneChatRoom* lResult = linphone_core_create_chat_room((LinphoneCore*)lc,to);
570 env->ReleaseStringUTFChars(jto, to);
571 return (long)lResult;
574 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_enableVideo(JNIEnv* env
577 ,jboolean vcap_enabled
578 ,jboolean display_enabled) {
579 linphone_core_enable_video((LinphoneCore*)lc, vcap_enabled,display_enabled);
582 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isVideoEnabled(JNIEnv* env
585 return linphone_core_video_enabled((LinphoneCore*)lc);
587 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setRing(JNIEnv* env
591 const char* path = jpath?env->GetStringUTFChars(jpath, NULL):NULL;
592 linphone_core_set_ring((LinphoneCore*)lc,path);
593 if (path) env->ReleaseStringUTFChars(jpath, path);
595 extern "C" jstring Java_org_linphone_core_LinphoneCoreImpl_getRing(JNIEnv* env
599 const char* path = linphone_core_get_ring((LinphoneCore*)lc);
601 return env->NewStringUTF(path);
610 extern "C" jlong Java_org_linphone_core_LinphoneProxyConfigImpl_newLinphoneProxyConfig(JNIEnv* env,jobject thiz) {
611 LinphoneProxyConfig* proxy = linphone_proxy_config_new();
612 return (jlong) proxy;
615 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_delete(JNIEnv* env,jobject thiz,jlong ptr) {
616 linphone_proxy_config_destroy((LinphoneProxyConfig*)ptr);
618 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setIdentity(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jidentity) {
619 const char* identity = env->GetStringUTFChars(jidentity, NULL);
620 linphone_proxy_config_set_identity((LinphoneProxyConfig*)proxyCfg,identity);
621 env->ReleaseStringUTFChars(jidentity, identity);
623 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getIdentity(JNIEnv* env,jobject thiz,jlong proxyCfg) {
624 const char* identity = linphone_proxy_config_get_identity((LinphoneProxyConfig*)proxyCfg);
626 return env->NewStringUTF(identity);
631 extern "C" int Java_org_linphone_core_LinphoneProxyConfigImpl_setProxy(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jproxy) {
632 const char* proxy = env->GetStringUTFChars(jproxy, NULL);
633 int err=linphone_proxy_config_set_server_addr((LinphoneProxyConfig*)proxyCfg,proxy);
634 env->ReleaseStringUTFChars(jproxy, proxy);
637 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getProxy(JNIEnv* env,jobject thiz,jlong proxyCfg) {
638 const char* proxy = linphone_proxy_config_get_addr((LinphoneProxyConfig*)proxyCfg);
640 return env->NewStringUTF(proxy);
645 extern "C" int Java_org_linphone_core_LinphoneProxyConfigImpl_setRoute(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jroute) {
646 if (jroute != NULL) {
647 const char* route = env->GetStringUTFChars(jroute, NULL);
648 int err=linphone_proxy_config_set_route((LinphoneProxyConfig*)proxyCfg,route);
649 env->ReleaseStringUTFChars(jroute, route);
652 return linphone_proxy_config_set_route((LinphoneProxyConfig*)proxyCfg,NULL);
655 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getRoute(JNIEnv* env,jobject thiz,jlong proxyCfg) {
656 const char* route = linphone_proxy_config_get_route((LinphoneProxyConfig*)proxyCfg);
658 return env->NewStringUTF(route);
664 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_enableRegister(JNIEnv* env,jobject thiz,jlong proxyCfg,jboolean enableRegister) {
665 linphone_proxy_config_enable_register((LinphoneProxyConfig*)proxyCfg,enableRegister);
667 extern "C" jboolean Java_org_linphone_core_LinphoneProxyConfigImpl_isRegistered(JNIEnv* env,jobject thiz,jlong proxyCfg) {
668 return linphone_proxy_config_is_registered((LinphoneProxyConfig*)proxyCfg);
670 extern "C" jboolean Java_org_linphone_core_LinphoneProxyConfigImpl_isRegisterEnabled(JNIEnv* env,jobject thiz,jlong proxyCfg) {
671 return linphone_proxy_config_register_enabled((LinphoneProxyConfig*)proxyCfg);
673 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_edit(JNIEnv* env,jobject thiz,jlong proxyCfg) {
674 linphone_proxy_config_edit((LinphoneProxyConfig*)proxyCfg);
676 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_done(JNIEnv* env,jobject thiz,jlong proxyCfg) {
677 linphone_proxy_config_done((LinphoneProxyConfig*)proxyCfg);
679 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_normalizePhoneNumber(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jnumber) {
681 ms_error("cannot normalized null number");
683 const char* number = env->GetStringUTFChars(jnumber, NULL);
684 int len = env->GetStringLength(jnumber);
686 ms_warning("cannot normalize empty number");
689 char targetBuff[2*len];// returned number can be greater than origin (specially in case of prefix insertion
690 linphone_proxy_config_normalize_number((LinphoneProxyConfig*)proxyCfg,number,targetBuff,sizeof(targetBuff));
691 jstring normalizedNumber = env->NewStringUTF(targetBuff);
692 env->ReleaseStringUTFChars(jnumber, number);
693 return normalizedNumber;
695 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getDomain(JNIEnv* env
698 const char* domain = linphone_proxy_config_get_domain((LinphoneProxyConfig*)proxyCfg);
700 return env->NewStringUTF(domain);
705 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setDialEscapePlus(JNIEnv* env,jobject thiz,jlong proxyCfg,jboolean value) {
706 linphone_proxy_config_set_dial_escape_plus((LinphoneProxyConfig*)proxyCfg,value);
709 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setDialPrefix(JNIEnv* env
713 const char* prefix = env->GetStringUTFChars(jprefix, NULL);
714 linphone_proxy_config_set_dial_prefix((LinphoneProxyConfig*)proxyCfg,prefix);
715 env->ReleaseStringUTFChars(jprefix, prefix);
717 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_enablePublish(JNIEnv* env
721 linphone_proxy_config_enable_publish((LinphoneProxyConfig*)proxyCfg,val);
723 extern "C" jboolean Java_org_linphone_core_LinphoneProxyConfigImpl_publishEnabled(JNIEnv* env,jobject thiz,jlong proxyCfg) {
724 return linphone_proxy_config_publish_enabled((LinphoneProxyConfig*)proxyCfg);
729 extern "C" jlong Java_org_linphone_core_LinphoneAuthInfoImpl_newLinphoneAuthInfo(JNIEnv* env
737 const char* username = env->GetStringUTFChars(jusername, NULL);
738 const char* password = env->GetStringUTFChars(jpassword, NULL);
739 jlong auth = (jlong)linphone_auth_info_new(username,NULL,password,NULL,NULL);
741 env->ReleaseStringUTFChars(jusername, username);
742 env->ReleaseStringUTFChars(jpassword, password);
746 extern "C" void Java_org_linphone_core_LinphoneAuthInfoImpl_delete(JNIEnv* env
749 linphone_auth_info_destroy((LinphoneAuthInfo*)ptr);
754 extern "C" jlong Java_org_linphone_core_LinphoneAddressImpl_newLinphoneAddressImpl(JNIEnv* env
757 ,jstring jdisplayName) {
758 const char* uri = env->GetStringUTFChars(juri, NULL);
759 LinphoneAddress* address = linphone_address_new(uri);
760 if (jdisplayName && address) {
761 const char* displayName = env->GetStringUTFChars(jdisplayName, NULL);
762 linphone_address_set_display_name(address,displayName);
763 env->ReleaseStringUTFChars(jdisplayName, displayName);
765 env->ReleaseStringUTFChars(juri, uri);
767 return (jlong) address;
769 extern "C" void Java_org_linphone_core_LinphoneAddressImpl_delete(JNIEnv* env
772 linphone_address_destroy((LinphoneAddress*)ptr);
775 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_getDisplayName(JNIEnv* env
778 const char* displayName = linphone_address_get_display_name((LinphoneAddress*)ptr);
780 return env->NewStringUTF(displayName);
785 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_getUserName(JNIEnv* env
788 const char* userName = linphone_address_get_username((LinphoneAddress*)ptr);
790 return env->NewStringUTF(userName);
795 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_getDomain(JNIEnv* env
798 const char* domain = linphone_address_get_domain((LinphoneAddress*)ptr);
800 return env->NewStringUTF(domain);
806 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_toString(JNIEnv* env
809 char* uri = linphone_address_as_string((LinphoneAddress*)ptr);
810 jstring juri =env->NewStringUTF(uri);
814 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_toUri(JNIEnv* env
817 char* uri = linphone_address_as_string_uri_only((LinphoneAddress*)ptr);
818 jstring juri =env->NewStringUTF(uri);
822 extern "C" void Java_org_linphone_core_LinphoneAddressImpl_setDisplayName(JNIEnv* env
825 ,jstring jdisplayName) {
826 const char* displayName = jdisplayName!= NULL?env->GetStringUTFChars(jdisplayName, NULL):NULL;
827 linphone_address_set_display_name((LinphoneAddress*)address,displayName);
828 if (displayName != NULL) env->ReleaseStringUTFChars(jdisplayName, displayName);
833 extern "C" jlong Java_org_linphone_core_LinphoneCallLogImpl_getFrom(JNIEnv* env
836 return (jlong)((LinphoneCallLog*)ptr)->from;
838 extern "C" jlong Java_org_linphone_core_LinphoneCallLogImpl_getTo(JNIEnv* env
841 return (jlong)((LinphoneCallLog*)ptr)->to;
843 extern "C" jboolean Java_org_linphone_core_LinphoneCallLogImpl_isIncoming(JNIEnv* env
846 return ((LinphoneCallLog*)ptr)->dir==LinphoneCallIncoming?JNI_TRUE:JNI_FALSE;
849 extern "C" jstring Java_org_linphone_core_PayloadTypeImpl_toString(JNIEnv* env
853 PayloadType* pt = (PayloadType*)ptr;
854 char* value = ms_strdup_printf("[%s] clock [%s], bitrate [%s]"
855 ,payload_type_get_mime(pt)
856 ,payload_type_get_rate(pt)
857 ,payload_type_get_bitrate(pt));
858 jstring jvalue =env->NewStringUTF(value);
863 extern "C" void Java_org_linphone_core_LinphoneCallImpl_ref(JNIEnv* env
866 linphone_call_ref((LinphoneCall*)ptr);
869 extern "C" void Java_org_linphone_core_LinphoneCallImpl_unref(JNIEnv* env
872 linphone_call_unref((LinphoneCall*)ptr);
875 extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_getCallLog( JNIEnv* env
878 return (jlong)linphone_call_get_call_log((LinphoneCall*)ptr);
881 extern "C" jboolean Java_org_linphone_core_LinphoneCallImpl_isIncoming( JNIEnv* env
884 return linphone_call_get_dir((LinphoneCall*)ptr)==LinphoneCallIncoming?JNI_TRUE:JNI_FALSE;
887 extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_getRemoteAddress( JNIEnv* env
890 return (jlong)linphone_call_get_remote_address((LinphoneCall*)ptr);
893 extern "C" jint Java_org_linphone_core_LinphoneCallImpl_getState( JNIEnv* env
896 return (jint)linphone_call_get_state((LinphoneCall*)ptr);
900 extern "C" long Java_org_linphone_core_LinphoneFriendImpl_newLinphoneFriend(JNIEnv* env
902 ,jstring jFriendUri) {
903 LinphoneFriend* lResult;
906 const char* friendUri = env->GetStringUTFChars(jFriendUri, NULL);
907 lResult= linphone_friend_new_with_addr(friendUri);
908 env->ReleaseStringUTFChars(jFriendUri, friendUri);
910 lResult = linphone_friend_new();
912 return (long)lResult;
914 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_setAddress(JNIEnv* env
917 ,jlong linphoneAddress) {
918 linphone_friend_set_addr((LinphoneFriend*)ptr,(LinphoneAddress*)linphoneAddress);
920 extern "C" long Java_org_linphone_core_LinphoneFriendImpl_getAddress(JNIEnv* env
923 return (long)linphone_friend_get_address((LinphoneFriend*)ptr);
925 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_setIncSubscribePolicy(JNIEnv* env
929 linphone_friend_set_inc_subscribe_policy((LinphoneFriend*)ptr,(LinphoneSubscribePolicy)policy);
931 extern "C" jint Java_org_linphone_core_LinphoneFriendImpl_getIncSubscribePolicy(JNIEnv* env
934 return linphone_friend_get_inc_subscribe_policy((LinphoneFriend*)ptr);
936 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_enableSubscribes(JNIEnv* env
940 linphone_friend_enable_subscribes((LinphoneFriend*)ptr,value);
942 extern "C" jboolean Java_org_linphone_core_LinphoneFriendImpl_isSubscribesEnabled(JNIEnv* env
945 return linphone_friend_subscribes_enabled((LinphoneFriend*)ptr);
947 extern "C" jboolean Java_org_linphone_core_LinphoneFriendImpl_getStatus(JNIEnv* env
950 return linphone_friend_get_status((LinphoneFriend*)ptr);
952 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_edit(JNIEnv* env
955 return linphone_friend_edit((LinphoneFriend*)ptr);
957 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_done(JNIEnv* env
960 linphone_friend_done((LinphoneFriend*)ptr);
963 extern "C" long Java_org_linphone_core_LinphoneChatRoomImpl_getPeerAddress(JNIEnv* env
966 return (long) linphone_chat_room_get_peer_address((LinphoneChatRoom*)ptr);
968 extern "C" void Java_org_linphone_core_LinphoneChatRoomImpl_sendMessage(JNIEnv* env
972 const char* message = env->GetStringUTFChars(jmessage, NULL);
973 linphone_chat_room_send_message((LinphoneChatRoom*)ptr,message);
974 env->ReleaseStringUTFChars(jmessage, message);
978 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setVideoWindowId(JNIEnv* env
982 linphone_core_set_native_video_window_id((LinphoneCore*)lc,(unsigned long)obj);
986 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setFirewallPolicy(JNIEnv *env, jobject thiz, jlong lc, int enum_value){
987 linphone_core_set_firewall_policy((LinphoneCore*)lc,(LinphoneFirewallPolicy)enum_value);
990 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getFirewallPolicy(JNIEnv *env, jobject thiz, jlong lc){
991 return linphone_core_get_firewall_policy((LinphoneCore*)lc);
994 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setStunServer(JNIEnv *env, jobject thiz, jlong lc, jstring jserver){
995 const char* server = NULL;
996 if (jserver) server=env->GetStringUTFChars(jserver, NULL);
997 linphone_core_set_stun_server((LinphoneCore*)lc,server);
998 if (server) env->ReleaseStringUTFChars(jserver,server);
1001 extern "C" jstring Java_org_linphone_core_LinphoneCoreImpl_getStunServer(JNIEnv *env, jobject thiz, jlong lc){
1002 const char *ret= linphone_core_get_stun_server((LinphoneCore*)lc);
1003 if (ret==NULL) return NULL;
1004 jstring jvalue =env->NewStringUTF(ret);
1008 extern "C" void Java_org_linphone_core_LinphoneCallParamsImpl_enableVideo(JNIEnv *env, jobject thiz, jlong lcp, jboolean b){
1009 linphone_call_params_enable_video((LinphoneCallParams*)lcp, b);
1012 extern "C" jboolean Java_org_linphone_core_LinphoneCallParamsImpl_getVideoEnabled(JNIEnv *env, jobject thiz, jlong lcp){
1013 return linphone_call_params_video_enabled((LinphoneCallParams*)lcp);
1015 extern "C" jlong Java_org_linphone_core_LinphoneCallParamsImpl_copy(JNIEnv *env, jobject thiz, jlong lcp){
1016 return (jlong) linphone_call_params_copy((LinphoneCallParams*)lcp);
1018 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_createDefaultCallParams(JNIEnv *env, jobject thiz, jlong lc){
1019 return (jlong) linphone_core_create_default_call_parameters((LinphoneCore*)lc);
1022 extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_getCurrentParams(JNIEnv *env, jobject thiz, jlong lc){
1023 return (jlong) linphone_call_get_current_params((LinphoneCall*)lc);
1026 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_inviteAddressWithParams(JNIEnv *env, jobject thiz, jlong lc, jlong addr, jlong params){
1027 return (jlong) linphone_core_invite_address_with_params((LinphoneCore *)lc, (const LinphoneAddress *)addr, (const LinphoneCallParams *)params);
1030 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_updateAddressWithParams(JNIEnv *env, jobject thiz, jlong lc, jlong call, jlong params){
1031 return (jint) linphone_core_update_call((LinphoneCore *)lc, (LinphoneCall *)call, (LinphoneCallParams *)params);
1034 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_updateCall(JNIEnv *env, jobject thiz, jlong lc, jlong call, jlong params){
1035 return (jint) linphone_core_update_call((LinphoneCore *)lc, (LinphoneCall *)call, (LinphoneCallParams *)params);
1039 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPreferredVideoSize(JNIEnv *env, jobject thiz, jlong lc, jint width, jint height){
1041 vsize.width = (int)width;
1042 vsize.height = (int)height;
1043 linphone_core_set_preferred_video_size((LinphoneCore *)lc, vsize);
1046 extern "C" jintArray Java_org_linphone_core_LinphoneCoreImpl_getPreferredVideoSize(JNIEnv *env, jobject thiz, jlong lc){
1047 MSVideoSize vsize = linphone_core_get_preferred_video_size((LinphoneCore *)lc);
1048 jintArray arr = env->NewIntArray(2);
1049 int tVsize [2]= {vsize.width,vsize.height};
1050 env->SetIntArrayRegion(arr, 0, 2, tVsize);
1054 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setDownloadBandwidth(JNIEnv *env, jobject thiz, jlong lc, jint bw){
1055 linphone_core_set_download_bandwidth((LinphoneCore *)lc, (int) bw);
1058 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setUploadBandwidth(JNIEnv *env, jobject thiz, jlong lc, jint bw){
1059 linphone_core_set_upload_bandwidth((LinphoneCore *)lc, (int) bw);