diff options
-rw-r--r-- | Make.config.template | 8 | ||||
-rw-r--r-- | Makefile.1.6 | 14 | ||||
-rw-r--r-- | Makefile.1.7.x | 20 | ||||
-rw-r--r-- | run.c | 65 | ||||
-rw-r--r-- | run.h | 27 | ||||
-rw-r--r-- | script/vdr-uactivity | 5 | ||||
-rw-r--r-- | uactivity.c | 103 |
7 files changed, 167 insertions, 75 deletions
diff --git a/Make.config.template b/Make.config.template index 0f423ff..c1a9c93 100644 --- a/Make.config.template +++ b/Make.config.template @@ -4,6 +4,14 @@ # Copy this file to 'Make.config' and change the parameters as necessary. # +# The shell comman used +# If you are using upstart you may use +# PLUGIN_UACTIVITY_COMMAND=initctl emit --system --no-wait vdr-uactivity reason=%1$$s orgin=%2$$s value=%3$$s ConfigDirectory=%4$$s CacheDirectory=%5$$s ResourceDirectory=%6$$s + +PLUGIN_UACTIVITY_COMMAND?=echo vdr-uactivity -r %1$$s -o %2$$s -v %3$$s -C %4$$s -c %5$$s -R %6$$s | at now + + + # Set to supress the install of the shell script package #PLUGIN_UACTIVITY_NOINSTALL=true diff --git a/Makefile.1.6 b/Makefile.1.6 index 824e5fe..5026e6a 100644 --- a/Makefile.1.6 +++ b/Makefile.1.6 @@ -30,10 +30,18 @@ TMPDIR ?= /tmp include $(VDRDIR)/Make.global -### Allow user defined options to overwrite defaults: +### Allow global user defined options to overwrite defaults: -include $(VDRDIR)/Make.config +### Allow user defined options to overwrite defaults: + +-include Make.config + +### Default values: + +PLUGIN_UACTIVITY_COMMAND?=echo vdr-uactivity -r %1$$s -o %2$$s -v %3$$s -C %4$$s -c %5$$s -R %6$$s | at now + ### The version number of VDR's plugin API (taken from VDR's "config.h"): APIVERSION = $(shell sed -ne '/define APIVERSION/s/^.*"\(.*\)".*$$/\1/p' $(VDRDIR)/config.h) @@ -47,11 +55,11 @@ PACKAGE = vdr-$(ARCHIVE) INCLUDES += -I$(VDRDIR)/include -DEFINES += -D_GNU_SOURCE -DPLUGIN_NAME_I18N='"$(PLUGIN)"' +DEFINES += -D_GNU_SOURCE -DPLUGIN_NAME_I18N='"$(PLUGIN)"' -DUACTIVITY_COMMAND='"$(PLUGIN_UACTIVITY_COMMAND)"' ### The object files (add further files here): -OBJS = $(PLUGIN).o +OBJS = $(PLUGIN).o run.o ### The main target: diff --git a/Makefile.1.7.x b/Makefile.1.7.x index 06010c9..3695f3b 100644 --- a/Makefile.1.7.x +++ b/Makefile.1.7.x @@ -20,6 +20,7 @@ PKGCFG = $(if $(VDRDIR),$(shell pkg-config --variable=$(1) $(VDRDIR)/vdr.pc),$(s LIBDIR = $(call PKGCFG,libdir) LOCDIR = $(call PKGCFG,locdir) PLGCFG = $(call PKGCFG,plgcfg) +BINDIR = $(call PKGCFG,bindir) # TMPDIR ?= /tmp @@ -32,10 +33,18 @@ export CXXFLAGS = $(call PKGCFG,cxxflags) APIVERSION = $(call PKGCFG,apiversion) -### Allow user defined options to overwrite defaults: +### Allow global user defined options to overwrite defaults: -include $(PLGCFG) +### Allow user defined options to overwrite defaults: + +-include Make.config + +### Default values: + +PLUGIN_UACTIVITY_COMMAND?=echo vdr-uactivity -r %1$$s -o %2$$s -v %3$$s -C %4$$s -c %5$$s -R %6$$s | at now + ### The name of the distribution archive: ARCHIVE = $(PLUGIN)-$(VERSION) @@ -49,11 +58,11 @@ SOFILE = libvdr-$(PLUGIN).so INCLUDES += -DEFINES += -DPLUGIN_NAME_I18N='"$(PLUGIN)"' +DEFINES += -DPLUGIN_NAME_I18N='"$(PLUGIN)"' -DUACTIVITY_COMMAND='"$(PLUGIN_UACTIVITY_COMMAND)"' ### The object files (add further files here): -OBJS = $(PLUGIN).o +OBJS = $(PLUGIN).o run.o ### The main target: @@ -107,7 +116,10 @@ $(SOFILE): $(OBJS) install-lib: $(SOFILE) install -D $^ $(DESTDIR)$(LIBDIR)/$^.$(APIVERSION) -install: install-lib install-i18n +install-bin: + install -D script/vdr-uactivity $(DESTDIR)$(BINDIR)/vdr-uactivity + +install: install-lib install-i18n install-bin dist: $(I18Npo) clean @-rm -rf $(TMPDIR)/$(ARCHIVE) @@ -0,0 +1,65 @@ + +#include "run.h" +#include <vdr/thread.h> + +cRun Run; + +cRun::~cRun() +{ + if (myConfigDirectory) free(myConfigDirectory); + if (myCacheDirectory) free(myCacheDirectory); + if (myResourceDirectory) free(myResourceDirectory); +} + +void cRun::SetConfigDirectory(const char *Directory) +{ + myConfigDirectory = strdup(Directory); +} + +void cRun::SetCacheDirectory(const char *Directory) +{ + myCacheDirectory = strdup(Directory); +} + +void cRun::SetResourceDirectory(const char *Directory) +{ + myResourceDirectory = strdup(Directory); +} + +void cRun::Call(eOrgin Orgin, bool Active) +{ + char *OrginStr = NULL; + if (Orgin == oStartUp) OrginStr = strdup("startup"); + else if (Orgin == oShutDown) OrginStr = strdup("shutdown"); + else if (Orgin == oRunning) OrginStr = strdup("running"); + + char *ActivityStatusStr = NULL; + if (Active) + ActivityStatusStr = strdup("true"); + else + ActivityStatusStr = strdup("false"); + + char *buffer; + asprintf(&buffer, UACTIVITY_COMMAND, "activity", OrginStr, ActivityStatusStr, myConfigDirectory, myCacheDirectory, myResourceDirectory); + SystemExec(buffer, true); + free(buffer); + + if (ActivityStatusStr) free(ActivityStatusStr); + if (OrginStr) free(OrginStr); +} + +void cRun::Call(eKeys Key) +{ + char *buffer; + asprintf(&buffer, UACTIVITY_COMMAND, "key", "none", myKey.ToString(Key), myConfigDirectory, myCacheDirectory, myResourceDirectory); + SystemExec(buffer, true); + free(buffer); +} + +void cRun::Call() +{ + char *buffer; + asprintf(&buffer, UACTIVITY_COMMAND, "watchdog", "none", "none", myConfigDirectory, myCacheDirectory, myResourceDirectory); + SystemExec(buffer, true); + free(buffer); +} @@ -0,0 +1,27 @@ +#ifndef __RUN_H +#define __RUN_H + +#include <vdr/keys.h> + +enum eOrgin {oStartUp, oShutDown, oRunning}; + +class cRun { +private: + char *myConfigDirectory; + char *myCacheDirectory; + char *myResourceDirectory; + cKey myKey; +public: + cRun() { }; + ~cRun(); + void SetConfigDirectory(const char *Directory); + void SetCacheDirectory(const char *Directory); + void SetResourceDirectory(const char *Directory); + void Call(eOrgin Orgin, bool Active=false); + void Call(eKeys Key); + void Call(); +}; + +extern cRun Run; + +#endif //__RUN_H diff --git a/script/vdr-uactivity b/script/vdr-uactivity new file mode 100644 index 0000000..912cf63 --- /dev/null +++ b/script/vdr-uactivity @@ -0,0 +1,5 @@ +#!/bin/sh + +logger -t vdr-uactivity "$1" "$2" "$3" "$4" "$5" "$6" + +exit 0 diff --git a/uactivity.c b/uactivity.c index a49d981..44b7323 100644 --- a/uactivity.c +++ b/uactivity.c @@ -7,35 +7,30 @@ */ #include <getopt.h> +#include <time.h> #include <vdr/plugin.h> #include <vdr/osdbase.h> -#include <vdr/keys.h> #include <vdr/shutdown.h> +#include "run.h" #define STRINGIFYX(x) #x #define STRINGIFY(x) STRINGIFYX(x) #define WATCHDOG 0 -static const char *VERSION = "0.0.1"; +static const char *VERSION = "0.0.1pre"; static const char *DESCRIPTION = trNOOP("running shellscipts based upton user aktivity changes"); -enum eOrgin {oStartUp, oShutDown, oRunning}; - class cPluginUactivity : public cPlugin { private: // Add any member variables or functions you may need here. - void Call(eOrgin Orgin, bool Active=false); - void Call(); bool LastActivity; - bool WatchdogTimer; - char *myConfigDirectory; - char *myCacheDirectory; - char *myResourceDirectory; + int WatchdogTimer; + time_t LastTime; public: cPluginUactivity(void); - virtual ~cPluginUactivity(); - virtual const char *Version(void) { return VERSION; } - virtual const char *Description(void) { return tr(DESCRIPTION); } + virtual ~cPluginUactivity() { }; + virtual const char *Version(void) { return VERSION; }; + virtual const char *Description(void) { return tr(DESCRIPTION); }; virtual const char *CommandLineHelp(void); virtual bool ProcessArgs(int argc, char *argv[]); virtual bool Initialize(void) { return true; }; @@ -52,24 +47,18 @@ public: virtual bool Service(const char *Id, void *Data = NULL) { return false; }; virtual const char **SVDRPHelpPages(void) { return NULL; }; virtual cString SVDRPCommand(const char *Command, const char *Option, int &ReplyCode) { return NULL; }; - }; +}; class cPluginUactivityMenu : public cOsdMenu { -private: - cKey myKey; - void Call(eKeys Key) { - esyslog("%s: Key -> %s", PLUGIN_NAME_I18N, myKey.ToString(Key)); - } - protected: virtual eOSState ProcessKey(eKeys Key) { eOSState state = cOsdMenu::ProcessKey(Key); if (state == osUnknown) if ((Key >= kUp) && (Key < kNone)) { - Call(Key); + Run.Call(Key); return osEnd; } - return osContinue; + return state; } public: cPluginUactivityMenu() : cOsdMenu(PLUGIN_NAME_I18N) { } @@ -80,42 +69,9 @@ cPluginUactivity::cPluginUactivity(void) // Initialize any member variables here. // DON'T DO ANYTHING ELSE THAT MAY HAVE SIDE EFFECTS, REQUIRE GLOBAL // VDR OBJECTS TO EXIST OR PRODUCE ANY OUTPUT! - LastActivity = false; WatchdogTimer = WATCHDOG; } -cPluginUactivity::~cPluginUactivity() -{ - // Clean up after yourself! - if (myConfigDirectory) free(myConfigDirectory); - if (myCacheDirectory) free(myCacheDirectory); - if (myResourceDirectory) free(myResourceDirectory); -} - -void cPluginUactivity::Call(eOrgin Orgin, bool Active) -{ - char *OrginStr = NULL; - if (Orgin == oStartUp) OrginStr = strdup("startup"); - else if (Orgin == oShutDown) OrginStr = strdup("shutdown"); - else if (Orgin == oRunning) OrginStr = strdup("running"); - - char *ActivityStatusStr = NULL; - if (Active) - ActivityStatusStr = strdup("true"); - else - ActivityStatusStr = strdup("false"); - - esyslog("%s: Orgin -> %s Activity -> %s", PLUGIN_NAME_I18N, OrginStr, ActivityStatusStr); - - if (ActivityStatusStr) free(ActivityStatusStr); - if (OrginStr) free(OrginStr); -} - -void cPluginUactivity::Call() -{ - esyslog("%s: Watchdog", PLUGIN_NAME_I18N); -} - const char *cPluginUactivity::CommandLineHelp(void) { // Return a string that describes all known command line options. @@ -129,7 +85,7 @@ bool cPluginUactivity::ProcessArgs(int argc, char *argv[]) { // Implement command line argument processing here if applicable. static struct option long_options[] = { - {"watchdog-timer", required_argument, NULL, 'w'}, + {"watchdog", required_argument, NULL, 'w'}, { NULL } }; @@ -137,10 +93,8 @@ bool cPluginUactivity::ProcessArgs(int argc, char *argv[]) while ((c = getopt_long(argc, argv, "w:", long_options, NULL)) != -1) { switch (c) { case 'w': if (isnumber(optarg)) - if (atoi(optarg) > 0) - WatchdogTimer = atoi(optarg); - else - return false; + if (atoi(optarg) > 0) WatchdogTimer = atoi(optarg); + else return false; else return false; break; @@ -153,25 +107,29 @@ bool cPluginUactivity::ProcessArgs(int argc, char *argv[]) bool cPluginUactivity::Start(void) { // Start any background activities the plugin shall perform. - myConfigDirectory = strdup(ConfigDirectory(PLUGIN_NAME_I18N)); + Run.SetConfigDirectory(ConfigDirectory(PLUGIN_NAME_I18N)); #if VDRVERSNUM >= 10729 - myCacheDirectory = strdup(CacheDirectory(PLUGIN_NAME_I18N)); - myResourceDirectory = strdup(ResourceDirectory(PLUGIN_NAME_I18N)); + Run.SetCacheDirectory(CacheDirectory(PLUGIN_NAME_I18N)); + Run.SetResourceDirectory(ResourceDirectory(PLUGIN_NAME_I18N)); #else - myCacheDirectory = strdup(myConfigDirectory); - myResourceDirectory = strdup(myConfigDirectory); + Run.SetCacheDirectory(ConfigDirectory(PLUGIN_NAME_I18N)); + Run.SetResourceDirectory(ConfigDirectory(PLUGIN_NAME_I18N)); #endif bool ActivityStatus = !ShutdownHandler.IsUserInactive(); - Call(oStartUp, ActivityStatus); LastActivity = ActivityStatus; + Run.Call(oStartUp, ActivityStatus); + + time(&LastTime); + if (WatchdogTimer > 0) Run.Call(); + return true; } void cPluginUactivity::Stop(void) { // Stop any background activities the plugin is performing. - Call(oShutDown); + Run.Call(oShutDown); } void cPluginUactivity::MainThreadHook(void) @@ -180,8 +138,17 @@ void cPluginUactivity::MainThreadHook(void) // WARNING: Use with great care - see PLUGINS.html! bool ActivityStatus = !ShutdownHandler.IsUserInactive(); if (ActivityStatus != LastActivity) { - Call(oRunning, ActivityStatus); LastActivity = ActivityStatus; + Run.Call(oRunning, ActivityStatus); + } + + if (WatchdogTimer > 0) { + time_t Seconds; + time(&Seconds); + if (difftime(Seconds, LastTime) >= WatchdogTimer) { + time(&LastTime); + Run.Call(); + } } } |