mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-19 03:58:08 +00:00
feat(utils): add a BackgroundTask component
This commit is contained in:
parent
bb2274e56d
commit
6c88e6be87
3 changed files with 104 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
48
src/utils/background-task.cpp
Normal file
48
src/utils/background-task.cpp
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* 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
|
||||
54
src/utils/background-task.h
Normal file
54
src/utils/background-task.h
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* 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_
|
||||
Loading…
Add table
Reference in a new issue