Commit 19f0ffa8 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Made platfromHelper herit CoreAccessor

parent f7a6af14
......@@ -2342,14 +2342,14 @@ static void linphone_core_init(LinphoneCore * lc, LinphoneCoreCbs *cbs, LpConfig
#ifdef __ANDROID__
if (system_context)
lc->platform_helper = LinphonePrivate::createAndroidPlatformHelpers(lc, system_context);
lc->platform_helper = LinphonePrivate::createAndroidPlatformHelpers(lc->cppPtr, system_context);
else
ms_fatal("You must provide the Android's app context when creating the core!");
#elif TARGET_OS_IPHONE
lc->platform_helper = LinphonePrivate::createIosPlatformHelpers(lc, system_context);
lc->platform_helper = LinphonePrivate::createIosPlatformHelpers(lc->cppPtr, system_context);
#endif
if (lc->platform_helper == NULL)
lc->platform_helper = new LinphonePrivate::GenericPlatformHelpers(lc);
lc->platform_helper = new LinphonePrivate::GenericPlatformHelpers(lc->cppPtr);
msplugins_dir = linphone_factory_get_msplugins_dir(lfactory);
image_resources_dir = linphone_factory_get_image_resources_dir(lfactory);
......
......@@ -34,7 +34,7 @@ LINPHONE_BEGIN_NAMESPACE
class AndroidPlatformHelpers : public PlatformHelpers {
public:
AndroidPlatformHelpers (LinphoneCore *lc, void *systemContext);
AndroidPlatformHelpers (std::shared_ptr<LinphonePrivate::Core> core, void *systemContext);
~AndroidPlatformHelpers ();
void acquireWifiLock () override;
......@@ -113,14 +113,14 @@ jmethodID AndroidPlatformHelpers::getMethodId (JNIEnv *env, jclass klass, const
return id;
}
AndroidPlatformHelpers::AndroidPlatformHelpers (LinphoneCore *lc, void *systemContext) : PlatformHelpers(lc) {
AndroidPlatformHelpers::AndroidPlatformHelpers (std::shared_ptr<LinphonePrivate::Core> core, void *systemContext) : PlatformHelpers(core) {
JNIEnv *env = ms_get_jni_env();
jclass klass = env->FindClass("org/linphone/core/tools/AndroidPlatformHelper");
if (!klass)
lFatal() << "Could not find java AndroidPlatformHelper class.";
jmethodID ctor = env->GetMethodID(klass, "<init>", "(JLjava/lang/Object;Z)V");
mJavaHelper = env->NewObject(klass, ctor, (jlong)this, (jobject)systemContext, (jboolean)linphone_core_wifi_only_enabled(getCore()));
mJavaHelper = env->NewObject(klass, ctor, (jlong)this, (jobject)systemContext, (jboolean)linphone_core_wifi_only_enabled(getCore()->getCCore()));
if (!mJavaHelper) {
lError() << "Could not instanciate AndroidPlatformHelper object.";
return;
......@@ -256,7 +256,7 @@ string AndroidPlatformHelpers::getSoundResource (const string &filename) const {
void AndroidPlatformHelpers::setVideoPreviewWindow (void *windowId) {
JNIEnv *env = ms_get_jni_env();
if (env && mJavaHelper) {
string displayFilter = L_C_TO_STRING(linphone_core_get_video_display_filter(getCore()));
string displayFilter = L_C_TO_STRING(linphone_core_get_video_display_filter(getCore()->getCCore()));
if (windowId && (displayFilter.empty() || displayFilter == "MSAndroidTextureDisplay")) {
env->CallVoidMethod(mJavaHelper, mSetNativePreviewVideoWindowId, (jobject)windowId);
} else {
......@@ -268,7 +268,7 @@ void AndroidPlatformHelpers::setVideoPreviewWindow (void *windowId) {
void AndroidPlatformHelpers::setVideoWindow (void *windowId) {
JNIEnv *env = ms_get_jni_env();
if (env && mJavaHelper) {
string displayFilter = L_C_TO_STRING(linphone_core_get_video_display_filter(getCore()));
string displayFilter = L_C_TO_STRING(linphone_core_get_video_display_filter(getCore()->getCCore()));
if (windowId && (displayFilter.empty() || displayFilter == "MSAndroidTextureDisplay")) {
env->CallVoidMethod(mJavaHelper, mSetNativeVideoWindowId, (jobject)windowId);
} else {
......@@ -291,8 +291,8 @@ void AndroidPlatformHelpers::onWifiOnlyEnabled(bool enabled) {
}
void AndroidPlatformHelpers::setHttpProxy(string host, int port) {
linphone_core_set_http_proxy_host(getCore(), host.c_str());
linphone_core_set_http_proxy_port(getCore(), port);
linphone_core_set_http_proxy_host(getCore()->getCCore(), host.c_str());
linphone_core_set_http_proxy_port(getCore()->getCCore(), port);
}
void AndroidPlatformHelpers::setDnsServers () {
......@@ -300,7 +300,7 @@ void AndroidPlatformHelpers::setDnsServers () {
lError() << "AndroidPlatformHelpers' mJavaHelper is null.";
return;
}
if (linphone_core_get_dns_set_by_app(getCore())) return;
if (linphone_core_get_dns_set_by_app(getCore()->getCCore())) return;
JNIEnv *env = ms_get_jni_env();
if (env) {
......@@ -327,14 +327,14 @@ void AndroidPlatformHelpers::setDnsServers () {
lError() << "AndroidPlatformHelpers::setDnsServers() failed to get DNS servers list";
return;
}
linphone_core_set_dns_servers(getCore(), l);
linphone_core_set_dns_servers(getCore()->getCCore(), l);
bctbx_list_free_with_data(l, ms_free);
}
}
void AndroidPlatformHelpers::setNetworkReachable(bool reachable) {
mNetworkReachable = reachable;
linphone_core_set_network_reachable_internal(getCore(), reachable ? 1 : 0);
linphone_core_set_network_reachable_internal(getCore()->getCCore(), reachable ? 1 : 0);
}
// -----------------------------------------------------------------------------
......@@ -357,7 +357,7 @@ void AndroidPlatformHelpers::onLinphoneCoreStop() {
void AndroidPlatformHelpers::_setPreviewVideoWindow(jobject window) {
JNIEnv *env = ms_get_jni_env();
LinphoneCore *lc = getCore();
LinphoneCore *lc = getCore()->getCCore();
if (window != nullptr && window != mPreviewVideoWindow) {
if (mPreviewVideoWindow != nullptr) {
env->DeleteGlobalRef(mPreviewVideoWindow);
......@@ -372,7 +372,7 @@ void AndroidPlatformHelpers::_setPreviewVideoWindow(jobject window) {
void AndroidPlatformHelpers::_setVideoWindow(jobject window) {
JNIEnv *env = ms_get_jni_env();
LinphoneCore *lc = getCore();
LinphoneCore *lc = getCore()->getCCore();
if (window != nullptr && window != mVideoWindow) {
if (mVideoWindow != nullptr) {
env->DeleteGlobalRef(mVideoWindow);
......@@ -412,8 +412,8 @@ string AndroidPlatformHelpers::getNativeLibraryDir () {
return libPath;
}
PlatformHelpers *createAndroidPlatformHelpers (LinphoneCore *lc, void *systemContext) {
return new AndroidPlatformHelpers(lc, systemContext);
PlatformHelpers *createAndroidPlatformHelpers (std::shared_ptr<LinphonePrivate::Core> core, void *systemContext) {
return new AndroidPlatformHelpers(core, systemContext);
}
extern "C" JNIEXPORT void JNICALL Java_org_linphone_core_tools_AndroidPlatformHelper_setNativePreviewWindowId(JNIEnv *env, jobject thiz, jlong ptr, jobject id) {
......@@ -428,11 +428,10 @@ extern "C" JNIEXPORT void JNICALL Java_org_linphone_core_tools_AndroidPlatformHe
extern "C" JNIEXPORT void JNICALL Java_org_linphone_core_tools_AndroidPlatformHelper_setNetworkReachable(JNIEnv* env, jobject thiz, jlong ptr, jboolean reachable) {
AndroidPlatformHelpers *androidPlatformHelper = static_cast<AndroidPlatformHelpers *>((void *)ptr);
belle_sip_main_loop_t *loop = belle_sip_stack_get_main_loop(static_cast<belle_sip_stack_t*>(androidPlatformHelper->getCore()->sal->getStackImpl()));
std::function<void(void)> fun = [androidPlatformHelper, reachable]() {
const std::function<void ()> fun = [androidPlatformHelper, reachable]() {
androidPlatformHelper->setNetworkReachable(reachable);
};
belle_sip_main_loop_cpp_do_later(loop, fun);
androidPlatformHelper->getCore()->doLater(fun);
}
extern "C" JNIEXPORT void JNICALL Java_org_linphone_core_tools_AndroidPlatformHelper_setHttpProxy(JNIEnv* env, jobject thiz, jlong ptr, jstring host, jint port) {
......@@ -441,12 +440,11 @@ extern "C" JNIEXPORT void JNICALL Java_org_linphone_core_tools_AndroidPlatformHe
char * httpProxyHost = ms_strdup(hostC);
ReleaseStringUTFChars(env, host, hostC);
belle_sip_main_loop_t *loop = belle_sip_stack_get_main_loop(static_cast<belle_sip_stack_t*>(androidPlatformHelper->getCore()->sal->getStackImpl()));
std::function<void(void)> fun = [androidPlatformHelper, httpProxyHost, port]() {
const std::function<void ()> fun = [androidPlatformHelper, httpProxyHost, port]() {
androidPlatformHelper->setHttpProxy(httpProxyHost, port);
ms_free(httpProxyHost);
};
belle_sip_main_loop_cpp_do_later(loop, fun);
androidPlatformHelper->getCore()->doLater(fun);
}
LINPHONE_END_NAMESPACE
......@@ -43,7 +43,7 @@ LINPHONE_BEGIN_NAMESPACE
class IosPlatformHelpers : public PlatformHelpers {
public:
IosPlatformHelpers (LinphoneCore *lc, void *system_context);
IosPlatformHelpers (std::shared_ptr<LinphonePrivate::Core> core, void *system_context);
~IosPlatformHelpers () = default;
void acquireWifiLock () override {}
......@@ -89,7 +89,7 @@ private:
const string IosPlatformHelpers::Framework = "org.linphone.linphone";
IosPlatformHelpers::IosPlatformHelpers (LinphoneCore *lc, void *system_context) : PlatformHelpers(lc) {
IosPlatformHelpers::IosPlatformHelpers (std::shared_ptr<LinphonePrivate::Core> core, void *system_context) : PlatformHelpers(core) {
mCpuLockCount = 0;
mCpuLockTaskId = 0;
......@@ -196,13 +196,13 @@ string IosPlatformHelpers::getResourcePath (const string &framework, const strin
// -----------------------------------------------------------------------------
PlatformHelpers *createIosPlatformHelpers (LinphoneCore *lc, void *system_context) {
return new IosPlatformHelpers(lc, system_context);
PlatformHelpers *createIosPlatformHelpers (std::shared_ptr<LinphonePrivate::Core> core, void *system_context) {
return new IosPlatformHelpers(core, system_context);
}
void IosPlatformHelpers::onLinphoneCoreStart (bool monitoringEnabled) {
// workaround
LinphoneCore *lc = getCore();
LinphoneCore *lc = getCore()->getCCore();
linphone_core_set_network_reachable_internal(lc, monitoringEnabled);
}
......
......@@ -29,7 +29,7 @@ using namespace std;
LINPHONE_BEGIN_NAMESPACE
GenericPlatformHelpers::GenericPlatformHelpers (LinphoneCore *lc) : PlatformHelpers(lc), mMonitorTimer(nullptr) {}
GenericPlatformHelpers::GenericPlatformHelpers (std::shared_ptr<LinphonePrivate::Core> core) : PlatformHelpers(core), mMonitorTimer(nullptr) {}
GenericPlatformHelpers::~GenericPlatformHelpers () {
if (mMonitorTimer) {
......@@ -134,7 +134,7 @@ void GenericPlatformHelpers::onLinphoneCoreStop () {}
int GenericPlatformHelpers::monitorTimerExpired (void *data, unsigned int revents) {
GenericPlatformHelpers *helper = static_cast<GenericPlatformHelpers *>(data);
LinphoneCore *core = helper->getCore();
LinphoneCore *core = helper->getCore()->getCCore();
char newIp[LINPHONE_IPADDR_SIZE];
linphone_core_get_local_ip(core, AF_UNSPEC, nullptr, newIp);
......
......@@ -24,6 +24,7 @@
#include <sstream>
#include "linphone/utils/general.h"
#include "core/core-accessor.h"
// =============================================================================
......@@ -37,12 +38,10 @@ LINPHONE_BEGIN_NAMESPACE
* This interface aims at abstracting some features offered by the platform, most often mobile platforms.
* A per platform implementation is to be made to implement these features, if available on the platform.
*/
class PlatformHelpers {
class PlatformHelpers: public CoreAccessor {
public:
virtual ~PlatformHelpers () = default;
LinphoneCore *getCore() const { return mCore; }
virtual void acquireWifiLock () = 0;
virtual void releaseWifiLock () = 0;
virtual void acquireMcastLock () = 0;
......@@ -72,20 +71,18 @@ public:
virtual void onLinphoneCoreStop () = 0;
protected:
inline explicit PlatformHelpers (LinphoneCore *lc) : mCore(lc) {}
inline explicit PlatformHelpers (std::shared_ptr<LinphonePrivate::Core> core) : CoreAccessor(core) {}
inline std::string getFilePath (const std::string &directory, const std::string &filename) const {
std::ostringstream oss;
oss << directory << "/" << filename;
return oss.str();
}
LinphoneCore *mCore;
};
class GenericPlatformHelpers : public PlatformHelpers {
public:
explicit GenericPlatformHelpers (LinphoneCore *lc);
explicit GenericPlatformHelpers (std::shared_ptr<LinphonePrivate::Core> core);
~GenericPlatformHelpers ();
void acquireWifiLock () 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