From 5d733e59ee0b0de00cf4967287ef7f431828726a Mon Sep 17 00:00:00 2001 From: Klaus Schmidinger Date: Sun, 12 May 2002 10:20:17 +0200 Subject: [PATCH] Added the cPlugin::Housekeeping() function --- CONTRIBUTORS | 1 + HISTORY | 1 + PLUGINS.html | 27 +++++++++++++++++++++++++++ PLUGINS/src/hello/HISTORY | 1 + PLUGINS/src/hello/hello.c | 8 +++++++- newplugin | 8 +++++++- plugin.c | 28 ++++++++++++++++++++++++++-- plugin.h | 6 +++++- vdr.c | 4 +++- 9 files changed, 78 insertions(+), 6 deletions(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index fb42367c..35ef4090 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -132,6 +132,7 @@ Stefan Huelswitt lists" for suggesting to make the cPlugin::Start() function return a boolean value that indicates if the plugin will not be able to perform its task + for suggesting to add the cPlugin::Housekeeping() function Ulrich Röder for pointing out that there are channels that have a symbol rate higher than diff --git a/HISTORY b/HISTORY index 406aac9d..332f1880 100644 --- a/HISTORY +++ b/HISTORY @@ -1274,3 +1274,4 @@ Video Disk Recorder Revision History - Changed the cPlugin::Start() function to return a boolean value that indicates if the plugin will not be able to perform its task (suggested by Stefan Huelswitt). +- Added the cPlugin::Housekeeping() function (suggested by Stefan Huelswitt). diff --git a/PLUGINS.html b/PLUGINS.html index b2af135b..3ecad7e5 100644 --- a/PLUGINS.html +++ b/PLUGINS.html @@ -482,6 +482,33 @@ interaction is possible. If a specific action takes longer than a few seconds, the plugin should launch a separate thread to do this. +
  +

Housekeeping

+ +
Chores, chores...

+ +From time to time a plugin may want to do some regular tasks, like cleaning +up some files or other things. In order to do this it can implement the function + +


+virtual void Housekeeping(void); +

+ +which gets called when VDR is otherwise idle. The intervals between subsequent +calls to this function are not defined. There may be several hours between two +calls (if, for instance, there are recordings or replays going on) or they may +be as close as ten seconds. The only thing that is guaranteed is that there are +at least ten seconds between two subsequent calls to the Housekeeping() +function of the same plugin. +

+ +It is very important that a call to Housekeeping() returns as soon +as possible! As long as the program stays inside this function, no other user +interaction is possible. If a specific action takes longer than a few seconds, +the plugin should launch a separate thread to do this. + +

+

Setup parameters

Remember me...

diff --git a/PLUGINS/src/hello/HISTORY b/PLUGINS/src/hello/HISTORY index 9abd4971..31b668e8 100644 --- a/PLUGINS/src/hello/HISTORY +++ b/PLUGINS/src/hello/HISTORY @@ -12,3 +12,4 @@ VDR Plugin 'hello' Revision History 2002-05-12: Version 0.0.3 - Changed return type of cPluginHello::Start(). +- Added cPluginHello::Housekeeping(). diff --git a/PLUGINS/src/hello/hello.c b/PLUGINS/src/hello/hello.c index 55e6bcbb..9a6c6e31 100644 --- a/PLUGINS/src/hello/hello.c +++ b/PLUGINS/src/hello/hello.c @@ -3,7 +3,7 @@ * * See the README file for copyright information and how to reach the author. * - * $Id: hello.c 1.3 2002/05/12 09:24:08 kls Exp $ + * $Id: hello.c 1.4 2002/05/12 10:18:59 kls Exp $ */ #include @@ -28,6 +28,7 @@ public: virtual const char *CommandLineHelp(void); virtual bool ProcessArgs(int argc, char *argv[]); virtual bool Start(void); + virtual void Housekeeping(void); virtual const char *MainMenuEntry(void) { return tr(MAINMENUENTRY); } virtual cOsdMenu *MainMenuAction(void); virtual cMenuSetupPage *SetupMenu(void); @@ -117,6 +118,11 @@ bool cPluginHello::Start(void) return true; } +void cPluginHello::Housekeeping(void) +{ + // Perform any cleanup or other regular tasks. +} + cOsdMenu *cPluginHello::MainMenuAction(void) { // Perform the action when selected from the main VDR menu. diff --git a/newplugin b/newplugin index b1e51ca1..8254f3a2 100755 --- a/newplugin +++ b/newplugin @@ -12,7 +12,7 @@ # See the main source file 'vdr.c' for copyright information and # how to reach the author. # -# $Id: newplugin 1.2 2002/05/12 09:06:43 kls Exp $ +# $Id: newplugin 1.3 2002/05/12 10:14:47 kls Exp $ $PLUGIN_NAME = $ARGV[0] || die "Usage: newplugin \n"; @@ -159,6 +159,7 @@ public: virtual const char *CommandLineHelp(void); virtual bool ProcessArgs(int argc, char *argv[]); virtual bool Start(void); + virtual void Housekeeping(void); virtual const char *MainMenuEntry(void) { return MAINMENUENTRY; } virtual cOsdMenu *MainMenuAction(void); virtual cMenuSetupPage *SetupMenu(void); @@ -195,6 +196,11 @@ bool cPlugin${PLUGIN_CLASS}::Start(void) return true; } +void cPlugin${PLUGIN_CLASS}::Housekeeping(void) +{ + // Perform any cleanup or other regular tasks. +} + cOsdMenu *cPlugin${PLUGIN_CLASS}::MainMenuAction(void) { // Perform the action when selected from the main VDR menu. diff --git a/plugin.c b/plugin.c index 00dfb7d4..3bf5112f 100644 --- a/plugin.c +++ b/plugin.c @@ -4,19 +4,21 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: plugin.c 1.2 2002/05/12 09:04:51 kls Exp $ + * $Id: plugin.c 1.3 2002/05/12 10:10:38 kls Exp $ */ #include "plugin.h" #include #include #include +#include #include "config.h" #define LIBVDR_PREFIX "libvdr-" #define SO_INDICATOR ".so." #define MAXPLUGINARGS 1024 +#define HOUSEKEEPINGDELTA 10 // seconds // --- cPlugin --------------------------------------------------------------- @@ -50,6 +52,10 @@ bool cPlugin::Start(void) return true; } +void cPlugin::Housekeeping(void) +{ +} + const char *cPlugin::MainMenuEntry(void) { return NULL; @@ -202,6 +208,8 @@ cPluginManager *cPluginManager::pluginManager = NULL; cPluginManager::cPluginManager(const char *Directory) { directory = NULL; + lastHousekeeping = time(NULL); + nextHousekeeping = -1; if (pluginManager) { fprintf(stderr, "vdr: attempt to create more than one plugin manager - exiting!\n"); exit(2); @@ -278,13 +286,29 @@ bool cPluginManager::StartPlugins(void) Setup.OSDLanguage = 0; // the i18n texts are only available _after_ Start() isyslog(LOG_INFO, "starting plugin: %s (%s): %s", p->Name(), p->Version(), p->Description()); Setup.OSDLanguage = Language; - if (!dll->Plugin()->Start()) + if (!p->Start()) return false; } } return true; } +void cPluginManager::Housekeeping(void) +{ + if (time(NULL) - lastHousekeeping > HOUSEKEEPINGDELTA) { + if (++nextHousekeeping >= dlls.Count()) + nextHousekeeping = 0; + cDll *dll = dlls.Get(nextHousekeeping); + if (dll) { + cPlugin *p = dll->Plugin(); + if (p) { + p->Housekeeping(); + } + } + lastHousekeeping = time(NULL); + } +} + bool cPluginManager::HasPlugins(void) { return pluginManager && pluginManager->dlls.Count(); diff --git a/plugin.h b/plugin.h index 827df23e..d1a617d4 100644 --- a/plugin.h +++ b/plugin.h @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: plugin.h 1.2 2002/05/12 09:05:06 kls Exp $ + * $Id: plugin.h 1.3 2002/05/12 09:58:54 kls Exp $ */ #ifndef __PLUGIN_H @@ -33,6 +33,7 @@ public: virtual bool ProcessArgs(int argc, char *argv[]); virtual bool Start(void); + virtual void Housekeeping(void); virtual const char *MainMenuEntry(void); virtual cOsdMenu *MainMenuAction(void); @@ -64,6 +65,8 @@ class cPluginManager { private: static cPluginManager *pluginManager; char *directory; + time_t lastHousekeeping; + int nextHousekeeping; cDlls dlls; public: cPluginManager(const char *Directory); @@ -72,6 +75,7 @@ public: void AddPlugin(const char *Args); bool LoadPlugins(bool Log = false); bool StartPlugins(void); + void Housekeeping(void); static bool HasPlugins(void); static cPlugin *GetPlugin(int Index); static cPlugin *GetPlugin(const char *Name); diff --git a/vdr.c b/vdr.c index 26f4ea6f..04bcc07a 100644 --- a/vdr.c +++ b/vdr.c @@ -22,7 +22,7 @@ * * The project's page is at http://www.cadsoft.de/people/kls/vdr * - * $Id: vdr.c 1.106 2002/05/12 09:05:37 kls Exp $ + * $Id: vdr.c 1.107 2002/05/12 10:11:08 kls Exp $ */ #include @@ -574,6 +574,8 @@ int main(int argc, char *argv[]) } // Disk housekeeping: RemoveDeletedRecordings(); + // Plugins housekeeping: + PluginManager.Housekeeping(); } } }