Commit 94ce0fa2 authored by Ghislain MARY's avatar Ghislain MARY

Fix background task handling on platforms that do not support wakelocks.

parent ead7221c
......@@ -139,8 +139,8 @@ void ClientGroupChatRoomPrivate::onCallSessionStateChanged (
if (q->getState() == ChatRoom::State::CreationPending) {
IdentityAddress addr(session->getRemoteContactAddress()->asStringUriOnly());
q->onConferenceCreated(addr);
if (session->getRemoteContactAddress()->hasParam("isfocus")){
bgTask.start(q->getCore(), 32); /*it will be stopped when receiving the first notify*/
if (session->getRemoteContactAddress()->hasParam("isfocus")) {
bgTask.start(q->getCore(), 32); // It will be stopped when receiving the first notify
qConference->getPrivate()->eventHandler->subscribe(q->getChatRoomId());
}
} else if (q->getState() == ChatRoom::State::TerminationPending)
......@@ -484,12 +484,13 @@ void ClientGroupChatRoom::onFirstNotifyReceived (const IdentityAddress &addr) {
shared_ptr<AbstractChatRoom> chatRoom = getCore()->findChatRoom(id);
if (chatRoom && (chatRoom->getCapabilities() & ChatRoom::Capabilities::Basic)) {
BasicToClientGroupChatRoom::migrate(getSharedFromThis(), chatRoom);
goto end;
d->bgTask.stop();
return;
}
}
d->chatRoomListener->onChatRoomInsertInDatabaseRequested(getSharedFromThis());
end:
d->bgTask.stop();
// TODO: Bug. Event is inserted many times.
// Avoid this in the future. Deal with signals/slots system.
......
......@@ -21,39 +21,45 @@
#include "c-wrapper/internal/c-sal.h"
#include "logger/logger.h"
#include "core/core-p.h"
#include "private.h" //to get access to the Sal
// TODO: Remove me
#include "private.h" // To get access to the Sal
// =============================================================================
LINPHONE_BEGIN_NAMESPACE
void BackgroundTask::sHandleTimeout(void *context) {
void BackgroundTask::sHandleTimeout (void *context) {
static_cast<BackgroundTask *>(context)->handleTimeout();
}
int BackgroundTask::sHandleSalTimeout(void *data, unsigned int events){
int BackgroundTask::sHandleSalTimeout (void *data, unsigned int events) {
static_cast<BackgroundTask *>(data)->handleSalTimeout();
return BELLE_SIP_STOP;
}
void BackgroundTask::handleSalTimeout(){
lWarning() << "Background task [" << mId << "] with name : [" << mName << "] is now expiring.";
void BackgroundTask::handleSalTimeout () {
lWarning() << "Background task [" << mId << "] with name: [" << mName << "] is now expiring";
stop();
}
void BackgroundTask::start (const std::shared_ptr<Core> &core, int max_duration_seconds) {
void BackgroundTask::start (const std::shared_ptr<Core> &core, int maxDurationSeconds) {
if (mName.empty()) {
lError() << "No name was set on background task.";
lError() << "No name was set on background task";
return;
}
unsigned long newId = sal_begin_background_task(mName.c_str(), sHandleTimeout, this);
lInfo() << "Starting background task [" << newId << "] with name : [" << mName << "] and expiration of ["<<max_duration_seconds<<"].";
stop();
if (newId == 0)
return;
lInfo() << "Starting background task [" << newId << "] with name: [" << mName
<< "] and expiration of [" << maxDurationSeconds << "]";
mId = newId;
if (max_duration_seconds > 0){
if (maxDurationSeconds > 0) {
mSal = core->getCCore()->sal;
mTimeout = mSal->create_timer(sHandleSalTimeout, this, (unsigned int) max_duration_seconds * 1000, mName.c_str());
mTimeout = mSal->create_timer(sHandleSalTimeout, this, (unsigned int)maxDurationSeconds * 1000, mName.c_str());
}
}
......@@ -61,18 +67,19 @@ void BackgroundTask::stop () {
if (mId == 0)
return;
lInfo() << "Ending background task [" << mId << "] with name : [" << mName << "].";
lInfo() << "Ending background task [" << mId << "] with name: [" << mName << "]";
sal_end_background_task(mId);
if (mTimeout){
if (mTimeout) {
mSal->cancel_timer(mTimeout);
belle_sip_object_unref(mTimeout);
mTimeout = NULL;
mTimeout = nullptr;
}
mId = 0;
}
void BackgroundTask::handleTimeout () {
lWarning() << "Background task [" << mId << "] with name : [" << mName << "] is expiring from OS before completion...";
lWarning() << "Background task [" << mId << "] with name: [" << mName
<< "] is expiring from OS before completion...";
stop();
}
......
......@@ -34,8 +34,8 @@ class Core;
class BackgroundTask {
public:
BackgroundTask() : mTimeout(NULL), mSal(NULL), mId(0){}
BackgroundTask (const std::string &name) : mTimeout(NULL), mSal(NULL), mName(name), mId(0) {}
BackgroundTask () {}
BackgroundTask (const std::string &name) {}
virtual ~BackgroundTask () {
stop();
}
......@@ -43,26 +43,29 @@ public:
void setName (const std::string &name) {
mName = name;
}
/**
* Start a long running task for at most max_duration_seconds, after which it is automatically terminated
*/
void start(const std::shared_ptr<Core> &core, int max_duration_seconds = 15*60); /*15 mn by default, like on iOS*/
void stop();
const std::string &getName () const {
return mName;
}
/**
* Start a long running task for at most max_duration_seconds, after which it is automatically terminated
*/
void start (const std::shared_ptr<Core> &core, int maxDurationSeconds = 15 * 60); // 15 min by default, like on iOS
void stop ();
protected:
virtual void handleTimeout ();
private:
static int sHandleSalTimeout(void *data, unsigned int events);
static void sHandleTimeout(void *data);
belle_sip_source_t *mTimeout;
Sal *mSal;
void handleSalTimeout();
belle_sip_source_t *mTimeout = nullptr;
Sal *mSal = nullptr;
std::string mName;
unsigned long mId = 0;
void handleSalTimeout();
};
LINPHONE_END_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