From 2b80393ff4ccf2e2c1b206cc166d3ac5ff4032b7 Mon Sep 17 00:00:00 2001 From: Jehan Monnier Date: Mon, 24 Jan 2011 16:38:29 +0100 Subject: [PATCH] add linphone_core_enable_keep_alive --- coreapi/linphonecore.c | 17 ++++++++++++++++- coreapi/linphonecore.h | 8 ++++++++ coreapi/linphonecore_jni.cc | 11 +++++++++++ coreapi/sal.h | 5 +++++ coreapi/sal_eXosip2.c | 3 +++ java/common/org/linphone/core/LinphoneCore.java | 10 +++++++++- 6 files changed, 52 insertions(+), 2 deletions(-) diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index ef145c2fd..7252a5490 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -4037,4 +4037,19 @@ const char *linphone_error_to_string(LinphoneReason err){ } return "unknown error"; } - +/** + * enable signaling keep alive + */ +void linphone_core_enable_keep_alive(LinphoneCore* lc,bool_t enable) { + if (enable > 0) { + sal_set_keepalive_period(lc->sal,lc->sip_conf.keepalive_period); + } else { + sal_set_keepalive_period(lc->sal,0); + } +} +/** + * Is signaling keep alive + */ +bool_t linphone_core_keep_alive_enabled(LinphoneCore* lc) { + return sal_get_keepalive_period(lc->sal) > 0; +} diff --git a/coreapi/linphonecore.h b/coreapi/linphonecore.h index 0b9823f3c..6ad65d8d4 100644 --- a/coreapi/linphonecore.h +++ b/coreapi/linphonecore.h @@ -919,6 +919,14 @@ void linphone_core_set_network_reachable(LinphoneCore* lc,bool_t value); */ bool_t linphone_core_is_network_reachabled(LinphoneCore* lc); +/** + * enable signaling keep alive. small udp packet sent periodically to keep udp NAT association + */ +void linphone_core_enable_keep_alive(LinphoneCore* lc,bool_t enable); +/** + * Is signaling keep alive + */ +bool_t linphone_core_keep_alive_enabled(LinphoneCore* lc); void *linphone_core_get_user_data(LinphoneCore *lc); diff --git a/coreapi/linphonecore_jni.cc b/coreapi/linphonecore_jni.cc index fbd8f01ea..93ea0012e 100644 --- a/coreapi/linphonecore_jni.cc +++ b/coreapi/linphonecore_jni.cc @@ -614,8 +614,19 @@ extern "C" jstring Java_org_linphone_core_LinphoneCoreImpl_getRing(JNIEnv* env return NULL; } } +extern "C" void Java_org_linphone_core_LinphoneCoreImpl_enableKeepAlive(JNIEnv* env + ,jobject thiz + ,jlong lc + ,jboolean enable) { + linphone_core_enable_keep_alive((LinphoneCore*)lc,enable); +} +extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isKeepAliveEnabled(JNIEnv* env + ,jobject thiz + ,jlong lc) { + return linphone_core_keep_alive_enabled((LinphoneCore*)lc); +} //ProxyConfig extern "C" jlong Java_org_linphone_core_LinphoneProxyConfigImpl_newLinphoneProxyConfig(JNIEnv* env,jobject thiz) { diff --git a/coreapi/sal.h b/coreapi/sal.h index 359d81883..3434b54c2 100644 --- a/coreapi/sal.h +++ b/coreapi/sal.h @@ -249,6 +249,11 @@ ortp_socket_t sal_get_socket(Sal *ctx); void sal_set_user_agent(Sal *ctx, const char *user_agent); /*keepalive period in ms*/ void sal_set_keepalive_period(Sal *ctx,unsigned int value); +/** + * returns keepalive period in ms + * 0 desactiaved + * */ +unsigned int sal_get_keepalive_period(Sal *ctx); void sal_use_session_timers(Sal *ctx, int expires); void sal_use_one_matching_codec_policy(Sal *ctx, bool_t one_matching_codec); int sal_iterate(Sal *sal); diff --git a/coreapi/sal_eXosip2.c b/coreapi/sal_eXosip2.c index 4203cb85e..f4bc03280 100644 --- a/coreapi/sal_eXosip2.c +++ b/coreapi/sal_eXosip2.c @@ -1982,6 +1982,9 @@ void sal_set_keepalive_period(Sal *ctx,unsigned int value) { ctx->keepalive_period=value; eXosip_set_option (EXOSIP_OPT_UDP_KEEP_ALIVE, &value); } +unsigned int sal_get_keepalive_period(Sal *ctx) { + return ctx->keepalive_period; +} const char * sal_address_get_port(const SalAddress *addr) { const osip_from_t *u=(const osip_from_t*)addr; diff --git a/java/common/org/linphone/core/LinphoneCore.java b/java/common/org/linphone/core/LinphoneCore.java index 3e33bdce6..e0e0d4ba8 100644 --- a/java/common/org/linphone/core/LinphoneCore.java +++ b/java/common/org/linphone/core/LinphoneCore.java @@ -488,5 +488,13 @@ public interface LinphoneCore { public VideoSize getPreferredVideoSize(); public PayloadType[] listVideoCodecs(); - + /** + * enable signaling keep alive. small udp packet sent periodically to keep udp NAT association + */ + void enableKeepAlive(boolean enable); + /** + * get keep elive mode + * @return true if enable + */ + boolean isKeepAliveEnabled(); }