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