summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJochen Dolze <vdr@dolze.de>2012-04-01 21:57:08 +0200
committerJochen Dolze <vdr@dolze.de>2012-04-01 21:57:08 +0200
commit8038c2e9448cde9292b692014a70a38768d8e90b (patch)
tree994d0a4e10ad8ed081f0a2c4e4beb52f5300af1f
parentd43463d62b8b4ee5c7f0aed5ac1893e838dae088 (diff)
downloadvdr-plugin-xmltv2vdr-8038c2e9448cde9292b692014a70a38768d8e90b.tar.gz
vdr-plugin-xmltv2vdr-8038c2e9448cde9292b692014a70a38768d8e90b.tar.bz2
Added locking between epghandler, timer and importer thread - should close bug #927
-rw-r--r--import.cpp1
-rw-r--r--import.h4
-rw-r--r--xmltv2vdr.cpp43
-rw-r--r--xmltv2vdr.h19
4 files changed, 47 insertions, 20 deletions
diff --git a/import.cpp b/import.cpp
index 0bd1d00..51d4ea9 100644
--- a/import.cpp
+++ b/import.cpp
@@ -247,6 +247,7 @@ bool cImport::WasChanged(cEvent* event)
if (!event) return false;
if (!event->Description()) return false;
int len=strlen(event->Description());
+ if (len<1) return false;
if ((uchar)(event->Description()[len-1])==0xA0) return true;
return false;
}
diff --git a/import.h b/import.h
index a2020a6..374e3f4 100644
--- a/import.h
+++ b/import.h
@@ -59,12 +59,12 @@ private:
cEvent *SearchVDREvent(cSchedule* schedule, cXMLTVEvent *event);
bool FetchXMLTVEvent(sqlite3_stmt *stmt, cXMLTVEvent *xevent);
char *RemoveNonASCII(const char *src);
- cXMLTVEvent *PrepareAndReturn(sqlite3 *db, char *sql, sqlite3_stmt *stmt);
- bool WasChanged(cEvent *event);
+ cXMLTVEvent *PrepareAndReturn(sqlite3 *db, char *sql, sqlite3_stmt *stmt);
public:
cImport(cEPGSource *Source, cEPGMappings *Maps, cTEXTMappings *Texts);
~cImport();
int Process(cEPGExecutor &myExecutor);
+ bool WasChanged(cEvent *event);
bool PutEvent(cEPGSource *source, sqlite3 *db, cSchedule* schedule, cEvent *event,
cXMLTVEvent *xevent, int Flags, int Option=IMPORT_ALL);
cXMLTVEvent *SearchXMLTVEvent(const char *EPGFile, const char *ChannelID, const cEvent *event);
diff --git a/xmltv2vdr.cpp b/xmltv2vdr.cpp
index c5a2142..450a79d 100644
--- a/xmltv2vdr.cpp
+++ b/xmltv2vdr.cpp
@@ -15,9 +15,10 @@
// -------------------------------------------------------------
-cEPGHandler::cEPGHandler(const char *EpgFile, cEPGSources *Sources, cEPGMappings *Maps,
- cTEXTMappings *Texts)
+cEPGHandler::cEPGHandler(cPluginXmltv2vdr *Plugin, const char *EpgFile, cEPGSources *Sources,
+ cEPGMappings *Maps, cTEXTMappings *Texts)
{
+ baseplugin=Plugin;
epall=false;
epgfile=EpgFile;
maps=Maps;
@@ -47,6 +48,7 @@ bool cEPGHandler::SetDescription(cEvent* Event, const char* Description)
if (!Event) return false;
if (!maps) return false;
if (!import) return false;
+ if (!baseplugin) return false;
bool special_epall_timer_handling=false;
if (!maps->ProcessChannel(Event->ChannelID()))
@@ -57,6 +59,12 @@ bool cEPGHandler::SetDescription(cEvent* Event, const char* Description)
special_epall_timer_handling=true;
}
+ if (!baseplugin->IsIdle())
+ {
+ if (import->WasChanged(Event)) return true;
+ return false;
+ }
+
int Flags=0;
const char *ChannelID;
@@ -99,8 +107,9 @@ bool cEPGHandler::SetDescription(cEvent* Event, const char* Description)
(cSchedule *) Event->Schedule(),
Event,xevent,Flags,IMPORT_DESCRIPTION);
delete xevent;
- if (!ret) {
- dsyslog("xmltv2vdr: failed to put event description!");
+ if (!ret)
+ {
+ dsyslog("xmltv2vdr: failed to put event description!");
}
return ret;
}
@@ -118,6 +127,12 @@ bool cEPGHandler::SetShortText(cEvent* Event, const char* UNUSED(ShortText))
if (!maps->ProcessChannel(Event->ChannelID())) return false;
+ if (!baseplugin->IsIdle())
+ {
+ if (import->WasChanged(Event)) return true;
+ return false;
+ }
+
cEPGMapping *map=maps->GetMap(Event->ChannelID());
if (!map) return false;
@@ -131,9 +146,10 @@ bool cEPGHandler::SetShortText(cEvent* Event, const char* UNUSED(ShortText))
(cSchedule *) Event->Schedule(),Event,xevent,
map->Flags(),IMPORT_SHORTTEXT);
delete xevent;
- if (!ret) {
- dsyslog("xmltv2vdr: failed to put event shorttext!");
- }
+ if (!ret)
+ {
+ dsyslog("xmltv2vdr: failed to put event shorttext!");
+ }
return ret;
}
@@ -245,9 +261,16 @@ cPluginXmltv2vdr::~cPluginXmltv2vdr()
#endif
}
+bool cPluginXmltv2vdr::IsIdle()
+{
+ if (!epgexecutor.Active() && (!epgtimer->Active())) return true;
+ return false;
+}
+
bool cPluginXmltv2vdr::EPGSourceMove(int From, int To)
{
if (From==To) return false;
+ if (!IsIdle()) return false;
sqlite3 *db=NULL;
char *sql=NULL;
if (sqlite3_open_v2(epgfile,&db,SQLITE_OPEN_READWRITE,NULL)==SQLITE_OK)
@@ -326,7 +349,7 @@ bool cPluginXmltv2vdr::Start(void)
cParse::InitLibXML();
ReadInEPGSources();
- epghandler = new cEPGHandler(epgfile,&epgsources,&epgmappings,&textmappings);
+ epghandler = new cEPGHandler(this,epgfile,&epgsources,&epgmappings,&textmappings);
epgtimer = new cEPGTimer(epgfile,&epgsources,&epgmappings,&textmappings);
if (sqlite3_threadsafe()==0) esyslog("xmltv2vdr: ERROR sqlite3 not threadsafe!");
@@ -406,7 +429,7 @@ void cPluginXmltv2vdr::MainThreadHook(void)
time_t now=time(NULL);
if (now>(last_maintime_t+60))
{
- if (!epgexecutor.Active() && (!epgtimer->Active()))
+ if (IsIdle())
{
if (epgsources.RunItNow()) epgexecutor.Start();
}
@@ -416,7 +439,7 @@ void cPluginXmltv2vdr::MainThreadHook(void)
{
if (now>(last_epcheck_t+600))
{
- if (!epgtimer->Active() && (!epgexecutor.Active()))
+ if (IsIdle())
{
epgtimer->Start();
}
diff --git a/xmltv2vdr.h b/xmltv2vdr.h
index 5a4551d..4b8d80a 100644
--- a/xmltv2vdr.h
+++ b/xmltv2vdr.h
@@ -20,7 +20,7 @@
#define UNUSED(x) x
#endif
-static const char *VERSION = "0.1.0";
+static const char *VERSION = "0.1.1pre";
static const char *DESCRIPTION = trNOOP("Imports xmltv epg into vdr");
#if VDRVERSNUM < 10726 && !EPGHANDLER
@@ -53,19 +53,21 @@ public:
#endif
class cEPGSources;
-
class cImport;
+class cPluginXmltv2vdr;
class cEPGHandler : public cEpgHandler
{
private:
+ cPluginXmltv2vdr *baseplugin;
const char *epgfile;
cEPGMappings *maps;
cEPGSources *sources;
cImport *import;
bool epall;
public:
- cEPGHandler(const char *EpgFile, cEPGSources *Sources, cEPGMappings *Maps, cTEXTMappings *Texts);
+ cEPGHandler(cPluginXmltv2vdr *Plugin, const char *EpgFile, cEPGSources *Sources,
+ cEPGMappings *Maps, cTEXTMappings *Texts);
void SetEPAll(bool Value)
{
epall=Value;
@@ -80,14 +82,14 @@ public:
class cEPGTimer : public cThread
{
- private:
+private:
const char *epgfile;
cEPGSources *sources;
cEPGMappings *maps;
cImport *import;
- public:
+public:
cEPGTimer(const char *EpgFile, cEPGSources *Sources, cEPGMappings *Maps,
- cTEXTMappings *Texts);
+ cTEXTMappings *Texts);
bool StillRunning()
{
return Running();
@@ -96,7 +98,7 @@ class cEPGTimer : public cThread
{
Cancel(3);
}
- virtual void Action();
+ virtual void Action();
};
class cPluginXmltv2vdr : public cPlugin
@@ -138,10 +140,11 @@ public:
{
epgsources.ReadIn(confdir,epgfile,&epgmappings,&textmappings,srcorder,Reload);
}
+ bool IsIdle();
bool EPGSourceMove(int From, int To);
int EPGSourceCount()
{
- if (!epgsources.Count()) return 0;
+ if (!epgsources.Count()) return 0;
return epgsources.Count()-1;
}
cEPGSource *EPGSource(int Index)