Commit 9e2ef624 authored by Simon Morlat's avatar Simon Morlat
Browse files

add ios platform helpers to fix issue with background tasks.

parent 5b13469e
......@@ -125,6 +125,7 @@ set(LINPHONE_SOURCE_FILES_CXX
conference.cc
platform-helpers.cpp
android-helpers.cpp
ios-helpers.cpp
)
if(ANDROID)
list(APPEND LINPHONE_SOURCE_FILES_CXX linphonecore_jni.cc)
......
/*
linphone
Copyright (C) 2017 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.
*/
#ifdef __APPLE__
#include "TargetConditionals.h"
#endif
#if TARGET_OS_IPHONE
#include "private.h"
#include "platform-helpers.h"
namespace LinphonePrivate{
class IosPlatformHelpers : public PlatformHelpers{
public:
IosPlatformHelpers(LinphoneCore *lc, void *system_context);
virtual void setDnsServers();
virtual void acquireWifiLock();
virtual void releaseWifiLock();
virtual void acquireMcastLock();
virtual void releaseMcastLock();
virtual void acquireCpuLock();
virtual void releaseCpuLock();
~IosPlatformHelpers();
private:
void bgTaskTimeout();
static void sBgTaskTimeout(void *data);
long int mCpuLockTaskId;
int mCpuLockCount;
};
IosPlatformHelpers::IosPlatformHelpers(LinphoneCore *lc, void *system_context) : PlatformHelpers(lc) {
mCpuLockCount = 0;
mCpuLockTaskId = 0;
ms_message("IosPlatformHelpers is fully initialised");
}
IosPlatformHelpers::~IosPlatformHelpers(){
}
void IosPlatformHelpers::setDnsServers(){
}
void IosPlatformHelpers::acquireWifiLock(){
}
void IosPlatformHelpers::releaseWifiLock(){
}
void IosPlatformHelpers::acquireMcastLock(){
}
void IosPlatformHelpers::releaseMcastLock(){
}
void IosPlatformHelpers::bgTaskTimeout(){
ms_error("IosPlatformHelpers: the system requests that the cpu lock is released now.");
if (mCpuLockTaskId != 0){
belle_sip_end_background_task(mCpuLockTaskId);
mCpuLockTaskId = 0;
}
}
void IosPlatformHelpers::sBgTaskTimeout(void *data){
IosPlatformHelpers *zis = (IosPlatformHelpers*)data;
zis->bgTaskTimeout();
}
void IosPlatformHelpers::acquireCpuLock(){
if (mCpuLockCount == 0){
/* on iOS, cpu lock is implemented by a long running task (obcj-C) and it is abstracted by belle-sip,
so let's use belle-sip directly.*/
mCpuLockTaskId = belle_sip_begin_background_task("Liblinphone cpu lock", sBgTaskTimeout, this);
}
mCpuLockCount++;
}
void IosPlatformHelpers::releaseCpuLock(){
mCpuLockCount--;
if (mCpuLockCount == 0){
if (mCpuLockTaskId != 0){
belle_sip_end_background_task(mCpuLockTaskId);
mCpuLockTaskId = 0;
}else{
ms_error("IosPlatformHelpers::releaseCpuLock(): too late, the lock has been released already by the system.");
}
}
}
PlatformHelpers *createIosPlatformHelpers(LinphoneCore *lc, void *system_context){
return new IosPlatformHelpers(lc, system_context);
}
}//end of namespace
#endif
......@@ -2169,6 +2169,8 @@ static void linphone_core_init(LinphoneCore * lc, LinphoneCoreCbs *cbs, LpConfig
#ifdef __ANDROID__
if (system_context)
lc->platform_helper = LinphonePrivate::createAndroidPlatformHelpers(lc, system_context);
#elif TARGET_OS_IPHONE
lc->platform_helper = LinphonePrivate::createIosPlatformHelpers(lc, system_context);
#endif
if (lc->platform_helper == NULL)
lc->platform_helper = new LinphonePrivate::StubbedPlatformHelpers(lc);
......
......@@ -58,6 +58,7 @@ public:
};
PlatformHelpers *createAndroidPlatformHelpers(LinphoneCore *lc, void *system_context);
PlatformHelpers *createIosPlatformHelpers(LinphoneCore *lc, void *system_context);
}//end of namespace
......
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