20 #define LIBVDR_PREFIX "libvdr-" 21 #define SO_INDICATOR ".so." 23 #define MAXPLUGINARGS 1024 24 #define HOUSEKEEPINGDELTA 10 // seconds 144 esyslog(
"ERROR: plugin '%s' called cPlugin::ConfigDirectory(), which is not thread safe!", PluginName ? PluginName :
"<no name given>");
146 return MakeDirs(buffer,
true) ? *buffer : NULL;
158 esyslog(
"ERROR: plugin '%s' called cPlugin::CacheDirectory(), which is not thread safe!", PluginName ? PluginName :
"<no name given>");
160 return MakeDirs(buffer,
true) ? *buffer : NULL;
172 esyslog(
"ERROR: plugin '%s' called cPlugin::ResourceDirectory(), which is not thread safe!", PluginName ? PluginName :
"<no name given>");
174 return MakeDirs(buffer,
true) ? *buffer : NULL;
181 fileName = strdup(FileName);
182 args = Args ? strdup(Args) : NULL;
199 memmove(s, s + 1, strlen(s));
200 while (*s && *s != c) {
202 memmove(s, s + 1, strlen(s));
207 memmove(s, s + 1, strlen(s));
210 esyslog(
"ERROR: missing closing %c", c);
211 fprintf(stderr,
"vdr: missing closing %c\n", c);
218 isyslog(
"loading plugin: %s", fileName);
220 esyslog(
"attempt to load plugin '%s' twice!", fileName);
223 handle = dlopen(fileName, RTLD_NOW);
224 const char *error = dlerror();
226 void *(*creator)(void);
227 creator = (
void *(*)(void))dlsym(handle,
"VDRPluginCreator");
228 if (!(error = dlerror()))
232 if (plugin && args) {
242 case '\\': memmove(p, p + 1, strlen(p));
246 esyslog(
"ERROR: missing character after \\");
247 fprintf(stderr,
"vdr: missing character after \\\n");
252 case '\'':
if ((p =
SkipQuote(p)) == NULL)
255 default:
if (!*p || isspace(*p)) {
262 esyslog(
"ERROR: plugin argument list too long");
263 fprintf(stderr,
"vdr: plugin argument list too long\n");
275 plugin->SetName(argv[0]);
277 return !Log || !argc || plugin->ProcessArgs(argc, argv);
282 fprintf(stderr,
"vdr: %s\n", error);
284 return !error && plugin;
294 lastHousekeeping = time(NULL);
295 nextHousekeeping = -1;
297 fprintf(stderr,
"vdr: attempt to create more than one plugin manager - exiting!\n");
300 SetDirectory(Directory);
301 pluginManager =
this;
308 if (pluginManager ==
this)
309 pluginManager = NULL;
315 directory = Directory ? strdup(Directory) : NULL;
320 if (strcmp(Args,
"*") == 0) {
323 while ((e = d.
Next()) != NULL) {
331 if (strcmp(name,
"*") != 0) {
341 char *p = strchr(s,
' ');
346 esyslog(
"WARN: missing plugin '%s'", s);
347 fprintf(stderr,
"vdr: missing plugin '%s'\n", s);
356 for (
cDll *dll = dlls.First(); dll; dll = dlls.
Next(dll)) {
365 for (
cDll *dll = dlls.First(); dll; dll = dlls.
Next(dll)) {
378 for (
cDll *dll = dlls.First(); dll; dll = dlls.
Next(dll)) {
393 if (++nextHousekeeping >= dlls.Count())
394 nextHousekeeping = 0;
395 cDll *dll = dlls.Get(nextHousekeeping);
402 lastHousekeeping = time(NULL);
408 for (
cDll *dll = pluginManager->dlls.First(); dll; dll = pluginManager->dlls.
Next(dll)) {
418 for (
cDll *dll = pluginManager->dlls.First(); dll; dll = pluginManager->dlls.
Next(dll)) {
436 time_t Now = time(NULL);
438 for (
cDll *dll = pluginManager->dlls.First(); dll; dll = pluginManager->dlls.
Next(dll)) {
442 if (t > Now && (!Next || t < Next)) {
454 return pluginManager && pluginManager->dlls.Count();
459 cDll *dll = pluginManager ? pluginManager->dlls.Get(Index) : NULL;
460 return dll ? dll->
Plugin() : NULL;
465 if (pluginManager && Name) {
466 for (
cDll *dll = pluginManager->dlls.First(); dll; dll = pluginManager->dlls.
Next(dll)) {
468 if (p && strcmp(p->
Name(),
Name) == 0)
478 for (
cDll *dll = pluginManager->dlls.First(); dll; dll = pluginManager->dlls.
Next(dll)) {
491 for (
cDll *dll = pluginManager->dlls.First(); dll; dll = pluginManager->dlls.
Next(dll)) {
502 for (
cDll *dll = dlls.Last(); dll; dll = dlls.
Prev(dll)) {
515 while ((dll = dlls.Last()) != NULL) {
struct dirent * Next(void)
virtual cString SVDRPCommand(const char *Command, const char *Option, int &ReplyCode)
static const char * ResourceDirectory(const char *PluginName=NULL)
bool Confirm(const char *s, int Seconds=10, bool WaitForTimeout=false)
bool LoadPlugins(bool Log=false)
virtual cString Active(void)
void Shutdown(bool Log=false)
virtual const char ** SVDRPHelpPages(void)
void Store(const char *Name, const char *Value, const char *Plugin=NULL, bool AllowMultiple=false)
virtual const char * Version(void)=0
static cString sprintf(const char *fmt,...) __attribute__((format(printf
void SetupStore(const char *Name, const char *Value=NULL)
virtual cOsdObject * MainMenuAction(void)
virtual bool ProcessArgs(int argc, char *argv[])
cPluginManager(const char *Directory)
bool Load(bool Log=false)
static tThreadId IsMainThread(void)
static const char * ConfigDirectory(const char *PluginName=NULL)
static cString resourceDirectory
bool InitializePlugins(void)
void MainThreadHook(void)
static const char * CacheDirectory(const char *PluginName=NULL)
static bool Active(const char *Prompt=NULL)
virtual const char * Description(void)=0
virtual const char * CommandLineHelp(void)
static bool CallAllServices(const char *Id, void *Data=NULL)
virtual void MainThreadHook(void)
static cPlugin * CallFirstService(const char *Id, void *Data=NULL)
static char * SkipQuote(char *s)
static cString configDirectory
virtual bool SetupParse(const char *Name, const char *Value)
cListObject * Next(void) const
void SetName(const char *s)
virtual cMenuSetupPage * SetupMenu(void)
void I18nRegister(const char *Plugin)
Registers the named plugin, so that it can use internationalized texts.
virtual void Housekeeping(void)
static bool HasPlugins(void)
virtual bool Initialize(void)
static cPluginManager * pluginManager
cListObject * Prev(void) const
virtual const char * MainMenuEntry(void)
static void SetCacheDirectory(const char *Dir)
virtual ~cPluginManager()
static cPlugin * GetNextWakeupPlugin(void)
static cString cacheDirectory
void AddPlugin(const char *Args)
void SetDirectory(const char *Directory)
#define HOUSEKEEPINGDELTA
static cPlugin * GetPlugin(int Index)
virtual time_t WakeupTime(void)
static void SetResourceDirectory(const char *Dir)
cDll(const char *FileName, const char *Args)
static void SetConfigDirectory(const char *Dir)
virtual bool Service(const char *Id, void *Data=NULL)