summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitar Petrovski <dimeptr@gmail.com>2012-05-23 21:36:14 +0200
committerDimitar Petrovski <dimeptr@gmail.com>2012-05-23 21:36:14 +0200
commit61eded224bc4660b41f6754e83b91a262af3f8ce (patch)
tree34c06a64e23d1ae7c6a87a79769344cae972b52c
parentfeee46aeed74157e104335918741f266fd576f29 (diff)
downloadvdr-plugin-eepg-61eded224bc4660b41f6754e83b91a262af3f8ce.tar.gz
vdr-plugin-eepg-61eded224bc4660b41f6754e83b91a262af3f8ce.tar.bz2
move equivalence to separate file/class
-rw-r--r--eepg.c247
-rw-r--r--eepg.h2
-rw-r--r--epghandler.c31
-rw-r--r--epghandler.h3
-rw-r--r--equivhandler.cpp207
-rw-r--r--equivhandler.h37
-rw-r--r--setupeepg.c7
-rw-r--r--setupeepg.h13
8 files changed, 334 insertions, 213 deletions
diff --git a/eepg.c b/eepg.c
index 9be57c5..91a08c0 100644
--- a/eepg.c
+++ b/eepg.c
@@ -43,6 +43,7 @@
#endif
#include "log.h"
#include "setupeepg.h"
+#include "equivhandler.h"
#include <map>
#include <string>
@@ -97,7 +98,7 @@ char *cs_hexdump (int m, const uchar * buf, int n)
}
cSetupEEPG* SetupPE = cSetupEEPG::getInstance();
-
+cEquivHandler* EquivHandler;
// --- cMenuSetupPremiereEpg ------------------------------------------------------------
@@ -171,8 +172,6 @@ static int AvailableSources[32];
static int NumberOfAvailableSources = 0;
static int LastVersionNagra = -1; //currently only used for Nagra, should be stored per transponder, per system
-static multimap<string, string> equiChanMap;
-static long equiChanFileTime = 0;
#ifdef USE_NOEPG
@@ -200,7 +199,7 @@ class cFilterEEPG:public cFilter
private:
int pmtpid, pmtsid, pmtidx, pmtnext;
int UnprocessedFormat[HIGHEST_FORMAT + 1]; //stores the pid when a format is detected on this transponder, and that are not processed yet
- int nEquivChannels, nChannels, nThemes, nTitles, nSummaries, NumberOfTables, Version;
+ int nChannels, nThemes, nTitles, nSummaries, NumberOfTables, Version;
int TitleCounter, SummaryCounter, NoSummaryCounter, RejectTableId;
bool EndChannels, EndThemes; //only used for ??
int MHWStartTime; //only used for MHW1
@@ -347,8 +346,8 @@ struct hufftab {
int freesat_decode_error = 0; /* If set an error has occurred during decoding */
-static struct hufftab *tables[2][256];
-static int table_size[2][256];
+static struct hufftab *tables[2][128];
+static int table_size[2][128];
static sNodeH* sky_tables[2];
/** \brief Convert a textual character description into a value
@@ -429,6 +428,9 @@ static bool load_freesat_file (int tableid, const char *filename)
tables[tableid][from_char][i].value = bin;
tables[tableid][from_char][i].next = to_char;
tables[tableid][from_char][i].bits = bin_len;
+ /* char from; unsigned int value; short bits; char next; */
+ LogI(2, prep("%02x;%08x;%04x;%02x"), from_char, bin, bin_len, to_char);
+
free (from);
free (to);
free (binary);
@@ -766,7 +768,7 @@ nextloop1:
//here all declarations for global variables over all devices
-char *ConfDir;
+//char *ConfDir;
//unsigned char DecodeErrorText[4096]; //TODO only used for debugging?
@@ -879,7 +881,7 @@ cChannel *GetChannelByID(tChannelID & channelID, bool searchOtherPos)
bool cFilterEEPG::GetThemesSKYBOX (void) //TODO can't we read this from the DVB stream?
{
- string FileName = ConfDir;
+ string FileName = cSetupEEPG::getInstance()->getConfDir();
FILE *FileThemes;
char *Line;
char Buffer[256];
@@ -927,7 +929,7 @@ bool cFilterEEPG::GetThemesSKYBOX (void) //TODO can't we read this from the DVB
*/
bool cFilterEEPG::InitDictionary (void)
{
- string FileName = ConfDir;
+ string FileName = cSetupEEPG::getInstance()->getConfDir();
switch (Format) {
case SKY_IT:
if (sky_tables[0] == NULL) {
@@ -951,7 +953,7 @@ bool cFilterEEPG::InitDictionary (void)
FileName += "/freesat.t1";
if (!load_freesat_file (1, FileName.c_str()))
return false;
- FileName = ConfDir;
+ FileName = cSetupEEPG::getInstance()->getConfDir();
FileName += "/freesat.t2";
return load_freesat_file (2, FileName.c_str());
} else
@@ -987,190 +989,18 @@ void decodeText2 (const unsigned char *from, int len, char *buffer, int buffsize
//LogE(5, prep("decodeText2 buffer %s - buffsize %d"), buffer, buffsize);
}
-void loadEquivalentChannelMap (void)
-{
- char Buffer[1024];
- char *Line;
- FILE *File;
- string FileName = string(ConfDir) + "/" + EEPG_FILE_EQUIV;
- multimap<string,string>::iterator it,it2;
- pair<multimap<string,string>::iterator,multimap<string,string>::iterator> ret;
-
- //Test if file is changed and reload
- struct stat st;
- if (stat(FileName.c_str(), &st)) {
- LogE(0, prep("Error obtaining stats for '%s' "), FileName.c_str());
- return;
- }
-
- if (equiChanMap.size() > 0 && equiChanFileTime == st.st_mtim.tv_nsec)
- return;
- else
- equiChanMap.clear();
-
-
- File = fopen (FileName.c_str(), "r");
- if (File) {
- memset (Buffer, 0, sizeof (Buffer));
- char origChanID[256];
- char equiChanID[256];
- char source[256];
- int nid = 0;
- int tid = 0;
- int sid = 0;
- int rid = 0;
- while ((Line = fgets (Buffer, sizeof (Buffer), File)) != NULL) {
- Line = compactspace (skipspace (stripspace (Line)));
- if (!isempty (Line)) {
- if (sscanf (Line, "%[^ ] %[^ ] %[^\n]\n", origChanID, equiChanID, source) == 3) {
- if (origChanID[0] != '#' && origChanID[0] != ';') {
- nid = 0;
- tid = 0;
- sid = 0;
- rid = 0;
- if (sscanf (origChanID, "%[^-]-%i -%i -%i ", source, &nid, &tid, &sid) == 4)
- if (sscanf (equiChanID, "%[^-]-%i -%i -%i ", source, &nid, &tid, &sid) == 4) {
- if (sscanf (origChanID, "%[^-]-%i -%i -%i -%i ", source, &nid, &tid, &sid, &rid) != 5) {
- rid = 0;
- }
- tChannelID OriginalChID = tChannelID (cSource::FromString (source), nid, tid, sid, rid);
- bool found = false;
- //int i = 0;
- cChannel *OriginalChannel = Channels.GetByChannelID (OriginalChID, false);
- if (!OriginalChannel) {
- LogI(2, prep("Warning, not found epg channel \'%s\' in channels.conf. Equivalency is assumed to be valid, but perhaps you should check the entry in the equivalents file"), origChanID); //TODO: skip this ing?
- continue;
- }
- if (sscanf (equiChanID, "%[^-]-%i -%i -%i ", source, &nid, &tid, &sid) == 4) {
- if (sscanf (equiChanID, "%[^-]-%i -%i -%i -%i ", source, &nid, &tid, &sid, &rid)
- != 5) {
- rid = 0;
- }
- tChannelID EquivChID = tChannelID (cSource::FromString (source), nid, tid, sid, rid);
- cChannel *EquivChannel = Channels.GetByChannelID (EquivChID, false); //TODO use valid function?
- if (EquivChannel) {
- ret = equiChanMap.equal_range(*OriginalChID.ToString());
- for (it=ret.first; it!=ret.second; ++it)
- if ((*it).second == *OriginalChID.ToString()) {
- found = true;
- break;
- }
-
- if (!found) {
- string origCh(*OriginalChID.ToString());
- string equiCh(*EquivChID.ToString());
- equiChanMap.insert(pair<string,string>(origCh.c_str(),equiCh.c_str()));
- LogD(4, prep("Found %s equivalent to %s. origCh %s"), *EquivChID.ToString(), *OriginalChID.ToString(), origCh.c_str());
- for ( it2=equiChanMap.begin() ; it2 != equiChanMap.end(); it2++ )
- LogD(3, prep("Original ID %s <-> Equivalent ID %s"), (*it2).first.c_str(), it2->second.c_str());
- }
- } else
- LogI(0, prep("Warning, not found equivalent channel \'%s\' in channels.conf"), equiChanID);
- }
- } //if scanf string1
- } //if string1
- } //if scanf
- } //if isempty
- } //while
- fclose (File);
- equiChanFileTime = st.st_mtim.tv_nsec;
- LogD(3, prep("Loaded %i equivalents."), equiChanMap.size());
- for ( it2=equiChanMap.begin() ; it2 != equiChanMap.end(); it2++ )
- LogD(3, prep("Original ID %s <-> Equivalent ID %s"), (*it2).first.c_str(), it2->second.c_str());
- } //if file
-}
-
-void updateEquivalent(cSchedules * Schedules, 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()));
- cChannel *equChannel = GetChannelByID (equChannelID, false);
- if (equChannel) {
- LogD(3, prep("found Equivalent channel %s"), *equChannelID.ToString());
- cSchedule *pSchedule = (cSchedule *) Schedules->GetSchedule (equChannel, true);
- cEvent *pEqvEvent = (cEvent *) pSchedule->GetEvent (pEvent->EventID(), pEvent->StartTime());
- if (pEqvEvent) {
- LogD(1, prep("equivalent event exists"));
- if (pEqvEvent == pEvent) {
- LogD(1, prep("equal event exists"));
-
- } else {
- LogD(1, prep("remove equivalent"));
- pSchedule->DelEvent(pEqvEvent);
- 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());
- newEvent->FixEpgBugs ();
-
- pSchedule->AddEvent(newEvent);
-
- }
-
- } else {
- LogD(1, prep("equivalent event does not exist"));
- 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());
- newEvent->FixEpgBugs ();
-
- pSchedule->AddEvent(newEvent);
-
- }
- }
- }
-}
-
void sortSchedules(cSchedules * Schedules, tChannelID channelID){
- multimap<string,string>::iterator it;
- pair<multimap<string,string>::iterator,multimap<string,string>::iterator> ret;
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);
- }
-
- ret = equiChanMap.equal_range(*channelID.ToString());
- for (it=ret.first; it!=ret.second; ++it) {
- LogD(3, prep("equivalent channel exists"));
- tChannelID equChannelID (tChannelID::FromString((*it).second.c_str()));
- pChannel = GetChannelByID (equChannelID, false);
- if (pChannel) {
- LogD(3, prep("found Equivalent channel %s"), *equChannelID.ToString());
- pSchedule = (cSchedule *) Schedules->GetSchedule (pChannel, true);
-
- pSchedule->Sort ();
- Schedules->SetModified (pSchedule);
+ pSchedule = (cSchedule *) (Schedules->GetSchedule(pChannel, true));
+ pSchedule->Sort();
+ Schedules->SetModified(pSchedule);
}
- }
+ EquivHandler->sortEquivalents(channelID, Schedules);
}
@@ -1254,7 +1084,7 @@ int cFilterEEPG::GetChannelsMHW (const u_char * Data, int Length, int MHW)
} //for loop
} //else nChannels > MAX_CHANNELS
//LoadEquivalentChannels ();
- loadEquivalentChannelMap();
+ EquivHandler->loadEquivalentChannelMap();
GetLocalTimeOffset (); //reread timing variables, only used for MHW
return 2; //obviously, when you get here, channels are read successfully, but since all channels are sent at once, you can stop now
} //if nChannels == 0
@@ -1614,7 +1444,7 @@ void cFilterEEPG::WriteToSchedule (tChannelID channelID, cSchedules* pSchedules,
if (ps && newEvent)
ps->AddEvent (newEvent);
- updateEquivalent(pSchedules, channelID, Event);
+ EquivHandler->updateEquivalent(pSchedules, channelID, Event);
if (!ps) {
//the event is not send to VDR so it has to be deleted.
@@ -1958,7 +1788,7 @@ int cFilterEEPG::GetChannelsNagra (const u_char * Data, int Length)
if (p != DataEnd)
LogE(0, prep("Warning, possible problem at end of channel table; p = %p, DataEnd = %p"), p, DataEnd);
//LoadEquivalentChannels ();
- loadEquivalentChannelMap();
+ EquivHandler->loadEquivalentChannelMap();
return 2; //obviously, when you get here, channels are read succesfully, but since all channels are sent at once, you can stop now
}
@@ -2434,7 +2264,7 @@ int cFilterEEPG::GetChannelsSKYBOX (const u_char * Data, int Length)
if (memcmp (InitialChannel, Data, 8) == 0) { //data is the same as initial title
//LoadEquivalentChannels ();
- loadEquivalentChannelMap();
+ EquivHandler->loadEquivalentChannelMap();
return 2;
} else {
if (nChannels == 0)
@@ -2865,11 +2695,11 @@ void cFilterEEPG::LoadIntoSchedule (void)
} //while title
} // if s
else
- esyslog ("EEPG Error: could not lock schedules.");
+ LogE (0, prep("Error: could not lock schedules."));
cSchedules::Cleanup (true); //deletes all past events
- isyslog ("EEPG: found %i equivalents channels", nEquivChannels);
+ //isyslog ("EEPG: found %i equivalents channels", nEquivChannels);
isyslog ("EEPG: found %i themes", nThemes);
isyslog ("EEPG: found %i channels", nChannels);
isyslog ("EEPG: found %i titles", nTitles);
@@ -3506,7 +3336,7 @@ cEIT2::cEIT2 (cSchedules * Schedules, int Source, u_char Tid, const u_char * Dat
}
}
#endif /* DDEPGENTRY */
- updateEquivalent(Schedules, channel->GetChannelID(), pEvent);
+ EquivHandler->updateEquivalent(Schedules, channel->GetChannelID(), pEvent);
}
if (Empty && Tid == 0x4E && getSectionNumber () == 0)
// ETR 211: an empty entry in section 0 of table 0x4E means there is currently no event running
@@ -3535,7 +3365,7 @@ void cFilterEEPG::ProcessNextFormat (bool FirstTime = false)
esyslog ("EEPGDEBUG: Format %i on pid %x", i, UnprocessedFormat[i]); */
if (!FirstTime) {
- isyslog ("EEPG: found %i equivalents channels", nEquivChannels);
+ //isyslog ("EEPG: found %i equivalents channels", equiChanMap.size());
isyslog ("EEPG: found %i themes", nThemes);
isyslog ("EEPG: found %i channels", nChannels);
isyslog ("EEPG: found %i titles", nTitles);
@@ -3577,7 +3407,7 @@ void cFilterEEPG::ProcessNextFormat (bool FirstTime = false)
if (SetupPE->ProcessEIT && !UnprocessedFormat[EIT]
&& !UnprocessedFormat[FREEVIEW] && !UnprocessedFormat[DISH_BEV]) {
UnprocessedFormat[EIT] = EIT_PID;
- loadEquivalentChannelMap();
+ EquivHandler->loadEquivalentChannelMap();
}
//now start looking for next format to process
@@ -3604,7 +3434,6 @@ void cFilterEEPG::ProcessNextFormat (bool FirstTime = false)
memset (&InitialSummary, 0, 64);
NagraCounter = 0;
Version = -1; //because 0 can be a valid version number...
- nEquivChannels = 0;
nChannels = 0;
nThemes = 0;
EndChannels = false;
@@ -4383,7 +4212,7 @@ cPluginEEPG::cPluginEEPG (void)
void cPluginEEPG::CheckCreateFile(const char* Name, const char *fileContent[])
{
FILE *File;
- string FileName = string(ConfDir) + "/" + Name;
+ string FileName = string(cSetupEEPG::getInstance()->getConfDir()) + "/" + Name;
File = fopen(FileName.c_str(), "r");
if (File == NULL) {
LogE (0, prep("Error opening file '%s', %s"), FileName.c_str(), strerror (errno));
@@ -4417,12 +4246,12 @@ bool cPluginEEPG::Start (void)
isyslog ("Attached EEPG filter to device %d", i);
}
}
- ConfDir = NULL;
+ char *ConfDir = NULL;
// Initialize any background activities the plugin shall perform.
DIR *ConfigDir;
- if (ConfDir == NULL) {
- Asprintf (&ConfDir, "%s/eepg", cPlugin::ConfigDirectory ());
- }
+ //if (ConfDir == NULL) {
+ Asprintf (&ConfDir, "%s/eepg", cPlugin::ConfigDirectory ());
+ //}
ConfigDir = opendir (ConfDir);
if (ConfigDir == NULL) {
esyslog ("EEPG: Error opening directory '%s', %s", ConfDir, strerror (errno));
@@ -4432,6 +4261,8 @@ bool cPluginEEPG::Start (void)
isyslog ("EEPG: Success creating directory '%s'", ConfDir);
}
}
+ cSetupEEPG::getInstance()->setConfDir(ConfDir);
+
CheckCreateFile(EEPG_FILE_EQUIV, FileEquivalences);
CheckCreateFile("sky_it.dict", SkyItDictionary);
CheckCreateFile("sky_uk.dict", SkyUkDictionary);
@@ -4462,7 +4293,11 @@ bool cPluginEEPG::Start (void)
#if APIVERSNUM > 10725
new cEEpgHandler();
#endif
+ EquivHandler = new cEquivHandler();
+ if (ConfDir) {
+ free (ConfDir);
+ }
closedir(ConfigDir);
return true;
}
@@ -4479,15 +4314,19 @@ void cPluginEEPG::Stop (void)
}
// Clean up after yourself!
- if (ConfDir) {
- free (ConfDir);
- }
+// if (ConfDir) {
+// free (ConfDir);
+// }
if (sky_tables[0]) {
free(sky_tables[0]);
}
if (sky_tables[1]) {
free(sky_tables[1]);
}
+ if (EquivHandler) {
+ delete EquivHandler;
+ }
+
}
cMenuSetupPage *cPluginEEPG::SetupMenu (void)
diff --git a/eepg.h b/eepg.h
index b661809..18690de 100644
--- a/eepg.h
+++ b/eepg.h
@@ -1,8 +1,6 @@
//#define DEBUG false
//#define DEBUG_STARTTIME false
-#define EEPG_FILE_EQUIV "eepg.equiv"
-
#define MAX_THEMES 2046 //this should always be >=256, or Nagra will go wrong!!
#define MAX_CHANNELS 2048
#define MAX_TITLES 262144
diff --git a/epghandler.c b/epghandler.c
index 29f092b..426958d 100644
--- a/epghandler.c
+++ b/epghandler.c
@@ -8,20 +8,28 @@
#include "epghandler.h"
#if APIVERSNUM > 10725
#include "log.h"
+#include "equivhandler.h"
+#include <vdr/sources.h>
cEEpgHandler::cEEpgHandler() {
- // TODO Auto-generated constructor stub
LogD(4, prep("cEEpgHandler()"));
-
+ equivHandler = new cEquivHandler();
}
cEEpgHandler::~cEEpgHandler() {
- // TODO Auto-generated destructor stub
+ delete equivHandler;
+ equivHandler = NULL;
}
bool cEEpgHandler::HandleEitEvent(cSchedule* Schedule,
const SI::EIT::Event* EitEvent, uchar TableID, uchar Version) {
//LogD(1, prep("HandleEitEvent"));
+ //DISH NID 0x1001 to 0x100B BEV 0x100 and 0x101
+ //TODO move the eit handling code at least for NA providers here instead of discarding.
+ int nid = Schedule->ChannelID().Nid();
+ if ((nid >= 0x1001 && nid <= 0x100B) || nid == 0x101 || nid == 0x100)
+ return true;
+
return false;
// return true;
}
@@ -103,6 +111,14 @@ bool cEEpgHandler::HandleEvent(cEvent* Event) {
if (!Event->Description() && !origDescription.empty()) {
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."));
+
//TODO just to see the difference
//else if (!origDescription.empty() && !origDescription.compare(Event->Description())) {
// origDescription.append(" | EIT: ");
@@ -114,7 +130,16 @@ bool cEEpgHandler::HandleEvent(cEvent* Event) {
}
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."));
+
return true;
}
diff --git a/epghandler.h b/epghandler.h
index 61f295b..e1c6915 100644
--- a/epghandler.h
+++ b/epghandler.h
@@ -12,6 +12,8 @@
#include <vdr/epg.h>
#include <string>
+class cEquivHandler;
+
class cEEpgHandler : public cEpgHandler {
public:
cEEpgHandler();
@@ -35,6 +37,7 @@ public:
private:
std::string origShortText;
std::string origDescription;
+ cEquivHandler* equivHandler;
};
#endif /*APIVERSNUM > 10725*/
diff --git a/equivhandler.cpp b/equivhandler.cpp
new file mode 100644
index 0000000..4868f88
--- /dev/null
+++ b/equivhandler.cpp
@@ -0,0 +1,207 @@
+/*
+ * equivhandler.cpp
+ *
+ * Created on: 19.5.2012
+ * Author: d.petrovski
+ */
+
+#include "equivhandler.h"
+#include "setupeepg.h"
+#include "log.h"
+
+#include <string>
+
+
+static multimap<string, string> cEquivHandler::equiChanMap;
+static long cEquivHandler::equiChanFileTime = 0;
+
+cEquivHandler::cEquivHandler()
+{
+ loadEquivalentChannelMap();
+}
+
+cEquivHandler::~cEquivHandler()
+{
+ // TODO Auto-generated destructor stub
+}
+
+void cEquivHandler::loadEquivalentChannelMap (void)
+{
+ char Buffer[1024];
+ char *Line;
+ FILE *File;
+ string FileName = string(cSetupEEPG::getInstance()->getConfDir()) + "/" + EEPG_FILE_EQUIV;
+ multimap<string,string>::iterator it,it2;
+ pair<multimap<string,string>::iterator,multimap<string,string>::iterator> ret;
+
+ //Test if file is changed and reload
+ struct stat st;
+ if (stat(FileName.c_str(), &st)) {
+ LogE(0, prep("Error obtaining stats for '%s' "), FileName.c_str());
+ return;
+ }
+
+ if (equiChanMap.size() > 0 && equiChanFileTime == st.st_mtim.tv_nsec)
+ return;
+ else
+ equiChanMap.clear();
+
+
+ File = fopen (FileName.c_str(), "r");
+ if (File) {
+ memset (Buffer, 0, sizeof (Buffer));
+ char origChanID[256];
+ char equiChanID[256];
+ char source[256];
+ int nid = 0;
+ int tid = 0;
+ int sid = 0;
+ int rid = 0;
+ while ((Line = fgets (Buffer, sizeof (Buffer), File)) != NULL) {
+ Line = compactspace (skipspace (stripspace (Line)));
+ if (!isempty (Line)) {
+ if (sscanf (Line, "%[^ ] %[^ ] %[^\n]\n", origChanID, equiChanID, source) == 3) {
+ if (origChanID[0] != '#' && origChanID[0] != ';') {
+ nid = 0;
+ tid = 0;
+ sid = 0;
+ rid = 0;
+ if (sscanf (origChanID, "%[^-]-%i -%i -%i ", source, &nid, &tid, &sid) == 4)
+ if (sscanf (equiChanID, "%[^-]-%i -%i -%i ", source, &nid, &tid, &sid) == 4) {
+ if (sscanf (origChanID, "%[^-]-%i -%i -%i -%i ", source, &nid, &tid, &sid, &rid) != 5) {
+ rid = 0;
+ }
+ tChannelID OriginalChID = tChannelID (cSource::FromString (source), nid, tid, sid, rid);
+ bool found = false;
+ //int i = 0;
+ cChannel *OriginalChannel = Channels.GetByChannelID (OriginalChID, false);
+ if (!OriginalChannel) {
+ LogI(2, prep("Warning, not found epg channel \'%s\' in channels.conf. Equivalency is assumed to be valid, but perhaps you should check the entry in the equivalents file"), origChanID); //TODO: skip this ing?
+ continue;
+ }
+ if (sscanf (equiChanID, "%[^-]-%i -%i -%i ", source, &nid, &tid, &sid) == 4) {
+ if (sscanf (equiChanID, "%[^-]-%i -%i -%i -%i ", source, &nid, &tid, &sid, &rid)
+ != 5) {
+ rid = 0;
+ }
+ tChannelID EquivChID = tChannelID (cSource::FromString (source), nid, tid, sid, rid);
+ cChannel *EquivChannel = Channels.GetByChannelID (EquivChID, false); //TODO use valid function?
+ if (EquivChannel) {
+ ret = equiChanMap.equal_range(*OriginalChID.ToString());
+ for (it=ret.first; it!=ret.second; ++it)
+ if ((*it).second == *OriginalChID.ToString()) {
+ found = true;
+ break;
+ }
+
+ if (!found) {
+ string origCh(*OriginalChID.ToString());
+ string equiCh(*EquivChID.ToString());
+ equiChanMap.insert(pair<string,string>(origCh.c_str(),equiCh.c_str()));
+ LogD(4, prep("Found %s equivalent to %s. origCh %s"), *EquivChID.ToString(), *OriginalChID.ToString(), origCh.c_str());
+ for ( it2=equiChanMap.begin() ; it2 != equiChanMap.end(); it2++ )
+ LogD(3, prep("Original ID %s <-> Equivalent ID %s"), (*it2).first.c_str(), it2->second.c_str());
+ }
+ } else
+ LogI(0, prep("Warning, not found equivalent channel \'%s\' in channels.conf"), equiChanID);
+ }
+ } //if scanf string1
+ } //if string1
+ } //if scanf
+ } //if isempty
+ } //while
+ fclose (File);
+ equiChanFileTime = st.st_mtim.tv_nsec;
+ LogD(3, prep("Loaded %i equivalents."), equiChanMap.size());
+ for ( it2=equiChanMap.begin() ; it2 != equiChanMap.end(); it2++ )
+ LogD(3, prep("Original ID %s <-> Equivalent ID %s"), (*it2).first.c_str(), it2->second.c_str());
+ } //if file
+}
+
+void cEquivHandler::updateEquivalent(cSchedules * Schedules, 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()));
+ cChannel *equChannel = GetChannelByID (equChannelID, false);
+ if (equChannel) {
+ LogD(3, prep("found Equivalent channel %s"), *equChannelID.ToString());
+ cSchedule *pSchedule = (cSchedule *) Schedules->GetSchedule (equChannel, true);
+ cEvent *pEqvEvent = (cEvent *) pSchedule->GetEvent (pEvent->EventID(), pEvent->StartTime());
+ if (pEqvEvent) {
+ LogD(1, prep("equivalent event exists"));
+ if (pEqvEvent == pEvent) {
+ LogD(1, prep("equal event exists"));
+
+ } else {
+ LogD(1, prep("remove equivalent"));
+ pSchedule->DelEvent(pEqvEvent);
+ 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());
+ newEvent->FixEpgBugs ();
+
+ pSchedule->AddEvent(newEvent);
+
+ }
+
+ } else {
+ LogD(1, prep("equivalent event does not exist"));
+ 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());
+ newEvent->FixEpgBugs ();
+
+ pSchedule->AddEvent(newEvent);
+
+ }
+ }
+ }
+}
+
+void cEquivHandler::sortEquivalents(tChannelID channelID, cSchedules* Schedules)
+{
+ multimap<string, string>::iterator it;
+ pair < multimap < string, string > ::iterator, multimap < string, string
+ > ::iterator > ret;
+ ret = cEquivHandler::getEquiChanMap().equal_range(*channelID.ToString());
+ for (it = ret.first; it != ret.second; ++it)
+ {
+ LogD(3, prep("equivalent channel exists"));
+ tChannelID equChannelID(tChannelID::FromString((*it).second.c_str()));
+ cChannel* pChannel = GetChannelByID(equChannelID, false);
+ if (pChannel)
+ {
+ LogD(3, prep("found Equivalent channel %s"),
+ *equChannelID.ToString());
+ cSchedule* pSchedule = (cSchedule *) Schedules->GetSchedule(pChannel,
+ true);
+
+ pSchedule->Sort();
+ Schedules->SetModified(pSchedule);
+ }
+ }
+}
diff --git a/equivhandler.h b/equivhandler.h
new file mode 100644
index 0000000..da2d7d9
--- /dev/null
+++ b/equivhandler.h
@@ -0,0 +1,37 @@
+/*
+ * equivhandler.h
+ *
+ * Created on: 19.5.2012
+ * Author: d.petrovski
+ */
+
+#ifndef EQUIVHANDLER_H_
+#define EQUIVHANDLER_H_
+
+#include <vdr/epg.h>
+#include <vdr/channels.h>
+#include <map>
+
+#define EEPG_FILE_EQUIV "eepg.equiv"
+
+using namespace std;
+
+class cEquivHandler
+{
+public:
+ cEquivHandler();
+ virtual ~cEquivHandler();
+
+ void loadEquivalentChannelMap (void);
+ void updateEquivalent(cSchedules * Schedules, tChannelID channelID, cEvent *pEvent);
+ void sortEquivalents(tChannelID channelID, cSchedules* Schedules);
+
+ static multimap<string, string> getEquiChanMap() { return cEquivHandler::equiChanMap; };
+
+private:
+ static multimap<string, string> equiChanMap;
+ static long equiChanFileTime;
+
+};
+
+#endif /* EQUIVHANDLER_H_ */
diff --git a/setupeepg.c b/setupeepg.c
index 3738227..54f8243 100644
--- a/setupeepg.c
+++ b/setupeepg.c
@@ -23,14 +23,13 @@ cSetupEEPG::cSetupEEPG (void)
#ifdef DEBUG
LogLevel = 0;
#endif
-
}
cSetupEEPG* cSetupEEPG::getInstance()
{
- if (!_setupEEPG)
- _setupEEPG = new cSetupEEPG();
+ if (!_setupEEPG)
+ _setupEEPG = new cSetupEEPG();
- return _setupEEPG;
+ return _setupEEPG;
}
diff --git a/setupeepg.h b/setupeepg.h
index f5e342a..ffd9eb8 100644
--- a/setupeepg.h
+++ b/setupeepg.h
@@ -24,12 +24,25 @@ public:
public:
static cSetupEEPG* getInstance();
+ char* getConfDir() const
+ {
+ return ConfDir;
+ }
+
+ void setConfDir(char* confDir)
+ {
+ ConfDir = confDir;
+ }
+
private:
cSetupEEPG (void);
cSetupEEPG(cSetupEEPG const&); // copy constructor is private
cSetupEEPG& operator=(cSetupEEPG const&); // assignment operator is private
static cSetupEEPG* _setupEEPG;
+private:
+ char *ConfDir;
+
};
#endif /* SETUPEEPG_H_ */