summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--epghandler.c30
-rw-r--r--equivhandler.c56
-rw-r--r--equivhandler.h1
-rw-r--r--util.c85
-rw-r--r--util.h2
5 files changed, 162 insertions, 12 deletions
diff --git a/epghandler.c b/epghandler.c
index 426958d..4f1c786 100644
--- a/epghandler.c
+++ b/epghandler.c
@@ -112,12 +112,17 @@ bool cEEpgHandler::HandleEvent(cEvent* Event) {
Event->SetDescription(origDescription.c_str());
}
- cSchedulesLock SchedulesLock (true);
- cSchedules *s = (cSchedules *) cSchedules::Schedules (SchedulesLock);
- if (s) {
- equivHandler->updateEquivalent(s, Event->ChannelID(), Event);
- } else
- LogE (0, prep("Error: could not lock schedules."));
+ if (equivHandler->getEquiChanMap().count(*Event->ChannelID().ToString()) <= 0)
+ return true;
+
+ equivHandler->updateEquivalent(Event->ChannelID(), Event);
+
+// cSchedulesLock SchedulesLock (true);
+// cSchedules *s = (cSchedules *) cSchedules::Schedules (SchedulesLock);
+// if (s) {
+// equivHandler->updateEquivalent(s, Event->ChannelID(), Event);
+// } else
+// LogE (0, prep("Error: could not lock schedules."));
//TODO just to see the difference
//else if (!origDescription.empty() && !origDescription.compare(Event->Description())) {
@@ -133,12 +138,13 @@ bool cEEpgHandler::SortSchedule(cSchedule* Schedule) {
Schedule->Sort();
- cSchedulesLock SchedulesLock (true);
- cSchedules *s = (cSchedules *) cSchedules::Schedules (SchedulesLock);
- if (s) {
- equivHandler->sortEquivalents(Schedule->ChannelID(), s);
- } else
- LogE (0, prep("Error: could not lock schedules."));
+ //NOK
+// cSchedulesLock SchedulesLock (true);
+// cSchedules *s = (cSchedules *) cSchedules::Schedules (SchedulesLock);
+// if (s) {
+// equivHandler->sortEquivalents(Schedule->ChannelID(), s);
+// } else
+// LogE (0, prep("Error: could not lock schedules."));
return true;
}
diff --git a/equivhandler.c b/equivhandler.c
index 9b0e989..c2846f7 100644
--- a/equivhandler.c
+++ b/equivhandler.c
@@ -184,6 +184,62 @@ void cEquivHandler::updateEquivalent(cSchedules * Schedules, tChannelID channelI
}
}
+void cEquivHandler::updateEquivalent(tChannelID channelID, cEvent *pEvent){
+ multimap<string,string>::iterator it;
+ pair<multimap<string,string>::iterator,multimap<string,string>::iterator> ret;
+
+ LogD(3, prep("Start updateEquivalent %s"), *channelID.ToString());
+
+ ret = equiChanMap.equal_range(*channelID.ToString());
+ for (it=ret.first; it!=ret.second; ++it) {
+ LogD(1, prep("equivalent channel exists"));
+ tChannelID equChannelID (tChannelID::FromString((*it).second.c_str()));
+ cEvent* newEvent = new cEvent (pEvent->EventID());
+ newEvent->SetTableID (pEvent->TableID());
+ newEvent->SetStartTime (pEvent->StartTime());
+ newEvent->SetDuration (pEvent->Duration());
+ newEvent->SetVersion (pEvent->Version());
+// newEvent->SetContents(pEvent->Contents());
+ newEvent->SetParentalRating(pEvent->ParentalRating());
+ newEvent->SetVps (pEvent->Vps());
+ newEvent->SetTitle (pEvent->Title ());
+ newEvent->SetShortText (pEvent->ShortText ());
+ newEvent->SetDescription (pEvent->Description ());
+// newEvent->SetComponents (pEvent->Components());
+ AddEvent(newEvent, equChannelID);
+ }
+}
+
+
+//cSchedule * findFisrtSchedule (cSchedule * Schedule) {
+// if (Schedule->Prev())
+// return findFisrtSchedule((cSchedule *)Schedule->Prev());
+// else
+// return Schedule;
+//}
+//
+//cSchedule * findSchedule (cSchedule * Schedule, tChannelID channelID) {
+// if (Schedule->ChannelID() == channelID)
+// return Schedule;
+//
+// if (Schedule->Next())
+// return findSchedule((cSchedule *)Schedule->Next(), channelID);
+// else
+// return NULL;
+//}
+//
+//cSchedule * findEqvSchedule (cSchedule * Schedule, tChannelID channelID) {
+// cSchedule* foundSchedule = findSchedule(findFisrtSchedule(Schedule),channelID);
+//
+// if (foundSchedule)
+// return foundSchedule;
+//
+// cSchedule* sch = new cSchedule(channelID);
+// Schedule->Insert(sch);
+// return sch;
+//}
+
+
void cEquivHandler::sortEquivalents(tChannelID channelID, cSchedules* Schedules)
{
multimap<string, string>::iterator it;
diff --git a/equivhandler.h b/equivhandler.h
index fdfd343..7e7cad7 100644
--- a/equivhandler.h
+++ b/equivhandler.h
@@ -25,6 +25,7 @@ public:
void loadEquivalentChannelMap (void);
void updateEquivalent(cSchedules * Schedules, tChannelID channelID, cEvent *pEvent);
+ void updateEquivalent(tChannelID channelID, cEvent *pEvent);
void sortEquivalents(tChannelID channelID, cSchedules* Schedules);
static multimap<string, string> getEquiChanMap() { return cEquivHandler::equiChanMap; };
diff --git a/util.c b/util.c
index b60547d..d2a5c36 100644
--- a/util.c
+++ b/util.c
@@ -6,6 +6,7 @@
*/
#include "util.h"
#include <vdr/channels.h>
+#include <vdr/thread.h>
namespace util
{
@@ -113,4 +114,88 @@ void CleanString (unsigned char *String)
// LogD (1, prep("Clean: %s"), String);
}
+// --- cAddEventThread ----------------------------------------
+// Taken from VDR EPGFixer Plug-in
+// http://projects.vdr-developer.org/projects/plg-epgfixer
+// by Matti Lehtimaki
+
+class cAddEventListItem : public cListObject
+{
+protected:
+ cEvent *event;
+ tChannelID channelID;
+public:
+ cAddEventListItem(cEvent *Event, tChannelID ChannelID) { event = Event; channelID = ChannelID; }
+ tChannelID GetChannelID() { return channelID; }
+ cEvent *GetEvent() { return event; }
+ ~cAddEventListItem() { }
+};
+
+class cAddEventThread : public cThread
+{
+private:
+ cTimeMs LastHandleEvent;
+ cList<cAddEventListItem> *list;
+ enum { INSERT_TIMEOUT_IN_MS = 10000 };
+protected:
+ virtual void Action(void);
+public:
+ cAddEventThread(void);
+ ~cAddEventThread(void);
+ void AddEvent(cEvent *Event, tChannelID ChannelID);
+};
+
+cAddEventThread::cAddEventThread(void)
+:cThread("cAddEventThread"), LastHandleEvent()
+{
+ list = new cList<cAddEventListItem>;
+}
+
+cAddEventThread::~cAddEventThread(void)
+{
+ LOCK_THREAD;
+ list->cList::Clear();
+ Cancel(3);
+}
+
+void cAddEventThread::Action(void)
+{
+ SetPriority(19);
+ while (Running() && !LastHandleEvent.TimedOut()) {
+ cAddEventListItem *e = NULL;
+ cSchedulesLock SchedulesLock(true, 10);
+ cSchedules *schedules = (cSchedules *)cSchedules::Schedules(SchedulesLock);
+ Lock();
+ while (schedules && (e = list->First()) != NULL) {
+ cSchedule *schedule = (cSchedule *)schedules->GetSchedule(Channels.GetByChannelID(e->GetChannelID()), true);
+ schedule->AddEvent(e->GetEvent());
+ EpgHandlers.SortSchedule(schedule);
+ EpgHandlers.DropOutdated(schedule, e->GetEvent()->StartTime(), e->GetEvent()->EndTime(), e->GetEvent()->TableID(), e->GetEvent()->Version());
+ list->Del(e);
+ }
+ Unlock();
+ cCondWait::SleepMs(10);
+ }
}
+
+void cAddEventThread::AddEvent(cEvent *Event, tChannelID ChannelID)
+{
+ LOCK_THREAD;
+ list->Add(new cAddEventListItem(Event, ChannelID));
+ LastHandleEvent.Set(INSERT_TIMEOUT_IN_MS);
+}
+
+static cAddEventThread AddEventThread;
+
+// ---
+
+void AddEvent(cEvent *Event, tChannelID ChannelID)
+{
+ AddEventThread.AddEvent(Event, ChannelID);
+ if (!AddEventThread.Active())
+ AddEventThread.Start();
+}
+
+
+}
+
diff --git a/util.h b/util.h
index 8c12184..41a8204 100644
--- a/util.h
+++ b/util.h
@@ -20,6 +20,8 @@ int Yesterday;
int YesterdayEpoch;
int YesterdayEpochUTC;
+void AddEvent(cEvent *event, tChannelID ChannelID);
+
cChannel *GetChannelByID(tChannelID & channelID, bool searchOtherPos);
time_t LocalTime2UTC (time_t t);
time_t UTC2LocalTime (time_t t);