diff options
author | Jochen Dolze <vdr@dolze.de> | 2012-04-13 00:25:50 +0200 |
---|---|---|
committer | Jochen Dolze <vdr@dolze.de> | 2012-04-13 00:25:50 +0200 |
commit | 38dc897af5dc53fba5ce21a5aad55a6454effea5 (patch) | |
tree | a3bc9b0a7f22b1b7dcae02f0298313048b83876d | |
parent | 5d943515babc18cba0576f21f4c89a389d5f60c0 (diff) | |
download | vdr-plugin-xmltv2vdr-38dc897af5dc53fba5ce21a5aad55a6454effea5.tar.gz vdr-plugin-xmltv2vdr-38dc897af5dc53fba5ce21a5aad55a6454effea5.tar.bz2 |
Improved sqlite handling
-rw-r--r-- | import.cpp | 156 | ||||
-rw-r--r-- | import.h | 12 | ||||
-rw-r--r-- | parse.cpp | 18 | ||||
-rw-r--r-- | source.cpp | 14 | ||||
-rw-r--r-- | source.h | 1 | ||||
-rw-r--r-- | xmltv2vdr.cpp | 63 | ||||
-rw-r--r-- | xmltv2vdr.h | 30 |
7 files changed, 195 insertions, 99 deletions
@@ -168,7 +168,7 @@ cEvent *cImport::SearchVDREvent(cSchedule* schedule, cXMLTVEvent *xevent) if (diff<=maxdiff) { if (p->TableID()!=0) - source->Dlog("found '%s' for '%s'",p->Title(),conv->Convert(xevent->Title())); + source->Tlog("found '%s' for '%s'",p->Title(),conv->Convert(xevent->Title())); f=p; maxdiff=diff; } @@ -386,7 +386,7 @@ 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("adding '%s'@%s-%s",xevent->Title(),from,till); + source->Tlog("adding '%s'@%s-%s",xevent->Title(),from,till); } else { @@ -401,7 +401,7 @@ bool cImport::PutEvent(cEPGSource *source, sqlite3 *db, cSchedule* schedule, { if (!strcasecmp(xevent->ShortText(),event->Title())) { - source->Dlog("title and subtitle equal, clearing subtitle"); + source->Tlog("title and subtitle equal, clearing subtitle"); event->SetShortText(""); } else @@ -435,7 +435,7 @@ bool cImport::PutEvent(cEPGSource *source, sqlite3 *db, cSchedule* schedule, if (!description && event->Description() && (strlen(event->Description())>0)) { if (WasChanged(event)) return true; - UpdateXMLTVEvent(source,source->EPGFile(),db,event,source->Name(),xevent->EventID(), + UpdateXMLTVEvent(source,db,event,source->Name(),xevent->EventID(), event->EventID(),event->Description()); description=strdup(event->Description()); } @@ -741,13 +741,13 @@ bool cImport::PutEvent(cEPGSource *source, sqlite3 *db, cSchedule* schedule, switch (changed) { case CHANGED_SHORTTEXT: - source->Dlog("changing shorttext of '%s'@%s-%s",event->Title(),from,till); + source->Tlog("changing shorttext of '%s'@%s-%s",event->Title(),from,till); break; case CHANGED_DESCRIPTION: - source->Dlog("changing description of '%s'@%s-%s",event->Title(),from,till); + source->Tlog("changing description of '%s'@%s-%s",event->Title(),from,till); break; case CHANGED_ALL: - source->Dlog("changing stext+descr of '%s'@%s-%s",event->Title(),from,till); + source->Tlog("changing stext+descr of '%s'@%s-%s",event->Title(),from,till); break; } } @@ -903,7 +903,7 @@ cXMLTVEvent *cImport::AddXMLTVEvent(const char *EPGFile, const char *ChannelID, sqlite3 *db=NULL; if (sqlite3_open_v2(EPGFile,&db,SQLITE_OPEN_READWRITE,NULL)!=SQLITE_OK) { - esyslog("epghandler: failed to open or create %s",EPGFile); + esyslog("epghandler: failed to open %s",EPGFile); free(epdir); iconv_close(conv); return NULL; @@ -945,20 +945,23 @@ cXMLTVEvent *cImport::AddXMLTVEvent(const char *EPGFile, const char *ChannelID, return xevent; } -void cImport::UpdateXMLTVEvent(cEPGSource *Source, const char *EPGFile, sqlite3 *Db, const cEvent *Event, +void cImport::UpdateXMLTVEvent(cEPGSource *Source, sqlite3 *Db, const cEvent *Event, const char *SourceName, tEventID EventID, tEventID EITEventID, const char *EITDescription) { if (!Source) return; - bool closedb=false; - if (!Db) + if (!pendingtransaction) { - if (sqlite3_open_v2(EPGFile,&Db,SQLITE_OPEN_READWRITE,NULL)!=SQLITE_OK) + char *errmsg; + if (sqlite3_exec(Db,"BEGIN",NULL,NULL,&errmsg)!=SQLITE_OK) { - Source->Elog("failed to open %s",EPGFile); - return; + Source->Elog("BEGIN -> %s",errmsg); + sqlite3_free(errmsg); + } + else + { + pendingtransaction=true; } - closedb=true; } char *sql=NULL; @@ -968,7 +971,6 @@ void cImport::UpdateXMLTVEvent(cEPGSource *Source, const char *EPGFile, sqlite3 if (!eitdescription) { Source->Elog("out of memory"); - if (closedb) sqlite3_close(Db); return; } @@ -987,7 +989,6 @@ void cImport::UpdateXMLTVEvent(cEPGSource *Source, const char *EPGFile, sqlite3 { free(eitdescription); Source->Elog("out of memory"); - if (closedb) sqlite3_close(Db); return; } free(eitdescription); @@ -1004,7 +1005,7 @@ void cImport::UpdateXMLTVEvent(cEPGSource *Source, const char *EPGFile, sqlite3 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("updating description of '%s'@%s-%s in db",Event->Title(),from,till); + Source->Tlog("updating description of '%s'@%s-%s in db",Event->Title(),from,till); } } else @@ -1013,7 +1014,6 @@ void cImport::UpdateXMLTVEvent(cEPGSource *Source, const char *EPGFile, sqlite3 (long int) EITEventID,(long int) EventID,SourceName)==-1) { Source->Elog("out of memory"); - if (closedb) sqlite3_close(Db); return; } } @@ -1024,48 +1024,44 @@ void cImport::UpdateXMLTVEvent(cEPGSource *Source, const char *EPGFile, sqlite3 Source->Elog("%s -> %s",sql,errmsg); free(sql); sqlite3_free(errmsg); - if (closedb) sqlite3_close(Db); return; } free(sql); - if (closedb) sqlite3_close(Db); return; } -cXMLTVEvent *cImport::SearchXMLTVEvent(const char *EPGFile, const char *ChannelID, const cEvent *Event) +cXMLTVEvent *cImport::SearchXMLTVEvent(sqlite3 **Db, const char *ChannelID, const cEvent *Event) { if (!Event) return NULL; - if (!EPGFile) return NULL; + if (!Db) return NULL; + if (!*Db) + { + // we need READWRITE because the db maybe updated + if (sqlite3_open_v2(epgfile,Db,SQLITE_OPEN_READWRITE,NULL)!=SQLITE_OK) + { + esyslog("epghandler: failed to open %s",epgfile); + *Db=NULL; + return NULL; + } + } cXMLTVEvent *xevent=NULL; sqlite3_stmt *stmt=NULL; - sqlite3 *db=NULL; char *sql=NULL; - if (sqlite3_open_v2(EPGFile,&db,SQLITE_OPEN_READONLY,NULL)!=SQLITE_OK) - { - esyslog("epghandler: failed to open %s",EPGFile); - return NULL; - } - if (asprintf(&sql,"select channelid,eventid,starttime,duration,title,origtitle,shorttext,description," \ "country,year,credits,category,review,rating,starrating,video,audio,season,episode," \ "mixing,src,eiteventid,eitdescription from epg where eiteventid=%li and channelid='%s' " \ "order by srcidx asc limit 1",(long int) Event->EventID(),ChannelID)==-1) { - sqlite3_close(db); esyslog("epghandler: out of memory"); return NULL; } - xevent=PrepareAndReturn(db,sql,stmt); - if (xevent) - { - sqlite3_close(db); - return xevent; - } + xevent=PrepareAndReturn(*Db,sql,stmt); + if (xevent) return xevent; int eventTimeDiff=0; if (Event->Duration()) eventTimeDiff=Event->Duration()/4; @@ -1074,7 +1070,6 @@ cXMLTVEvent *cImport::SearchXMLTVEvent(const char *EPGFile, const char *ChannelI char *sqltitle=strdup(Event->Title()); if (!sqltitle) { - sqlite3_close(db); esyslog("epghandler: out of memory"); return NULL; } @@ -1101,23 +1096,39 @@ cXMLTVEvent *cImport::SearchXMLTVEvent(const char *EPGFile, const char *ChannelI Event->StartTime()+eventTimeDiff,sqltitle,ChannelID)==-1) { free(sqltitle); - sqlite3_close(db); esyslog("epghandler: out of memory"); return NULL; } free(sqltitle); - xevent=PrepareAndReturn(db,sql,stmt); - if (xevent) - { - sqlite3_close(db); - return xevent; - } + xevent=PrepareAndReturn(*Db,sql,stmt); + if (xevent) return xevent; - sqlite3_close(db); return NULL; } +void cImport::Commit(sqlite3 *Db) +{ + if (!Db) return; + if (pendingtransaction) + { + char *errmsg; + if (sqlite3_exec(Db,"COMMIT",NULL,NULL,&errmsg)!=SQLITE_OK) + { + if (source) + { + source->Elog("sqlite3: %s",errmsg); + } + else + { + esyslog("sqlite3: %s", errmsg); + } + sqlite3_free(errmsg); + } + pendingtransaction=false; + } +} + int cImport::Process(cEPGExecutor &myExecutor) { if (!source) return 0; @@ -1126,29 +1137,11 @@ int cImport::Process(cEPGExecutor &myExecutor) #if VDRVERSNUM < 10726 && (!EPGHANDLER) time_t endoneday=begin+86400; #endif - const cSchedules *schedules=NULL; - cSchedulesLock *schedulesLock=NULL; - int l=0; - while (l<300) - { - if (schedulesLock) delete schedulesLock; - schedulesLock = new cSchedulesLock(true,200); // wait up to 60 secs for lock! - schedules = cSchedules::Schedules(*schedulesLock); - if (schedules) break; - if (!myExecutor.StillRunning()) - { - delete schedulesLock; - source->Ilog("request to stop from vdr"); - return 0; - } - l++; - } sqlite3 *db=NULL; if (sqlite3_open_v2(source->EPGFile(),&db,SQLITE_OPEN_READWRITE,NULL)!=SQLITE_OK) { source->Elog("failed to open %s",source->EPGFile()); - delete schedulesLock; return 141; } @@ -1157,11 +1150,10 @@ int cImport::Process(cEPGExecutor &myExecutor) "country,year,credits,category,review,rating,starrating,video,audio,season,episode," \ "mixing,src,eiteventid,eitdescription from epg where (starttime > %li or " \ " (starttime + duration) > %li) and (starttime + duration) < %li "\ - " and src='%s'",begin,begin,end,source->Name())==-1) + " and src='%s';",begin,begin,end,source->Name())==-1) { sqlite3_close(db); source->Elog("out of memory"); - delete schedulesLock; return 134; } @@ -1171,12 +1163,14 @@ int cImport::Process(cEPGExecutor &myExecutor) sqlite3_close(db); source->Elog("failed to prepare %s",sql); free(sql); - delete schedulesLock; return 141; } free(sql); + cSchedulesLock *schedulesLock=NULL; + const cSchedules *schedules=NULL; int lerr=0; + int cnt=0; for (;;) { if (sqlite3_step(stmt)==SQLITE_ROW) @@ -1207,6 +1201,25 @@ int cImport::Process(cEPGExecutor &myExecutor) lerr=IMPORT_NOCHANNEL; continue; } + + int l=0; + while (l<300) + { + if (schedulesLock) delete schedulesLock; + schedulesLock = new cSchedulesLock(true,200); // wait up to 60 secs for lock! + schedules = cSchedules::Schedules(*schedulesLock); + if (schedules) break; + if (!myExecutor.StillRunning()) + { + delete schedulesLock; + source->Ilog("request to stop from vdr"); + sqlite3_finalize(stmt); + sqlite3_close(db); + return 0; + } + l++; + } + cSchedule* schedule = (cSchedule *) schedules->GetSchedule(channel,addevents); if (!schedule) { @@ -1231,6 +1244,10 @@ int cImport::Process(cEPGExecutor &myExecutor) if ((!addevents) && (xevent.StartTime()>endoneday)) continue; #endif PutEvent(source, db, schedule, event, &xevent, map->Flags()); + cnt++; + + delete schedulesLock; + schedulesLock=NULL; } } } @@ -1240,9 +1257,11 @@ int cImport::Process(cEPGExecutor &myExecutor) } } + Commit(db); + source->Dlog("processed %i xmltv events",cnt); + sqlite3_finalize(stmt); sqlite3_close(db); - delete schedulesLock; return 0; } @@ -1251,6 +1270,7 @@ cImport::cImport(cEPGSource *Source, cEPGMappings* Maps, cTEXTMappings *Texts) maps=Maps; source=Source; texts=Texts; + pendingtransaction=false; if (source) epgfile=source->EPGFile(); char *CodeSet=NULL; @@ -48,11 +48,12 @@ private: cEPGSource *source; cTEXTMappings *texts; cCharSetConv *conv; + bool pendingtransaction; const char *epgfile; char *RemoveLastCharFromDescription(char *description); - char *Add2Description(char *description, const char *Value); - char *Add2Description(char *description, const char *Name, const char *Value); - char *Add2Description(char *description, const char *Name, int Value); + char *Add2Description(char *description, const char *value); + char *Add2Description(char *description, const char *name, const char *value); + char *Add2Description(char *description, const char *name, int value); char *AddEOT2Description(char *description); struct split split(char *in, char delim); cEvent *GetEventBefore(cSchedule* schedule, time_t start); @@ -64,11 +65,12 @@ public: cImport(cEPGSource *Source, cEPGMappings *Maps, cTEXTMappings *Texts); ~cImport(); int Process(cEPGExecutor &myExecutor); + void Commit(sqlite3 *Db); 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); - void UpdateXMLTVEvent(cEPGSource *Source, const char *EPGFile, sqlite3 *Db, const cEvent *Event, + cXMLTVEvent *SearchXMLTVEvent(sqlite3 **Db, const char *ChannelID, const cEvent *Event); + void UpdateXMLTVEvent(cEPGSource *Source, sqlite3 *Db, const cEvent *Event, const char *SourceName, tEventID EventID, tEventID EITEventID, const char *EITDescription=NULL); cXMLTVEvent *AddXMLTVEvent(const char *EPGFile, const char *ChannelID, const cEvent *Event, @@ -564,7 +564,13 @@ int cParse::Process(cEPGExecutor &myExecutor,char *buffer, int bufsize) "starrating text, video text, audio text, season int, episode int, mixing int," \ "srcidx int," \ "PRIMARY KEY(src, channelid, eventid)" \ - ")"; + ");" \ + "CREATE UNIQUE INDEX IF NOT EXISTS idx1 on epg (eventid, src); " \ + "CREATE UNIQUE INDEX IF NOT EXISTS idx2 on epg (eventid, channelid); " \ + "CREATE UNIQUE INDEX IF NOT EXISTS idx3 on epg (eventid, channelid, src); " \ + "CREATE UNIQUE INDEX IF NOT EXISTS idx4 on epg (starttime, title, channelid); " \ + "CREATE INDEX IF NOT EXISTS idx5 on epg (starttime, src); " \ + "BEGIN"; char *errmsg; if (sqlite3_exec(db,sql,NULL,NULL,&errmsg)!=SQLITE_OK) @@ -655,13 +661,12 @@ int cParse::Process(cEPGExecutor &myExecutor,char *buffer, int bufsize) if (!FetchEvent(node)) // sets xevent { - source->Dlog("failed to fetch event"); + source->Tlog("failed to fetch event"); node=node->next; xmlFree(channelid); continue; } - char *errmsg; const char *sql=xevent.GetSQL(source->Name(),source->Index(),(const char *) channelid); if (sqlite3_exec(db,sql,NULL,NULL,&errmsg)!=SQLITE_OK) { @@ -679,6 +684,13 @@ int cParse::Process(cEPGExecutor &myExecutor,char *buffer, int bufsize) break; } } + + if (sqlite3_exec(db,"COMMIT",NULL,NULL,&errmsg)!=SQLITE_OK) + { + source->Elog("sqlite3: %s",errmsg); + sqlite3_free(errmsg); + } + sqlite3_close(db); xmlFreeDoc(xmltv); @@ -781,6 +781,20 @@ void cEPGSource::Elog(const char *format, ...) free(ptr); } +void cEPGSource::Tlog(const char *format, ...) +{ + va_list ap; + char fmt[255]; + if (snprintf(fmt,sizeof(fmt),"xmltv2vdr: '%s' %s",name,format)==-1) return; + va_start(ap, format); + char *ptr; + if (vasprintf(&ptr,fmt,ap)==-1) return; + va_end(ap); + //tsyslog(ptr); + add2Log('D',ptr+14+strlen(name)); + free(ptr); +} + void cEPGSource::Dlog(const char *format, ...) { va_list ap; @@ -158,6 +158,7 @@ public: { return lastexec; } + void Tlog(const char *format, ...); void Dlog(const char *format, ...); void Elog(const char *format, ...); void Ilog(const char *format, ...); diff --git a/xmltv2vdr.cpp b/xmltv2vdr.cpp index 8fdc139..db16f1c 100644 --- a/xmltv2vdr.cpp +++ b/xmltv2vdr.cpp @@ -91,6 +91,7 @@ cEPGHandler::cEPGHandler(cPluginXmltv2vdr *Plugin, const char *EpgFile, cEPGSour epgfile=EpgFile; maps=Maps; sources=Sources; + db=NULL; import = new cImport(NULL,Maps,Texts); } @@ -130,7 +131,7 @@ bool cEPGHandler::SetDescription(cEvent* Event, const char* Description) special_epall_timer_handling=true; } - if (!baseplugin->IsIdle()) + if (!baseplugin->IsIdle(false)) { if (import->WasChanged(Event)) return true; return false; @@ -154,7 +155,7 @@ bool cEPGHandler::SetDescription(cEvent* Event, const char* Description) ChannelID=map->ChannelName(); } - cXMLTVEvent *xevent=import->SearchXMLTVEvent(epgfile,ChannelID,Event); + cXMLTVEvent *xevent=import->SearchXMLTVEvent(&db,ChannelID,Event); if (!xevent) { if (!epall) return false; @@ -166,7 +167,7 @@ bool cEPGHandler::SetDescription(cEvent* Event, const char* Description) } else { - if (!baseplugin->IsIdle()) + if (!baseplugin->IsIdle(false)) { if (import->WasChanged(Event)) return true; return false; @@ -182,7 +183,7 @@ bool cEPGHandler::SetDescription(cEvent* Event, const char* Description) if (update) { - import->UpdateXMLTVEvent(last.Source(),epgfile,NULL,Event,last.xEvent()->Source(), + import->UpdateXMLTVEvent(last.Source(),db,Event,last.xEvent()->Source(), last.xEvent()->EventID(),Event->EventID(),Description); } @@ -208,7 +209,7 @@ bool cEPGHandler::SetParentalRating(cEvent* Event, int ParentalRating) if (!maps->ProcessChannel(Event->ChannelID())) return false; - if (!baseplugin->IsIdle()) + if (!baseplugin->IsIdle(false)) { if (import->WasChanged(Event)) return true; return false; @@ -217,18 +218,18 @@ bool cEPGHandler::SetParentalRating(cEvent* Event, int ParentalRating) cEPGMapping *map=maps->GetMap(Event->ChannelID()); if (!map) return false; - cXMLTVEvent *xevent=import->SearchXMLTVEvent(epgfile,map->ChannelName(),Event); + cXMLTVEvent *xevent=import->SearchXMLTVEvent(&db,map->ChannelName(),Event); if (!xevent) return false; cEPGSource *source=sources->GetSource(xevent->Source()); - if (!xevent->EITEventID()) import->UpdateXMLTVEvent(source,epgfile,NULL,Event,xevent->Source(), + if (!xevent->EITEventID()) import->UpdateXMLTVEvent(source,db,Event,xevent->Source(), xevent->EventID(),Event->EventID()); last.Set(source,xevent,map->Flags()); } else { - if (!baseplugin->IsIdle()) + if (!baseplugin->IsIdle(false)) { if (import->WasChanged(Event)) return true; return false; @@ -236,7 +237,11 @@ bool cEPGHandler::SetParentalRating(cEvent* Event, int ParentalRating) } if (ParentalRating>last.xEvent()->ParentalRating()) return false; // use dvb value - Event->SetParentalRating(last.xEvent()->ParentalRating()); + if (Event->ParentalRating()!=last.xEvent()->ParentalRating()) + { + last.Source()->Tlog("changing rating of '%s'",Event->Title()); + Event->SetParentalRating(last.xEvent()->ParentalRating()); + } return true; } @@ -252,7 +257,7 @@ bool cEPGHandler::SetShortText(cEvent* Event, const char* UNUSED(ShortText)) if (!maps->ProcessChannel(Event->ChannelID())) return false; - if (!baseplugin->IsIdle()) + if (!baseplugin->IsIdle(false)) { if (import->WasChanged(Event)) return true; return false; @@ -261,25 +266,25 @@ bool cEPGHandler::SetShortText(cEvent* Event, const char* UNUSED(ShortText)) cEPGMapping *map=maps->GetMap(Event->ChannelID()); if (!map) return false; - cXMLTVEvent *xevent=import->SearchXMLTVEvent(epgfile,map->ChannelName(),Event); + cXMLTVEvent *xevent=import->SearchXMLTVEvent(&db,map->ChannelName(),Event); if (!xevent) return false; cEPGSource *source=sources->GetSource(xevent->Source()); - if (!xevent->EITEventID()) import->UpdateXMLTVEvent(source,epgfile,NULL,Event,xevent->Source(), + if (!xevent->EITEventID()) import->UpdateXMLTVEvent(source,db,Event,xevent->Source(), xevent->EventID(),Event->EventID()); last.Set(source,xevent,map->Flags()); } else { - if (!baseplugin->IsIdle()) + if (!baseplugin->IsIdle(false)) { if (import->WasChanged(Event)) return true; return false; } } - bool ret=import->PutEvent(last.Source(),NULL,(cSchedule *) Event->Schedule(),Event,last.xEvent(), + bool ret=import->PutEvent(last.Source(),db,(cSchedule *) Event->Schedule(),Event,last.xEvent(), last.Flags(),IMPORT_SHORTTEXT); if (!ret) { @@ -288,6 +293,17 @@ bool cEPGHandler::SetShortText(cEvent* Event, const char* UNUSED(ShortText)) return ret; } +bool cEPGHandler::SortSchedule(cSchedule* UNUSED(Schedule)) +{ + if (db) + { + import->Commit(db); + sqlite3_close(db); + } + return false; // we dont sort! +} + + // ------------------------------------------------------------- cEPGTimer::cEPGTimer(const char *EpgFile, cEPGSources *Sources, cEPGMappings *Maps, @@ -321,6 +337,7 @@ void cEPGTimer::Action() return; } + sqlite3 *db=NULL; for (cTimer *Timer = Timers.First(); Timer; Timer = Timers.Next(Timer)) { cEvent *event=(cEvent *) Timer->Event(); @@ -333,7 +350,7 @@ void cEPGTimer::Action() if (!chan) continue; const char *ChannelID=chan->Name(); - cXMLTVEvent *xevent=import->SearchXMLTVEvent(epgfile,ChannelID,event); + cXMLTVEvent *xevent=import->SearchXMLTVEvent(&db,ChannelID,event); if (!xevent) { xevent=import->AddXMLTVEvent(epgfile,ChannelID,event,event->Description()); @@ -348,6 +365,11 @@ void cEPGTimer::Action() } delete xevent; } + if (db) + { + import->Commit(db); + sqlite3_close(db); + } Timers.DecBeingEdited(); delete schedulesLock; cSchedules::Cleanup(true); @@ -404,9 +426,16 @@ cPluginXmltv2vdr::~cPluginXmltv2vdr() #endif } -bool cPluginXmltv2vdr::IsIdle() +bool cPluginXmltv2vdr::IsIdle(bool IncludeHandler) { - if (!epgexecutor.Active() && (!epgtimer->Active())) return true; + if (IncludeHandler) + { + if (!epgexecutor.Active() && (!epgtimer->Active()) && (!epghandler->Active())) return true; + } + else + { + if (!epgexecutor.Active() && (!epgtimer->Active())) return true; + } return false; } diff --git a/xmltv2vdr.h b/xmltv2vdr.h index 693c0ac..1910ba3 100644 --- a/xmltv2vdr.h +++ b/xmltv2vdr.h @@ -8,6 +8,7 @@ #ifndef _XMLTV2VDR_H #define _XMLTV2VDR_H +#include <sqlite3.h> #include <vdr/plugin.h> #include "maps.h" #include "parse.h" @@ -51,6 +52,10 @@ public: { return false; } + virtual bool SortSchedule(cSchedule *Schedule) + { + return false; + } }; #endif @@ -60,19 +65,28 @@ class cPluginXmltv2vdr; class cEPGHandlerState { - private: +private: cXMLTVEvent *xevent; cEPGSource *source; int flags; - public: +public: cEPGHandlerState(); ~cEPGHandlerState(); void Clear(); void Set(cEPGSource *Source, cXMLTVEvent *xEvent, int Flags); bool isSame(tEventID EventID); - cXMLTVEvent *xEvent() { return xevent; } - cEPGSource *Source() { return source; } - int Flags() { return flags; } + cXMLTVEvent *xEvent() + { + return xevent; + } + cEPGSource *Source() + { + return source; + } + int Flags() + { + return flags; + } }; class cEPGHandler : public cEpgHandler @@ -84,6 +98,8 @@ private: cEPGSources *sources; cImport *import; bool epall; + sqlite3 *db; + void closedb(void); cEPGHandlerState last; public: cEPGHandler(cPluginXmltv2vdr *Plugin, const char *EpgFile, cEPGSources *Sources, @@ -92,12 +108,14 @@ public: { epall=Value; } + bool Active() { return (db!=NULL); } virtual ~cEPGHandler(); virtual bool IgnoreChannel(const cChannel *Channel); virtual bool SetShortText(cEvent *Event, const char *ShortText); virtual bool SetDescription(cEvent *Event, const char *Description); virtual bool SetContents(cEvent *Event, uchar *Contents); virtual bool SetParentalRating(cEvent *Event, int ParentalRating); + virtual bool SortSchedule(cSchedule *Schedule); }; class cEPGTimer : public cThread @@ -161,7 +179,7 @@ public: epgsources.ReadIn(confdir,epgfile,&epgmappings,&textmappings,srcorder,Reload); } void Wait4TimerThread(); - bool IsIdle(); + bool IsIdle(bool IncludeHandler=true); bool EPGSourceMove(int From, int To); int EPGSourceCount() { |