From 49fcbf19fa2a179d06990443349575ffa86a697f Mon Sep 17 00:00:00 2001 From: Klaus Schmidinger Date: Mon, 13 May 2002 16:11:19 +0200 Subject: [PATCH] Made the config directory available to plugins --- CONTRIBUTORS | 1 + HISTORY | 4 +++- PLUGINS.html | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++- plugin.c | 17 ++++++++++++++- plugin.h | 6 +++++- vdr.c | 4 +++- 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 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 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. -

Setup parameters

+

Setup parameters

Remember me...

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

Configuration files

+ +
I want my own stuff!

+ +There may be situations where a plugin requires configuration files of its own, maybe +for data that can't be stored in the simple setup parameters +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 + +


+const char *ConfigDirectory(const char *PluginName = NULL); +

+ +which returns a string containing the directory that VDR uses for its own configuration +files (defined through the -c option in the call to VDR), extended by +"/plugins". So assuming the VDR configuration directory is /video +(the default if no -c or -v option is given), +a call to ConfigDirectory() will return /video/plugins. The first +call to ConfigDirectory() will automatically make sure that the plugins +subdirectory will exist. If, for some reason, this cannot be achieved, NULL +will be returned. +

+The additional plugins 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 +name.conf, where name shall be the name of the plugin. +

+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 ConfigDirectory() function can be given an additional string that will +be appended to the returned directory name, as in + +


+const char *MyConfigDir = ConfigDirectory(Name()); +

+ +where Name() 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 NULL in case of an error). +

+ +The returned string is statically allocated and will be overwritten by subsequent +calls to ConfigDirectory()! + +

+The ConfigDirectory() function is a static member function of the cPlugin +class. This allows it to be called even from outside any member function of the derived +plugin class, by writing + +


+const char *MyConfigDir = cPlugin::ConfigDirectory(); +

+

+


Internationalization

Welcome to Babylon!

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