From 53a6987b89e5cb5d77becaf750814ae074b826e4 Mon Sep 17 00:00:00 2001 From: jehan monnier Date: Mon, 1 Mar 2010 10:42:39 +0100 Subject: [PATCH 1/2] add network state management api --- coreapi/linphonecore.c | 28 +++++++++++++++++++++++----- coreapi/linphonecore.h | 16 ++++++++++++++++ 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index bc12c08e5..bb1992419 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -655,7 +655,7 @@ static void sip_config_read(LinphoneCore *lc) lc->sip_conf.sdp_200_ack=lp_config_get_int(lc->config,"sip","sdp_200_ack",0); lc->sip_conf.only_one_codec=lp_config_get_int(lc->config,"sip","only_one_codec",0); lc->sip_conf.register_only_when_network_is_up= - lp_config_get_int(lc->config,"sip","register_only_when_network_is_up",0); + lp_config_get_int(lc->config,"sip","register_only_when_network_is_up",1); } static void rtp_config_read(LinphoneCore *lc) @@ -1403,7 +1403,7 @@ static void linphone_core_disconnected(LinphoneCore *lc){ } static void proxy_update(LinphoneCore *lc, time_t curtime){ - bool_t doit=FALSE; + static time_t last_check=0; static bool_t last_status=FALSE; if (lc->sip_conf.register_only_when_network_is_up){ @@ -1418,9 +1418,10 @@ static void proxy_update(LinphoneCore *lc, time_t curtime){ } last_check=curtime; } - doit=last_status; - }else doit=TRUE; - if (doit) ms_list_for_each(lc->sip_conf.proxies,(void (*)(void*))&linphone_proxy_config_update); + linphone_core_set_network_reachable(lc,last_status); + }else { + ms_list_for_each(lc->sip_conf.proxies,(void (*)(void*))&linphone_proxy_config_update); + } } static void assign_buddy_info(LinphoneCore *lc, BuddyInfo *info){ @@ -3488,6 +3489,23 @@ static void linphone_core_uninit(LinphoneCore *lc) gstate_new_state(lc, GSTATE_POWER_OFF, NULL); } +void linphone_core_set_network_reachable(LinphoneCore* lc,bool_t isReachable) { + // first get the list of available proxies + const MSList *elem=linphone_core_get_proxy_config_list(lc); + for(;elem!=NULL;elem=elem->next){ + LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)elem->data; + if (linphone_proxy_config_register_enabled(cfg) ) { + if (!isReachable) { + cfg->registered=0; + cfg->commit=TRUE; + } else { + linphone_proxy_config_update(cfg); + } + } + + } + +} /** * Destroys a LinphoneCore * diff --git a/coreapi/linphonecore.h b/coreapi/linphonecore.h index 9ce867053..85208fc67 100644 --- a/coreapi/linphonecore.h +++ b/coreapi/linphonecore.h @@ -657,6 +657,10 @@ typedef struct _LinphoneCore int rsvp_enable; int rpc_enable; #endif + /*set this field to false if application manage the network connection state + * In case of false, network state must be communicate to linphone core with method linphone_core_ + */ + bool_t auto_net_state_mon; } LinphoneCore; @@ -897,6 +901,18 @@ const LinphoneAddress *linphone_core_get_remote_uri(LinphoneCore *lc); int linphone_core_get_mtu(const LinphoneCore *lc); void linphone_core_set_mtu(LinphoneCore *lc, int mtu); +/** + * Calling this method with false disable automatiic + */ +void linphone_core_enable_auto_net_stat_mon(LinphoneCore* lc,bool_t value); +/** + * This method is called by the application to notify the linphone core library when network is reachable. + * Calling this method with true trigger linphone to initiate a registration process for all proxy + * configuration with parameter register set to enable + * + */ +void linphone_core_set_network_reachable(LinphoneCore* lc,bool_t value); + bool_t linphone_core_is_in_main_thread(LinphoneCore *lc); From 0024812b966d1d34537926a6ae41a59c85c758f3 Mon Sep 17 00:00:00 2001 From: Jehan Monnier Date: Wed, 3 Mar 2010 14:20:16 +0100 Subject: [PATCH 2/2] fix network state manual management --- coreapi/linphonecore.c | 11 +++++++++-- coreapi/linphonecore.h | 10 ++++------ coreapi/linphonecore_jni.cc | 6 ++++++ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index bb1992419..5f94e634e 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -951,7 +951,8 @@ static void linphone_core_init (LinphoneCore * lc, const LinphoneCoreVTable *vta ms_mutex_init(&lc->lock,NULL); lc->vtable.display_status(lc,_("Ready")); gstate_new_state(lc, GSTATE_POWER_ON, NULL); - lc->ready=TRUE; + lc->auto_net_state_mon=TRUE; + lc->ready=TRUE; } /** @@ -3490,7 +3491,13 @@ static void linphone_core_uninit(LinphoneCore *lc) } void linphone_core_set_network_reachable(LinphoneCore* lc,bool_t isReachable) { - // first get the list of available proxies + //first disable automatic mode + if (lc->auto_net_state_mon) { + ms_message("Disabling automatic network state monitoring"); + lc->auto_net_state_mon=FALSE; + } + ms_message("Network state is now [%s]",isReachable?"UP":"DOWN"); + // second get the list of available proxies const MSList *elem=linphone_core_get_proxy_config_list(lc); for(;elem!=NULL;elem=elem->next){ LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)elem->data; diff --git a/coreapi/linphonecore.h b/coreapi/linphonecore.h index 85208fc67..0796a6d05 100644 --- a/coreapi/linphonecore.h +++ b/coreapi/linphonecore.h @@ -657,7 +657,7 @@ typedef struct _LinphoneCore int rsvp_enable; int rpc_enable; #endif - /*set this field to false if application manage the network connection state + /*set this field to false if application manage network connection state * In case of false, network state must be communicate to linphone core with method linphone_core_ */ bool_t auto_net_state_mon; @@ -901,14 +901,12 @@ const LinphoneAddress *linphone_core_get_remote_uri(LinphoneCore *lc); int linphone_core_get_mtu(const LinphoneCore *lc); void linphone_core_set_mtu(LinphoneCore *lc, int mtu); -/** - * Calling this method with false disable automatiic - */ -void linphone_core_enable_auto_net_stat_mon(LinphoneCore* lc,bool_t value); + /** * This method is called by the application to notify the linphone core library when network is reachable. * Calling this method with true trigger linphone to initiate a registration process for all proxy - * configuration with parameter register set to enable + * configuration with parameter register set to enable. + * This method disable the automatic registration mode. It means you must call this method after each network state changes * */ void linphone_core_set_network_reachable(LinphoneCore* lc,bool_t value); diff --git a/coreapi/linphonecore_jni.cc b/coreapi/linphonecore_jni.cc index b0ffbbf80..1c14757ca 100644 --- a/coreapi/linphonecore_jni.cc +++ b/coreapi/linphonecore_jni.cc @@ -261,6 +261,12 @@ extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getNumberOfCallLogs( JNI ,jlong lc) { return ms_list_size(linphone_core_get_call_logs((LinphoneCore*)lc)); } +extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setNetworkStateReachable( JNIEnv* env + ,jobject thiz + ,jlong lc + ,jboolean isReachable) { + linphone_core_set_network_reachable((LinphoneCore*)lc,isReachable); +} //ProxyConfig