summaryrefslogtreecommitdiff
path: root/tasks.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tasks.cpp')
-rw-r--r--tasks.cpp86
1 files changed, 45 insertions, 41 deletions
diff --git a/tasks.cpp b/tasks.cpp
index 07275e5..feaf6aa 100644
--- a/tasks.cpp
+++ b/tasks.cpp
@@ -1,69 +1,73 @@
#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 {
-TaskManager::TaskManager():
- m_switchChannel( 0, false ),
- m_replayRecording( "", false )
+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;
+ }
-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;
+ if ( !Channels.SwitchTo( channel->Number() ) )
+ SetError( tr("Couldn't switch channels") );
}
-bool TaskManager::ReplayRecording( std::string const& fileName )
+TaskManager::TaskManager()
{
- return ScheduleCommand( m_replayRecording, fileName );
- //cMutexLock lock( this );
- //m_replayFileName = fileName;
- //m_scheduleWait.Wait( *this );
- //return m_replayResult;
}
-void TaskManager::DoScheduledWork()
+bool TaskManager::Execute( Task* task, string& error )
{
- if ( m_switchChannel.first == 0 && m_replayRecording.first.empty() )
- return;
-
+ auto_ptr< Task > reaper( task );
cMutexLock lock( this );
- if ( m_switchChannel.first != 0 )
- DoSwitchChannel();
- if ( !m_replayRecording.first.empty() )
- DoReplayRecording();
- m_scheduleWait.Broadcast();
+
+ m_taskQueue.push_back( task );
+ m_scheduleWait.Wait( *this );
+ error = task->Error();
+ return task->Result();
}
-void TaskManager::DoSwitchChannel()
+bool TaskManager::Execute( Task* task )
{
- m_switchChannel.second = Channels.SwitchTo( m_switchChannel.first );
- m_switchChannel.first = 0;
+ string dummyError;
+ return Execute( task, dummyError );
}
-void TaskManager::DoReplayRecording()
+void TaskManager::DoScheduledTasks()
{
- bool result = false;
- cThreadLock lock( &Recordings );
+ if ( m_taskQueue.empty() )
+ return;
- 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;
+ cMutexLock lock( this );
+ while ( !m_taskQueue.empty() ) {
+ Task* current = m_taskQueue.front();
+ current->Action();
+ m_taskQueue.pop_front();
}
- m_replayRecording.first.clear();
+ 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()
{