summaryrefslogtreecommitdiff
path: root/tasks.cpp
blob: 07275e5119ab76f58773f02d997519b14623508c (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
#include <vdr/channels.h>
#include <vdr/menu.h>
#include <vdr/recording.h>
#include "tasks.h"

namespace vdrlive {

TaskManager::TaskManager():
		m_switchChannel( 0, false ),
		m_replayRecording( "", false )
{
}

bool TaskManager::SwitchChannel( int number )
{
	return ScheduleCommand( m_switchChannel, number );
	//cMutexLock lock( this );
	//m_switchChannel.first = number;
	//m_scheduleWait.Wait( *this );
	//return m_switchChannel.second;
}

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;
}

void TaskManager::DoScheduledWork()
{
	if ( m_switchChannel.first == 0 && m_replayRecording.first.empty() )
		return;

	cMutexLock lock( this );
	if ( m_switchChannel.first != 0 )
		DoSwitchChannel();
	if ( !m_replayRecording.first.empty() )
		DoReplayRecording();
	m_scheduleWait.Broadcast();
}

void TaskManager::DoSwitchChannel()
{
	m_switchChannel.second = Channels.SwitchTo( m_switchChannel.first );
	m_switchChannel.first = 0;
}

void TaskManager::DoReplayRecording()
{
	bool result = false;
	cThreadLock lock( &Recordings );

	cRecording* recording = Recordings.GetByName( m_replayRecording.first.c_str() );
	if ( recording ) {
		cReplayControl::SetRecording( 0, 0 );
		cControl::Shutdown();
		cReplayControl::SetRecording( recording->FileName(), recording->Title() );
		cControl::Launch( new cReplayControl );
		cControl::Attach();
		result = true;
	}
	m_replayRecording.first.clear();
}

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

} // namespace vdrlive