Commit 4a7d2211 authored by Nicolas Michon's avatar Nicolas Michon

Moved IOS reachability into platform helpers

parent 56943255
......@@ -6462,8 +6462,6 @@ void linphone_core_set_network_reachable(LinphoneCore *lc, bool_t is_reachable)
lc->sip_network_state.user_state = is_reachable;
lc->media_network_state.user_state = is_reachable;
if (lc->auto_net_state_mon) reachable = reachable && getPlatformHelpers(lc)->isNetworkReachable();
set_sip_network_reachable(lc, reachable, ms_time(NULL));
set_media_network_reachable(lc, reachable);
notify_network_reachable_change(lc);
......@@ -6474,8 +6472,6 @@ void linphone_core_set_media_network_reachable(LinphoneCore *lc, bool_t is_reach
lc->media_network_state.user_state = is_reachable;
if (lc->auto_net_state_mon) reachable = reachable && getPlatformHelpers(lc)->isNetworkReachable();
set_media_network_reachable(lc, reachable);
notify_network_reachable_change(lc);
}
......@@ -6485,8 +6481,6 @@ void linphone_core_set_sip_network_reachable(LinphoneCore *lc, bool_t is_reachab
lc->sip_network_state.user_state = is_reachable;
if (lc->auto_net_state_mon) reachable = reachable && getPlatformHelpers(lc)->isNetworkReachable();
set_sip_network_reachable(lc, reachable, ms_time(NULL));
notify_network_reachable_change(lc);
}
......
......@@ -368,7 +368,7 @@ set(LINPHONE_OBJC_SOURCE_FILES)
if (APPLE)
list(APPEND LINPHONE_OBJC_SOURCE_FILES core/paths/paths-apple.mm)
list(APPEND LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES core/paths/paths-apple.h)
list(APPEND LINPHONE_CXX_OBJECTS_SOURCE_FILES core/platform-helpers/ios-platform-helpers.cpp)
list(APPEND LINPHONE_OBJC_SOURCE_FILES core/platform-helpers/ios-platform-helpers.mm)
elseif (ANDROID)
list(APPEND LINPHONE_CXX_OBJECTS_SOURCE_FILES core/paths/paths-android.cpp core/platform-helpers/android-platform-helpers.cpp)
list(APPEND LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES core/paths/paths-android.h)
......@@ -415,7 +415,7 @@ if(ENABLE_STATIC)
target_include_directories(linphone-static PUBLIC ${LINPHONE_INCLUDE_DIRS})
target_link_libraries(linphone-static INTERFACE ${LIBS})
if(APPLE)
target_link_libraries(linphone-static INTERFACE "-framework Foundation" "-framework AVFoundation")
target_link_libraries(linphone-static INTERFACE "-framework Foundation" "-framework AVFoundation" "-framework SystemConfiguration")
endif()
install(TARGETS linphone-static EXPORT ${EXPORT_TARGETS_NAME}Targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
......@@ -456,7 +456,7 @@ if(ENABLE_SHARED)
target_include_directories(linphone PUBLIC ${LINPHONE_INCLUDE_DIRS})
target_link_libraries(linphone PRIVATE ${LIBS})
if(APPLE)
target_link_libraries(linphone PRIVATE "-framework Foundation" "-framework AVFoundation")
target_link_libraries(linphone PRIVATE "-framework Foundation" "-framework AVFoundation" "-framework SystemConfiguration")
endif()
if(WIN32)
# Export Xerces and Soci symbols.
......
......@@ -58,7 +58,7 @@ public:
void onWifiOnlyEnabled (bool enabled) override;
void setDnsServers () override;
void setNetworkReachable (bool reachable) override;
void setHttpProxy (string host, int port) override;
void setHttpProxy (const string &host, int port) override;
void onLinphoneCoreStart (bool monitoringEnabled) override;
void onLinphoneCoreStop () override;
......@@ -72,29 +72,29 @@ private:
static jmethodID getMethodId (JNIEnv *env, jclass klass, const char *method, const char *signature);
string getNativeLibraryDir();
jobject mJavaHelper = nullptr;
jmethodID mWifiLockAcquireId = nullptr;
jmethodID mWifiLockReleaseId = nullptr;
jmethodID mMcastLockAcquireId = nullptr;
jmethodID mMcastLockReleaseId = nullptr;
jmethodID mCpuLockAcquireId = nullptr;
jmethodID mCpuLockReleaseId = nullptr;
jmethodID mGetDnsServersId = nullptr;
jmethodID mGetPowerManagerId = nullptr;
jmethodID mGetDataPathId = nullptr;
jmethodID mGetConfigPathId = nullptr;
jmethodID mGetDownloadPathId = nullptr;
jmethodID mGetNativeLibraryDirId = nullptr;
jmethodID mSetNativeVideoWindowId = nullptr;
jmethodID mSetNativePreviewVideoWindowId = nullptr;
jmethodID mUpdateNetworkReachabilityId = nullptr;
jmethodID mOnLinphoneCoreStartId = nullptr;
jmethodID mOnLinphoneCoreStopId = nullptr;
jmethodID mOnWifiOnlyEnabledId = nullptr;
jobject mPreviewVideoWindow = nullptr;
jobject mVideoWindow = nullptr;
bool mNetworkReachable = false;
jobject mJavaHelper;
jmethodID mWifiLockAcquireId;
jmethodID mWifiLockReleaseId;
jmethodID mMcastLockAcquireId;
jmethodID mMcastLockReleaseId;
jmethodID mCpuLockAcquireId;
jmethodID mCpuLockReleaseId;
jmethodID mGetDnsServersId;
jmethodID mGetPowerManagerId;
jmethodID mGetDataPathId;
jmethodID mGetConfigPathId;
jmethodID mGetDownloadPathId;
jmethodID mGetNativeLibraryDirId;
jmethodID mSetNativeVideoWindowId;
jmethodID mSetNativePreviewVideoWindowId;
jmethodID mUpdateNetworkReachabilityId;
jmethodID mOnLinphoneCoreStartId;
jmethodID mOnLinphoneCoreStopId;
jmethodID mOnWifiOnlyEnabledId;
jobject mPreviewVideoWindow;
jobject mVideoWindow;
bool mNetworkReachable;
};
static const char *GetStringUTFChars (JNIEnv *env, jstring string) {
......@@ -290,20 +290,19 @@ void AndroidPlatformHelpers::onWifiOnlyEnabled(bool enabled) {
}
}
void AndroidPlatformHelpers::setHttpProxy(string host, int port) {
linphone_core_set_http_proxy_host(getCore()->getCCore(), host.c_str());
linphone_core_set_http_proxy_port(getCore()->getCCore(), port);
void AndroidPlatformHelpers::setHttpProxy(const string &host, int port) {
linphone_core_set_http_proxy_host(getCore(), host.c_str());
linphone_core_set_http_proxy_port(getCore(), port);
}
void AndroidPlatformHelpers::setDnsServers () {
if (!mJavaHelper) {
if (!mJavaHelper || linphone_core_get_dns_set_by_app(mCore)) {
lError() << "AndroidPlatformHelpers' mJavaHelper is null.";
return;
}
if (linphone_core_get_dns_set_by_app(getCore()->getCCore())) return;
JNIEnv *env = ms_get_jni_env();
if (env) {
if (env && mJavaHelper) {
jobjectArray jservers = (jobjectArray)env->CallObjectMethod(mJavaHelper, mGetDnsServersId);
bctbx_list_t *l = nullptr;
if (env->ExceptionCheck()) {
......@@ -316,16 +315,15 @@ void AndroidPlatformHelpers::setDnsServers () {
for (int i = 0; i < count; i++) {
jstring jserver = (jstring)env->GetObjectArrayElement(jservers, i);
const char *str = GetStringUTFChars(env, jserver);
const char *str = env->GetStringUTFChars(jserver, nullptr);
if (str) {
lInfo() << "AndroidPlatformHelpers found DNS server " << str;
l = bctbx_list_append(l, ms_strdup(str));
ReleaseStringUTFChars(env, jserver, str);
env->ReleaseStringUTFChars(jserver, str);
}
}
} else {
lError() << "AndroidPlatformHelpers::setDnsServers() failed to get DNS servers list";
return;
}
linphone_core_set_dns_servers(getCore()->getCCore(), l);
bctbx_list_free_with_data(l, ms_free);
......@@ -417,12 +415,12 @@ PlatformHelpers *createAndroidPlatformHelpers (std::shared_ptr<LinphonePrivate::
}
extern "C" JNIEXPORT void JNICALL Java_org_linphone_core_tools_AndroidPlatformHelper_setNativePreviewWindowId(JNIEnv *env, jobject thiz, jlong ptr, jobject id) {
AndroidPlatformHelpers *androidPlatformHelper = static_cast<AndroidPlatformHelpers *>((void *)ptr);
AndroidPlatformHelpers *androidPlatformHelper = (AndroidPlatformHelpers *)ptr;
androidPlatformHelper->_setPreviewVideoWindow(id);
}
extern "C" JNIEXPORT void JNICALL Java_org_linphone_core_tools_AndroidPlatformHelper_setNativeVideoWindowId(JNIEnv *env, jobject thiz, jlong ptr, jobject id) {
AndroidPlatformHelpers *androidPlatformHelper = static_cast<AndroidPlatformHelpers *>((void *)ptr);
AndroidPlatformHelpers *androidPlatformHelper = (AndroidPlatformHelpers *)ptr;
androidPlatformHelper->_setVideoWindow(id);
}
......@@ -435,7 +433,7 @@ extern "C" JNIEXPORT void JNICALL Java_org_linphone_core_tools_AndroidPlatformHe
}
extern "C" JNIEXPORT void JNICALL Java_org_linphone_core_tools_AndroidPlatformHelper_setHttpProxy(JNIEnv* env, jobject thiz, jlong ptr, jstring host, jint port) {
AndroidPlatformHelpers *androidPlatformHelper = static_cast<AndroidPlatformHelpers *>((void *)ptr);
AndroidPlatformHelpers *androidPlatformHelper = (AndroidPlatformHelpers *)ptr;
const char *hostC = GetStringUTFChars(env, host);
char * httpProxyHost = ms_strdup(hostC);
ReleaseStringUTFChars(env, host, hostC);
......
This diff is collapsed.
/*
* platform-helpers.cpp
* Copyright (C) 2010-2018 Belledonne Communications SARL
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "logger/logger.h"
#include "platform-helpers.h"
// TODO: Remove me.
#include "private.h"
// =============================================================================
using namespace std;
LINPHONE_BEGIN_NAMESPACE
GenericPlatformHelpers::GenericPlatformHelpers (std::shared_ptr<LinphonePrivate::Core> core) : PlatformHelpers(core), mMonitorTimer(nullptr) {}
GenericPlatformHelpers::~GenericPlatformHelpers () {
if (mMonitorTimer) {
if (getCore()->getCCore() && getCore()->getCCore()->sal) getCore()->getCCore()->sal->cancelTimer(mMonitorTimer);
belle_sip_object_unref(mMonitorTimer);
mMonitorTimer = nullptr;
}
}
void GenericPlatformHelpers::acquireWifiLock () {}
void GenericPlatformHelpers::releaseWifiLock () {}
void GenericPlatformHelpers::acquireMcastLock () {}
void GenericPlatformHelpers::releaseMcastLock () {}
void GenericPlatformHelpers::acquireCpuLock () {}
void GenericPlatformHelpers::releaseCpuLock () {}
string GenericPlatformHelpers::getConfigPath () const {
return "";
}
string GenericPlatformHelpers::getDataPath () const {
return "";
}
string GenericPlatformHelpers::getDataResource (const string &filename) const {
return getFilePath(
linphone_factory_get_data_resources_dir(linphone_factory_get()),
filename
);
}
string GenericPlatformHelpers::getImageResource (const string &filename) const {
return getFilePath(
linphone_factory_get_image_resources_dir(linphone_factory_get()),
filename
);
}
string GenericPlatformHelpers::getRingResource (const string &filename) const {
return getFilePath(
linphone_factory_get_ring_resources_dir(linphone_factory_get()),
filename
);
}
string GenericPlatformHelpers::getSoundResource (const string &filename) const {
return getFilePath(
linphone_factory_get_sound_resources_dir(linphone_factory_get()),
filename
);
}
void GenericPlatformHelpers::setVideoPreviewWindow (void *windowId) {}
void GenericPlatformHelpers::setVideoWindow (void *windowId) {}
bool GenericPlatformHelpers::isNetworkReachable () {
return mNetworkReachable;
}
void GenericPlatformHelpers::onWifiOnlyEnabled (bool enabled) {}
void GenericPlatformHelpers::setDnsServers () {}
void GenericPlatformHelpers::setHttpProxy (string host, int port) {}
void GenericPlatformHelpers::setNetworkReachable (bool reachable) {
mNetworkReachable = reachable;
linphone_core_set_network_reachable_internal(getCore()->getCCore(), reachable);
}
void GenericPlatformHelpers::onLinphoneCoreStart (bool monitoringEnabled) {
if (!monitoringEnabled) return;
if (!mMonitorTimer) {
mMonitorTimer = getCore()->getCCore()->sal->createTimer(
monitorTimerExpired,
this,
DefaultMonitorTimeout * 1000,
"monitor network timeout"
);
} else {
belle_sip_source_set_timeout(mMonitorTimer, DefaultMonitorTimeout * 1000);
}
// Get ip right now to avoid waiting for 5s
monitorTimerExpired(this, 0);
}
void GenericPlatformHelpers::onLinphoneCoreStop () {}
int GenericPlatformHelpers::monitorTimerExpired (void *data, unsigned int revents) {
GenericPlatformHelpers *helper = static_cast<GenericPlatformHelpers *>(data);
LinphoneCore *core = helper->getCore()->getCCore();
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;
}
string GenericPlatformHelpers::getDownloadPath () {
return "";
}
LINPHONE_END_NAMESPACE
......@@ -57,6 +57,9 @@ public:
virtual std::string getRingResource (const std::string &filename) const = 0;
virtual std::string getSoundResource (const std::string &filename) const = 0;
virtual std::string getWifiSSID() = 0;
virtual void setWifiSSID(const std::string &ssid) = 0;
virtual void setVideoPreviewWindow (void *windowId) = 0;
virtual std::string getDownloadPath () = 0;
virtual void setVideoWindow (void *windowId) = 0;
......@@ -65,9 +68,12 @@ public:
virtual bool isNetworkReachable () = 0;
virtual void onWifiOnlyEnabled (bool enabled) = 0;
virtual void setDnsServers () = 0;
virtual void setHttpProxy (std::string host, int port) = 0;
virtual void setHttpProxy (const std::string &host, int port) = 0;
virtual void setNetworkReachable (bool reachable) = 0;
virtual bool startNetworkMonitoring() = 0;
virtual void stopNetworkMonitoring() = 0;
virtual void onLinphoneCoreStart (bool monitoringEnabled) = 0;
virtual void onLinphoneCoreStop () = 0;
......@@ -100,26 +106,38 @@ public:
std::string getRingResource (const std::string &filename) const override;
std::string getSoundResource (const std::string &filename) const override;
std::string getWifiSSID() override;
void setWifiSSID(const std::string &ssid) override;
void setVideoPreviewWindow (void *windowId) override;
void setVideoWindow (void *windowId) override;
bool isNetworkReachable () override;
void onWifiOnlyEnabled (bool enabled) override;
void setDnsServers () override;
void setHttpProxy (std::string host, int port) override;
void setHttpProxy (const std::string &host, int port) override;
void setNetworkReachable (bool reachable) override;
bool startNetworkMonitoring() override;
void stopNetworkMonitoring() override;
void onLinphoneCoreStart (bool monitoringEnabled) override;
void onLinphoneCoreStop () override;
private:
static int monitorTimerExpired (void *data, unsigned int revents);
protected:
std::string mCurrentSSID;
bool mNetworkReachable = true;
bool mWifiOnly = false;
std::string mHttpProxyHost;
int mHttpProxyPort;
bool mHttpProxyEnabled = false;
bool mNetworkMonitoringEnabled;
private:
static int monitorTimerExpired (void *data, unsigned int revents);
static constexpr int DefaultMonitorTimeout = 5;
belle_sip_source_t *mMonitorTimer;
bool mNetworkReachable = false;
std::string getDownloadPath () override;
};
......
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