diff options
author | Lars Hanisch <dvb@flensrocker.de> | 2011-12-10 00:05:32 +0100 |
---|---|---|
committer | Lars Hanisch <dvb@flensrocker.de> | 2011-12-10 00:05:32 +0100 |
commit | e5899689c72ef8b583d08f79290739abafe2d7a2 (patch) | |
tree | 7f91110c92f6f576f83d1a2ed4e24033fe2d3fed | |
parent | 6766fad3d51a176dad50698a1b94c460ffd28578 (diff) | |
download | vdr-plugin-dynamite-e5899689c72ef8b583d08f79290739abafe2d7a2.tar.gz vdr-plugin-dynamite-e5899689c72ef8b583d08f79290739abafe2d7a2.tar.bz2 |
try to set the initial channel on device-attach if it hasn't been set so farv0.0.8f
-rw-r--r-- | HISTORY | 6 | ||||
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | dynamicdevice.c | 2 | ||||
-rw-r--r-- | dynamite.c | 6 | ||||
-rw-r--r-- | status.c | 70 | ||||
-rw-r--r-- | status.h | 25 |
6 files changed, 109 insertions, 2 deletions
@@ -208,3 +208,9 @@ VDR Plugin 'dynamite' Revision History 2011-12-08: Version 0.0.8e - fix a possible double attach of devices if they have a cardindex set with udev + +2011-12-10: Version 0.0.8f + +- try to set the initial channel on device-attach if it hasn't been set so far + and the user or a timer hasn't selected another channel + (giving up 60 seconds after startup) @@ -55,7 +55,7 @@ endif ### The object files (add further files here): -OBJS = $(PLUGIN).o dynamicdevice.o menu.o monitor.o udev.o +OBJS = $(PLUGIN).o dynamicdevice.o menu.o monitor.o status.o udev.o ### The main target: diff --git a/dynamicdevice.c b/dynamicdevice.c index 1758cf7..3a499fc 100644 --- a/dynamicdevice.c +++ b/dynamicdevice.c @@ -1,5 +1,6 @@ #include "dynamicdevice.h" #include "monitor.h" +#include "status.h" #include <glob.h> #include <vdr/skins.h> #include <vdr/transfer.h> @@ -226,6 +227,7 @@ attach: cString osdMsg = cString::sprintf(tr("attached %s"), DevPath); Skins.QueueMessage(mtInfo, *osdMsg); } + cDynamiteStatus::SetInitialChannel(); return ddrcSuccess; } @@ -9,8 +9,9 @@ #include "dynamicdevice.h" #include "menu.h" #include "monitor.h" +#include "status.h" -static const char *VERSION = "0.0.8e"; +static const char *VERSION = "0.0.8f"; static const char *DESCRIPTION = tr("attach/detach devices on the fly"); static const char *MAINMENUENTRY = NULL; @@ -110,6 +111,7 @@ cPluginDynamite::cPluginDynamite(void) cPluginDynamite::~cPluginDynamite() { + cDynamiteStatus::DeInit(); cUdevMonitor::ShutdownAllMonitors(); cUdev::Free(); if (cDynamicDevice::dvbprobe) @@ -278,6 +280,8 @@ bool cPluginDynamite::Initialize(void) bool cPluginDynamite::Start(void) { + cDynamiteStatus::Init(); + if (!cDynamicDevice::ProcessQueuedCommands()) esyslog("dynamite: can't process all queued commands"); return true; diff --git a/status.c b/status.c new file mode 100644 index 0000000..8c6998d --- /dev/null +++ b/status.c @@ -0,0 +1,70 @@ +#include "status.h" + +cDynamiteStatus *cDynamiteStatus::status = NULL; + +#define SETINITIALCHANNELTIMEOUT 60 // 60 seconds + +cDynamiteStatus::cDynamiteStatus(int InitialChannel) +{ + init = time(NULL); + initialChannel = InitialChannel; + initialChannelSet = false; + switchCount = 0; + isyslog("dynamite: initial channel is %d", initialChannel); +} + +void cDynamiteStatus::ChannelSwitch(const cDevice *Device, int ChannelNumber) +{ + if ((ChannelNumber == 0) || initialChannelSet || (initialChannel < 0) || (switchCount > 1)) + return; + if ((cDevice::PrimaryDevice() != cDevice::ActualDevice()) && (cDevice::PrimaryDevice() == Device)) + return; + if (ChannelNumber == initialChannel) { + initialChannelSet = true; + return; + } + if ((time(NULL) - init) > SETINITIALCHANNELTIMEOUT) { + isyslog("dynamite: no devices within %d seconds for receiving initial channel %d, giving up", SETINITIALCHANNELTIMEOUT, initialChannel); + initialChannelSet = true; + return; + } + isyslog("dynamite: device %d switches channel to %d", Device->DeviceNumber() + 1, ChannelNumber); + switchCount++; + if (switchCount > 1) + isyslog("dynamite: assuming manual channel switch, so give up trying to set initial channel on device attach"); +} + +void cDynamiteStatus::Init(void) +{ + if (status) + return; + if (*Setup.InitialChannel) { + cString cid = Setup.InitialChannel; + if (isnumber(cid)) { // for compatibility with old setup.conf files + if (cChannel *Channel = Channels.GetByNumber(atoi(cid))) + cid = Channel->GetChannelID().ToString(); + } + if (cChannel *Channel = Channels.GetByChannelID(tChannelID::FromString(cid))) + status = new cDynamiteStatus(Channel->Number()); + } +} + +void cDynamiteStatus::DeInit(void) +{ + if (status == NULL) + return; + delete status; + status = NULL; +} + +void cDynamiteStatus::SetInitialChannel(void) +{ + if (status == NULL) + return; + if (status->initialChannelSet) { + DeInit(); + return; + } + if (!Channels.SwitchTo(status->initialChannel)) + status->switchCount--; +} diff --git a/status.h b/status.h new file mode 100644 index 0000000..bb5e686 --- /dev/null +++ b/status.h @@ -0,0 +1,25 @@ +#ifndef __DYNAMITESTATUS_H +#define __DYNAMITESTATUS_H + +#include <vdr/status.h> + +class cDynamiteStatus : public cStatus { +private: + static cDynamiteStatus *status; + + time_t init; + int initialChannel; + bool initialChannelSet; + int switchCount; + + cDynamiteStatus(int InitialChannel); + + virtual void ChannelSwitch(const cDevice *Device, int ChannelNumber); + +public: + static void Init(void); + static void DeInit(void); + static void SetInitialChannel(void); + }; + +#endif // __DYNAMITESTATUS_H |