diff options
Diffstat (limited to 'plugin')
| -rw-r--r-- | plugin/Makefile | 105 | ||||
| -rw-r--r-- | plugin/markad.cpp | 175 | ||||
| -rw-r--r-- | plugin/markad.h | 59 | ||||
| -rw-r--r-- | plugin/po/de_DE.po | 19 | ||||
| -rw-r--r-- | plugin/po/it_IT.po | 22 | ||||
| -rw-r--r-- | plugin/status.cpp | 136 | ||||
| -rw-r--r-- | plugin/status.h | 30 |
7 files changed, 546 insertions, 0 deletions
diff --git a/plugin/Makefile b/plugin/Makefile new file mode 100644 index 0000000..9f721a4 --- /dev/null +++ b/plugin/Makefile @@ -0,0 +1,105 @@ +# +# Makefile for a Video Disk Recorder plugin +# + +# The official name of this plugin. +# This name will be used in the '-P...' option of VDR to load the plugin. +# By default the main source file also carries this name. +# IMPORTANT: the presence of this macro is important for the Make.config +# file. So it must be defined, even if it is not used here! +# +PLUGIN = markad + +### The version number of this plugin (taken from the main source file): + +VERSION = $(shell grep 'static const char \*VERSION *=' ../version.h | awk '{ print $$6 }' | sed -e 's/[";]//g') + +### The C++ compiler and options: + +CXX ?= g++ +CXXFLAGS ?= -fPIC -g -O2 -Wall -Wextra -Woverloaded-virtual -Wno-parentheses + +### The directory environment: + +VDRDIR = ../../../.. +LIBDIR = ../../../lib +TMPDIR = /tmp + +### Allow user defined options to overwrite defaults: + +-include $(VDRDIR)/Make.config + +### 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) + +### The name of the distribution archive: + +ARCHIVE = $(PLUGIN)-$(VERSION) +PACKAGE = vdr-$(ARCHIVE) + +### Includes and Defines (add further entries here): + +INCLUDES += -I$(VDRDIR)/include +INCLUDES += -I.. + +DEFINES += -D_GNU_SOURCE -DPLUGIN_NAME_I18N='"$(PLUGIN)"' +DEFINES += -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE + +### The object files (add further files here): + +OBJS = $(PLUGIN).o status.o + +### The main target: + +all: libvdr-$(PLUGIN).so i18n + +### Implicit rules: + +%.o: %.cpp + $(CXX) $(CXXFLAGS) -c $(DEFINES) $(INCLUDES) $< + +### Dependencies: + +MAKEDEP = $(CXX) -MM -MG +DEPFILE = .dependencies +$(DEPFILE): Makefile + @$(MAKEDEP) $(DEFINES) $(INCLUDES) $(OBJS:%.o=%.cpp) > $@ + +-include $(DEPFILE) + +### Internationalization (I18N): + +PODIR = po +LOCALEDIR = $(VDRDIR)/locale +I18Npo = $(wildcard $(PODIR)/*.po) +I18Nmsgs = $(addprefix $(LOCALEDIR)/, $(addsuffix /LC_MESSAGES/vdr-$(PLUGIN).mo, $(notdir $(foreach file, $(I18Npo), $(basename $(file)))))) +I18Npot = $(PODIR)/$(PLUGIN).pot + +%.mo: %.po + msgfmt -c -o $@ $< + +$(I18Npot): $(wildcard *.cpp *.h) + xgettext -C -cTRANSLATORS --no-wrap --no-location -k -ktr -ktrNOOP --msgid-bugs-address='<see README>' -o $@ $^ + +%.po: $(I18Npot) + msgmerge -U --no-wrap --no-location --backup=none -q $@ $< + @touch $@ + +$(I18Nmsgs): $(LOCALEDIR)/%/LC_MESSAGES/vdr-$(PLUGIN).mo: $(PODIR)/%.mo + @mkdir -p $(dir $@) + cp $< $@ + +.PHONY: i18n +i18n: $(I18Nmsgs) $(I18Npot) + +### Targets: + +install: + +libvdr-$(PLUGIN).so: $(OBJS) + $(CXX) $(CXXFLAGS) -shared $(OBJS) $(LIBS) -o $@ + @cp --remove-destination $@ $(LIBDIR)/$@.$(APIVERSION) + +clean: + @-rm -f $(OBJS) $(DEPFILE) *.so *.so.* *.tgz core* *~ $(PODIR)/*.mo $(PODIR)/*.pot diff --git a/plugin/markad.cpp b/plugin/markad.cpp new file mode 100644 index 0000000..4bf9a9c --- /dev/null +++ b/plugin/markad.cpp @@ -0,0 +1,175 @@ +/* + * markad.c: A plugin for the Video Disk Recorder + * + * See the README file for copyright information and how to reach the author. + * + */ + +#include <vdr/plugin.h> + +#include "markad.h" + +cPluginMarkAd::cPluginMarkAd(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! + statusMonitor=NULL; + bindir=strdup(DEF_BINDIR); + logodir=strdup(DEF_LOGODIR); +} + +cPluginMarkAd::~cPluginMarkAd() +{ + // Clean up after yourself! + if (statusMonitor) delete statusMonitor; + if (bindir) free(bindir); + if (logodir) free(logodir); +} + +const char *cPluginMarkAd::CommandLineHelp(void) +{ + // Return a string that describes all known command line options. + return " -b DIR, --bindir=DIR use DIR as location for markad executable\n" + " (default: /usr/bin)\n" + " -l DIR --logocachedir=DIR use DIR as location for markad logos\n" + " (default: /var/lib/markad)\n"; +} + +bool cPluginMarkAd::ProcessArgs(int argc, char *argv[]) +{ + // Command line argument processing + static struct option long_options[] = + { + { "bindir", required_argument, NULL, 'b' + }, + { "logocachedir", required_argument, NULL, 'l'}, + { NULL, 0, NULL, 0 } + }; + + int c; + while ((c = getopt_long(argc, argv, "b:l:", long_options, NULL)) != -1) + { + switch (c) + { + case 'b': + if ((access(optarg,R_OK | X_OK))!=-1) + { + if (bindir) free(bindir); + bindir=strdup(optarg); + } + else + { + fprintf(stderr,"markad: can't access bin directory: %s\n", + optarg); + return false; + } + break; + + case 'l': + if ((access(optarg,R_OK))!=-1) + { + if (logodir) free(logodir); + logodir=strdup(optarg); + } + else + { + fprintf(stderr,"markad: can't access logo directory: %s\n", + optarg); + return false; + } + break; + default: + return false; + } + } + return true; +} + +bool cPluginMarkAd::Initialize(void) +{ + // Initialize any background activities the plugin shall perform. + return true; +} + +bool cPluginMarkAd::Start(void) +{ + // Start any background activities the plugin shall perform. + statusMonitor = new cStatusMarkAd(bindir,logodir); + return true; +} + +void cPluginMarkAd::Stop(void) +{ + // Stop any background activities the plugin is performing. +} + +void cPluginMarkAd::Housekeeping(void) +{ + // Perform any cleanup or other regular tasks. +} + +const char *cPluginMarkAd::MainMenuEntry(void) +{ + return NULL; +} + +void cPluginMarkAd::MainThreadHook(void) +{ + // Perform actions in the context of the main program thread. + // WARNING: Use with great care - see PLUGINS.html! +} + +cString cPluginMarkAd::Active(void) +{ + // Return a message string if shutdown should be postponed + if (statusMonitor->MarkAdRunning()) + return tr("markad still running"); + return NULL; +} + +time_t cPluginMarkAd::WakeupTime(void) +{ + // Return custom wakeup time for shutdown script + return 0; +} + +cOsdObject *cPluginMarkAd::MainMenuAction(void) +{ + // Perform the action when selected from the main VDR menu. + return NULL; +} + +cMenuSetupPage *cPluginMarkAd::SetupMenu(void) +{ + // Return a setup menu in case the plugin supports one. + return NULL; +} + +bool cPluginMarkAd::SetupParse(const char *UNUSED(Name), const char *UNUSED(Value)) +{ + // Parse your own setup parameters and store their values. + return false; +} + +bool cPluginMarkAd::Service(const char *UNUSED(Id), void *UNUSED(Data)) +{ + // Handle custom service requests from other plugins + return false; +} + +const char **cPluginMarkAd::SVDRPHelpPages(void) +{ + // Return help text for SVDRP commands this plugin implements + return NULL; +} + +cString cPluginMarkAd::SVDRPCommand(const char *UNUSED(Command), const char *UNUSED(Option), + int &UNUSED(ReplyCode)) +{ + // Process SVDRP commands this plugin implements + return NULL; +} + + +VDRPLUGINCREATOR(cPluginMarkAd) // Don't touch this! diff --git a/plugin/markad.h b/plugin/markad.h new file mode 100644 index 0000000..4c45abd --- /dev/null +++ b/plugin/markad.h @@ -0,0 +1,59 @@ +/* + * markad.h: A plugin for the Video Disk Recorder + * + * See the README file for copyright information and how to reach the author. + * + */ + +#ifndef __markad_h_ +#define __markad_h_ + +#include <unistd.h> +#include <getopt.h> + +#include "version.h" +#include "status.h" + +#define DEF_BINDIR "/usr/bin" +#define DEF_LOGODIR "/var/lib/markad" + +extern const char *VERSION; +static const char *DESCRIPTION = trNOOP("Mark advertisements"); + +class cPluginMarkAd : public cPlugin +{ +private: + // Add any member variables or functions you may need here. + cStatusMarkAd *statusMonitor; + char *bindir; + char *logodir; +public: + cPluginMarkAd(void); + virtual ~cPluginMarkAd(); + 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); + virtual bool Start(void); + virtual void Stop(void); + virtual void Housekeeping(void); + virtual void MainThreadHook(void); + virtual cString Active(void); + virtual time_t WakeupTime(void); + virtual const char *MainMenuEntry(void); + virtual cOsdObject *MainMenuAction(void); + virtual cMenuSetupPage *SetupMenu(void); + virtual bool SetupParse(const char *Name, const char *Value); + virtual bool Service(const char *Id, void *Data = NULL); + virtual const char **SVDRPHelpPages(void); + virtual cString SVDRPCommand(const char *Command, const char *Option, int &ReplyCode); +}; + +#endif diff --git a/plugin/po/de_DE.po b/plugin/po/de_DE.po new file mode 100644 index 0000000..e3f8891 --- /dev/null +++ b/plugin/po/de_DE.po @@ -0,0 +1,19 @@ +# This file is distributed under the same license as the markad package. +# +msgid "" +msgstr "" +"Project-Id-Version: vdr\n" +"Report-Msgid-Bugs-To: <see README>\n" +"POT-Creation-Date: 2010-03-26 16:28+0100\n" +"PO-Revision-Date: 2009-08-27 14:18+0200\n" +"Last-Translator: Jochen Dolze <noad@dolze.de>\n" +"Language-Team: <vdr@linuxtv.org>\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +msgid "markad still running" +msgstr "markad läuft noch" + +msgid "Mark advertisements" +msgstr "Markiere Werbung" diff --git a/plugin/po/it_IT.po b/plugin/po/it_IT.po new file mode 100644 index 0000000..b504784 --- /dev/null +++ b/plugin/po/it_IT.po @@ -0,0 +1,22 @@ +# This file is distributed under the same license as the markad package. +# +msgid "" +msgstr "" +"Project-Id-Version: vdr\n" +"Report-Msgid-Bugs-To: <see README>\n" +"POT-Creation-Date: 2010-03-26 16:28+0100\n" +"PO-Revision-Date: 2009-11-14 18:06+0100\n" +"Last-Translator: Diego Pierotto <vdr-italian@tiscali.it>\n" +"Language-Team: <vdr@linuxtv.org>\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Poedit-Language: Italian\n" +"X-Poedit-Country: ITALY\n" +"X-Poedit-SourceCharset: utf-8\n" + +msgid "markad still running" +msgstr "" + +msgid "Mark advertisements" +msgstr "Segna i marcatori della pubblicità " diff --git a/plugin/status.cpp b/plugin/status.cpp new file mode 100644 index 0000000..8cf4966 --- /dev/null +++ b/plugin/status.cpp @@ -0,0 +1,136 @@ +/* + * status.cpp: A plugin for the Video Disk Recorder + * + * See the README file for copyright information and how to reach the author. + * + */ + +#include "status.h" + +void cStatusMarkAd::Recording(const cDevice *Device, const char *UNUSED(Name), const char *FileName, bool On) +{ + if (!Device) return; // just to be safe + if (!FileName) return; // we cannot operate without a filename + if (!bindir) return; // we cannot operate without bindir + if (!logodir) return; // we dont want to operate without logodir + + if (On) + { + // Start markad with (before) recording + cString cmd = cString::sprintf("\"%s\"/markad --online=2 -l \"%s\" before \"%s\"",bindir, + logodir,FileName); + if (SystemExec(cmd)!=-1) + { + Add(FileName); + } + } + else + { +#if 0 + // Start markad after recording + cString cmd = cString::sprintf("\"%s\"/markad -l \"%s\" after \"%s\"",bindir, + logodir,FileName); + if (SystemExec(cmd)!=-1) + { + Add(FileName); + } +#endif + // TODO: Start second pass? + } + +} + +cStatusMarkAd::cStatusMarkAd(const char *BinDir, const char *LogoDir) +{ + bindir=BinDir; + logodir=LogoDir; + memset(&recs,0,sizeof(recs)); +} + +cStatusMarkAd::~cStatusMarkAd() +{ + for (int i=0; i<(MAXDEVICES*MAXRECEIVERS); i++) + { + if (recs[i]) free(recs[i]); + } +} + +bool cStatusMarkAd::MarkAdRunning() +{ + bool running=false; + for (int i=0; i<(MAXDEVICES*MAXRECEIVERS); i++) + { + if (recs[i]) + { + char *buf; + if (asprintf(&buf,"%s/markad.pid",recs[i])==-1) + { + // this is crude, but if we fail to allocate memory something + // is going really wrong! + return false; + } + // check for running markad process + FILE *fpid=fopen(buf,"r"); + free(buf); + if (fpid) + { + int pid,ret; + ret=fscanf(fpid,"%i\n",&pid); + fclose(fpid); + if (ret==1) + { + char procname[256]=""; + snprintf(procname,sizeof(procname),"/proc/%i",pid); + struct stat statbuf; + if (stat(procname,&statbuf)==0) + { + // found a running markad + running=true; + } + else + { + if (errno==ENOENT) + { + // no such file or directory -> markad crashed? + // remove filename from list + free(recs[i]); + recs[i]=NULL; + } + else + { + // serious error? -> let vdr close + return false; + } + } + } + } + else + { + if (errno==ENOENT) + { + // no such file or directory -> markad already finished + // remove filename from list + free(recs[i]); + recs[i]=NULL; + } + else + { + // serious error? -> let vdr close + return false; + } + } + } + } + return running; +} + +void cStatusMarkAd::Add(const char *FileName) +{ + for (int i=0; i<(MAXDEVICES*MAXRECEIVERS); i++) + { + if (!recs[i]) + { + recs[i]=strdup(FileName); + } + } +} diff --git a/plugin/status.h b/plugin/status.h new file mode 100644 index 0000000..fbdd7c7 --- /dev/null +++ b/plugin/status.h @@ -0,0 +1,30 @@ +/* + * status.h: A plugin for the Video Disk Recorder + * + * See the README file for copyright information and how to reach the author. + * + */ +#ifndef __status_h_ +#define __status_h_ + +#include <vdr/status.h> + +#define UNUSED(v) UNUSED_ ## v __attribute__((unused)) + +// --- cStatusMarkAd +class cStatusMarkAd : public cStatus +{ +private: + char *recs[MAXDEVICES*MAXRECEIVERS]; + const char *bindir; + const char *logodir; + void Add(const char *FileName); +protected: + virtual void Recording(const cDevice *Device, const char *Name, const char *FileName, bool On); +public: + cStatusMarkAd(const char *BinDir,const char *LogoDir); + ~cStatusMarkAd(); + bool MarkAdRunning(void); +}; + +#endif |
