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 /status.c | |
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
Diffstat (limited to 'status.c')
-rw-r--r-- | status.c | 70 |
1 files changed, 70 insertions, 0 deletions
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--; +} |