summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSascha Volkenandt <sascha (at) akv-soft (dot) de>2007-01-13 18:37:21 +0000
committerSascha Volkenandt <sascha (at) akv-soft (dot) de>2007-01-13 18:37:21 +0000
commit2072c668df9ad48586fd2750713da0be742dda6d (patch)
treeb6a8af74320fe0b4af845fdc7ec0fca40d88f02d
parent872af377d5d207b0292c4deb3ebdff09c116ea3d (diff)
downloadvdr-plugin-live-2072c668df9ad48586fd2750713da0be742dda6d.tar.gz
vdr-plugin-live-2072c668df9ad48586fd2750713da0be742dda6d.tar.bz2
- added service to switch channels by channel-id
-rw-r--r--Makefile6
-rw-r--r--live.cpp4
-rw-r--r--pages/Makefile2
-rw-r--r--pages/switch_channel.ecpp31
-rw-r--r--tasks.cpp39
-rw-r--r--tasks.h31
-rw-r--r--timers.cpp13
-rw-r--r--timers.h2
8 files changed, 117 insertions, 11 deletions
diff --git a/Makefile b/Makefile
index 364d8bb..ff35b5a 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
#
# Makefile for a Video Disk Recorder plugin
#
-# $Id: Makefile,v 1.26 2007/01/06 21:48:26 tadi Exp $
+# $Id: Makefile,v 1.27 2007/01/13 18:37:21 lordjaxom Exp $
# The official name of this plugin.
# This name will be used in the '-P...' option of VDR to load the plugin.
@@ -59,10 +59,10 @@ SUBDIRS = httpd pages css images javascript
### The object files (add further files here):
PLUGINOBJS = $(PLUGIN).o thread.o tntconfig.o setup.o i18n.o timers.o \
- tools.o recordings.o
+ tools.o recordings.o tasks.o
WEBLIBS = pages/libpages.a css/libcss.a images/libimages.a \
- javascript/libjavascript.a
+ javascript/libjavascript.a
### Default rules:
diff --git a/live.cpp b/live.cpp
index ef482b5..9cd5eb1 100644
--- a/live.cpp
+++ b/live.cpp
@@ -3,13 +3,14 @@
*
* See the README file for copyright information and how to reach the author.
*
- * $Id: live.cpp,v 1.10 2007/01/05 19:51:38 lordjaxom Exp $
+ * $Id: live.cpp,v 1.11 2007/01/13 18:37:21 lordjaxom Exp $
*/
#include <vdr/plugin.h>
#include "i18n.h"
#include "live.h"
#include "setup.h"
+#include "tasks.h"
#include "thread.h"
#include "timers.h"
@@ -55,6 +56,7 @@ void Plugin::Stop(void)
void Plugin::MainThreadHook(void)
{
LiveTimerManager().DoPendingWork();
+ LiveTaskManager().DoScheduledWork();
}
cString Plugin::Active(void)
diff --git a/pages/Makefile b/pages/Makefile
index 8da6bb1..6bf3286 100644
--- a/pages/Makefile
+++ b/pages/Makefile
@@ -16,7 +16,7 @@ VDRDIR ?= ../../../..
### The object files (add further files here):
OBJS = menu.o channels.o recordings.o schedule.o \
- screenshot.o timers.o whats_on.o \
+ screenshot.o timers.o whats_on.o switch_channel.o \
keypress.o remote.o channels_widget.o edit_timer.o \
error.o pageelems.o tooltip_widget.o
diff --git a/pages/switch_channel.ecpp b/pages/switch_channel.ecpp
new file mode 100644
index 0000000..501715e
--- /dev/null
+++ b/pages/switch_channel.ecpp
@@ -0,0 +1,31 @@
+<%pre>
+#include <vdr/channels.h>
+#include "exception.h"
+#include "tasks.h"
+#include "tools.h"
+
+using namespace vdrlive;
+
+</%pre>
+<%args>
+ tChannelID channelid;
+</%args>
+<%cpp>
+ bool result = false;
+
+ reply.setContentType( "application/xml" );
+
+ ReadLock channelsLock( Channels );
+ if ( channelsLock ) {
+ cChannel* channel = Channels.GetByChannelID( channelid );
+ if ( channel != 0 )
+ result = LiveTaskManager().SwitchChannel( channel->Number() );
+ }
+</%cpp>
+<?xml version="1.0"?>
+<service>
+<request name="switch_channel">
+<param name="channel"><$ *channelid.ToString() $></param>
+</request>
+<response><$ result ? "1" : "0" $></response>
+</service>
diff --git a/tasks.cpp b/tasks.cpp
new file mode 100644
index 0000000..63a3358
--- /dev/null
+++ b/tasks.cpp
@@ -0,0 +1,39 @@
+#include <vdr/channels.h>
+#include "tasks.h"
+
+namespace vdrlive {
+
+TaskManager::TaskManager():
+ m_switchChannel( 0 ),
+ m_switchResult( false )
+{
+}
+
+bool TaskManager::SwitchChannel( int number )
+{
+ cMutexLock lock( this );
+ m_switchChannel = number;
+ m_scheduleWait.Wait( *this );
+ return m_switchResult;
+}
+
+void TaskManager::DoScheduledWork()
+{
+ if ( m_switchChannel == 0 )
+ return;
+
+ cMutexLock lock( this );
+ if ( m_switchChannel != 0 ) {
+ m_switchResult = Channels.SwitchTo( m_switchChannel );
+ m_switchChannel = 0;
+ m_scheduleWait.Broadcast();
+ }
+}
+
+TaskManager& LiveTaskManager()
+{
+ static TaskManager instance;
+ return instance;
+}
+
+} // namespace vdrlive
diff --git a/tasks.h b/tasks.h
new file mode 100644
index 0000000..21a0ae4
--- /dev/null
+++ b/tasks.h
@@ -0,0 +1,31 @@
+#ifndef VDR_LIVE_TASKS_H
+#define VDR_LIVE_TASKS_H
+
+#include <vdr/thread.h>
+
+namespace vdrlive {
+
+class TaskManager: public cMutex
+{
+ friend TaskManager& LiveTaskManager();
+
+public:
+ bool SwitchChannel( int number );
+
+ // may only be called from Plugin::MainThreadHook
+ void DoScheduledWork();
+
+private:
+ TaskManager();
+ TaskManager( TaskManager const& );
+
+ int m_switchChannel;
+ bool m_switchResult;
+ cCondVar m_scheduleWait;
+};
+
+TaskManager& LiveTaskManager();
+
+} // namespace vdrlive
+
+#endif // VDR_LIVE_TASKS_H
diff --git a/timers.cpp b/timers.cpp
index 91e9c67..b497d1b 100644
--- a/timers.cpp
+++ b/timers.cpp
@@ -63,9 +63,6 @@ cTimer* SortedTimers::GetByTimerId( string const& timerid )
void SortedTimers::ReloadTimers( bool initial )
{
- if ( !Timers.Modified( m_state ) && !initial )
- return;
-
dsyslog("live reloading timers");
clear();
@@ -103,9 +100,15 @@ void TimerManager::UpdateTimer( cTimer* timer, int flags, tChannelID& channel, s
void TimerManager::DoPendingWork()
{
+ if ( m_updateTimers.size() == 0 && !m_timers.Modified() )
+ return;
+
cMutexLock lock( this );
- if ( m_updateTimers.size() > 0 )
+ if ( m_updateTimers.size() > 0 ) {
DoUpdateTimers();
+ dsyslog("SV: signalling waiters");
+ m_updateWait.Broadcast();
+ }
m_timers.ReloadTimers();
}
@@ -121,8 +124,6 @@ void TimerManager::DoUpdateTimers()
DoUpdateTimer( *timer );
}
m_updateTimers.clear();
- dsyslog("SV: signalling waiters");
- m_updateWait.Broadcast();
}
void TimerManager::DoInsertTimer( TimerPair& timerData )
diff --git a/timers.h b/timers.h
index 85d6406..55feb46 100644
--- a/timers.h
+++ b/timers.h
@@ -17,6 +17,8 @@ class SortedTimers: public std::list< cTimer >
public:
std::string GetTimerId( cTimer const& timer );
cTimer* GetByTimerId( std::string const& timerid );
+
+ bool Modified() { return Timers.Modified( m_state ); }
private:
SortedTimers();