summaryrefslogtreecommitdiff
path: root/tasks.h
blob: 3ae63da56233ddedd58241175d1632a2df8d43d7 (plain)
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#ifndef VDR_LIVE_TASKS_H
#define VDR_LIVE_TASKS_H

#include <string>
#include <utility>
#include <vdr/thread.h>

namespace vdrlive {

class TaskManager: public cMutex
{
	friend TaskManager& LiveTaskManager();

public:
	bool SwitchChannel( int number );
	bool ReplayRecording( std::string const& fileName );

	// may only be called from Plugin::MainThreadHook
	void DoScheduledWork();
	
private:
	template< typename Type >
	struct Task: std::pair< Type, bool > 
	{
		Task( Type const& first, bool second ): std::pair< Type, bool >( first, second ) {}
	};

	TaskManager();
	TaskManager( TaskManager const& );

	Task< int > m_switchChannel;
	Task< std::string > m_replayRecording;
	cCondVar m_scheduleWait;

	template< typename Type >
	bool ScheduleCommand( Task< Type >& member, Type const& param );

	void DoSwitchChannel();
	void DoReplayRecording();
};
	
template< typename Type >
inline bool TaskManager::ScheduleCommand( Task< Type >& member, Type const& param )
{
	cMutexLock lock( this );
	member.first = param;
	m_scheduleWait.Wait( *this );
	return member.second;
}

TaskManager& LiveTaskManager();

} // namespace vdrlive

#endif // VDR_LIVE_TASKS_H