background-task.h 1.91 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
/*
 * 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"
26
#include "sal/sal.h"
27 28 29 30 31

// =============================================================================

LINPHONE_BEGIN_NAMESPACE

32 33 34
class Sal;
class Core;

35 36
class BackgroundTask {
public:
37
	BackgroundTask () {}
38 39
	BackgroundTask (const std::string &name) : mName(name) {}
	virtual ~BackgroundTask () { stop(); }
40

41
	void setName (const std::string &name) { mName = name; }
42

43
	const std::string &getName () const { return mName; }
44 45 46 47

	/**
	 * Start a long running task for at most max_duration_seconds, after which it is automatically terminated
	 */
48
	void start (const std::shared_ptr<Core> &core, int maxDurationSeconds = 15 * 60); // 15 min by default, like on iOS
49 50
	void stop ();

51
protected:
52
	virtual void handleTimeout ();
53 54

private:
55 56
	static int sHandleSalTimeout(void *data, unsigned int events);
	static void sHandleTimeout(void *data);
57 58 59 60
	void handleSalTimeout();

	belle_sip_source_t *mTimeout = nullptr;
	Sal *mSal = nullptr;
61
	std::string mName;
62
	unsigned long mId = 0;
63 64 65 66 67
};

LINPHONE_END_NAMESPACE

#endif // ifndef _L_BACKGROUND_TASK_H_