]> sjero.net Git - linphone/blob - coreapi/linphonecore_jni.cc
Enable ipv6 support for Android.
[linphone] / coreapi / linphonecore_jni.cc
1 /*
2 linphonecore_jni.cc
3 Copyright (C) 2010  Belledonne Communications, Grenoble, France
4
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.
9
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.
14
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.
18  */
19 #include <jni.h>
20 #include "linphonecore_utils.h"
21
22 #include "mediastreamer2/msjava.h"
23
24 #ifdef ANDROID
25 #include <android/log.h>
26 extern "C" void libmsilbc_init();
27 #ifdef HAVE_X264
28 extern "C" void libmsx264_init();
29 #endif
30 #endif /*ANDROID*/
31
32 static JavaVM *jvm=0;
33
34 #ifdef ANDROID
35 static void linphone_android_log_handler(OrtpLogLevel lev, const char *fmt, va_list args){
36         int prio;
37         switch(lev){
38         case ORTP_DEBUG:        prio = ANDROID_LOG_DEBUG;       break;
39         case ORTP_MESSAGE:      prio = ANDROID_LOG_INFO;        break;
40         case ORTP_WARNING:      prio = ANDROID_LOG_WARN;        break;
41         case ORTP_ERROR:        prio = ANDROID_LOG_ERROR;       break;
42         case ORTP_FATAL:        prio = ANDROID_LOG_FATAL;       break;
43         default:                prio = ANDROID_LOG_DEFAULT;     break;
44         }
45         __android_log_vprint(prio, LOG_DOMAIN, fmt, args);
46 }
47 #endif /*ANDROID*/
48
49 JNIEXPORT jint JNICALL  JNI_OnLoad(JavaVM *ajvm, void *reserved)
50 {
51 #ifdef ANDROID
52         ms_set_jvm(ajvm);
53 #endif /*ANDROID*/
54         jvm=ajvm;
55         return JNI_VERSION_1_2;
56 }
57
58
59 //LinphoneFactory
60 extern "C" void Java_org_linphone_core_LinphoneCoreFactoryImpl_setDebugMode(JNIEnv*  env
61                 ,jobject  thiz
62                 ,jboolean isDebug) {
63         if (isDebug) {
64                 linphone_core_enable_logs_with_cb(linphone_android_log_handler);
65         } else {
66                 linphone_core_disable_logs();
67         }
68 }
69 // LinphoneCore
70
71 class LinphoneCoreData {
72 public:
73         LinphoneCoreData(JNIEnv*  env, jobject lc,jobject alistener, jobject auserdata) {
74
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;
90
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;");
106                 /*void ecCalibrationStatus(LinphoneCore.EcCalibratorStatus status, int delay_ms, Object data);*/
107                 ecCalibrationStatusId = env->GetMethodID(listernerClass,"ecCalibrationStatus","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCore$EcCalibratorStatus;ILjava/lang/Object;)V");
108                 ecCalibratorStatusClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCore$EcCalibratorStatus"));
109                 ecCalibratorStatusFromIntId = env->GetStaticMethodID(ecCalibratorStatusClass,"fromInt","(I)Lorg/linphone/core/LinphoneCore$EcCalibratorStatus;");
110                 /*void newSubscriptionRequest(LinphoneCore lc, LinphoneFriend lf, String url)*/
111                 newSubscriptionRequestId = env->GetMethodID(listernerClass,"newSubscriptionRequest","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneFriend;Ljava/lang/String;)V");
112
113                 /*void notifyPresenceReceived(LinphoneCore lc, LinphoneFriend lf);*/
114                 notifyPresenceReceivedId = env->GetMethodID(listernerClass,"notifyPresenceReceived","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneFriend;)V");
115
116                 /*void textReceived(LinphoneCore lc, LinphoneChatRoom cr,LinphoneAddress from,String message);*/
117                 textReceivedId = env->GetMethodID(listernerClass,"textReceived","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneChatRoom;Lorg/linphone/core/LinphoneAddress;Ljava/lang/String;)V");
118
119                 proxyClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneProxyConfigImpl"));
120                 proxyCtrId = env->GetMethodID(proxyClass,"<init>", "(J)V");
121
122                 callClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCallImpl"));
123                 callCtrId = env->GetMethodID(callClass,"<init>", "(J)V");
124
125                 chatRoomClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneChatRoomImpl"));
126                 chatRoomCtrId = env->GetMethodID(chatRoomClass,"<init>", "(J)V");
127
128                 friendClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneFriendImpl"));;
129                 friendCtrId =env->GetMethodID(friendClass,"<init>", "(J)V");
130
131                 addressClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneAddressImpl"));
132                 addressCtrId =env->GetMethodID(addressClass,"<init>", "(J)V");
133
134         }
135
136         ~LinphoneCoreData() {
137                 JNIEnv *env = 0;
138                 jvm->AttachCurrentThread(&env,NULL);
139                 env->DeleteGlobalRef(core);
140                 env->DeleteGlobalRef(listener);
141                 if (userdata) env->DeleteGlobalRef(userdata);
142                 env->DeleteGlobalRef(listernerClass);
143                 env->DeleteGlobalRef(globalStateClass);
144                 env->DeleteGlobalRef(registrationStateClass);
145                 env->DeleteGlobalRef(callStateClass);
146                 env->DeleteGlobalRef(proxyClass);
147                 env->DeleteGlobalRef(callClass);
148                 env->DeleteGlobalRef(chatRoomClass);
149                 env->DeleteGlobalRef(friendClass);
150
151         }
152         jobject core;
153         jobject listener;
154         jobject userdata;
155
156         jclass listernerClass;
157         jmethodID displayStatusId;
158         jmethodID newSubscriptionRequestId;
159         jmethodID notifyPresenceReceivedId;
160         jmethodID textReceivedId;
161
162         jclass globalStateClass;
163         jmethodID globalStateId;
164         jmethodID globalStateFromIntId;
165
166         jclass registrationStateClass;
167         jmethodID registrationStateId;
168         jmethodID registrationStateFromIntId;
169
170         jclass callStateClass;
171         jmethodID callStateId;
172         jmethodID callStateFromIntId;
173
174         jclass ecCalibratorStatusClass;
175         jmethodID ecCalibrationStatusId;
176         jmethodID ecCalibratorStatusFromIntId;
177
178         jclass proxyClass;
179         jmethodID proxyCtrId;
180
181         jclass callClass;
182         jmethodID callCtrId;
183
184         jclass chatRoomClass;
185         jmethodID chatRoomCtrId;
186
187         jclass friendClass;
188         jmethodID friendCtrId;
189
190         jclass addressClass;
191         jmethodID addressCtrId;
192
193         LinphoneCoreVTable vTable;
194
195         static void showInterfaceCb(LinphoneCore *lc) {
196
197         }
198         static void byeReceivedCb(LinphoneCore *lc, const char *from) {
199
200         }
201         static void displayStatusCb(LinphoneCore *lc, const char *message) {
202                 JNIEnv *env = 0;
203                 jint result = jvm->AttachCurrentThread(&env,NULL);
204                 if (result != 0) {
205                         ms_error("cannot attach VM\n");
206                         return;
207                 }
208                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
209                 env->CallVoidMethod(lcData->listener,lcData->displayStatusId,lcData->core,env->NewStringUTF(message));
210         }
211         static void displayMessageCb(LinphoneCore *lc, const char *message) {
212
213         }
214         static void authInfoRequested(LinphoneCore *lc, const char *realm, const char *username) {
215
216         }
217         static void globalStateChange(LinphoneCore *lc, LinphoneGlobalState gstate,const char* message) {
218                 JNIEnv *env = 0;
219                 jint result = jvm->AttachCurrentThread(&env,NULL);
220                 if (result != 0) {
221                         ms_error("cannot attach VM\n");
222                         return;
223                 }
224                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
225                 env->CallVoidMethod(lcData->listener
226                                                         ,lcData->globalStateId
227                                                         ,lcData->core
228                                                         ,env->CallStaticObjectMethod(lcData->globalStateClass,lcData->globalStateFromIntId,(jint)gstate),
229                                                         message ? env->NewStringUTF(message) : NULL);
230         }
231         static void registrationStateChange(LinphoneCore *lc, LinphoneProxyConfig* proxy,LinphoneRegistrationState state,const char* message) {
232                 JNIEnv *env = 0;
233                 jint result = jvm->AttachCurrentThread(&env,NULL);
234                 if (result != 0) {
235                         ms_error("cannot attach VM\n");
236                         return;
237                 }
238                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
239                 env->CallVoidMethod(lcData->listener
240                                                         ,lcData->registrationStateId
241                                                         ,lcData->core
242                                                         ,env->NewObject(lcData->proxyClass,lcData->proxyCtrId,(jlong)proxy)
243                                                         ,env->CallStaticObjectMethod(lcData->registrationStateClass,lcData->registrationStateFromIntId,(jint)state),
244                                                         message ? env->NewStringUTF(message) : NULL);
245         }
246         static void callStateChange(LinphoneCore *lc, LinphoneCall* call,LinphoneCallState state,const char* message) {
247                 JNIEnv *env = 0;
248                 jint result = jvm->AttachCurrentThread(&env,NULL);
249                 if (result != 0) {
250                         ms_error("cannot attach VM\n");
251                         return;
252                 }
253                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
254                 env->CallVoidMethod(lcData->listener
255                                                         ,lcData->callStateId
256                                                         ,lcData->core
257                                                         ,env->NewObject(lcData->callClass,lcData->callCtrId,(jlong)call)
258                                                         ,env->CallStaticObjectMethod(lcData->callStateClass,lcData->callStateFromIntId,(jint)state),
259                                                         message ? env->NewStringUTF(message) : NULL);
260         }
261         static void notify_presence_recv (LinphoneCore *lc,  LinphoneFriend *my_friend) {
262                 JNIEnv *env = 0;
263                 jint result = jvm->AttachCurrentThread(&env,NULL);
264                 if (result != 0) {
265                         ms_error("cannot attach VM\n");
266                         return;
267                 }
268                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
269                 env->CallVoidMethod(lcData->listener
270                                                         ,lcData->notifyPresenceReceivedId
271                                                         ,lcData->core
272                                                         ,env->NewObject(lcData->friendClass,lcData->friendCtrId,(jlong)my_friend));
273         }
274         static void new_subscription_request (LinphoneCore *lc,  LinphoneFriend *my_friend, const char* url) {
275                 JNIEnv *env = 0;
276                 jint result = jvm->AttachCurrentThread(&env,NULL);
277                 if (result != 0) {
278                         ms_error("cannot attach VM\n");
279                         return;
280                 }
281                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
282                 env->CallVoidMethod(lcData->listener
283                                                         ,lcData->newSubscriptionRequestId
284                                                         ,lcData->core
285                                                         ,env->NewObject(lcData->friendClass,lcData->friendCtrId,(jlong)my_friend)
286                                                         ,url ? env->NewStringUTF(url) : NULL);
287         }
288         static void text_received(LinphoneCore *lc, LinphoneChatRoom *room, const LinphoneAddress *from, const char *message) {
289                 JNIEnv *env = 0;
290                 jint result = jvm->AttachCurrentThread(&env,NULL);
291                 if (result != 0) {
292                         ms_error("cannot attach VM\n");
293                         return;
294                 }
295                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
296                 env->CallVoidMethod(lcData->listener
297                                                         ,lcData->textReceivedId
298                                                         ,lcData->core
299                                                         ,env->NewObject(lcData->chatRoomClass,lcData->chatRoomCtrId,(jlong)room)
300                                                         ,env->NewObject(lcData->addressClass,lcData->addressCtrId,(jlong)from)
301                                                         ,message ? env->NewStringUTF(message) : NULL);
302         }
303         static void ecCalibrationStatus(LinphoneCore *lc, LinphoneEcCalibratorStatus status, int delay_ms, void *data) {
304                 JNIEnv *env = 0;
305                 jint result = jvm->AttachCurrentThread(&env,NULL);
306                 if (result != 0) {
307                         ms_error("cannot attach VM\n");
308                         return;
309                 }
310                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
311                 env->CallVoidMethod(lcData->listener
312                                                         ,lcData->ecCalibrationStatusId
313                                                         ,lcData->core
314                                                         ,env->CallStaticObjectMethod(lcData->ecCalibratorStatusClass,lcData->ecCalibratorStatusFromIntId,(jint)status)
315                                                         ,delay_ms
316                                                         ,data ? data : NULL);
317                 if (data != NULL &&status !=LinphoneEcCalibratorInProgress ) {
318                         //final state, releasing global ref
319                         env->DeleteGlobalRef((jobject)data);
320                 }
321
322         }
323
324
325 };
326 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_newLinphoneCore(JNIEnv*  env
327                 ,jobject  thiz
328                 ,jobject jlistener
329                 ,jstring juserConfig
330                 ,jstring jfactoryConfig
331                 ,jobject  juserdata){
332
333         const char* userConfig = juserConfig?env->GetStringUTFChars(juserConfig, NULL):NULL;
334         const char* factoryConfig = jfactoryConfig?env->GetStringUTFChars(jfactoryConfig, NULL):NULL;
335         LinphoneCoreData* ldata = new LinphoneCoreData(env,thiz,jlistener,juserdata);
336
337 #ifdef HAVE_ILBC
338         libmsilbc_init(); // requires an fpu
339 #endif
340 #ifdef HAVE_X264
341         libmsx264_init();
342 #endif
343         jlong nativePtr = (jlong)linphone_core_new(     &ldata->vTable
344                         ,userConfig
345                         ,factoryConfig
346                         ,ldata);
347         //clear auth info list
348         linphone_core_clear_all_auth_info((LinphoneCore*) nativePtr);
349         //clear existing proxy config
350         linphone_core_clear_proxy_config((LinphoneCore*) nativePtr);
351
352         if (userConfig) env->ReleaseStringUTFChars(juserConfig, userConfig);
353         if (factoryConfig) env->ReleaseStringUTFChars(jfactoryConfig, factoryConfig);
354         return nativePtr;
355 }
356 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_delete(JNIEnv*  env
357                 ,jobject  thiz
358                 ,jlong lc) {
359         LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data((LinphoneCore*)lc);
360         linphone_core_destroy((LinphoneCore*)lc);
361         delete lcData;
362 }
363
364 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_clearProxyConfigs(JNIEnv* env, jobject thiz,jlong lc) {
365         linphone_core_clear_proxy_config((LinphoneCore*)lc);
366 }
367
368 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setDefaultProxyConfig(  JNIEnv*  env
369                 ,jobject  thiz
370                 ,jlong lc
371                 ,jlong pc) {
372         linphone_core_set_default_proxy((LinphoneCore*)lc,(LinphoneProxyConfig*)pc);
373 }
374 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_getDefaultProxyConfig( JNIEnv*  env
375                 ,jobject  thiz
376                 ,jlong lc) {
377         LinphoneProxyConfig *config=0;
378         linphone_core_get_default_proxy((LinphoneCore*)lc,&config);
379         return (jlong)config;
380 }
381
382 extern "C" int Java_org_linphone_core_LinphoneCoreImpl_addProxyConfig(  JNIEnv*  env
383                 ,jobject  thiz
384                 ,jobject jproxyCfg
385                 ,jlong lc
386                 ,jlong pc) {
387         LinphoneProxyConfig* proxy = (LinphoneProxyConfig*)pc;
388         linphone_proxy_config_set_user_data(proxy, env->NewGlobalRef(jproxyCfg));
389
390         return linphone_core_add_proxy_config((LinphoneCore*)lc,(LinphoneProxyConfig*)pc);
391 }
392
393 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_clearAuthInfos(JNIEnv* env, jobject thiz,jlong lc) {
394         linphone_core_clear_all_auth_info((LinphoneCore*)lc);
395 }
396
397 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_addAuthInfo(    JNIEnv*  env
398                 ,jobject  thiz
399                 ,jlong lc
400                 ,jlong pc) {
401         linphone_core_add_auth_info((LinphoneCore*)lc,(LinphoneAuthInfo*)pc);
402 }
403 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_iterate(        JNIEnv*  env
404                 ,jobject  thiz
405                 ,jlong lc) {
406         linphone_core_iterate((LinphoneCore*)lc);
407 }
408 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_invite(        JNIEnv*  env
409                 ,jobject  thiz
410                 ,jlong lc
411                 ,jstring juri) {
412         const char* uri = env->GetStringUTFChars(juri, NULL);
413         LinphoneCall* lCall = linphone_core_invite((LinphoneCore*)lc,uri);
414         env->ReleaseStringUTFChars(juri, uri);
415         return (jlong)lCall;
416 }
417 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_inviteAddress( JNIEnv*  env
418                 ,jobject  thiz
419                 ,jlong lc
420                 ,jlong to) {
421         return (jlong) linphone_core_invite_address((LinphoneCore*)lc,(LinphoneAddress*)to);
422 }
423
424 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_terminateCall(  JNIEnv*  env
425                 ,jobject  thiz
426                 ,jlong lc
427                 ,jlong call) {
428         linphone_core_terminate_call((LinphoneCore*)lc,(LinphoneCall*)call);
429 }
430
431 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_getRemoteAddress(      JNIEnv*  env
432                 ,jobject  thiz
433                 ,jlong lc) {
434         return (jlong)linphone_core_get_current_call_remote_address((LinphoneCore*)lc);
435 }
436 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isInCall(   JNIEnv*  env
437                 ,jobject  thiz
438                 ,jlong lc) {
439
440         return linphone_core_in_call((LinphoneCore*)lc);
441 }
442 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isInComingInvitePending(    JNIEnv*  env
443                 ,jobject  thiz
444                 ,jlong lc) {
445
446         return linphone_core_inc_invite_pending((LinphoneCore*)lc);
447 }
448 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_acceptCall(     JNIEnv*  env
449                 ,jobject  thiz
450                 ,jlong lc
451                 ,jlong call) {
452
453         linphone_core_accept_call((LinphoneCore*)lc,(LinphoneCall*)call);
454 }
455
456 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_getCallLog(    JNIEnv*  env
457                 ,jobject  thiz
458                 ,jlong lc
459                 ,jint position) {
460                 return (jlong)ms_list_nth_data(linphone_core_get_call_logs((LinphoneCore*)lc),position);
461 }
462 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getNumberOfCallLogs(    JNIEnv*  env
463                 ,jobject  thiz
464                 ,jlong lc) {
465                 return ms_list_size(linphone_core_get_call_logs((LinphoneCore*)lc));
466 }
467 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setNetworkStateReachable(       JNIEnv*  env
468                 ,jobject  thiz
469                 ,jlong lc
470                 ,jboolean isReachable) {
471                 linphone_core_set_network_reachable((LinphoneCore*)lc,isReachable);
472 }
473
474 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPlaybackGain(        JNIEnv*  env
475                 ,jobject  thiz
476                 ,jlong lc
477                 ,jfloat gain) {
478                 linphone_core_set_playback_gain_db((LinphoneCore*)lc,gain);
479 }
480
481 extern "C" float Java_org_linphone_core_LinphoneCoreImpl_getPlaybackGain(       JNIEnv*  env
482                 ,jobject  thiz
483                 ,jlong lc) {
484                 return linphone_core_get_playback_gain_db((LinphoneCore*)lc);
485 }
486
487 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_muteMic(        JNIEnv*  env
488                 ,jobject  thiz
489                 ,jlong lc
490                 ,jboolean isMuted) {
491                 linphone_core_mute_mic((LinphoneCore*)lc,isMuted);
492 }
493
494 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_interpretUrl(  JNIEnv*  env
495                 ,jobject  thiz
496                 ,jlong lc
497                 ,jstring jurl) {
498         const char* url = env->GetStringUTFChars(jurl, NULL);
499         jlong result = (jlong)linphone_core_interpret_url((LinphoneCore*)lc,url);
500         env->ReleaseStringUTFChars(jurl, url);
501         return result;
502 }
503 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_sendDtmf(       JNIEnv*  env
504                 ,jobject  thiz
505                 ,jlong lc
506                 ,jchar dtmf) {
507         linphone_core_send_dtmf((LinphoneCore*)lc,dtmf);
508 }
509 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_playDtmf(       JNIEnv*  env
510                 ,jobject  thiz
511                 ,jlong lc
512                 ,jchar dtmf
513                 ,jint duration) {
514         linphone_core_play_dtmf((LinphoneCore*)lc,dtmf,duration);
515 }
516 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_stopDtmf(       JNIEnv*  env
517                 ,jobject  thiz
518                 ,jlong lc) {
519         linphone_core_stop_dtmf((LinphoneCore*)lc);
520 }
521
522 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_clearCallLogs(JNIEnv*  env
523                                                                                                                                                 ,jobject  thiz
524                                                                                                                                                 ,jlong lc) {
525         linphone_core_clear_call_logs((LinphoneCore*)lc);
526 }
527 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isMicMuted( JNIEnv*  env
528                 ,jobject  thiz
529                 ,jlong lc) {
530         return linphone_core_is_mic_muted((LinphoneCore*)lc);
531 }
532 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_findPayloadType(JNIEnv*  env
533                                                                                                                                                         ,jobject  thiz
534                                                                                                                                                         ,jlong lc
535                                                                                                                                                         ,jstring jmime
536                                                                                                                                                         ,jint rate) {
537         const char* mime = env->GetStringUTFChars(jmime, NULL);
538         jlong result = (jlong)linphone_core_find_payload_type((LinphoneCore*)lc,mime,rate);
539         env->ReleaseStringUTFChars(jmime, mime);
540         return result;
541 }
542 extern "C" jlongArray Java_org_linphone_core_LinphoneCoreImpl_listVideoPayloadTypes(JNIEnv*  env
543                                                                                                                                                         ,jobject  thiz
544                                                                                                                                                         ,jlong lc) {
545         const MSList* codecs = linphone_core_get_video_codecs((LinphoneCore*)lc);
546         int codecsCount = ms_list_size(codecs);
547         jlongArray jCodecs = env->NewLongArray(codecsCount);
548         jlong *jInternalArray = env->GetLongArrayElements(jCodecs, NULL);
549
550         for (int i = 0; i < codecsCount; i++ ) {
551                 jInternalArray[i] = (unsigned long) (codecs->data);
552                 codecs = codecs->next;
553         }
554
555         env->ReleaseLongArrayElements(jCodecs, jInternalArray, 0);
556
557         return jCodecs;
558 }
559
560 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_enablePayloadType(JNIEnv*  env
561                                                                                                                                                         ,jobject  thiz
562                                                                                                                                                         ,jlong lc
563                                                                                                                                                         ,jlong pt
564                                                                                                                                                         ,jboolean enable) {
565         return linphone_core_enable_payload_type((LinphoneCore*)lc,(PayloadType*)pt,enable);
566 }
567 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_enableEchoCancellation(JNIEnv*  env
568                                                                                                                                                         ,jobject  thiz
569                                                                                                                                                         ,jlong lc
570                                                                                                                                                         ,jboolean enable) {
571         linphone_core_enable_echo_cancellation((LinphoneCore*)lc,enable);
572 }
573 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isEchoCancellationEnabled(JNIEnv*  env
574                                                                                                                                                         ,jobject  thiz
575                                                                                                                                                         ,jlong lc
576                                                                                                                                                         ) {
577         return linphone_core_echo_cancellation_enabled((LinphoneCore*)lc);
578 }
579
580 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_getCurrentCall(JNIEnv*  env
581                                                                                                                                                         ,jobject  thiz
582                                                                                                                                                         ,jlong lc
583                                                                                                                                                         ) {
584         return (jlong)linphone_core_get_current_call((LinphoneCore*)lc);
585 }
586 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_addFriend(JNIEnv*  env
587                                                                                                                                                         ,jobject  thiz
588                                                                                                                                                         ,jlong lc
589                                                                                                                                                         ,jlong aFriend
590                                                                                                                                                         ) {
591         linphone_core_add_friend((LinphoneCore*)lc,(LinphoneFriend*)aFriend);
592 }
593 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPresenceInfo(JNIEnv*  env
594                                                                                                                                                         ,jobject  thiz
595                                                                                                                                                         ,jlong lc
596                                                                                                                                                         ,jint minute_away
597                                                                                                                                                         ,jstring jalternative_contact
598                                                                                                                                                         ,jint status) {
599         const char* alternative_contact = jalternative_contact?env->GetStringUTFChars(jalternative_contact, NULL):NULL;
600         linphone_core_set_presence_info((LinphoneCore*)lc,minute_away,alternative_contact,(LinphoneOnlineStatus)status);
601         if (alternative_contact) env->ReleaseStringUTFChars(jalternative_contact, alternative_contact);
602 }
603
604 extern "C" long Java_org_linphone_core_LinphoneCoreImpl_createChatRoom(JNIEnv*  env
605                                                                                                                                                         ,jobject  thiz
606                                                                                                                                                         ,jlong lc
607                                                                                                                                                         ,jstring jto) {
608
609         const char* to = env->GetStringUTFChars(jto, NULL);
610         LinphoneChatRoom* lResult = linphone_core_create_chat_room((LinphoneCore*)lc,to);
611         env->ReleaseStringUTFChars(jto, to);
612         return (long)lResult;
613 }
614
615 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_enableVideo(JNIEnv*  env
616                                                                                                                                                         ,jobject  thiz
617                                                                                                                                                         ,jlong lc
618                                                                                                                                                         ,jboolean vcap_enabled
619                                                                                                                                                         ,jboolean display_enabled) {
620         linphone_core_enable_video((LinphoneCore*)lc, vcap_enabled,display_enabled);
621
622 }
623 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isVideoEnabled(JNIEnv*  env
624                                                                                                                                                         ,jobject  thiz
625                                                                                                                                                         ,jlong lc) {
626         return linphone_core_video_enabled((LinphoneCore*)lc);
627 }
628 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setRing(JNIEnv*  env
629                                                                                                                                                         ,jobject  thiz
630                                                                                                                                                         ,jlong lc
631                                                                                                                                                         ,jstring jpath) {
632         const char* path = jpath?env->GetStringUTFChars(jpath, NULL):NULL;
633         linphone_core_set_ring((LinphoneCore*)lc,path);
634         if (path) env->ReleaseStringUTFChars(jpath, path);
635 }
636 extern "C" jstring Java_org_linphone_core_LinphoneCoreImpl_getRing(JNIEnv*  env
637                                                                                                                                                         ,jobject  thiz
638                                                                                                                                                         ,jlong lc
639                                                                                                                                                         ) {
640         const char* path = linphone_core_get_ring((LinphoneCore*)lc);
641         if (path) {
642                 return env->NewStringUTF(path);
643         } else {
644                 return NULL;
645         }
646 }
647 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_enableKeepAlive(JNIEnv*  env
648                                                                                                                                 ,jobject  thiz
649                                                                                                                                 ,jlong lc
650                                                                                                                                 ,jboolean enable) {
651         linphone_core_enable_keep_alive((LinphoneCore*)lc,enable);
652
653 }
654 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isKeepAliveEnabled(JNIEnv*  env
655                                                                                                                                 ,jobject  thiz
656                                                                                                                                 ,jlong lc) {
657         return linphone_core_keep_alive_enabled((LinphoneCore*)lc);
658
659 }
660 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_startEchoCalibration(JNIEnv*  env
661                                                                                                                                                                 ,jobject  thiz
662                                                                                                                                                                 ,jlong lc
663                                                                                                                                                                 ,jobject data) {
664         return linphone_core_start_echo_calibration((LinphoneCore*)lc
665                                                                                                         , LinphoneCoreData::ecCalibrationStatus
666                                                                                                         , data?env->NewGlobalRef(data):NULL);
667
668 }
669
670
671
672 //ProxyConfig
673
674 extern "C" jlong Java_org_linphone_core_LinphoneProxyConfigImpl_newLinphoneProxyConfig(JNIEnv*  env,jobject  thiz) {
675         LinphoneProxyConfig* proxy = linphone_proxy_config_new();
676         return  (jlong) proxy;
677 }
678
679 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_delete(JNIEnv*  env,jobject  thiz,jlong ptr) {
680         linphone_proxy_config_destroy((LinphoneProxyConfig*)ptr);
681 }
682 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setIdentity(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jidentity) {
683         const char* identity = env->GetStringUTFChars(jidentity, NULL);
684         linphone_proxy_config_set_identity((LinphoneProxyConfig*)proxyCfg,identity);
685         env->ReleaseStringUTFChars(jidentity, identity);
686 }
687 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getIdentity(JNIEnv* env,jobject thiz,jlong proxyCfg) {
688         const char* identity = linphone_proxy_config_get_identity((LinphoneProxyConfig*)proxyCfg);
689         if (identity) {
690                 return env->NewStringUTF(identity);
691         } else {
692                 return NULL;
693         }
694 }
695 extern "C" int Java_org_linphone_core_LinphoneProxyConfigImpl_setProxy(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jproxy) {
696         const char* proxy = env->GetStringUTFChars(jproxy, NULL);
697         int err=linphone_proxy_config_set_server_addr((LinphoneProxyConfig*)proxyCfg,proxy);
698         env->ReleaseStringUTFChars(jproxy, proxy);
699         return err;
700 }
701 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getProxy(JNIEnv* env,jobject thiz,jlong proxyCfg) {
702         const char* proxy = linphone_proxy_config_get_addr((LinphoneProxyConfig*)proxyCfg);
703         if (proxy) {
704                 return env->NewStringUTF(proxy);
705         } else {
706                 return NULL;
707         }
708 }
709 extern "C" int Java_org_linphone_core_LinphoneProxyConfigImpl_setRoute(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jroute) {
710         if (jroute != NULL) {
711                 const char* route = env->GetStringUTFChars(jroute, NULL);
712                 int err=linphone_proxy_config_set_route((LinphoneProxyConfig*)proxyCfg,route);
713                 env->ReleaseStringUTFChars(jroute, route);
714                 return err;
715         } else {
716                 return linphone_proxy_config_set_route((LinphoneProxyConfig*)proxyCfg,NULL);
717         }
718 }
719 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getRoute(JNIEnv* env,jobject thiz,jlong proxyCfg) {
720         const char* route = linphone_proxy_config_get_route((LinphoneProxyConfig*)proxyCfg);
721         if (route) {
722                 return env->NewStringUTF(route);
723         } else {
724                 return NULL;
725         }
726 }
727
728 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_enableRegister(JNIEnv* env,jobject thiz,jlong proxyCfg,jboolean enableRegister) {
729         linphone_proxy_config_enable_register((LinphoneProxyConfig*)proxyCfg,enableRegister);
730 }
731 extern "C" jboolean Java_org_linphone_core_LinphoneProxyConfigImpl_isRegistered(JNIEnv* env,jobject thiz,jlong proxyCfg) {
732         return linphone_proxy_config_is_registered((LinphoneProxyConfig*)proxyCfg);
733 }
734 extern "C" jboolean Java_org_linphone_core_LinphoneProxyConfigImpl_isRegisterEnabled(JNIEnv* env,jobject thiz,jlong proxyCfg) {
735         return linphone_proxy_config_register_enabled((LinphoneProxyConfig*)proxyCfg);
736 }
737 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_edit(JNIEnv* env,jobject thiz,jlong proxyCfg) {
738         linphone_proxy_config_edit((LinphoneProxyConfig*)proxyCfg);
739 }
740 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_done(JNIEnv* env,jobject thiz,jlong proxyCfg) {
741         linphone_proxy_config_done((LinphoneProxyConfig*)proxyCfg);
742 }
743 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_normalizePhoneNumber(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jnumber) {
744         if (jnumber == 0) {
745                 ms_error("cannot normalized null number");
746         }
747         const char* number = env->GetStringUTFChars(jnumber, NULL);
748         int len = env->GetStringLength(jnumber);
749         if (len == 0) {
750                 ms_warning("cannot normalize empty number");
751                 return jnumber;
752         }
753         char targetBuff[2*len];// returned number can be greater than origin (specially in case of prefix insertion
754         linphone_proxy_config_normalize_number((LinphoneProxyConfig*)proxyCfg,number,targetBuff,sizeof(targetBuff));
755         jstring normalizedNumber = env->NewStringUTF(targetBuff);
756         env->ReleaseStringUTFChars(jnumber, number);
757         return normalizedNumber;
758 }
759 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getDomain(JNIEnv* env
760                                                                                                                                                         ,jobject thiz
761                                                                                                                                                         ,jlong proxyCfg) {
762         const char* domain = linphone_proxy_config_get_domain((LinphoneProxyConfig*)proxyCfg);
763         if (domain) {
764                 return env->NewStringUTF(domain);
765         } else {
766                 return NULL;
767         }
768 }
769 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setDialEscapePlus(JNIEnv* env,jobject thiz,jlong proxyCfg,jboolean value) {
770         linphone_proxy_config_set_dial_escape_plus((LinphoneProxyConfig*)proxyCfg,value);
771 }
772
773 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setDialPrefix(JNIEnv* env
774                                                                                                                                         ,jobject thiz
775                                                                                                                                         ,jlong proxyCfg
776                                                                                                                                         ,jstring jprefix) {
777         const char* prefix = env->GetStringUTFChars(jprefix, NULL);
778         linphone_proxy_config_set_dial_prefix((LinphoneProxyConfig*)proxyCfg,prefix);
779         env->ReleaseStringUTFChars(jprefix, prefix);
780 }
781 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_enablePublish(JNIEnv* env
782                                                                                                                                                                 ,jobject thiz
783                                                                                                                                                                 ,jlong proxyCfg
784                                                                                                                                                                 ,jboolean val) {
785         linphone_proxy_config_enable_publish((LinphoneProxyConfig*)proxyCfg,val);
786 }
787 extern "C" jboolean Java_org_linphone_core_LinphoneProxyConfigImpl_publishEnabled(JNIEnv* env,jobject thiz,jlong proxyCfg) {
788         return linphone_proxy_config_publish_enabled((LinphoneProxyConfig*)proxyCfg);
789 }
790
791 //Auth Info
792
793 extern "C" jlong Java_org_linphone_core_LinphoneAuthInfoImpl_newLinphoneAuthInfo(JNIEnv* env
794                 , jobject thiz
795                 , jstring jusername
796                 , jstring juserid
797                 , jstring jpassword
798                 , jstring jha1
799                 , jstring jrealm) {
800
801         const char* username = env->GetStringUTFChars(jusername, NULL);
802         const char* password = env->GetStringUTFChars(jpassword, NULL);
803         jlong auth = (jlong)linphone_auth_info_new(username,NULL,password,NULL,NULL);
804
805         env->ReleaseStringUTFChars(jusername, username);
806         env->ReleaseStringUTFChars(jpassword, password);
807         return auth;
808
809 }
810 extern "C" void Java_org_linphone_core_LinphoneAuthInfoImpl_delete(JNIEnv* env
811                 , jobject thiz
812                 , jlong ptr) {
813         linphone_auth_info_destroy((LinphoneAuthInfo*)ptr);
814 }
815
816 //LinphoneAddress
817
818 extern "C" jlong Java_org_linphone_core_LinphoneAddressImpl_newLinphoneAddressImpl(JNIEnv*  env
819                                                                                                                                                                         ,jobject  thiz
820                                                                                                                                                                         ,jstring juri
821                                                                                                                                                                         ,jstring jdisplayName) {
822         const char* uri = env->GetStringUTFChars(juri, NULL);
823         LinphoneAddress* address = linphone_address_new(uri);
824         if (jdisplayName && address) {
825                 const char* displayName = env->GetStringUTFChars(jdisplayName, NULL);
826                 linphone_address_set_display_name(address,displayName);
827                 env->ReleaseStringUTFChars(jdisplayName, displayName);
828         }
829         env->ReleaseStringUTFChars(juri, uri);
830
831         return  (jlong) address;
832 }
833 extern "C" void Java_org_linphone_core_LinphoneAddressImpl_delete(JNIEnv*  env
834                                                                                                                                                 ,jobject  thiz
835                                                                                                                                                 ,jlong ptr) {
836         linphone_address_destroy((LinphoneAddress*)ptr);
837 }
838
839 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_getDisplayName(JNIEnv*  env
840                                                                                                                                                 ,jobject  thiz
841                                                                                                                                                 ,jlong ptr) {
842         const char* displayName = linphone_address_get_display_name((LinphoneAddress*)ptr);
843         if (displayName) {
844                 return env->NewStringUTF(displayName);
845         } else {
846                 return 0;
847         }
848 }
849 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_getUserName(JNIEnv*  env
850                                                                                                                                                 ,jobject  thiz
851                                                                                                                                                 ,jlong ptr) {
852         const char* userName = linphone_address_get_username((LinphoneAddress*)ptr);
853         if (userName) {
854                 return env->NewStringUTF(userName);
855         } else {
856                 return 0;
857         }
858 }
859 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_getDomain(JNIEnv*  env
860                                                                                                                                                 ,jobject  thiz
861                                                                                                                                                 ,jlong ptr) {
862         const char* domain = linphone_address_get_domain((LinphoneAddress*)ptr);
863         if (domain) {
864                 return env->NewStringUTF(domain);
865         } else {
866                 return 0;
867         }
868 }
869
870 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_toString(JNIEnv*  env
871                                                                                                                                                 ,jobject  thiz
872                                                                                                                                                 ,jlong ptr) {
873         char* uri = linphone_address_as_string((LinphoneAddress*)ptr);
874         jstring juri =env->NewStringUTF(uri);
875         ms_free(uri);
876         return juri;
877 }
878 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_toUri(JNIEnv*  env
879                                                                                                                                                 ,jobject  thiz
880                                                                                                                                                 ,jlong ptr) {
881         char* uri = linphone_address_as_string_uri_only((LinphoneAddress*)ptr);
882         jstring juri =env->NewStringUTF(uri);
883         ms_free(uri);
884         return juri;
885 }
886 extern "C" void Java_org_linphone_core_LinphoneAddressImpl_setDisplayName(JNIEnv*  env
887                                                                                                                                                 ,jobject  thiz
888                                                                                                                                                 ,jlong address
889                                                                                                                                                 ,jstring jdisplayName) {
890         const char* displayName = jdisplayName!= NULL?env->GetStringUTFChars(jdisplayName, NULL):NULL;
891         linphone_address_set_display_name((LinphoneAddress*)address,displayName);
892         if (displayName != NULL) env->ReleaseStringUTFChars(jdisplayName, displayName);
893 }
894
895
896 //CallLog
897 extern "C" jlong Java_org_linphone_core_LinphoneCallLogImpl_getFrom(JNIEnv*  env
898                                                                                                                                                 ,jobject  thiz
899                                                                                                                                                 ,jlong ptr) {
900         return (jlong)((LinphoneCallLog*)ptr)->from;
901 }
902 extern "C" jlong Java_org_linphone_core_LinphoneCallLogImpl_getTo(JNIEnv*  env
903                                                                                                                                                 ,jobject  thiz
904                                                                                                                                                 ,jlong ptr) {
905         return (jlong)((LinphoneCallLog*)ptr)->to;
906 }
907 extern "C" jboolean Java_org_linphone_core_LinphoneCallLogImpl_isIncoming(JNIEnv*  env
908                                                                                                                                                 ,jobject  thiz
909                                                                                                                                                 ,jlong ptr) {
910         return ((LinphoneCallLog*)ptr)->dir==LinphoneCallIncoming?JNI_TRUE:JNI_FALSE;
911 }
912
913 /*payloadType*/
914 extern "C" jstring Java_org_linphone_core_PayloadTypeImpl_toString(JNIEnv*  env,jobject  thiz,jlong ptr) {
915         PayloadType* pt = (PayloadType*)ptr;
916         char* value = ms_strdup_printf("[%s] clock [%i], bitrate [%i]"
917                                                                         ,payload_type_get_mime(pt)
918                                                                         ,payload_type_get_rate(pt)
919                                                                         ,payload_type_get_bitrate(pt));
920         jstring jvalue =env->NewStringUTF(value);
921         ms_free(value);
922         return jvalue;
923 }
924 extern "C" jstring Java_org_linphone_core_PayloadTypeImpl_getMime(JNIEnv*  env,jobject  thiz,jlong ptr) {
925         PayloadType* pt = (PayloadType*)ptr;
926         jstring jvalue =env->NewStringUTF(payload_type_get_mime(pt));
927         return jvalue;
928 }
929 extern "C" jint Java_org_linphone_core_PayloadTypeImpl_getRate(JNIEnv*  env,jobject  thiz, jlong ptr) {
930         PayloadType* pt = (PayloadType*)ptr;
931         return payload_type_get_rate(pt);
932 }
933
934 //LinphoneCall
935 extern "C" void Java_org_linphone_core_LinphoneCallImpl_ref(JNIEnv*  env
936                                                                                                                                                 ,jobject  thiz
937                                                                                                                                                 ,jlong ptr) {
938         linphone_call_ref((LinphoneCall*)ptr);
939 }
940
941 extern "C" void Java_org_linphone_core_LinphoneCallImpl_unref(JNIEnv*  env
942                                                                                                                                                 ,jobject  thiz
943                                                                                                                                                 ,jlong ptr) {
944         linphone_call_unref((LinphoneCall*)ptr);
945 }
946
947 extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_getCallLog(    JNIEnv*  env
948                                                                                                                                                 ,jobject  thiz
949                                                                                                                                                 ,jlong ptr) {
950         return (jlong)linphone_call_get_call_log((LinphoneCall*)ptr);
951 }
952
953 extern "C" jboolean Java_org_linphone_core_LinphoneCallImpl_isIncoming( JNIEnv*  env
954                                                                                                                                                 ,jobject  thiz
955                                                                                                                                                 ,jlong ptr) {
956         return linphone_call_get_dir((LinphoneCall*)ptr)==LinphoneCallIncoming?JNI_TRUE:JNI_FALSE;
957 }
958
959 extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_getRemoteAddress(      JNIEnv*  env
960                                                                                                                                                 ,jobject  thiz
961                                                                                                                                                 ,jlong ptr) {
962         return (jlong)linphone_call_get_remote_address((LinphoneCall*)ptr);
963 }
964
965 extern "C" jint Java_org_linphone_core_LinphoneCallImpl_getState(       JNIEnv*  env
966                                                                                                                                                 ,jobject  thiz
967                                                                                                                                                 ,jlong ptr) {
968         return (jint)linphone_call_get_state((LinphoneCall*)ptr);
969 }
970 extern "C" void Java_org_linphone_core_LinphoneCallImpl_enableEchoCancellation( JNIEnv*  env
971                                                                                                                                                 ,jobject  thiz
972                                                                                                                                                 ,jlong ptr
973                                                                                                                                                 ,jboolean value) {
974         linphone_call_enable_echo_cancellation((LinphoneCall*)ptr,value);
975 }
976 extern "C" jboolean Java_org_linphone_core_LinphoneCallImpl_isEchoCancellationEnabled(  JNIEnv*  env
977                                                                                                                                                 ,jobject  thiz
978                                                                                                                                                 ,jlong ptr) {
979         return linphone_call_echo_cancellation_enabled((LinphoneCall*)ptr);
980 }
981
982 extern "C" void Java_org_linphone_core_LinphoneCallImpl_enableEchoLimiter(      JNIEnv*  env
983                                                                                                                                                 ,jobject  thiz
984                                                                                                                                                 ,jlong ptr
985                                                                                                                                                 ,jboolean value) {
986         linphone_call_enable_echo_limiter((LinphoneCall*)ptr,value);
987 }
988 extern "C" jboolean Java_org_linphone_core_LinphoneCallImpl_isEchoLimiterEnabled(       JNIEnv*  env
989                                                                                                                                                 ,jobject  thiz
990                                                                                                                                                 ,jlong ptr) {
991         return linphone_call_echo_limiter_enabled((LinphoneCall*)ptr);
992 }
993
994 extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_getReplacedCall(       JNIEnv*  env
995                                                                                                                                                 ,jobject  thiz
996                                                                                                                                                 ,jlong ptr) {
997         return (jlong)linphone_call_get_replaced_call((LinphoneCall*)ptr);
998 }
999
1000
1001 //LinphoneFriend
1002 extern "C" long Java_org_linphone_core_LinphoneFriendImpl_newLinphoneFriend(JNIEnv*  env
1003                                                                                                                                                 ,jobject  thiz
1004                                                                                                                                                 ,jstring jFriendUri) {
1005         LinphoneFriend* lResult;
1006
1007         if (jFriendUri) {
1008                 const char* friendUri = env->GetStringUTFChars(jFriendUri, NULL);
1009                 lResult= linphone_friend_new_with_addr(friendUri);
1010                 env->ReleaseStringUTFChars(jFriendUri, friendUri);
1011         } else {
1012                 lResult = linphone_friend_new();
1013         }
1014         return (long)lResult;
1015 }
1016 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_setAddress(JNIEnv*  env
1017                                                                                                                                                 ,jobject  thiz
1018                                                                                                                                                 ,jlong ptr
1019                                                                                                                                                 ,jlong linphoneAddress) {
1020         linphone_friend_set_addr((LinphoneFriend*)ptr,(LinphoneAddress*)linphoneAddress);
1021 }
1022 extern "C" long Java_org_linphone_core_LinphoneFriendImpl_getAddress(JNIEnv*  env
1023                                                                                                                                                 ,jobject  thiz
1024                                                                                                                                                 ,jlong ptr) {
1025         return (long)linphone_friend_get_address((LinphoneFriend*)ptr);
1026 }
1027 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_setIncSubscribePolicy(JNIEnv*  env
1028                                                                                                                                                 ,jobject  thiz
1029                                                                                                                                                 ,jlong ptr
1030                                                                                                                                                 ,jint policy) {
1031         linphone_friend_set_inc_subscribe_policy((LinphoneFriend*)ptr,(LinphoneSubscribePolicy)policy);
1032 }
1033 extern "C" jint Java_org_linphone_core_LinphoneFriendImpl_getIncSubscribePolicy(JNIEnv*  env
1034                                                                                                                                                 ,jobject  thiz
1035                                                                                                                                                 ,jlong ptr) {
1036         return linphone_friend_get_inc_subscribe_policy((LinphoneFriend*)ptr);
1037 }
1038 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_enableSubscribes(JNIEnv*  env
1039                                                                                                                                                 ,jobject  thiz
1040                                                                                                                                                 ,jlong ptr
1041                                                                                                                                                 ,jboolean value) {
1042         linphone_friend_enable_subscribes((LinphoneFriend*)ptr,value);
1043 }
1044 extern "C" jboolean Java_org_linphone_core_LinphoneFriendImpl_isSubscribesEnabled(JNIEnv*  env
1045                                                                                                                                                 ,jobject  thiz
1046                                                                                                                                                 ,jlong ptr) {
1047         return linphone_friend_subscribes_enabled((LinphoneFriend*)ptr);
1048 }
1049 extern "C" jboolean Java_org_linphone_core_LinphoneFriendImpl_getStatus(JNIEnv*  env
1050                                                                                                                                                 ,jobject  thiz
1051                                                                                                                                                 ,jlong ptr) {
1052         return linphone_friend_get_status((LinphoneFriend*)ptr);
1053 }
1054 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_edit(JNIEnv*  env
1055                                                                                                                                                 ,jobject  thiz
1056                                                                                                                                                 ,jlong ptr) {
1057         return linphone_friend_edit((LinphoneFriend*)ptr);
1058 }
1059 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_done(JNIEnv*  env
1060                                                                                                                                                 ,jobject  thiz
1061                                                                                                                                                 ,jlong ptr) {
1062          linphone_friend_done((LinphoneFriend*)ptr);
1063 }
1064 //LinphoneChatRoom
1065 extern "C" long Java_org_linphone_core_LinphoneChatRoomImpl_getPeerAddress(JNIEnv*  env
1066                                                                                                                                                 ,jobject  thiz
1067                                                                                                                                                 ,jlong ptr) {
1068         return (long) linphone_chat_room_get_peer_address((LinphoneChatRoom*)ptr);
1069 }
1070 extern "C" void Java_org_linphone_core_LinphoneChatRoomImpl_sendMessage(JNIEnv*  env
1071                                                                                                                                                 ,jobject  thiz
1072                                                                                                                                                 ,jlong ptr
1073                                                                                                                                                 ,jstring jmessage) {
1074         const char* message = env->GetStringUTFChars(jmessage, NULL);
1075         linphone_chat_room_send_message((LinphoneChatRoom*)ptr,message);
1076         env->ReleaseStringUTFChars(jmessage, message);
1077
1078 }
1079
1080 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setVideoWindowId(JNIEnv* env
1081                                                                                                                                                 ,jobject thiz
1082                                                                                                                                                 ,jlong lc
1083                                                                                                                                                 ,jobject obj) {
1084         linphone_core_set_native_video_window_id((LinphoneCore*)lc,(unsigned long)obj);
1085 }
1086
1087
1088 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setFirewallPolicy(JNIEnv *env, jobject thiz, jlong lc, int enum_value){
1089         linphone_core_set_firewall_policy((LinphoneCore*)lc,(LinphoneFirewallPolicy)enum_value);
1090 }
1091
1092 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getFirewallPolicy(JNIEnv *env, jobject thiz, jlong lc){
1093         return linphone_core_get_firewall_policy((LinphoneCore*)lc);
1094 }
1095
1096 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setStunServer(JNIEnv *env, jobject thiz, jlong lc, jstring jserver){
1097         const char* server = NULL;
1098         if (jserver) server=env->GetStringUTFChars(jserver, NULL);
1099         linphone_core_set_stun_server((LinphoneCore*)lc,server);
1100         if (server) env->ReleaseStringUTFChars(jserver,server);
1101 }
1102
1103 extern "C" jstring Java_org_linphone_core_LinphoneCoreImpl_getStunServer(JNIEnv *env, jobject thiz, jlong lc){
1104         const char *ret= linphone_core_get_stun_server((LinphoneCore*)lc);
1105         if (ret==NULL) return NULL;
1106         jstring jvalue =env->NewStringUTF(ret);
1107         return jvalue;
1108 }
1109
1110 extern "C" void Java_org_linphone_core_LinphoneCallParamsImpl_audioBandwidth(JNIEnv *env, jobject thiz, jlong lcp, jint bw){
1111         linphone_call_params_set_audio_bandwidth_limit((LinphoneCallParams*)lcp, bw);
1112 }
1113
1114 extern "C" void Java_org_linphone_core_LinphoneCallParamsImpl_enableVideo(JNIEnv *env, jobject thiz, jlong lcp, jboolean b){
1115         linphone_call_params_enable_video((LinphoneCallParams*)lcp, b);
1116 }
1117
1118 extern "C" jboolean Java_org_linphone_core_LinphoneCallParamsImpl_getVideoEnabled(JNIEnv *env, jobject thiz, jlong lcp){
1119         return linphone_call_params_video_enabled((LinphoneCallParams*)lcp);
1120 }
1121 extern "C" void Java_org_linphone_core_LinphoneCallParamsImpl_destroy(JNIEnv *env, jobject thiz, jlong lc){
1122         return linphone_call_params_destroy((LinphoneCallParams*)lc);
1123 }
1124 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_createDefaultCallParams(JNIEnv *env, jobject thiz, jlong lc){
1125         return (jlong) linphone_core_create_default_call_parameters((LinphoneCore*)lc);
1126 }
1127
1128 extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_getCurrentParamsCopy(JNIEnv *env, jobject thiz, jlong lc){
1129         return (jlong) linphone_call_params_copy(linphone_call_get_current_params((LinphoneCall*)lc));
1130 }
1131
1132 extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_enableCamera(JNIEnv *env, jobject thiz, jlong lc, jboolean b){
1133         linphone_call_enable_camera((LinphoneCall *)lc, (bool_t) b);
1134 }
1135
1136 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_inviteAddressWithParams(JNIEnv *env, jobject thiz, jlong lc, jlong addr, jlong params){
1137         return (jlong) linphone_core_invite_address_with_params((LinphoneCore *)lc, (const LinphoneAddress *)addr, (const LinphoneCallParams *)params);
1138 }
1139
1140 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_updateAddressWithParams(JNIEnv *env, jobject thiz, jlong lc, jlong call, jlong params){
1141         return (jint) linphone_core_update_call((LinphoneCore *)lc, (LinphoneCall *)call, (LinphoneCallParams *)params);
1142 }
1143
1144 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_updateCall(JNIEnv *env, jobject thiz, jlong lc, jlong call, jlong params){
1145         return (jint) linphone_core_update_call((LinphoneCore *)lc, (LinphoneCall *)call, (const LinphoneCallParams *)params);
1146 }
1147
1148
1149 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPreferredVideoSize(JNIEnv *env, jobject thiz, jlong lc, jint width, jint height){
1150         MSVideoSize vsize;
1151         vsize.width = (int)width;
1152         vsize.height = (int)height;
1153         linphone_core_set_preferred_video_size((LinphoneCore *)lc, vsize);
1154 }
1155
1156 extern "C" jintArray Java_org_linphone_core_LinphoneCoreImpl_getPreferredVideoSize(JNIEnv *env, jobject thiz, jlong lc){
1157         MSVideoSize vsize = linphone_core_get_preferred_video_size((LinphoneCore *)lc);
1158     jintArray arr = env->NewIntArray(2);
1159         int tVsize [2]= {vsize.width,vsize.height};
1160     env->SetIntArrayRegion(arr, 0, 2, tVsize);
1161     return arr;
1162 }
1163
1164 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setDownloadBandwidth(JNIEnv *env, jobject thiz, jlong lc, jint bw){
1165         linphone_core_set_download_bandwidth((LinphoneCore *)lc, (int) bw);
1166 }
1167
1168 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setUploadBandwidth(JNIEnv *env, jobject thiz, jlong lc, jint bw){
1169         linphone_core_set_upload_bandwidth((LinphoneCore *)lc, (int) bw);
1170 }
1171 extern "C" int Java_org_linphone_core_LinphoneProxyConfigImpl_getState(JNIEnv*  env,jobject thiz,jlong ptr) {
1172         return (int) linphone_proxy_config_get_state((const LinphoneProxyConfig *) ptr);
1173 }
1174 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setExpires(JNIEnv*  env,jobject thiz,jlong ptr,jint delay) {
1175         linphone_proxy_config_expires((LinphoneProxyConfig *) ptr, (int) delay);
1176 }
1177
1178 extern "C" jint Java_org_linphone_core_LinphoneCallImpl_getDuration(JNIEnv*  env,jobject thiz,jlong ptr) {
1179         linphone_call_get_duration((LinphoneCall *) ptr);
1180 }
1181         
1182 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getSignalingTransportPort(JNIEnv* env,jobject thiz,jlong ptr, jint code) {
1183         LCSipTransports tr;
1184         linphone_core_get_sip_transports((LinphoneCore *) ptr, &tr);
1185                 switch (code) {
1186         case 0:
1187                 return tr.udp_port;
1188         case 1:
1189                 return tr.tcp_port;
1190         case 3:
1191                 return tr.tls_port;
1192         default:
1193                 return -2;
1194         }
1195 }
1196
1197 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setSignalingTransportPorts(JNIEnv*  env,jobject thiz,jlong ptr,jint udp, jint tcp, jint tls) {
1198         LinphoneCore *lc = (LinphoneCore *) ptr;
1199         LCSipTransports tr;
1200         tr.udp_port = udp;
1201         tr.tcp_port = tcp;
1202         tr.tls_port = tls;
1203         
1204         linphone_core_set_sip_transports(lc, &tr); // tr will be copied
1205 }
1206
1207 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_enableIpv6(JNIEnv* env,jobject  thiz
1208               ,jlong lc, jboolean enable) {
1209               linphone_core_enable_ipv6((LinphoneCore*)lc,enable);
1210 }