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

The new function cPlugin::MainThreadHook() can be used by plugins to perform actions in the context of the main program thread

This commit is contained in:
Klaus Schmidinger 2006-04-17 10:02:18 +02:00
parent acf716f1ef
commit 8433190d5a
6 changed files with 53 additions and 4 deletions

View File

@ -4616,3 +4616,6 @@ Video Disk Recorder Revision History
Reinhard Nissl). If it returns false, another plugin call is currently pending Reinhard Nissl). If it returns false, another plugin call is currently pending
and the caller should try again later. This also means that the SVDRP command and the caller should try again later. This also means that the SVDRP command
PLUG can now return an error code is the call fails. PLUG can now return an error code is the call fails.
- The new function cPlugin::MainThreadHook() can be used by plugins to perform
actions in the context of the main program thread. Use this function with great
care and only of you absolutely have to! See also PLUGINS.html.

View File

@ -63,6 +63,7 @@ structures and allows it to hook itself into specific areas to perform special a
<li><a href="#User interaction">User interaction</a> <li><a href="#User interaction">User interaction</a>
<li><a href="#Housekeeping">Housekeeping</a> <li><a href="#Housekeeping">Housekeeping</a>
<!--X1.3.47--><table width=100%><tr><td bgcolor=#FF0000>&nbsp;</td><td width=100%> <!--X1.3.47--><table width=100%><tr><td bgcolor=#FF0000>&nbsp;</td><td width=100%>
<li><a href="#Main thread hook">Main thread hook</a>
<li><a href="#Activity">Activity</a> <li><a href="#Activity">Activity</a>
<!--X1.3.47--></td></tr></table> <!--X1.3.47--></td></tr></table>
<li><a href="#Setup parameters">Setup parameters</a> <li><a href="#Setup parameters">Setup parameters</a>
@ -620,6 +621,27 @@ the plugin should launch a separate thread to do this.
</b> </b>
<!--X1.3.47--><table width=100%><tr><td bgcolor=#FF0000>&nbsp;</td><td width=100%> <!--X1.3.47--><table width=100%><tr><td bgcolor=#FF0000>&nbsp;</td><td width=100%>
<a name="Main thread hook"><hr><h2>Main thread hook</h2>
<center><i><b>Pushing in...</b></i></center><p>
Normally a plugin only reacts on user input if directly called through its
<a href="#Main menu entry">main menu entry</a>, or performs some background
activity in a separate thread. However, sometimes a plugin may need to do
something in the context of the main program thread, without being explicitly
called up by the user. In such a case it can implement the function
<p><table><tr><td bgcolor=#F0F0F0><pre>
virtual void MainThreadHook(void);
</pre></td></tr></table><p>
in which it can do this. This function is called for every plugin once during
every cycle of VDR's main program loop, which typically happens once every
second.
<b>Be very careful when using this function, and make sure you return from it
as soon as possible! If you spend too much time in this function, the user
interface performance will become sluggish!</b>
<a name="Activity"><hr><h2>Activity</h2> <a name="Activity"><hr><h2>Activity</h2>
<center><i><b>Now is not a good time!</b></i></center><p> <center><i><b>Now is not a good time!</b></i></center><p>

View File

