Commit 6c88e6be authored by Ronan's avatar Ronan

feat(utils): add a BackgroundTask component

parent bb2274e5
......@@ -144,6 +144,7 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES
object/property-container.h
object/singleton.h
sal/sal.h
utils/background-task.h
utils/payload-type-handler.h
variant/variant.h
xml/conference-info.h
......@@ -248,6 +249,7 @@ set(LINPHONE_CXX_OBJECTS_SOURCE_FILES
sal/refer-op.cpp
sal/register-op.cpp
sal/sal.cpp
utils/background-task.cpp
utils/fs.cpp
utils/general.cpp
utils/payload-type-handler.cpp
......
/*
* background-task.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 "background-task.h"
#include "c-wrapper/internal/c-sal.h"
#include "logger/logger.h"
// =============================================================================
LINPHONE_BEGIN_NAMESPACE
static void notifier (void *context) {
static_cast<BackgroundTask *>(context)->handleTimeout();
}
void BackgroundTask::start () {
unsigned long newId = sal_begin_background_task(mName.c_str(), notifier, this);
lInfo() << "Starting background task [" << newId << "] with name : [" << mName << "].";
stop();
mId = newId;
}
void BackgroundTask::stop () {
if (mId == 0)
return;
lInfo() << "Ending background task [" << mId << "] with name : [" << mName << "].";
sal_end_background_task(mId);
mId = 0;
}
LINPHONE_END_NAMESPACE
/*
* background-task.h
* 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.
*/
#ifndef _L_BACKGROUND_TASK_H_
#define _L_BACKGROUND_TASK_H_
#include <string>
#include "linphone/utils/general.h"
// =============================================================================
LINPHONE_BEGIN_NAMESPACE
class BackgroundTask {
public:
BackgroundTask (const std::string &name) : mName(name) {}
virtual ~BackgroundTask () {
stop();
}
void start ();
void stop ();
const std::string &getName () const {
return mName;
}
virtual void handleTimeout () {}
private:
std::string mName;
unsigned long mId;
};
LINPHONE_END_NAMESPACE
#endif // ifndef _L_BACKGROUND_TASK_H_
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