From 2072c668df9ad48586fd2750713da0be742dda6d Mon Sep 17 00:00:00 2001 From: Sascha Volkenandt Date: Sat, 13 Jan 2007 18:37:21 +0000 Subject: - added service to switch channels by channel-id --- Makefile | 6 +++--- live.cpp | 4 +++- pages/Makefile | 2 +- pages/switch_channel.ecpp | 31 +++++++++++++++++++++++++++++++ tasks.cpp | 39 +++++++++++++++++++++++++++++++++++++++ tasks.h | 31 +++++++++++++++++++++++++++++++ timers.cpp | 13 +++++++------ timers.h | 2 ++ 8 files changed, 117 insertions(+), 11 deletions(-) create mode 100644 pages/switch_channel.ecpp create mode 100644 tasks.cpp create mode 100644 tasks.h 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 #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 +#include "exception.h" +#include "tasks.h" +#include "tools.h" + +using namespace vdrlive; + + +<%args> + tChannelID channelid; + +<%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() ); + } + + + + +<$ *channelid.ToString() $> + +<$ result ? "1" : "0" $> + 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 +#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 + +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(); -- cgit v1.2.3