1
0
mirror of https://github.com/VDR4Arch/vdr.git synced 2023-10-10 13:36:52 +02:00

Added the cPlugin::Housekeeping() function

This commit is contained in:
Klaus Schmidinger 2002-05-12 10:20:17 +02:00
parent 01c68def34
commit 5d733e59ee
9 changed files with 78 additions and 6 deletions

View File

@ -132,6 +132,7 @@ Stefan Huelswitt <huels@iname.com>
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 <roeder@efr-net.de>
for pointing out that there are channels that have a symbol rate higher than

View File

@ -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).

View File

@ -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.
</b>
<!--X1.1.2--><table width=100%><tr><td bgcolor=red>&nbsp;</td><td width=100%>
<hr><h2>Housekeeping</h2>
<center><i><b>Chores, chores...</b></i></center><p>
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
<p><table><tr><td bgcolor=#F0F0F0><pre><br>
virtual void Housekeeping(void);
</pre></td></tr></table><p>
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 <tt>Housekeeping()</tt>
function of the same plugin.
<p>
<b>
It is very important that a call to <tt>Housekeeping()</tt> 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.
</b>
<!--X1.1.2--></td></tr></table>
<hr><h2>Setup parameters</h2>
<center><i><b>Remember me...</b></i></center><p>

View File

@ -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().

View File

@ -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 <getopt.h>
@ -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.

View File

@ -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 <name>\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.

View File

@ -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 <ctype.h>
#include <dirent.h>
#include <dlfcn.h>
#include <time.h>
#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();

View File

@ -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);

4
vdr.c
View File

@ -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 <getopt.h>
@ -574,6 +574,8 @@ int main(int argc, char *argv[])
}
// Disk housekeeping:
RemoveDeletedRecordings();
// Plugins housekeeping:
PluginManager.Housekeeping();
}
}
}