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