From 7089617d8186143cfe946596dfafd650cb3028f9 Mon Sep 17 00:00:00 2001 From: Dimitar Petrovski Date: Wed, 23 May 2012 22:07:47 +0200 Subject: move utilities to separate files --- util.c | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 util.c (limited to 'util.c') diff --git a/util.c b/util.c new file mode 100644 index 0000000..68708d7 --- /dev/null +++ b/util.c @@ -0,0 +1,113 @@ +/* + * util.c + * + * Created on: 23.5.2012 + * Author: d.petrovski + */ + +int NumberOfAvailableSources = 0; + +cChannel *GetChannelByID(tChannelID & channelID, bool searchOtherPos) +{ + cChannel *VC = Channels.GetByChannelID(channelID, true); + if(!VC && searchOtherPos){ + //look on other satpositions + for(int i = 0;i < NumberOfAvailableSources;i++){ + channelID = tChannelID(AvailableSources[i], channelID.Nid(), channelID.Tid(), channelID.Sid()); + VC = Channels.GetByChannelID(channelID, true); + if(VC){ + //found this actually on satellite nextdoor... + break; + } + } + } + + return VC; +} + +/* + * Convert local time to UTC + */ +time_t LocalTime2UTC (time_t t) +{ + struct tm *temp; + + temp = gmtime (&t); + temp->tm_isdst = -1; + return mktime (temp); +} + +/* + * Convert UTC to local time + */ +time_t UTC2LocalTime (time_t t) +{ + return 2 * t - LocalTime2UTC (t); +} + +void GetLocalTimeOffset (void) +{ + time_t timeLocal; + struct tm *tmCurrent; + + timeLocal = time (NULL); + timeLocal -= 86400; + tmCurrent = gmtime (&timeLocal); + Yesterday = tmCurrent->tm_wday; + tmCurrent->tm_hour = 0; + tmCurrent->tm_min = 0; + tmCurrent->tm_sec = 0; + tmCurrent->tm_isdst = -1; + YesterdayEpoch = mktime (tmCurrent); + YesterdayEpochUTC = UTC2LocalTime (mktime (tmCurrent)); +} + +void CleanString (unsigned char *String) +{ + +// LogD (1, prep("Unclean: %s"), String); + unsigned char *Src; + unsigned char *Dst; + int Spaces; + int pC; + Src = String; + Dst = String; + Spaces = 0; + pC = 0; + while (*Src) { + // corrections + if (*Src == 0x8c) { // iso-8859-2 LATIN CAPITAL LETTER S WITH ACUTE + *Src = 0xa6; + } + if (*Src == 0x8f) { // iso-8859-2 LATIN CAPITAL LETTER Z WITH ACUTE + *Src = 0xac; + } + + if (*Src!=0x0A && *Src < 0x20) { //don't remove newline + *Src = 0x20; + } + if (*Src == 0x20) { + Spaces++; + if (pC == 0) { + Spaces++; + } + } else { + Spaces = 0; + } + if (Spaces < 2) { + *Dst = *Src; + Dst++; + pC++; + } + Src++; + } + if (Spaces > 0) { + Dst--; + *Dst = 0; + } else { + *Dst = 0; + } +// LogD (1, prep("Clean: %s"), String); +} + + -- cgit v1.2.3 From 80c9c7fa84f17dbe2779c2a27dac82a001e33101 Mon Sep 17 00:00:00 2001 From: Dimitar Petrovski Date: Thu, 24 May 2012 10:49:55 +0200 Subject: add namespace util --- util.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'util.c') diff --git a/util.c b/util.c index 68708d7..b60547d 100644 --- a/util.c +++ b/util.c @@ -4,8 +4,11 @@ * Created on: 23.5.2012 * Author: d.petrovski */ +#include "util.h" +#include -int NumberOfAvailableSources = 0; +namespace util +{ cChannel *GetChannelByID(tChannelID & channelID, bool searchOtherPos) { @@ -110,4 +113,4 @@ void CleanString (unsigned char *String) // LogD (1, prep("Clean: %s"), String); } - +} -- cgit v1.2.3 From 15fee6896cb3cc24c0ae14106efdbc328a07ff79 Mon Sep 17 00:00:00 2001 From: Dimitar Petrovski Date: Fri, 1 Jun 2012 01:17:44 +0200 Subject: fix compile, but can not lock schedule --- util.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'util.c') diff --git a/util.c b/util.c index b60547d..069753f 100644 --- a/util.c +++ b/util.c @@ -10,6 +10,13 @@ namespace util { +int AvailableSources[32]; +int NumberOfAvailableSources = 0; + +int Yesterday; +int YesterdayEpoch; +int YesterdayEpochUTC; + cChannel *GetChannelByID(tChannelID & channelID, bool searchOtherPos) { cChannel *VC = Channels.GetByChannelID(channelID, true); -- cgit v1.2.3 From 2505269770dafd11394db3443a2a165a353d73c4 Mon Sep 17 00:00:00 2001 From: Dimitar Petrovski Date: Fri, 1 Jun 2012 16:00:14 +0200 Subject: added cAddEventThread from VDR EPGFixer Plug-in to update equivalent channels in separate thread --- util.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) (limited to 'util.c') 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 +#include 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 *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; +} + +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(); +} + + +} + -- cgit v1.2.3 From eb44800641ed5e60e23d173e027688f67c1981cc Mon Sep 17 00:00:00 2001 From: Dimitar Petrovski Date: Sat, 2 Jun 2012 11:52:32 +0200 Subject: fix compile fix sortEquivalents modify loging --- util.c | 1 + 1 file changed, 1 insertion(+) (limited to 'util.c') diff --git a/util.c b/util.c index bbfffb2..3d92dda 100644 --- a/util.c +++ b/util.c @@ -7,6 +7,7 @@ #include "util.h" #include #include +#include namespace util { -- cgit v1.2.3 From 786d8d3a6194141ef78f309e22aca6c3b4d16491 Mon Sep 17 00:00:00 2001 From: Dimitar Petrovski Date: Sat, 2 Jun 2012 17:20:45 +0200 Subject: use map instead of list in cAddEventThread to reduce sorting --- util.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 56 insertions(+), 23 deletions(-) (limited to 'util.c') diff --git a/util.c b/util.c index 3d92dda..38e5074 100644 --- a/util.c +++ b/util.c @@ -9,6 +9,8 @@ #include #include +#include + namespace util { @@ -127,23 +129,24 @@ void CleanString (unsigned char *String) // 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 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 *list; +// cList *list; + std::map*> *map_list; enum { INSERT_TIMEOUT_IN_MS = 10000 }; protected: virtual void Action(void); @@ -156,13 +159,17 @@ public: cAddEventThread::cAddEventThread(void) :cThread("cAddEventThread"), LastHandleEvent() { - list = new cList; +// list = new cList; + map_list = new std::map*>; } cAddEventThread::~cAddEventThread(void) { LOCK_THREAD; - list->cList::Clear(); +// list->cList::Clear(); + std::map*>::iterator it; + for ( it=map_list->begin() ; it != map_list->end(); it++ ) + (*it).second->cList::Clear(); Cancel(3); } @@ -170,17 +177,36 @@ void cAddEventThread::Action(void) { SetPriority(19); while (Running() && !LastHandleEvent.TimedOut()) { - cAddEventListItem *e = NULL; +// 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); - } +// 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); +// } + std::map*>::iterator it; + if (schedules) { + for ( it=map_list->begin() ; it != map_list->end(); it++ ) { + (*it).second->cList::Clear(); + cSchedule *schedule = (cSchedule *)schedules->GetSchedule(Channels.GetByChannelID((*it).first), true); + while (schedules && ((*it).second->First()) != NULL) { + cEvent* event = (*it).second->First(); + + cEvent *pEqvEvent = (cEvent *) schedule->GetEvent (event->EventID(), event->StartTime()); + if (pEqvEvent) + schedule->DelEvent(pEqvEvent); + + schedule->AddEvent(event); + (*it).second->Del(event); + } + EpgHandlers.SortSchedule(schedule); + + } + } Unlock(); cCondWait::SleepMs(10); } @@ -189,7 +215,14 @@ void cAddEventThread::Action(void) void cAddEventThread::AddEvent(cEvent *Event, tChannelID ChannelID) { LOCK_THREAD; - list->Add(new cAddEventListItem(Event, ChannelID)); + if (map_list->empty() || map_list->count(ChannelID) == 0) { + cList* list = new cList; + list->Add(Event); + map_list->insert(std::pair*>(ChannelID, list)); + } else { + (*map_list->find(ChannelID)).second->Add(Event); + } +// list->Add(new cAddEventListItem(Event, ChannelID)); LastHandleEvent.Set(INSERT_TIMEOUT_IN_MS); } -- cgit v1.2.3 From 1e5c78ae3b461343f87d49210116c20d5203ca7a Mon Sep 17 00:00:00 2001 From: Dimitar Petrovski Date: Sat, 2 Jun 2012 18:02:38 +0200 Subject: add tChannelIDCompare --- util.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'util.c') diff --git a/util.c b/util.c index 38e5074..08514bf 100644 --- a/util.c +++ b/util.c @@ -141,12 +141,21 @@ void CleanString (unsigned char *String) // ~cAddEventListItem() { } //}; +struct tChannelIDCompare +{ + bool operator() (const tChannelID& lhs, const tChannelID& rhs) + { + return lhs.ToString() < rhs.ToString(); + } +}; + + class cAddEventThread : public cThread { private: cTimeMs LastHandleEvent; // cList *list; - std::map*> *map_list; + std::map*,tChannelIDCompare> *map_list; enum { INSERT_TIMEOUT_IN_MS = 10000 }; protected: virtual void Action(void); @@ -194,7 +203,7 @@ void cAddEventThread::Action(void) (*it).second->cList::Clear(); cSchedule *schedule = (cSchedule *)schedules->GetSchedule(Channels.GetByChannelID((*it).first), true); while (schedules && ((*it).second->First()) != NULL) { - cEvent* event = (*it).second->First(); + cEvent* event = *(*it).second->First(); cEvent *pEqvEvent = (cEvent *) schedule->GetEvent (event->EventID(), event->StartTime()); if (pEqvEvent) @@ -218,7 +227,7 @@ void cAddEventThread::AddEvent(cEvent *Event, tChannelID ChannelID) if (map_list->empty() || map_list->count(ChannelID) == 0) { cList* list = new cList; list->Add(Event); - map_list->insert(std::pair*>(ChannelID, list)); + map_list->insert(std::make_pair(ChannelID, list)); } else { (*map_list->find(ChannelID)).second->Add(Event); } -- cgit v1.2.3 From 0a2aad0200af8d7fd43e72600eaeea043fb1d37a Mon Sep 17 00:00:00 2001 From: Dimitar Petrovski Date: Sat, 2 Jun 2012 19:13:11 +0200 Subject: fix compile but crashes --- util.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'util.c') diff --git a/util.c b/util.c index 08514bf..a508525 100644 --- a/util.c +++ b/util.c @@ -143,9 +143,9 @@ void CleanString (unsigned char *String) struct tChannelIDCompare { - bool operator() (const tChannelID& lhs, const tChannelID& rhs) + bool operator() (const tChannelID& lhs, const tChannelID& rhs) const { - return lhs.ToString() < rhs.ToString(); + return *lhs.ToString() < *rhs.ToString(); } }; @@ -169,14 +169,14 @@ cAddEventThread::cAddEventThread(void) :cThread("cAddEventThread"), LastHandleEvent() { // list = new cList; - map_list = new std::map*>; + map_list = new std::map*,tChannelIDCompare>; } cAddEventThread::~cAddEventThread(void) { LOCK_THREAD; // list->cList::Clear(); - std::map*>::iterator it; + std::map*,tChannelIDCompare>::iterator it; for ( it=map_list->begin() ; it != map_list->end(); it++ ) (*it).second->cList::Clear(); Cancel(3); @@ -197,7 +197,7 @@ void cAddEventThread::Action(void) // EpgHandlers.DropOutdated(schedule, e->GetEvent()->StartTime(), e->GetEvent()->EndTime(), e->GetEvent()->TableID(), e->GetEvent()->Version()); // list->Del(e); // } - std::map*>::iterator it; + std::map*,tChannelIDCompare>::iterator it; if (schedules) { for ( it=map_list->begin() ; it != map_list->end(); it++ ) { (*it).second->cList::Clear(); -- cgit v1.2.3 From a443439bbf37cf77a349aa7d848536505ab9fafa Mon Sep 17 00:00:00 2001 From: Dimitar Petrovski Date: Sun, 3 Jun 2012 22:44:02 +0200 Subject: revert util.c and moved to separate branch --- util.c | 84 +++++++++++++++++------------------------------------------------- 1 file changed, 21 insertions(+), 63 deletions(-) (limited to 'util.c') diff --git a/util.c b/util.c index a508525..3d92dda 100644 --- a/util.c +++ b/util.c @@ -9,8 +9,6 @@ #include #include -#include - namespace util { @@ -129,33 +127,23 @@ void CleanString (unsigned char *String) // 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() { } -//}; - -struct tChannelIDCompare +class cAddEventListItem : public cListObject { - bool operator() (const tChannelID& lhs, const tChannelID& rhs) const - { - return *lhs.ToString() < *rhs.ToString(); - } +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 *list; - std::map*,tChannelIDCompare> *map_list; + cList *list; enum { INSERT_TIMEOUT_IN_MS = 10000 }; protected: virtual void Action(void); @@ -168,17 +156,13 @@ public: cAddEventThread::cAddEventThread(void) :cThread("cAddEventThread"), LastHandleEvent() { -// list = new cList; - map_list = new std::map*,tChannelIDCompare>; + list = new cList; } cAddEventThread::~cAddEventThread(void) { LOCK_THREAD; -// list->cList::Clear(); - std::map*,tChannelIDCompare>::iterator it; - for ( it=map_list->begin() ; it != map_list->end(); it++ ) - (*it).second->cList::Clear(); + list->cList::Clear(); Cancel(3); } @@ -186,36 +170,17 @@ void cAddEventThread::Action(void) { SetPriority(19); while (Running() && !LastHandleEvent.TimedOut()) { -// cAddEventListItem *e = NULL; + 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); -// } - std::map*,tChannelIDCompare>::iterator it; - if (schedules) { - for ( it=map_list->begin() ; it != map_list->end(); it++ ) { - (*it).second->cList::Clear(); - cSchedule *schedule = (cSchedule *)schedules->GetSchedule(Channels.GetByChannelID((*it).first), true); - while (schedules && ((*it).second->First()) != NULL) { - cEvent* event = *(*it).second->First(); - - cEvent *pEqvEvent = (cEvent *) schedule->GetEvent (event->EventID(), event->StartTime()); - if (pEqvEvent) - schedule->DelEvent(pEqvEvent); - - schedule->AddEvent(event); - (*it).second->Del(event); - } - EpgHandlers.SortSchedule(schedule); - - } - } + 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); } @@ -224,14 +189,7 @@ void cAddEventThread::Action(void) void cAddEventThread::AddEvent(cEvent *Event, tChannelID ChannelID) { LOCK_THREAD; - if (map_list->empty() || map_list->count(ChannelID) == 0) { - cList* list = new cList; - list->Add(Event); - map_list->insert(std::make_pair(ChannelID, list)); - } else { - (*map_list->find(ChannelID)).second->Add(Event); - } -// list->Add(new cAddEventListItem(Event, ChannelID)); + list->Add(new cAddEventListItem(Event, ChannelID)); LastHandleEvent.Set(INSERT_TIMEOUT_IN_MS); } -- cgit v1.2.3 From 5e7d26da37cee78f6cb943ba10bae6455ee1e73b Mon Sep 17 00:00:00 2001 From: Dimitar Petrovski Date: Sun, 3 Jun 2012 23:56:44 +0200 Subject: removed list clear --- util.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 62 insertions(+), 21 deletions(-) (limited to 'util.c') diff --git a/util.c b/util.c index 3d92dda..e398eca 100644 --- a/util.c +++ b/util.c @@ -9,6 +9,8 @@ #include #include +#include + namespace util { @@ -127,23 +129,33 @@ void CleanString (unsigned char *String) // http://projects.vdr-developer.org/projects/plg-epgfixer // by Matti Lehtimaki -class cAddEventListItem : public cListObject +//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() { } +//}; + +struct tChannelIDCompare { -protected: - cEvent *event; - tChannelID channelID; -public: - cAddEventListItem(cEvent *Event, tChannelID ChannelID) { event = Event; channelID = ChannelID; } - tChannelID GetChannelID() { return channelID; } - cEvent *GetEvent() { return event; } - ~cAddEventListItem() { } + bool operator() (const tChannelID& lhs, const tChannelID& rhs) const + { + return *lhs.ToString() < *rhs.ToString(); + } }; + class cAddEventThread : public cThread { private: cTimeMs LastHandleEvent; - cList *list; +// cList *list; + std::map*,tChannelIDCompare> *map_list; enum { INSERT_TIMEOUT_IN_MS = 10000 }; protected: virtual void Action(void); @@ -156,13 +168,17 @@ public: cAddEventThread::cAddEventThread(void) :cThread("cAddEventThread"), LastHandleEvent() { - list = new cList; +// list = new cList; + map_list = new std::map*,tChannelIDCompare>; } cAddEventThread::~cAddEventThread(void) { LOCK_THREAD; - list->cList::Clear(); +// list->cList::Clear(); + std::map*,tChannelIDCompare>::iterator it; + for ( it=map_list->begin() ; it != map_list->end(); it++ ) + (*it).second->cList::Clear(); Cancel(3); } @@ -170,17 +186,35 @@ void cAddEventThread::Action(void) { SetPriority(19); while (Running() && !LastHandleEvent.TimedOut()) { - cAddEventListItem *e = NULL; +// 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); - } +// 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); +// } + std::map*,tChannelIDCompare>::iterator it; + if (schedules) { + for ( it=map_list->begin() ; it != map_list->end(); it++ ) { + cSchedule *schedule = (cSchedule *)schedules->GetSchedule(Channels.GetByChannelID((*it).first), true); + while (schedules && ((*it).second->First()) != NULL) { + cEvent* event = *(*it).second->First(); + + cEvent *pEqvEvent = (cEvent *) schedule->GetEvent (event->EventID(), event->StartTime()); + if (pEqvEvent) + schedule->DelEvent(pEqvEvent); + + schedule->AddEvent(event); + (*it).second->Del(event); + } + EpgHandlers.SortSchedule(schedule); + + } + } Unlock(); cCondWait::SleepMs(10); } @@ -189,7 +223,14 @@ void cAddEventThread::Action(void) void cAddEventThread::AddEvent(cEvent *Event, tChannelID ChannelID) { LOCK_THREAD; - list->Add(new cAddEventListItem(Event, ChannelID)); + if (map_list->empty() || map_list->count(ChannelID) == 0) { + cList* list = new cList; + list->Add(Event); + map_list->insert(std::make_pair(ChannelID, list)); + } else { + (*map_list->find(ChannelID)).second->Add(Event); + } +// list->Add(new cAddEventListItem(Event, ChannelID)); LastHandleEvent.Set(INSERT_TIMEOUT_IN_MS); } -- cgit v1.2.3 From 7335a91779b6bef557cef1a4697f27b85a0627c0 Mon Sep 17 00:00:00 2001 From: Dimitar Petrovski Date: Mon, 4 Jun 2012 00:15:36 +0200 Subject: remove empty list from map --- util.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'util.c') diff --git a/util.c b/util.c index e398eca..076401f 100644 --- a/util.c +++ b/util.c @@ -198,22 +198,23 @@ void cAddEventThread::Action(void) // list->Del(e); // } std::map*,tChannelIDCompare>::iterator it; - if (schedules) { - for ( it=map_list->begin() ; it != map_list->end(); it++ ) { - cSchedule *schedule = (cSchedule *)schedules->GetSchedule(Channels.GetByChannelID((*it).first), true); - while (schedules && ((*it).second->First()) != NULL) { - cEvent* event = *(*it).second->First(); - - cEvent *pEqvEvent = (cEvent *) schedule->GetEvent (event->EventID(), event->StartTime()); - if (pEqvEvent) - schedule->DelEvent(pEqvEvent); - - schedule->AddEvent(event); - (*it).second->Del(event); - } - EpgHandlers.SortSchedule(schedule); - + it=map_list->begin(); + while (schedules && it != map_list->end()) { + cSchedule *schedule = (cSchedule *)schedules->GetSchedule(Channels.GetByChannelID((*it).first), true); + while (((*it).second->First()) != NULL) { + cEvent* event = *(*it).second->First(); + + cEvent *pEqvEvent = (cEvent *) schedule->GetEvent (event->EventID(), event->StartTime()); + if (pEqvEvent) + schedule->DelEvent(pEqvEvent); + + schedule->AddEvent(event); + (*it).second->Del(event); } + EpgHandlers.SortSchedule(schedule); + delete (*it).second; + map_list->erase(it++); + } Unlock(); cCondWait::SleepMs(10); -- cgit v1.2.3 From cee549473dacfa3e82cb13bd9bbe1c8f0e8c1a6a Mon Sep 17 00:00:00 2001 From: Dimitar Petrovski Date: Tue, 16 Oct 2012 21:01:06 +0200 Subject: fix some includes --- util.c | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) (limited to 'util.c') diff --git a/util.c b/util.c index 3d92dda..c1cc69d 100644 --- a/util.c +++ b/util.c @@ -204,6 +204,123 @@ void AddEvent(cEvent *Event, tChannelID ChannelID) AddEventThread.Start(); } +/** \brief Decode an EPG string as necessary + * + * \param src - Possibly encoded string + * \param size - Size of the buffer + * + * \retval NULL - Can't decode + * \return A decoded string + */ +char *freesat_huffman_decode (const unsigned char *src, size_t size) +{ + int tableid; +// freesat_decode_error = 0; + + if (src[0] == 0x1f && (src[1] == 1 || src[1] == 2)) { + int uncompressed_len = 30; + char *uncompressed = (char *) calloc (1, uncompressed_len + 1); + unsigned value = 0, byte = 2, bit = 0; + int p = 0; + unsigned char lastch = START; + + tableid = src[1] - 1; + while (byte < 6 && byte < size) { + value |= src[byte] << ((5 - byte) * 8); + byte++; + } + //freesat_table_load (); /**< Load the tables as necessary */ + + do { + bool found = false; + unsigned bitShift = 0; + if (lastch == ESCAPE) { + char nextCh = (value >> 24) & 0xff; + found = true; + // Encoded in the next 8 bits. + // Terminated by the first ASCII character. + bitShift = 8; + if ((nextCh & 0x80) == 0) + lastch = nextCh; + if (p >= uncompressed_len) { + uncompressed_len += 10; + uncompressed = (char *) REALLOC (uncompressed, uncompressed_len + 1); + } + uncompressed[p++] = nextCh; + uncompressed[p] = 0; + } else { + int j; + for (j = 0; j < table_size[tableid][lastch]; j++) { + unsigned mask = 0, maskbit = 0x80000000; + short kk; + for (kk = 0; kk < tables[tableid][lastch][j].bits; kk++) { + mask |= maskbit; + maskbit >>= 1; + } + if ((value & mask) == tables[tableid][lastch][j].value) { + char nextCh = tables[tableid][lastch][j].next; + bitShift = tables[tableid][lastch][j].bits; + if (nextCh != STOP && nextCh != ESCAPE) { + if (p >= uncompressed_len) { + uncompressed_len += 10; + uncompressed = (char *) REALLOC (uncompressed, uncompressed_len + 1); + } + uncompressed[p++] = nextCh; + uncompressed[p] = 0; + } + found = true; + lastch = nextCh; + break; + } + } + } + if (found) { + // Shift up by the number of bits. + unsigned b; + for (b = 0; b < bitShift; b++) { + value = (value << 1) & 0xfffffffe; + if (byte < size) + value |= (src[byte] >> (7 - bit)) & 1; + if (bit == 7) { + bit = 0; + byte++; + } else + bit++; + } + } else { + LogE (0, prep("Missing table %d entry: <%s>"), tableid + 1, uncompressed); + // Entry missing in table. + return uncompressed; + } + } while (lastch != STOP && value != 0); + + return uncompressed; + } + return NULL; +} + +void decodeText2 (const unsigned char *from, int len, char *buffer, int buffsize) +{ + if (from[0] == 0x1f) { + char *temp = freesat_huffman_decode (from, len); + if (temp) { + len = strlen (temp); + len = len < buffsize - 1 ? len : buffsize - 1; + strncpy (buffer, temp, len); + buffer[len] = 0; + free (temp); + return; + } + } + + SI::String convStr; + SI::CharArray charArray; + charArray.assign(from, len); + convStr.setData(charArray, len); + //LogE(5, prep("decodeText2 from %s - length %d"), from, len); + convStr.getText(buffer, buffsize); + //LogE(5, prep("decodeText2 buffer %s - buffsize %d"), buffer, buffsize); +} } -- cgit v1.2.3 From 6810f79e1b5f78a0b3d2389714924738295a6497 Mon Sep 17 00:00:00 2001 From: Dimitar Petrovski Date: Thu, 18 Oct 2012 14:32:04 +0200 Subject: fix compile --- util.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'util.c') diff --git a/util.c b/util.c index c1cc69d..2683131 100644 --- a/util.c +++ b/util.c @@ -5,6 +5,8 @@ * Author: d.petrovski */ #include "util.h" +#include "log.h" +#include "equivhandler.h" #include #include #include @@ -19,6 +21,12 @@ int Yesterday; int YesterdayEpoch; int YesterdayEpochUTC; +struct hufftab *tables[2][128]; +int table_size[2][128]; + +EFormat Format; +cEquivHandler* EquivHandler; + cChannel *GetChannelByID(tChannelID & channelID, bool searchOtherPos) { cChannel *VC = Channels.GetByChannelID(channelID, true); @@ -322,5 +330,20 @@ void decodeText2 (const unsigned char *from, int len, char *buffer, int buffsize //LogE(5, prep("decodeText2 buffer %s - buffsize %d"), buffer, buffsize); } +void sortSchedules(cSchedules * Schedules, tChannelID channelID){ + + LogD(3, prep("Start sortEquivalent %s"), *channelID.ToString()); + + cChannel *pChannel = GetChannelByID (channelID, false); + cSchedule *pSchedule; + if (pChannel) { + pSchedule = (cSchedule *) (Schedules->GetSchedule(pChannel, true)); + pSchedule->Sort(); + Schedules->SetModified(pSchedule); + } + if (EquivHandler->getEquiChanMap().count(*channelID.ToString()) > 0) + EquivHandler->sortEquivalents(channelID, Schedules); +} + } -- cgit v1.2.3 From 0e805561c58f3a63448b99b71b23a02caa9641e3 Mon Sep 17 00:00:00 2001 From: Dimitar Petrovski Date: Fri, 19 Oct 2012 11:13:06 +0200 Subject: modified iterator increment --- util.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'util.c') diff --git a/util.c b/util.c index 076401f..6df6137 100644 --- a/util.c +++ b/util.c @@ -213,7 +213,8 @@ void cAddEventThread::Action(void) } EpgHandlers.SortSchedule(schedule); delete (*it).second; - map_list->erase(it++); + map_list->erase(it); + it=map_list->begin(); } Unlock(); -- cgit v1.2.3 From 296fe61d7cf2f10dabd762ba29fe1cbf5a3368c5 Mon Sep 17 00:00:00 2001 From: Dimitar Petrovski Date: Sat, 20 Oct 2012 12:46:13 +0200 Subject: removed some valgrind warinigs try: optimize the sort schedule in add event thread optimize updating of equivalent channels fix deletion of theme and category on eit update --- util.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'util.c') diff --git a/util.c b/util.c index 2683131..92164a6 100644 --- a/util.c +++ b/util.c @@ -183,11 +183,17 @@ void cAddEventThread::Action(void) cSchedules *schedules = (cSchedules *)cSchedules::Schedules(SchedulesLock); Lock(); while (schedules && (e = list->First()) != NULL) { + tChannelID chID = e->GetChannelID(); cSchedule *schedule = (cSchedule *)schedules->GetSchedule(Channels.GetByChannelID(e->GetChannelID()), true); + while (schedules && (e = list->First()) != NULL) { + + if (chID == e->GetChannelID()) { 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); + } + } + EpgHandlers.SortSchedule(schedule); +// EpgHandlers.DropOutdated(schedule, e->GetEvent()->StartTime(), e->GetEvent()->EndTime(), e->GetEvent()->TableID(), e->GetEvent()->Version()); } Unlock(); cCondWait::SleepMs(10); -- cgit v1.2.3 From c048d5c85ebb94afb8543be5aca1f8a57c36525b Mon Sep 17 00:00:00 2001 From: Dimitar Petrovski Date: Sat, 20 Oct 2012 17:25:43 +0200 Subject: fix valgrind warinigs --- util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'util.c') diff --git a/util.c b/util.c index 92164a6..428aeb8 100644 --- a/util.c +++ b/util.c @@ -121,7 +121,7 @@ void CleanString (unsigned char *String) } Src++; } - if (Spaces > 0) { + if (Spaces > 0 && String > Dst) { Dst--; *Dst = 0; } else { -- cgit v1.2.3 From 28d4e67c2a4bcb355f8e525890a9acf515a70f70 Mon Sep 17 00:00:00 2001 From: Dimitar Petrovski Date: Sat, 20 Oct 2012 17:36:32 +0200 Subject: wrong sign --- util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'util.c') diff --git a/util.c b/util.c index 428aeb8..640775a 100644 --- a/util.c +++ b/util.c @@ -121,7 +121,7 @@ void CleanString (unsigned char *String) } Src++; } - if (Spaces > 0 && String > Dst) { + if (Spaces > 0 && String < Dst) { Dst--; *Dst = 0; } else { -- cgit v1.2.3 From a09e46d0dbeb29954f6ae72b95e00063455de0a2 Mon Sep 17 00:00:00 2001 From: Dimitar Petrovski Date: Sun, 21 Oct 2012 19:08:07 +0200 Subject: fix compile with some compiler null check revert some changes --- util.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'util.c') diff --git a/util.c b/util.c index 640775a..9ca9484 100644 --- a/util.c +++ b/util.c @@ -121,7 +121,7 @@ void CleanString (unsigned char *String) } Src++; } - if (Spaces > 0 && String < Dst) { + if (Spaces > 0 && String && String < Dst) { Dst--; *Dst = 0; } else { @@ -176,25 +176,32 @@ cAddEventThread::~cAddEventThread(void) void cAddEventThread::Action(void) { + LogD (0, prep("Action")); SetPriority(19); while (Running() && !LastHandleEvent.TimedOut()) { +// LogD (0, prep("Running")); cAddEventListItem *e = NULL; cSchedulesLock SchedulesLock(true, 10); cSchedules *schedules = (cSchedules *)cSchedules::Schedules(SchedulesLock); Lock(); while (schedules && (e = list->First()) != NULL) { - tChannelID chID = e->GetChannelID(); +// tChannelID chID = e->GetChannelID(); cSchedule *schedule = (cSchedule *)schedules->GetSchedule(Channels.GetByChannelID(e->GetChannelID()), true); - while (schedules && (e = list->First()) != NULL) { +// while (schedules && (e = list->First()) != NULL) { - if (chID == e->GetChannelID()) { +// if (chID == e->GetChannelID()) { +// LogD (0, prep("AddEvent")); schedule->AddEvent(e->GetEvent()); +// LogD (0, prep("Del")); list->Del(e); - } - } +// } +// } + LogD (0, prep("Sort")); EpgHandlers.SortSchedule(schedule); -// EpgHandlers.DropOutdated(schedule, e->GetEvent()->StartTime(), e->GetEvent()->EndTime(), e->GetEvent()->TableID(), e->GetEvent()->Version()); + EpgHandlers.DropOutdated(schedule, e->GetEvent()->StartTime(), e->GetEvent()->EndTime(), e->GetEvent()->TableID(), e->GetEvent()->Version()); +// LogD (0, prep("Sorted")); } +// LogD (0, prep("Unlock")); Unlock(); cCondWait::SleepMs(10); } @@ -203,6 +210,7 @@ void cAddEventThread::Action(void) void cAddEventThread::AddEvent(cEvent *Event, tChannelID ChannelID) { LOCK_THREAD; +// LogD (0, prep("AddEventT %s channel: <%s>"), Event->Title(), *ChannelID.ToString()); list->Add(new cAddEventListItem(Event, ChannelID)); LastHandleEvent.Set(INSERT_TIMEOUT_IN_MS); } @@ -213,6 +221,7 @@ static cAddEventThread AddEventThread; void AddEvent(cEvent *Event, tChannelID ChannelID) { + LogD (0, prep("AddEvent %s channel: <%s>"), Event->Title(), *ChannelID.ToString()); AddEventThread.AddEvent(Event, ChannelID); if (!AddEventThread.Active()) AddEventThread.Start(); -- cgit v1.2.3 From 384796b93d7f28a291fad50a3143d65176037af1 Mon Sep 17 00:00:00 2001 From: Dimitar Petrovski Date: Sun, 21 Oct 2012 19:35:01 +0200 Subject: delete event from local list befora adding it to schedule. this fixes all problems with sorting since correct events are in previous / next --- util.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'util.c') diff --git a/util.c b/util.c index ae8c869..fb45360 100644 --- a/util.c +++ b/util.c @@ -213,17 +213,16 @@ void cAddEventThread::Action(void) while (((*it).second->First()) != NULL) { cEvent* event = (*it).second->First(); - cEvent *pEqvEvent = (cEvent *) schedule->GetEvent (event->EventID(), event->StartTime()); +/* cEvent *pEqvEvent = (cEvent *) schedule->GetEvent (event->EventID(), event->StartTime()); if (pEqvEvent){ LogD (0, prep("schedule->DelEvent(event)")); schedule->DelEvent(pEqvEvent); } - +*/ LogD (0, prep("schedule->AddEvent(event)")); //cCondWait::SleepMs(10); - if (event) - schedule->AddEvent(event); - (*it).second->Del(event); + (*it).second->Del(event, false); + schedule->AddEvent(event); } EpgHandlers.SortSchedule(schedule); //sortSchedules(schedules, (*it).first); -- cgit v1.2.3 From c28712e0563dd36638e9f6ad7c73a9dc6566abb1 Mon Sep 17 00:00:00 2001 From: Dimitar Petrovski Date: Sun, 21 Oct 2012 20:50:19 +0200 Subject: remove commented code --- util.c | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) (limited to 'util.c') diff --git a/util.c b/util.c index fb45360..04993f0 100644 --- a/util.c +++ b/util.c @@ -132,23 +132,6 @@ 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() { } -//}; - struct tChannelIDCompare { bool operator() (const tChannelID& lhs, const tChannelID& rhs) const @@ -162,7 +145,6 @@ class cAddEventThread : public cThread { private: cTimeMs LastHandleEvent; -// cList *list; std::map*,tChannelIDCompare> *map_list; enum { INSERT_TIMEOUT_IN_MS = 10000 }; protected: @@ -176,14 +158,12 @@ public: cAddEventThread::cAddEventThread(void) :cThread("cAddEventThread"), LastHandleEvent() { -// list = new cList; map_list = new std::map*,tChannelIDCompare>; } cAddEventThread::~cAddEventThread(void) { LOCK_THREAD; -// list->cList::Clear(); std::map*,tChannelIDCompare>::iterator it; for ( it=map_list->begin() ; it != map_list->end(); it++ ) (*it).second->cList::Clear(); @@ -195,8 +175,8 @@ void cAddEventThread::Action(void) LogD (0, prep("Action")); SetPriority(19); while (Running() && !LastHandleEvent.TimedOut()) { -// cAddEventListItem *e = NULL; - cSchedulesLock SchedulesLock(true, 10); + + cSchedulesLock SchedulesLock(true, 10); cSchedules *schedules = (cSchedules *)cSchedules::Schedules(SchedulesLock); Lock(); // while (schedules && (e = list->First()) != NULL) { @@ -219,9 +199,9 @@ void cAddEventThread::Action(void) schedule->DelEvent(pEqvEvent); } */ - LogD (0, prep("schedule->AddEvent(event)")); //cCondWait::SleepMs(10); (*it).second->Del(event, false); + EpgHandlers.DropOutdated(schedule, event->StartTime(), event->EndTime(), event->TableID(), event->Version()); schedule->AddEvent(event); } EpgHandlers.SortSchedule(schedule); @@ -239,9 +219,7 @@ void cAddEventThread::Action(void) void cAddEventThread::AddEvent(cEvent *Event, tChannelID ChannelID) { - LogD (0, prep("AddEventT start")); LOCK_THREAD; - LogD (0, prep("AddEventT lock ")); if (map_list->empty() || map_list->count(ChannelID) == 0) { LogD (0, prep("AddEventT if")); cList* list = new cList; -- cgit v1.2.3 From 26555852b2a8a840d2ccc1e91bbdbed1c46e838e Mon Sep 17 00:00:00 2001 From: Dimitar Petrovski Date: Sun, 21 Oct 2012 20:55:53 +0200 Subject: remove logging --- util.c | 49 ++++++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 25 deletions(-) (limited to 'util.c') diff --git a/util.c b/util.c index 04993f0..3d65f04 100644 --- a/util.c +++ b/util.c @@ -172,13 +172,13 @@ cAddEventThread::~cAddEventThread(void) void cAddEventThread::Action(void) { - LogD (0, prep("Action")); + //LogD (0, prep("Action")); SetPriority(19); while (Running() && !LastHandleEvent.TimedOut()) { cSchedulesLock SchedulesLock(true, 10); - cSchedules *schedules = (cSchedules *)cSchedules::Schedules(SchedulesLock); - Lock(); + 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()); @@ -186,12 +186,13 @@ void cAddEventThread::Action(void) // EpgHandlers.DropOutdated(schedule, e->GetEvent()->StartTime(), e->GetEvent()->EndTime(), e->GetEvent()->TableID(), e->GetEvent()->Version()); // list->Del(e); // } - std::map*,tChannelIDCompare>::iterator it; - it=map_list->begin(); - while (schedules && it != map_list->end()) { - cSchedule *schedule = (cSchedule *)schedules->GetSchedule(Channels.GetByChannelID((*it).first), true); - while (((*it).second->First()) != NULL) { - cEvent* event = (*it).second->First(); + std::map*, tChannelIDCompare>::iterator it; + it = map_list->begin(); + while (schedules && it != map_list->end()) { + cSchedule *schedule = (cSchedule *) schedules->GetSchedule( + Channels.GetByChannelID((*it).first), true); + while (((*it).second->First()) != NULL) { + cEvent* event = (*it).second->First(); /* cEvent *pEqvEvent = (cEvent *) schedule->GetEvent (event->EventID(), event->StartTime()); if (pEqvEvent){ @@ -200,38 +201,36 @@ void cAddEventThread::Action(void) } */ //cCondWait::SleepMs(10); - (*it).second->Del(event, false); - EpgHandlers.DropOutdated(schedule, event->StartTime(), event->EndTime(), event->TableID(), event->Version()); - schedule->AddEvent(event); - } - EpgHandlers.SortSchedule(schedule); + (*it).second->Del(event, false); + EpgHandlers.DropOutdated(schedule, event->StartTime(), event->EndTime(), event->TableID(), + event->Version()); + schedule->AddEvent(event); + } + EpgHandlers.SortSchedule(schedule); //sortSchedules(schedules, (*it).first); //schedule->Sort(); - delete (*it).second; - map_list->erase(it); - it=map_list->begin(); - - } - Unlock(); - cCondWait::SleepMs(10); - } + delete (*it).second; + map_list->erase(it); + it = map_list->begin(); + + } + Unlock(); + cCondWait::SleepMs(10); + } } void cAddEventThread::AddEvent(cEvent *Event, tChannelID ChannelID) { LOCK_THREAD; if (map_list->empty() || map_list->count(ChannelID) == 0) { - LogD (0, prep("AddEventT if")); cList* list = new cList; list->Add(Event); map_list->insert(std::make_pair(ChannelID, list)); } else { - LogD (0, prep("AddEventT else")); (*map_list->find(ChannelID)).second->Add(Event); } // LogD (0, prep("AddEventT %s channel: <%s>"), Event->Title(), *ChannelID.ToString()); LastHandleEvent.Set(INSERT_TIMEOUT_IN_MS); - LogD (0, prep("AddEventT end")); } static cAddEventThread AddEventThread; -- cgit v1.2.3 From bf45a222e707b0f778bc39abb171813bc39dd194 Mon Sep 17 00:00:00 2001 From: Dimitar Petrovski Date: Sun, 28 Oct 2012 16:47:07 +0100 Subject: fixed tChannelIDCompare which fixes the event map. try to change the activation of the thread. should be workged some more fix the Original Air Date for NA epg --- util.c | 66 ++++++++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 38 insertions(+), 28 deletions(-) (limited to 'util.c') diff --git a/util.c b/util.c index 3d65f04..88de2b6 100644 --- a/util.c +++ b/util.c @@ -136,17 +136,28 @@ struct tChannelIDCompare { bool operator() (const tChannelID& lhs, const tChannelID& rhs) const { - return *lhs.ToString() < *rhs.ToString(); + if (lhs.Source() < rhs.Source()) return true; + bool eq = lhs.Source() == rhs.Source(); + if (eq && lhs.Nid() < rhs.Nid()) return true; + eq &= lhs.Nid() == rhs.Nid(); + if (eq && lhs.Tid() < rhs.Tid()) return true; + eq &= lhs.Tid() == rhs.Tid(); + if (eq && lhs.Sid() < rhs.Sid()) return true; + eq &= lhs.Sid() == rhs.Sid(); + if (eq && lhs.Rid() < rhs.Rid()) return true; + return false; } }; +cTimeMs LastAddEventThread; +enum { INSERT_TIMEOUT_IN_MS = 10000 }; class cAddEventThread : public cThread { private: cTimeMs LastHandleEvent; std::map*,tChannelIDCompare> *map_list; - enum { INSERT_TIMEOUT_IN_MS = 10000 }; +// enum { INSERT_TIMEOUT_IN_MS = 10000 }; protected: virtual void Action(void); public: @@ -163,11 +174,11 @@ cAddEventThread::cAddEventThread(void) cAddEventThread::~cAddEventThread(void) { - LOCK_THREAD; +// LOCK_THREAD; + Cancel(3); std::map*,tChannelIDCompare>::iterator it; for ( it=map_list->begin() ; it != map_list->end(); it++ ) (*it).second->cList::Clear(); - Cancel(3); } void cAddEventThread::Action(void) @@ -175,18 +186,12 @@ void cAddEventThread::Action(void) //LogD (0, prep("Action")); SetPriority(19); while (Running() && !LastHandleEvent.TimedOut()) { + std::map*, tChannelIDCompare>::iterator it; 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); -// } - std::map*, tChannelIDCompare>::iterator it; + it = map_list->begin(); while (schedules && it != map_list->end()) { cSchedule *schedule = (cSchedule *) schedules->GetSchedule( @@ -194,17 +199,18 @@ void cAddEventThread::Action(void) while (((*it).second->First()) != NULL) { cEvent* event = (*it).second->First(); -/* cEvent *pEqvEvent = (cEvent *) schedule->GetEvent (event->EventID(), event->StartTime()); + cEvent *pEqvEvent = (cEvent *) schedule->GetEvent (event->EventID(), event->StartTime()); if (pEqvEvent){ - LogD (0, prep("schedule->DelEvent(event)")); - schedule->DelEvent(pEqvEvent); - } -*/ - //cCondWait::SleepMs(10); - (*it).second->Del(event, false); - EpgHandlers.DropOutdated(schedule, event->StartTime(), event->EndTime(), event->TableID(), - event->Version()); - schedule->AddEvent(event); +// LogD (0, prep("schedule->DelEvent(event) size:%d"), (*it).second->Count()); + (*it).second->Del(event); +// schedule->DelEvent(pEqvEvent); + } else { + + (*it).second->Del(event, false); + EpgHandlers.DropOutdated(schedule, event->StartTime(), event->EndTime(), event->TableID(), + event->Version()); + schedule->AddEvent(event); + } } EpgHandlers.SortSchedule(schedule); //sortSchedules(schedules, (*it).first); @@ -222,14 +228,14 @@ void cAddEventThread::Action(void) void cAddEventThread::AddEvent(cEvent *Event, tChannelID ChannelID) { LOCK_THREAD; - if (map_list->empty() || map_list->count(ChannelID) == 0) { + if (map_list->count(ChannelID) == 0) { cList* list = new cList; list->Add(Event); map_list->insert(std::make_pair(ChannelID, list)); } else { - (*map_list->find(ChannelID)).second->Add(Event); + map_list->find(ChannelID)->second->Add(Event); } -// LogD (0, prep("AddEventT %s channel: <%s>"), Event->Title(), *ChannelID.ToString()); +// LogD (0, prep("AddEventT %s channel: <%s> map size:%d"), Event->Title(), *ChannelID.ToString(), map_list->size()); LastHandleEvent.Set(INSERT_TIMEOUT_IN_MS); } @@ -241,8 +247,13 @@ void AddEvent(cEvent *Event, tChannelID ChannelID) { // LogD (0, prep("AddEvent %s channel: <%s>"), Event->Title(), *ChannelID.ToString()); AddEventThread.AddEvent(Event, ChannelID); - if (!AddEventThread.Active()) - AddEventThread.Start(); +// if (!AddEventThread.Active()) +// AddEventThread.Start(); + if (!AddEventThread.Active() && LastAddEventThread.TimedOut()){ + LastAddEventThread.Set(INSERT_TIMEOUT_IN_MS * 2); + AddEventThread.Start(); + } + } /** \brief Decode an EPG string as necessary @@ -256,7 +267,6 @@ void AddEvent(cEvent *Event, tChannelID ChannelID) char *freesat_huffman_decode (const unsigned char *src, size_t size) { int tableid; -// freesat_decode_error = 0; if (src[0] == 0x1f && (src[1] == 1 || src[1] == 2)) { int uncompressed_len = 30; -- cgit v1.2.3 From d723bdc772b60190af39a256bffc33c27cfb9575 Mon Sep 17 00:00:00 2001 From: Dimitar Petrovski Date: Mon, 29 Oct 2012 16:01:13 +0100 Subject: renamed thread so that it is different from EPGFixer plugin --- util.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'util.c') diff --git a/util.c b/util.c index 88de2b6..415f213 100644 --- a/util.c +++ b/util.c @@ -167,7 +167,7 @@ public: }; cAddEventThread::cAddEventThread(void) -:cThread("cAddEventThread"), LastHandleEvent() +:cThread("cAddEEPGEventThread"), LastHandleEvent() { map_list = new std::map*,tChannelIDCompare>; } @@ -178,7 +178,7 @@ cAddEventThread::~cAddEventThread(void) Cancel(3); std::map*,tChannelIDCompare>::iterator it; for ( it=map_list->begin() ; it != map_list->end(); it++ ) - (*it).second->cList::Clear(); + (*it).second->Clear(); } void cAddEventThread::Action(void) -- cgit v1.2.3