@ -12,7 +12,7 @@
# See the main source file 'vdr.c' for copyright information and # See the main source file 'vdr.c' for copyright information and
# how to reach the author. # how to reach the author.
# #
# $Id: newplugin 1.25 2006/04/16 09:04:21 kls Exp $ # $Id: newplugin 1.26 2006/04/17 09:49:13 kls Exp $
$PLUGIN_NAME = $ARGV[0] || die "Usage: newplugin <name>\n"; $PLUGIN_NAME = $ARGV[0] || die "Usage: newplugin <name>\n";
@ -165,6 +165,7 @@ public:
virtual bool Start(void); virtual bool Start(void);
virtual void Stop(void); virtual void Stop(void);
virtual void Housekeeping(void); virtual void Housekeeping(void);
virtual void MainThreadHook(void);
virtual cString Active(void); virtual cString Active(void);
virtual const char *MainMenuEntry(void) { return MAINMENUENTRY; } virtual const char *MainMenuEntry(void) { return MAINMENUENTRY; }
virtual cOsdObject *MainMenuAction(void); virtual cOsdObject *MainMenuAction(void);
@ -221,6 +222,12 @@ void cPlugin${PLUGIN_CLASS}::Housekeeping(void)
// Perform any cleanup or other regular tasks. // Perform any cleanup or other regular tasks.
} }
void cPlugin${PLUGIN_CLASS}::MainThreadHook(void)
{
// Perform actions in the context of the main program thread.
// WARNING: Use with great care - see PLUGINS.html!
}
cString cPlugin${PLUGIN_CLASS}::Active(void) cString cPlugin${PLUGIN_CLASS}::Active(void)
{ {
// Return a message string if shutdown should be postponed // Return a message string if shutdown should be postponed

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: plugin.c 1.21 2006/04/16 09:23:30 kls Exp $ * $Id: plugin.c 1.22 2006/04/17 09:20:05 kls Exp $
*/ */
#include "plugin.h" #include "plugin.h"
@ -70,6 +70,10 @@ void cPlugin::Housekeeping(void)
{ {
} }
void cPlugin::MainThreadHook(void)
{
}
cString cPlugin::Active(void) cString cPlugin::Active(void)
{ {
return NULL; return NULL;
@ -370,6 +374,15 @@ void cPluginManager::Housekeeping(void)
} }
} }
void cPluginManager::MainThreadHook(void)
{
for (cDll *dll = pluginManager->dlls.First(); dll; dll = pluginManager->dlls.Next(dll)) {
cPlugin *p = dll->Plugin();
if (p)
p->MainThreadHook();
}
}
bool cPluginManager::Active(const char *Prompt) bool cPluginManager::Active(const char *Prompt)
{ {
if (pluginManager) { if (pluginManager) {

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: plugin.h 1.12 2006/04/15 10:30:33 kls Exp $ * $Id: plugin.h 1.13 2006/04/17 09:18:16 kls Exp $
*/ */
#ifndef __PLUGIN_H #ifndef __PLUGIN_H
@ -39,6 +39,7 @@ public:
virtual bool Start(void); virtual bool Start(void);
virtual void Stop(void); virtual void Stop(void);
virtual void Housekeeping(void); virtual void Housekeeping(void);
virtual void MainThreadHook(void);
virtual cString Active(void); virtual cString Active(void);
virtual const char *MainMenuEntry(void); virtual const char *MainMenuEntry(void);
@ -90,6 +91,7 @@ public:
bool InitializePlugins(void); bool InitializePlugins(void);
bool StartPlugins(void); bool StartPlugins(void);
void Housekeeping(void); void Housekeeping(void);
void MainThreadHook(void);
static bool Active(const char *Prompt = NULL); static bool Active(const char *Prompt = NULL);
static bool HasPlugins(void); static bool HasPlugins(void);
static cPlugin *GetPlugin(int Index); static cPlugin *GetPlugin(int Index);

4
vdr.c
View File

@ -22,7 +22,7 @@
* *
* The project's page is at http://www.cadsoft.de/vdr * The project's page is at http://www.cadsoft.de/vdr
* *
* $Id: vdr.c 1.260 2006/04/15 13:51:52 kls Exp $ * $Id: vdr.c 1.261 2006/04/17 09:23:23 kls Exp $
*/ */
#include <getopt.h> #include <getopt.h>
@ -830,6 +830,8 @@ int main(int argc, char *argv[])
// Queued messages: // Queued messages:
if (!Skins.IsOpen()) if (!Skins.IsOpen())
Skins.ProcessQueuedMessages(); Skins.ProcessQueuedMessages();
// Main thread hooks of plugins:
PluginManager.MainThreadHook();
// User Input: // User Input:
cOsdObject *Interact = Menu ? Menu : cControl::Control(); cOsdObject *Interact = Menu ? Menu : cControl::Control();
eKeys key = Interface->GetKey((!Interact || !Interact->NeedsFastResponse()) && time(NULL) - LastCamMenu > LASTCAMMENUTIMEOUT); eKeys key = Interface->GetKey((!Interact || !Interact->NeedsFastResponse()) && time(NULL) - LastCamMenu > LASTCAMMENUTIMEOUT);