diff --git a/coreapi/TunnelManager.cc b/coreapi/TunnelManager.cc index d2fe02120..0a7545623 100644 --- a/coreapi/TunnelManager.cc +++ b/coreapi/TunnelManager.cc @@ -96,6 +96,7 @@ RtpTransport *TunnelManager::createRtpTransport(int port){ } void TunnelManager::startClient() { + ms_message("TunnelManager: Starting tunnel client"); if (mTunnelClient == NULL) { mTunnelClient = new TunnelClient(); mTunnelClient->setCallback((TunnelClientController::StateCallback)tunnelCallback,this); @@ -115,6 +116,7 @@ void TunnelManager::startClient() { } void TunnelManager::stopClient(){ + ms_message("TunnelManager: Stopping tunnel client"); linphone_core_set_rtp_transport_factories(mCore,NULL); sal_disable_tunnel(mCore->sal); if (mTunnelClient){ @@ -182,10 +184,12 @@ void TunnelManager::doRegistration(){ LinphoneProxyConfig* lProxy; linphone_core_get_default_proxy(mCore, &lProxy); if (lProxy) { + ms_message("TunnelManager: need to register"); if(linphone_proxy_config_get_state(lProxy) != LinphoneRegistrationProgress) { linphone_proxy_config_refresh_register(lProxy); mScheduledRegistration = false; } else { + ms_warning("TunnelManager: register difered. There is already a registration in progress"); mScheduledRegistration = true; } } else { @@ -196,7 +200,7 @@ void TunnelManager::doRegistration(){ void TunnelManager::processTunnelEvent(const Event &ev){ if (ev.mData.mConnected){ - ms_message("Tunnel is up, registering now"); + ms_message("Tunnel is connected"); doRegistration(); } else { ms_error("Tunnel has been disconnected"); @@ -206,6 +210,9 @@ void TunnelManager::processTunnelEvent(const Event &ev){ void TunnelManager::setMode(LinphoneTunnelMode mode) { if(mMode != mode) { + ms_message("TunnelManager: Switching mode from %s to %s", + tunnel_mode_to_string(mMode), + tunnel_mode_to_string(mode)); switch(mode) { case LinphoneTunnelModeEnable: mMode = mode; @@ -235,6 +242,7 @@ void TunnelManager::tunnelCallback(bool connected, TunnelManager *zis){ void TunnelManager::onIterate(){ if(mScheduledRegistration) { + ms_message("Apply difered registration"); doRegistration(); } mMutex.lock(); @@ -303,18 +311,19 @@ LinphoneTunnelMode TunnelManager::getMode() const { void TunnelManager::processUdpMirrorEvent(const Event &ev){ if (ev.mData.mHaveUdp) { - LOGI("Tunnel is not required, disabling"); + ms_message("TunnelManager: auto detection test succeed"); stopClient(); doRegistration(); mAutoDetecting = false; } else { + ms_message("TunnelManager: auto detection test failed"); mCurrentUdpMirrorClient++; if (mCurrentUdpMirrorClient !=mUdpMirrorClients.end()) { - LOGI("Tunnel is required, enabling; Trying backup udp mirror"); + ms_message("TunnelManager: trying another udp mirror"); UdpMirrorClient &lUdpMirrorClient=*mCurrentUdpMirrorClient; lUdpMirrorClient.start(TunnelManager::sUdpMirrorClientCallback,(void*)this); } else { - LOGI("Tunnel is required, enabling; no backup udp mirror available"); + ms_message("TunnelManager: all auto detection failed. Need ti enable tunnel"); startClient(); mAutoDetecting = false; } @@ -344,11 +353,11 @@ void TunnelManager::networkReachableCb(LinphoneCore *lc, bool_t reachable) { void TunnelManager::autoDetect() { if(mAutoDetecting) { - LOGE("Cannot start auto detection. One auto detection is going on"); + ms_error("TunnelManager: Cannot start auto detection. One auto detection is going on"); return; } if (mUdpMirrorClients.empty()) { - LOGE("No UDP mirror server configured aborting auto detection"); + ms_error("TunnelManager: No UDP mirror server configured aborting auto detection"); return; } mCurrentUdpMirrorClient = mUdpMirrorClients.begin(); diff --git a/coreapi/linphone_tunnel.cc b/coreapi/linphone_tunnel.cc index 8abeb3b05..beabd43a8 100644 --- a/coreapi/linphone_tunnel.cc +++ b/coreapi/linphone_tunnel.cc @@ -31,9 +31,6 @@ static const char *_tunnel_mode_str[3] = { "disable", "enable", "auto" }; -static LinphoneTunnelMode _string_to_tunnel_mode(const char *string); -static const char *_tunnel_mode_to_string(LinphoneTunnelMode mode); - LinphoneTunnel* linphone_core_get_tunnel(const LinphoneCore *lc){ return lc->tunnel; } @@ -237,7 +234,7 @@ void linphone_tunnel_clean_servers(LinphoneTunnel *tunnel){ } void linphone_tunnel_set_mode(LinphoneTunnel *tunnel, LinphoneTunnelMode mode){ - lp_config_set_string(config(tunnel),"tunnel","mode", _tunnel_mode_to_string(mode)); + lp_config_set_string(config(tunnel),"tunnel","mode", tunnel_mode_to_string(mode)); bcTunnel(tunnel)->setMode(mode); } @@ -335,7 +332,7 @@ static void my_ortp_logv(OrtpLogLevel level, const char *fmt, va_list args){ ortp_logv(level,fmt,args); } -static LinphoneTunnelMode _string_to_tunnel_mode(const char *string) { +LinphoneTunnelMode string_to_tunnel_mode(const char *string) { if(string != NULL) { int i; for(i=0; i<3 && strcmp(string, _tunnel_mode_str[i]) != 0; i++); @@ -350,7 +347,7 @@ static LinphoneTunnelMode _string_to_tunnel_mode(const char *string) { } } -static const char *_tunnel_mode_to_string(LinphoneTunnelMode mode) { +const char *tunnel_mode_to_string(LinphoneTunnelMode mode) { return _tunnel_mode_str[mode]; } @@ -359,7 +356,7 @@ static const char *_tunnel_mode_to_string(LinphoneTunnelMode mode) { * Called internally from linphonecore at startup. */ void linphone_tunnel_configure(LinphoneTunnel *tunnel){ - LinphoneTunnelMode mode = _string_to_tunnel_mode(lp_config_get_string(config(tunnel), "tunnel", "mode", NULL)); + LinphoneTunnelMode mode = string_to_tunnel_mode(lp_config_get_string(config(tunnel), "tunnel", "mode", NULL)); bool_t tunnelizeSIPPackets = (bool_t)lp_config_get_int(config(tunnel), "tunnel", "sip", TRUE); linphone_tunnel_enable_logs_with_handler(tunnel,TRUE,my_ortp_logv); linphone_tunnel_load_config(tunnel); diff --git a/coreapi/linphone_tunnel.h b/coreapi/linphone_tunnel.h index fa8317d1d..e07b33d7a 100644 --- a/coreapi/linphone_tunnel.h +++ b/coreapi/linphone_tunnel.h @@ -56,6 +56,21 @@ typedef enum _LinphoneTunnelMode { LinphoneTunnelModeAuto } LinphoneTunnelMode; +/** + * @brief Convert a string into LinphoneTunnelMode enum + * @param string String to convert + * @return An LinphoneTunnelMode enum. If the passed string is NULL or + * does not match with any mode, the LinphoneTunnelModeDisable is returned. + */ +LINPHONE_PUBLIC LinphoneTunnelMode string_to_tunnel_mode(const char *string); + +/** + * @brief Convert a tunnel mode enum into string + * @param mode Enum to convert + * @return "disable", "enable" or "auto" + */ +LINPHONE_PUBLIC const char *tunnel_mode_to_string(LinphoneTunnelMode mode); + /** * Create a new tunnel configuration */