summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CONTRIBUTORS1
-rw-r--r--HISTORY4
-rw-r--r--PLUGINS.html59
-rw-r--r--plugin.c17
-rw-r--r--plugin.h6
-rw-r--r--vdr.c4
6 files changed, 86 insertions, 5 deletions
diff --git a/CONTRIBUTORS b/CONTRIBUTORS
index eb86b300..22e72a79 100644
--- a/CONTRIBUTORS
+++ b/CONTRIBUTORS
@@ -136,6 +136,7 @@ Stefan Huelswitt <huels@iname.com>
for suggesting to add 'insert' capabilities to cList
for suggesting to make 'package' target in the plugin's Makefile produce a package that
expands to a directory with just the plugin name and version number
+ for suggesting to make the config directory available to plugins
Ulrich Röder <roeder@efr-net.de>
for pointing out that there are channels that have a symbol rate higher than
diff --git a/HISTORY b/HISTORY
index 57c322a8..560d1532 100644
--- a/HISTORY
+++ b/HISTORY
@@ -1270,7 +1270,7 @@ Video Disk Recorder Revision History
- Rearranged cleanup sequence at the end of the main program.
- Adapted PLUGINS.html to use the actual code examples from the 'hello' plugin.
-2002-05-12: Version 1.1.2
+2002-05-13: Version 1.1.2
- 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).
@@ -1280,3 +1280,5 @@ Video Disk Recorder Revision History
- Changed the 'package' target in the plugin's Makefile to produce a package that
expands to a directory with just the plugin name and version number (suggested
by Stefan Huelswitt).
+- Made the config directory available to plugins (suggested by Stefan Huelswitt).
+ See PLUGINS.html, section "Configuration files" for details.
diff --git a/PLUGINS.html b/PLUGINS.html
index de1a2ae9..5098ace6 100644
--- a/PLUGINS.html
+++ b/PLUGINS.html
@@ -513,7 +513,7 @@ the plugin should launch a separate thread to do this.
</b>
<!--X1.1.2--></td></tr></table>
-<hr><h2>Setup parameters</h2>
+<a name="Setup parameters"><hr><h2>Setup parameters</h2>
<center><i><b>Remember me...</b></i></center><p>
@@ -648,6 +648,63 @@ your setup parameters and use that one to copy all parameters with one single st
(like VDR does with its cSetup class).
<!--X1.1.1--></td></tr></table>
+<!--X1.1.2--><table width=100%><tr><td bgcolor=red>&nbsp;</td><td width=100%>
+<hr><h2>Configuration files</h2>
+
+<center><i><b>I want my own stuff!</b></i></center><p>
+
+There may be situations where a plugin requires configuration files of its own, maybe
+for data that can't be stored in the simple <a href="#Setup parameters">setup parameters</a>
+of VDR, or maybe because it needs to launch other programs that simply need a separate
+configuration file. While the plugin is free to store such files anywhere it
+sees fit, it might be a good idea to put them in a common place, preferably
+where other configuration data already exists. VDR provides the function
+
+<p><table><tr><td bgcolor=#F0F0F0><pre><br>
+const char *ConfigDirectory(const char *PluginName = NULL);
+</pre></td></tr></table><p>
+
+which returns a string containing the directory that VDR uses for its own configuration
+files (defined through the <tt><b>-c</b></tt> option in the call to VDR), extended by
+<tt>"/plugins"</tt>. So assuming the VDR configuration directory is <tt>/video</tt>
+(the default if no <tt><b>-c</b></tt> or <tt><b>-v</b></tt> option is given),
+a call to <tt>ConfigDirectory()</tt> will return <tt>/video/plugins</tt>. The first
+call to <tt>ConfigDirectory()</tt> will automatically make sure that the <tt>plugins</tt>
+subdirectory will exist. If, for some reason, this cannot be achieved, <tt>NULL</tt>
+will be returned.
+<p>
+The additional <tt>plugins</tt> directory is used to keep files from plugins apart
+from those of VDR itself, making sure there will be no name clashes. If a plugin
+needs only one extra configuration file, it is suggested that this file be named
+<tt>name.conf</tt>, where <i>name</i> shall be the name of the plugin.
+<p>
+If a plugin needs more than one such file, it is suggested that the plugin stores
+these in a subdirectory of its own, named after the plugin. To easily get such a name
+the <tt>ConfigDirectory()</tt> function can be given an additional string that will
+be appended to the returned directory name, as in
+
+<p><table><tr><td bgcolor=#F0F0F0><pre><br>
+const char *MyConfigDir = ConfigDirectory(Name());
+</pre></td></tr></table><p>
+
+where <tt>Name()</tt> is the member function of the plugin class that returns the
+plugin's name. Again, VDR will make sure that the requested directory will exist
+(or return <tt>NULL</tt> in case of an error).
+<p>
+<b>
+The returned string is statically allocated and will be overwritten by subsequent
+calls to ConfigDirectory()!
+</b>
+<p>
+The <tt>ConfigDirectory()</tt> function is a static member function of the <tt>cPlugin</tt>
+class. This allows it to be called even from outside any member function of the derived
+plugin class, by writing
+
+<p><table><tr><td bgcolor=#F0F0F0><pre><br>
+const char *MyConfigDir = cPlugin::ConfigDirectory();
+</pre></td></tr></table><p>
+<!--X1.1.2--></td></tr></table>
+
<a name="Internationalization"><hr><h2>Internationalization</h2>
<center><i><b>Welcome to Babylon!</b></i></center><p>
diff --git a/plugin.c b/plugin.c
index 3bf5112f..fa9de4ca 100644
--- a/plugin.c
+++ b/plugin.c
@@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
- * $Id: plugin.c 1.3 2002/05/12 10:10:38 kls Exp $
+ * $Id: plugin.c 1.4 2002/05/13 16:08:22 kls Exp $
*/
#include "plugin.h"
@@ -22,6 +22,8 @@
// --- cPlugin ---------------------------------------------------------------
+char *cPlugin::configDirectory = NULL;
+
cPlugin::cPlugin(void)
{
name = NULL;
@@ -91,6 +93,19 @@ void cPlugin::RegisterI18n(const tI18nPhrase * const Phrases)
I18nRegister(Phrases, Name());
}
+void cPlugin::SetConfigDirectory(const char *Dir)
+{
+ configDirectory = strdup(Dir);
+}
+
+const char *cPlugin::ConfigDirectory(const char *PluginName)
+{
+ static char *buffer = NULL;
+ delete buffer;
+ asprintf(&buffer, "%s/plugins%s%s", configDirectory, PluginName ? "/" : "", PluginName ? PluginName : "");
+ return MakeDirs(buffer, true) ? buffer : NULL;
+}
+
// --- cDll ------------------------------------------------------------------
cDll::cDll(const char *FileName, const char *Args)
diff --git a/plugin.h b/plugin.h
index d1a617d4..0b62e8bd 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.3 2002/05/12 09:58:54 kls Exp $
+ * $Id: plugin.h 1.4 2002/05/13 15:32:14 kls Exp $
*/
#ifndef __PLUGIN_H
@@ -20,6 +20,7 @@
class cPlugin {
friend class cDll;
private:
+ static char *configDirectory;
const char *name;
void SetName(const char *s);
public:
@@ -44,6 +45,9 @@ public:
void SetupStore(const char *Name, int Value);
void RegisterI18n(const tI18nPhrase * const Phrases);
+
+ static void SetConfigDirectory(const char *Dir);
+ static const char *ConfigDirectory(const char *PluginName = NULL);
};
class cDll : public cListObject {
diff --git a/vdr.c b/vdr.c
index 04bcc07a..b9bd0941 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.107 2002/05/12 10:11:08 kls Exp $
+ * $Id: vdr.c 1.108 2002/05/13 16:09:06 kls Exp $
*/
#include <getopt.h>
@@ -301,6 +301,8 @@ int main(int argc, char *argv[])
if (!ConfigDirectory)
ConfigDirectory = VideoDirectory;
+ cPlugin::SetConfigDirectory(ConfigDirectory);
+
Setup.Load(AddDirectory(ConfigDirectory, "setup.conf"));
Channels.Load(AddDirectory(ConfigDirectory, "channels.conf"));
Timers.Load(AddDirectory(ConfigDirectory, "timers.conf"));