summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Hanisch <dvb@flensrocker.de>2011-09-04 12:10:54 +0200
committerLars Hanisch <dvb@flensrocker.de>2011-09-04 12:10:54 +0200
commitbd9320efae00258436351f659625f211db1e4cbe (patch)
tree0db24f04067fb25ec839fc09365f00e096cb4474
parent0de06cd75153ed6d2b5c19424db1c7a948ec10de (diff)
downloadvdr-plugin-dynamite-bd9320efae00258436351f659625f211db1e4cbe.tar.gz
vdr-plugin-dynamite-bd9320efae00258436351f659625f211db1e4cbe.tar.bz2
add two new parameters to activate the auto-idle-mode
-rw-r--r--HISTORY6
-rw-r--r--README8
-rw-r--r--dynamicdevice.c42
-rw-r--r--dynamicdevice.h5
-rw-r--r--dynamite.c48
5 files changed, 103 insertions, 6 deletions
diff --git a/HISTORY b/HISTORY
index d4610a3..ea0b105 100644
--- a/HISTORY
+++ b/HISTORY
@@ -170,3 +170,9 @@ VDR Plugin 'dynamite' Revision History
2011-08-17: Version 0.0.7
- add patch for vdr 1.7.20
+
+2011-09-04: Version 0.0.7a
+
+- add two new parameters to activate the auto-idle-mode
+ --idle-timout=m set unused devices after m minutes to idle
+ --idle-wakeup=h waheup idle devices after h hours
diff --git a/README b/README
index 38cdc07..282d825 100644
--- a/README
+++ b/README
@@ -196,6 +196,8 @@ dynamite.DefaultGetTSTimeout = 0
dynamite.GetTSTimeoutHandler = /path/to/program
dynamite.FreeDeviceSlots = 0
dynamite.IdleHook = /path/to/program
+dynamite.IdleTimeout = 0
+dynamite.IdleWakeup = 0
Commandline Arguments
---------------------
@@ -212,6 +214,10 @@ Commandline Arguments
incompatible plugins
-i, --idle-hook=/path/to/program
set program to be called on SetIdle and reactivation
+-I, --idle-timeout=m
+ if a device is unused for m minutes set it to idle
+-W, --idle-wakeup=h
+ if a device is idle for h hours wake it up (e.g. for EPG scan)
Idle mode
---------
@@ -285,4 +291,4 @@ me how to do this...
TODO
----
-* implement auto-idle-mode
+...
diff --git a/dynamicdevice.c b/dynamicdevice.c
index 108ffaf..e0dc250 100644
--- a/dynamicdevice.c
+++ b/dynamicdevice.c
@@ -6,6 +6,8 @@
cPlugin *cDynamicDevice::dynamite = NULL;
int cDynamicDevice::defaultGetTSTimeout = 0;
+int cDynamicDevice::idleTimeoutMinutes = 0;
+int cDynamicDevice::idleWakeupHours = 0;
cString *cDynamicDevice::idleHook = NULL;
cDvbDeviceProbe *cDynamicDevice::dvbprobe = NULL;
bool cDynamicDevice::enableOsdMessages = false;
@@ -213,6 +215,7 @@ eDynamicDeviceReturnCode cDynamicDevice::AttachDevice(const char *DevPath)
return ddrcNotSupported;
attach:
+ dynamicdevice[freeIndex]->lastCloseDvr = time(NULL);
while (!dynamicdevice[freeIndex]->Ready())
cCondWait::SleepMs(2);
dynamicdevice[freeIndex]->devpath = new cString(DevPath);
@@ -322,10 +325,45 @@ eDynamicDeviceReturnCode cDynamicDevice::SetIdle(const char *DevPath, bool Idle)
}
else if (idleHook && !Idle)
CallIdleHook(**idleHook, dynamicdevice[index]->GetDevPath(), Idle);
-
+ if (Idle)
+ dynamicdevice[index]->idleSince = time(NULL);
+ else
+ dynamicdevice[index]->idleSince = 0;
return ddrcSuccess;
}
+void cDynamicDevice::AutoIdle(void)
+{
+ if (idleTimeoutMinutes <= 0)
+ return;
+ cMutexLock lock(&arrayMutex);
+ time_t now = time(NULL);
+ bool wokeupSomeDevice = false;
+ for (int i = 0; i < numDynamicDevices; i++) {
+ if (dynamicdevice[i]->devpath != NULL) {
+ if (dynamicdevice[i]->IsIdle()) {
+ int hours = 3600 * (now - dynamicdevice[i]->idleSince);
+ if ((dynamicdevice[i]->idleSince > 0) && (hours >= idleWakeupHours)) {
+ isyslog("dynamite: device %s idle for %d hours, waking up", dynamicdevice[i]->GetDevPath(), hours);
+ cDynamicDeviceProbe::QueueDynamicDeviceCommand(ddpcService, *cString::sprintf("dynamite-SetNotIdle-v0.1 %s", dynamicdevice[i]->GetDevPath()));
+ wokeupSomeDevice = true;
+ }
+ }
+ else {
+ int minutes = 60 * (now - dynamicdevice[i]->lastCloseDvr);
+ if ((dynamicdevice[i]->lastCloseDvr > 0) && (minutes >= idleTimeoutMinutes)) {
+ isyslog("dynamite: device %s unused for %d minutes, set to idle", dynamicdevice[i]->GetDevPath(), minutes);
+ cDynamicDeviceProbe::QueueDynamicDeviceCommand(ddpcService, *cString::sprintf("dynamite-SetIdle-v0.1 %s", dynamicdevice[i]->GetDevPath()));
+ }
+ }
+ }
+ }
+
+ if (wokeupSomeDevice) {
+ // initiate epg-scan?
+ }
+}
+
eDynamicDeviceReturnCode cDynamicDevice::SetGetTSTimeout(const char *DevPath, int Seconds)
{
if (!DevPath || (Seconds < 0))
@@ -888,6 +926,7 @@ bool cDynamicDevice::Ready(void)
bool cDynamicDevice::OpenDvr(void)
{
+ lastCloseDvr = 0;
if (subDevice) {
getTSWatchdog = 0;
return subDevice->OpenDvr();
@@ -897,6 +936,7 @@ bool cDynamicDevice::OpenDvr(void)
void cDynamicDevice::CloseDvr(void)
{
+ lastCloseDvr = time(NULL);
if (subDevice)
return subDevice->CloseDvr();
cDevice::CloseDvr();
diff --git a/dynamicdevice.h b/dynamicdevice.h
index a461118..95d1a3b 100644
--- a/dynamicdevice.h
+++ b/dynamicdevice.h
@@ -19,6 +19,8 @@ class cDynamicDevice : public cDevice {
private:
static cPlugin *dynamite;
static int defaultGetTSTimeout;
+ static int idleTimeoutMinutes;
+ static int idleWakeupHours;
static cString *idleHook;
static int numDynamicDevices;
@@ -40,6 +42,7 @@ public:
static eDynamicDeviceReturnCode DetachDevice(const char *DevPath, bool Force);
static eDynamicDeviceReturnCode SetLockDevice(const char *DevPath, bool Lock);
static eDynamicDeviceReturnCode SetIdle(const char *DevPath, bool Idle);
+ static void AutoIdle(void);
static eDynamicDeviceReturnCode SetGetTSTimeout(const char *DevPath, int Seconds);
static void SetDefaultGetTSTimeout(int Seconds);
static eDynamicDeviceReturnCode SetGetTSTimeoutHandlerArg(const char *DevPath, const char *Arg);
@@ -52,6 +55,8 @@ private:
time_t getTSWatchdog;
int getTSTimeout;
bool restartSectionHandler;
+ time_t lastCloseDvr; // for auto-idle
+ time_t idleSince;
void ReadUdevProperties(void);
void InternSetGetTSTimeout(int Seconds);
void InternSetGetTSTimeoutHandlerArg(const char *Arg);
diff --git a/dynamite.c b/dynamite.c
index 0ff29fb..12637c5 100644
--- a/dynamite.c
+++ b/dynamite.c
@@ -10,7 +10,7 @@
#include "menu.h"
#include "monitor.h"
-static const char *VERSION = "0.0.7";
+static const char *VERSION = "0.0.7a";
static const char *DESCRIPTION = tr("attach/detach devices on the fly");
static const char *MAINMENUENTRY = NULL;
@@ -69,6 +69,7 @@ private:
cDynamiteDeviceProbe *probe;
cString *getTSTimeoutHandler;
int freeDeviceSlots;
+ int lastHousekeeping;
public:
cPluginDynamite(void);
virtual ~cPluginDynamite();
@@ -96,6 +97,7 @@ cPluginDynamite::cPluginDynamite(void)
:probe(NULL)
,getTSTimeoutHandler(NULL)
,freeDeviceSlots(0)
+,lastHousekeeping(0)
{
cDynamicDevice::dynamite = this;
cDynamicDevice::dvbprobe = new cDynamiteDvbDeviceProbe;
@@ -129,7 +131,11 @@ const char *cPluginDynamite::CommandLineHelp(void)
" --free-device-slots=n\n"
" leave n slots free for non-dynamic devices\n"
" --idle-hook=/path/to/program\n"
- " set program to be called on SetIdle and reactivation";
+ " set program to be called on SetIdle and reactivation\n"
+ " --idle-timeout=m\n"
+ " if a device is unused for m minutes set it to idle\n"
+ " --idle-wakeup=h\n"
+ " if a device is idle for h hours wake it up (e.g. for EPG scan)";
}
bool cPluginDynamite::ProcessArgs(int argc, char *argv[])
@@ -142,12 +148,14 @@ bool cPluginDynamite::ProcessArgs(int argc, char *argv[])
{"GetTSTimeoutHandler", required_argument, 0, 'h'},
{"free-device-slots", required_argument, 0, 'f'},
{"idle-hook", required_argument, 0, 'i'},
+ {"idle-timeout", required_argument, 0, 'I'},
+ {"idle-wakeup", required_argument, 0, 'W'},
{0, 0, 0, 0}
};
while (true) {
int option_index = 0;
- int c = getopt_long(argc, argv, "udt:h:f:i:", options, &option_index);
+ int c = getopt_long(argc, argv, "udt:h:f:i:I:W:", options, &option_index);
if (c == -1)
break;
switch (c) {
@@ -202,6 +210,24 @@ bool cPluginDynamite::ProcessArgs(int argc, char *argv[])
}
break;
}
+ case 'I':
+ {
+ if ((optarg != NULL) && isnumber(optarg)) {
+ int tmp = strtol(optarg, NULL, 10);
+ if (tmp >= 0)
+ cDynamicDevice::idleTimeoutMinutes = tmp;
+ }
+ break;
+ }
+ case 'W':
+ {
+ if ((optarg != NULL) && isnumber(optarg)) {
+ int tmp = strtol(optarg, NULL, 10);
+ if (tmp >= 0)
+ cDynamicDevice::idleWakeupHours = tmp;
+ }
+ break;
+ }
}
}
return true;
@@ -257,7 +283,11 @@ void cPluginDynamite::Stop(void)
void cPluginDynamite::Housekeeping(void)
{
- // Perform any cleanup or other regular tasks.
+ int now = time(NULL);
+ if ((lastHousekeeping == 0) || ((now - lastHousekeeping) > 60)) {
+ cDynamicDevice::AutoIdle();
+ lastHousekeeping = now;
+ }
}
void cPluginDynamite::MainThreadHook(void)
@@ -324,6 +354,16 @@ bool cPluginDynamite::SetupParse(const char *Name, const char *Value)
isyslog("dynamite: installing idle-hook %s", **cDynamicDevice::idleHook);
}
}
+ else if (strcasecmp(Name, "IdleTimeout") == 0) {
+ int tmp = strtol(Value, NULL, 10);
+ if (tmp >= 0)
+ cDynamicDevice::idleTimeoutMinutes = tmp;
+ }
+ else if (strcasecmp(Name, "IdleWakeup") == 0) {
+ int tmp = strtol(Value, NULL, 10);
+ if (tmp >= 0)
+ cDynamicDevice::idleWakeupHours = tmp;
+ }
else
return false;
return true;