diff options
author | Jochen Dolze <vdr@dolze.de> | 2012-04-02 18:57:21 +0200 |
---|---|---|
committer | Jochen Dolze <vdr@dolze.de> | 2012-04-02 18:57:21 +0200 |
commit | 3033eb15a2e29abe3e30ed89a44179069e0b06a2 (patch) | |
tree | 34ae4529f114e812c8a28996a539a2d2636653fc | |
parent | 8038c2e9448cde9292b692014a70a38768d8e90b (diff) | |
download | vdr-plugin-xmltv2vdr-3033eb15a2e29abe3e30ed89a44179069e0b06a2.tar.gz vdr-plugin-xmltv2vdr-3033eb15a2e29abe3e30ed89a44179069e0b06a2.tar.bz2 |
Added execution priority to import thread, prevent housekeeping while importer thread is running
-rw-r--r-- | import.cpp | 3 | ||||
-rw-r--r-- | source.cpp | 12 | ||||
-rw-r--r-- | source.h | 5 | ||||
-rw-r--r-- | xmltv2vdr.cpp | 53 | ||||
-rw-r--r-- | xmltv2vdr.h | 1 |
5 files changed, 48 insertions, 26 deletions
@@ -722,7 +722,8 @@ bool cImport::PutEvent(cEPGSource *source, sqlite3 *db, cSchedule* schedule, strftime(from,sizeof(from)-1,"%b %d %H:%M",&tm); localtime_r(&end,&tm); strftime(till,sizeof(till)-1,"%b %d %H:%M",&tm); - source->Dlog("changing %s'%s'@%s-%s",xevent->EITDescription() ? "old " : "", + source->Dlog("changing %s%s'%s'@%s-%s",xevent->EITDescription() ? "old " : "", + (Option==IMPORT_SHORTTEXT) ? "shorttext " : "description ", event->Title(),from,till); } return true; @@ -10,6 +10,7 @@ #include <string.h> #include <sys/ioctl.h> +#include "xmltv2vdr.h" #include "source.h" #include "extpipe.h" @@ -32,19 +33,24 @@ int cEPGChannel::Compare(const cListObject &ListObject) const // ------------------------------------------------------------- -cEPGExecutor::cEPGExecutor(cEPGSources *Sources) : cThread("xmltv2vdr importer") +cEPGExecutor::cEPGExecutor(cPluginXmltv2vdr *Plugin,cEPGSources *Sources) : cThread("xmltv2vdr importer") { + baseplugin=Plugin; sources=Sources; } void cEPGExecutor::Action() { if (!sources) return; + if (!baseplugin) return; for (cEPGSource *epgs=sources->First(); epgs; epgs=sources->Next(epgs)) { if (epgs->RunItNow()) { + // if timer thread is runnung, wait till it's stopped + baseplugin->Wait4TimerThread(); + int retries=0; while (retries<=2) { @@ -895,8 +901,8 @@ void cEPGSources::ReadIn(const char *ConfDir, const char *EpgFile, cEPGMappings if (!Exists(EITSOURCE)) { Add(new cEPGSource(EITSOURCE,ConfDir,EpgFile,EPGMappings,TextMappings)); - } - + } + if (!SourceOrder) return; char *buf=strdup(SourceOrder); if (!buf) return; @@ -180,12 +180,15 @@ public: void Remove(); }; +class cPluginXmltv2vdr; + class cEPGExecutor : public cThread { private: cEPGSources *sources; + cPluginXmltv2vdr *baseplugin; public: - cEPGExecutor(cEPGSources *Sources); + cEPGExecutor(cPluginXmltv2vdr *Plugin, cEPGSources *Sources); bool StillRunning() { return Running(); diff --git a/xmltv2vdr.cpp b/xmltv2vdr.cpp index 450a79d..1ef897a 100644 --- a/xmltv2vdr.cpp +++ b/xmltv2vdr.cpp @@ -9,6 +9,7 @@ #include <vdr/videodir.h> #include <unistd.h> #include <getopt.h> +#include <pthread.h> #include "setup.h" #include "xmltv2vdr.h" @@ -156,7 +157,7 @@ bool cEPGHandler::SetShortText(cEvent* Event, const char* UNUSED(ShortText)) // ------------------------------------------------------------- cEPGTimer::cEPGTimer(const char *EpgFile, cEPGSources *Sources, cEPGMappings *Maps, - cTEXTMappings *Texts) : cThread("xmltv2vdr timer thread") + cTEXTMappings *Texts) : cThread("xmltv2vdr timer") { epgfile=EpgFile; sources=Sources; @@ -212,7 +213,7 @@ void cEPGTimer::Action() // ------------------------------------------------------------- -cPluginXmltv2vdr::cPluginXmltv2vdr(void) : epgexecutor(&epgsources) +cPluginXmltv2vdr::cPluginXmltv2vdr(void) : epgexecutor(this, &epgsources) { // Initialize any member variables here. // DON'T DO ANYTHING ELSE THAT MAY HAVE SIDE EFFECTS, REQUIRE GLOBAL @@ -267,6 +268,13 @@ bool cPluginXmltv2vdr::IsIdle() return false; } +void cPluginXmltv2vdr::Wait4TimerThread() +{ + if (!epgtimer->Active()) return; + dsyslog("xmltv2vdr: wait for timer thread"); + pthread_join(epgtimer->ThreadId(),NULL); +} + bool cPluginXmltv2vdr::EPGSourceMove(int From, int To) { if (From==To) return false; @@ -390,32 +398,35 @@ void cPluginXmltv2vdr::Housekeeping(void) time_t now=time(NULL); if (now>(last_housetime_t+3600)) { - struct stat statbuf; - if (stat(epgfile,&statbuf)!=-1) + if (IsIdle()) { - if (statbuf.st_size) + struct stat statbuf; + if (stat(epgfile,&statbuf)!=-1) { - sqlite3 *db=NULL; - if (sqlite3_open_v2(epgfile,&db,SQLITE_OPEN_READWRITE,NULL)==SQLITE_OK) + if (statbuf.st_size) { - char *sql; - if (asprintf(&sql,"delete from epg where ((starttime+duration) < %li)",now)!=-1) + sqlite3 *db=NULL; + if (sqlite3_open_v2(epgfile,&db,SQLITE_OPEN_READWRITE,NULL)==SQLITE_OK) { - char *errmsg; - if (sqlite3_exec(db,sql,NULL,NULL,&errmsg)!=SQLITE_OK) + char *sql; + if (asprintf(&sql,"delete from epg where ((starttime+duration) < %li)",now)!=-1) { - esyslog("xmltv2vdr: %s",errmsg); - sqlite3_free(errmsg); + char *errmsg; + if (sqlite3_exec(db,sql,NULL,NULL,&errmsg)!=SQLITE_OK) + { + esyslog("xmltv2vdr: %s",errmsg); + sqlite3_free(errmsg); + } + else + { + isyslog("xmltv2vdr: removed %i old entries from db",sqlite3_changes(db)); + sqlite3_exec(db,"VACCUM;",NULL,NULL,NULL); + } + free(sql); } - else - { - isyslog("xmltv2vdr: removed %i old entries from db",sqlite3_changes(db)); - sqlite3_exec(db,"VACCUM;",NULL,NULL,NULL); - } - free(sql); } + sqlite3_close(db); } - sqlite3_close(db); } } last_housetime_t=now; @@ -429,7 +440,7 @@ void cPluginXmltv2vdr::MainThreadHook(void) time_t now=time(NULL); if (now>(last_maintime_t+60)) { - if (IsIdle()) + if (!epgexecutor.Active()) { if (epgsources.RunItNow()) epgexecutor.Start(); } diff --git a/xmltv2vdr.h b/xmltv2vdr.h index 4b8d80a..8805a16 100644 --- a/xmltv2vdr.h +++ b/xmltv2vdr.h @@ -140,6 +140,7 @@ public: { epgsources.ReadIn(confdir,epgfile,&epgmappings,&textmappings,srcorder,Reload); } + void Wait4TimerThread(); bool IsIdle(); bool EPGSourceMove(int From, int To); int EPGSourceCount() |