summaryrefslogtreecommitdiff
path: root/tasks.cpp
blob: feaf6aacae4d3fe5b1bff1802a8b7888577c6e32 (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <vdr/channels.h>
#include <vdr/i18n.h>
#include <vdr/menu.h>
#include <vdr/recording.h>
#include "exception.h"
#include "tasks.h"
#include "tools.h"

using namespace std;

namespace vdrlive {

void SwitchChannelTask::Action() 
{
	ReadLock lock( Channels );
	cChannel* channel = Channels.GetByChannelID( m_channel );
	if ( channel == 0 ) {
		SetError( tr("Couldn't find channel or no channels available. Maybe you mistyped your request?") );
		return;
	}

	if ( !Channels.SwitchTo( channel->Number() ) )
		SetError( tr("Couldn't switch channels") );
}

TaskManager::TaskManager()
{
}

bool TaskManager::Execute( Task* task, string& error )
{
	auto_ptr< Task > reaper( task );
	cMutexLock lock( this );

	m_taskQueue.push_back( task );
	m_scheduleWait.Wait( *this );
	error = task->Error();
	return task->Result();
}

bool TaskManager::Execute( Task* task )
{
	string dummyError;
	return Execute( task, dummyError );
}

void TaskManager::DoScheduledTasks()
{
	if ( m_taskQueue.empty() )
		return;

	cMutexLock lock( this );
	while ( !m_taskQueue.empty() ) {
		Task* current = m_taskQueue.front();
		current->Action();
		m_taskQueue.pop_front();
	}
	m_scheduleWait.Broadcast();
}

/*
bool TaskManager::ReplayRecording( std::string const& fileName )
{
	return ScheduleCommand( m_replayRecording, fileName );
	//cMutexLock lock( this );
	//m_replayFileName = fileName;
	//m_scheduleWait.Wait( *this );
	//return m_replayResult;
}
*/

TaskManager& LiveTaskManager()
{
	static TaskManager instance;
	return instance;
}

} // namespace vdrlive