Commit ba47dd54 authored by Mickaël Turnel's avatar Mickaël Turnel

Network monitoring for platforms others than Android and iOS is now done in a...

Network monitoring for platforms others than Android and iOS is now done in a generic platform helper
parent 54361fd7
......@@ -2335,7 +2335,7 @@ static void linphone_core_init(LinphoneCore * lc, LinphoneCoreCbs *cbs, LpConfig
lc->platform_helper = LinphonePrivate::createIosPlatformHelpers(lc, system_context);
#endif
if (lc->platform_helper == NULL)
lc->platform_helper = new LinphonePrivate::StubbedPlatformHelpers(lc);
lc->platform_helper = new LinphonePrivate::GenericPlatformHelpers(lc);
msplugins_dir = linphone_factory_get_msplugins_dir(lfactory);
image_resources_dir = linphone_factory_get_image_resources_dir(lfactory);
......@@ -2375,7 +2375,6 @@ static void linphone_core_init(LinphoneCore * lc, LinphoneCoreCbs *cbs, LpConfig
lc->tunnel=linphone_core_tunnel_new(lc);
#endif
lc->network_last_check = 0;
lc->network_last_status = FALSE;
lc->network_reachable = TRUE;
......@@ -3261,38 +3260,6 @@ static void notify_network_reachable_change (LinphoneCore *lc) {
linphone_core_resolve_stun_server(lc);
}
static void monitor_network_state(LinphoneCore *lc, time_t curtime){
bool_t new_status=lc->network_last_status;
char newip[LINPHONE_IPADDR_SIZE];
// only do the network up checking every five seconds
if (lc->network_last_check==0 || (curtime-lc->network_last_check)>=5){
linphone_core_get_local_ip(lc,AF_UNSPEC,NULL,newip);
if (strcmp(newip,"::1")!=0 && strcmp(newip,"127.0.0.1")!=0){
new_status=TRUE;
}else new_status=FALSE; //no network
if (new_status==lc->network_last_status && new_status==TRUE && strcmp(newip,lc->localip)!=0){
//IP address change detected
ms_message("IP address change detected.");
set_network_reachable(lc,FALSE,curtime);
lc->network_last_status=FALSE;
}
strncpy(lc->localip,newip,sizeof(lc->localip));
if (new_status!=lc->network_last_status) {
if (new_status){
ms_message("New local ip address is %s",lc->localip);
}
set_network_reachable(lc,new_status, curtime);
lc->network_last_status=new_status;
}
lc->network_last_check=curtime;
}
notify_network_reachable_change(lc);
}
static void proxy_update(LinphoneCore *lc){
bctbx_list_t *elem,*next;
bctbx_list_for_each(lc->sip_conf.proxies,(void (*)(void*))&linphone_proxy_config_update);
......@@ -3437,7 +3404,6 @@ void linphone_core_iterate(LinphoneCore *lc){
lc->sal->iterate();
if (lc->msevq) ms_event_queue_pump(lc->msevq);
//if (lc->auto_net_state_mon) monitor_network_state(lc, current_real_time);
proxy_update(lc);
......
......@@ -769,7 +769,6 @@ namespace LinphonePrivate {
char* zrtp_secrets_cache; \
char* user_certificates_path; \
LinphoneVideoPolicy video_policy; \
time_t network_last_check; \
LinphoneNatPolicy *nat_policy; \
LinphoneImNotifPolicy *im_notif_policy; \
bool_t use_files; \
......
......@@ -18,6 +18,8 @@
*/
#include "platform-helpers.h"
#include "logger/logger.h"
#include "c-wrapper/c-wrapper.h"
// =============================================================================
......@@ -25,44 +27,91 @@ using namespace std;
LINPHONE_BEGIN_NAMESPACE
StubbedPlatformHelpers::StubbedPlatformHelpers (LinphoneCore *lc) : PlatformHelpers(lc) {}
GenericPlatformHelpers::GenericPlatformHelpers (LinphoneCore *lc) : PlatformHelpers(lc) {}
void StubbedPlatformHelpers::setDnsServers () {}
GenericPlatformHelpers::~GenericPlatformHelpers () {
if (mMonitorTimer) {
if (mCore && mCore->sal) mCore->sal->cancelTimer(mMonitorTimer);
belle_sip_object_unref(mMonitorTimer);
mMonitorTimer = nullptr;
}
}
void GenericPlatformHelpers::setDnsServers () {}
void StubbedPlatformHelpers::acquireWifiLock () {}
void GenericPlatformHelpers::acquireWifiLock () {}
void StubbedPlatformHelpers::releaseWifiLock () {}
void GenericPlatformHelpers::releaseWifiLock () {}
void StubbedPlatformHelpers::acquireMcastLock () {}
void GenericPlatformHelpers::acquireMcastLock () {}
void StubbedPlatformHelpers::releaseMcastLock () {}
void GenericPlatformHelpers::releaseMcastLock () {}
void StubbedPlatformHelpers::acquireCpuLock () {}
void GenericPlatformHelpers::acquireCpuLock () {}
void StubbedPlatformHelpers::releaseCpuLock () {}
void GenericPlatformHelpers::releaseCpuLock () {}
string StubbedPlatformHelpers::getDataPath () {
string GenericPlatformHelpers::getDataPath () {
return "";
}
string StubbedPlatformHelpers::getConfigPath () {
string GenericPlatformHelpers::getConfigPath () {
return "";
}
void StubbedPlatformHelpers::setVideoPreviewWindow (void *windowId) {}
void GenericPlatformHelpers::setVideoPreviewWindow (void *windowId) {}
void GenericPlatformHelpers::setVideoWindow (void *windowId) {}
void StubbedPlatformHelpers::setVideoWindow (void *windowId) {}
void GenericPlatformHelpers::setNetworkReachable (bool reachable) {
mNetworkReachable = reachable;
linphone_core_set_network_reachable_internal(mCore, reachable);
}
bool GenericPlatformHelpers::isNetworkReachable () {
return mNetworkReachable;
}
void StubbedPlatformHelpers::setNetworkReachable (bool reachable) {}
void GenericPlatformHelpers::onLinphoneCoreReady (bool monitoringEnabled) {
if (!monitoringEnabled) return;
bool StubbedPlatformHelpers::isNetworkReachable () {
return true;
if (!mMonitorTimer) {
mMonitorTimer = mCore->sal->createTimer(monitorTimerExpired, this,
mDefaultMonitorTimeout * 1000, "monitor network timeout");
} else {
belle_sip_source_set_timeout(mMonitorTimer, mDefaultMonitorTimeout * 1000);
}
}
void StubbedPlatformHelpers::onLinphoneCoreReady (bool monitoringEnabled) {}
void GenericPlatformHelpers::onWifiOnlyEnabled (bool enabled) {}
void StubbedPlatformHelpers::onWifiOnlyEnabled (bool enabled) {}
void GenericPlatformHelpers::setHttpProxy (string host, int port) {}
void StubbedPlatformHelpers::setHttpProxy (string host, int port) {}
int GenericPlatformHelpers::monitorTimerExpired (void *data, unsigned int revents) {
GenericPlatformHelpers *helper = static_cast<GenericPlatformHelpers *>(data);
LinphoneCore *core = helper->getCore();
char newIp[LINPHONE_IPADDR_SIZE];
linphone_core_get_local_ip(core, AF_UNSPEC, nullptr, newIp);
bool status = strcmp(newIp,"::1") != 0 && strcmp(newIp,"127.0.0.1") != 0;
if (status && core->network_last_status && strcmp(newIp, core->localip) != 0) {
lInfo() << "IP address change detected";
helper->setNetworkReachable(false);
core->network_last_status = FALSE;
}
strncpy(core->localip, newIp, sizeof core->localip);
if (bool_t(status) != core->network_last_status) {
if (status) {
lInfo() << "New local ip address is " << core->localip;
}
helper->setNetworkReachable(status);
core->network_last_status = status;
}
return BELLE_SIP_CONTINUE;
}
LINPHONE_END_NAMESPACE
......@@ -24,6 +24,9 @@
#include "linphone/utils/general.h"
// TODO: Remove me later.
#include "private.h"
// =============================================================================
L_DECL_C_STRUCT(LinphoneCore);
......@@ -64,10 +67,10 @@ protected:
LinphoneCore *mCore;
};
class StubbedPlatformHelpers : public PlatformHelpers {
class GenericPlatformHelpers : public PlatformHelpers {
public:
explicit StubbedPlatformHelpers (LinphoneCore *lc);
virtual ~StubbedPlatformHelpers () = default;
explicit GenericPlatformHelpers (LinphoneCore *lc);
~GenericPlatformHelpers ();
void setDnsServers () override;
void acquireWifiLock () override;
......@@ -85,6 +88,15 @@ public:
void onLinphoneCoreReady (bool monitoringEnabled) override;
void onWifiOnlyEnabled (bool enabled) override;
void setHttpProxy (std::string host, int port) override;
private:
static int monitorTimerExpired (void *data, unsigned int revents);
private:
static const int mDefaultMonitorTimeout = 5;
belle_sip_source_t *mMonitorTimer;
bool mNetworkReachable;
};
PlatformHelpers *createAndroidPlatformHelpers (LinphoneCore *lc, void *systemContext);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment