vdr
1.7.27
|
00001 /* 00002 * plugin.h: The VDR plugin interface 00003 * 00004 * See the main source file 'vdr.c' for copyright information and 00005 * how to reach the author. 00006 * 00007 * $Id: plugin.h 2.1 2012/03/11 13:55:56 kls Exp $ 00008 */ 00009 00010 #ifndef __PLUGIN_H 00011 #define __PLUGIN_H 00012 00013 #include "i18n.h" 00014 #include "menuitems.h" 00015 #include "osdbase.h" 00016 #include "tools.h" 00017 00018 #define VDRPLUGINCREATOR(PluginClass) extern "C" void *VDRPluginCreator(void) { return new PluginClass; } 00019 00020 class cPlugin { 00021 friend class cDll; 00022 friend class cPluginManager; 00023 private: 00024 static char *configDirectory; 00025 const char *name; 00026 bool started; 00027 void SetName(const char *s); 00028 public: 00029 cPlugin(void); 00030 virtual ~cPlugin(); 00031 00032 const char *Name(void) { return name; } 00033 virtual const char *Version(void) = 0; 00034 virtual const char *Description(void) = 0; 00035 virtual const char *CommandLineHelp(void); 00036 00037 virtual bool ProcessArgs(int argc, char *argv[]); 00038 virtual bool Initialize(void); 00039 virtual bool Start(void); 00040 virtual void Stop(void); 00041 virtual void Housekeeping(void); 00042 virtual void MainThreadHook(void); 00043 virtual cString Active(void); 00044 virtual time_t WakeupTime(void); 00045 00046 virtual const char *MainMenuEntry(void); 00047 virtual cOsdObject *MainMenuAction(void); 00048 00049 virtual cMenuSetupPage *SetupMenu(void); 00050 virtual bool SetupParse(const char *Name, const char *Value); 00051 void SetupStore(const char *Name, const char *Value = NULL); 00052 void SetupStore(const char *Name, int Value); 00053 00054 virtual bool Service(const char *Id, void *Data = NULL); 00055 virtual const char **SVDRPHelpPages(void); 00056 virtual cString SVDRPCommand(const char *Command, const char *Option, int &ReplyCode); 00057 00058 static void SetConfigDirectory(const char *Dir); 00059 static const char *ConfigDirectory(const char *PluginName = NULL); 00060 }; 00061 00062 class cDll : public cListObject { 00063 private: 00064 char *fileName; 00065 char *args; 00066 void *handle; 00067 cPlugin *plugin; 00068 public: 00069 cDll(const char *FileName, const char *Args); 00070 virtual ~cDll(); 00071 bool Load(bool Log = false); 00072 cPlugin *Plugin(void) { return plugin; } 00073 }; 00074 00075 class cDlls : public cList<cDll> {}; 00076 00077 class cPluginManager { 00078 private: 00079 static cPluginManager *pluginManager; 00080 char *directory; 00081 time_t lastHousekeeping; 00082 int nextHousekeeping; 00083 cDlls dlls; 00084 public: 00085 cPluginManager(const char *Directory); 00086 virtual ~cPluginManager(); 00087 void SetDirectory(const char *Directory); 00088 void AddPlugin(const char *Args); 00089 bool LoadPlugins(bool Log = false); 00090 bool InitializePlugins(void); 00091 bool StartPlugins(void); 00092 void Housekeeping(void); 00093 void MainThreadHook(void); 00094 static bool Active(const char *Prompt = NULL); 00095 static cPlugin *GetNextWakeupPlugin(void); 00096 static bool HasPlugins(void); 00097 static cPlugin *GetPlugin(int Index); 00098 static cPlugin *GetPlugin(const char *Name); 00099 static cPlugin *CallFirstService(const char *Id, void *Data = NULL); 00100 static bool CallAllServices(const char *Id, void *Data = NULL); 00101 void StopPlugins(void); 00102 void Shutdown(bool Log = false); 00103 }; 00104 00105 #endif //__PLUGIN_H