diff options
author | Jochen Dolze <vdr@dolze.de> | 2009-01-03 18:57:48 +0100 |
---|---|---|
committer | Jochen Dolze <vdr@dolze.de> | 2009-01-03 18:57:48 +0100 |
commit | fc926f81da5ac3d0a310a7fc8c960aee2b04c9bb (patch) | |
tree | 47723c32f55ed6d3717c118a8e6a9dd9e4b16da6 /global.cpp | |
parent | c0be4f653bd22b9ea3878a805ea97429a6a6d9f9 (diff) | |
download | vdr-plugin-infosatepg-fc926f81da5ac3d0a310a7fc8c960aee2b04c9bb.tar.gz vdr-plugin-infosatepg-fc926f81da5ac3d0a310a7fc8c960aee2b04c9bb.tar.bz2 |
Changed wakeup (now set automatically)
Changed setup
Changed device chooser
Bugfixed segfault with obsolete channels
Diffstat (limited to 'global.cpp')
-rw-r--r-- | global.cpp | 273 |
1 files changed, 166 insertions, 107 deletions
@@ -8,7 +8,7 @@ cGlobalInfosatdata::cGlobalInfosatdata() Init(NULL,0,0,0); } -bool cGlobalInfosatdata::NeverSeen(int Day, int Month, int Packetcount) +bool cGlobalInfosatdata::NeverSeen(int Day,int Month,int Packetcount) { if ((day!=Day) || (month!=Month) || (pktcnt!=Packetcount)) { @@ -20,15 +20,16 @@ bool cGlobalInfosatdata::NeverSeen(int Day, int Month, int Packetcount) } } -void cGlobalInfosatdata::Init(char *File, int Day, int Month, int Packetcount) +void cGlobalInfosatdata::Init(char *File,int Day,int Month,int Packetcount) { if (access(file,R_OK)==0) { dsyslog("infosatepg: deleting old %s",file); unlink(file); } - ready=false; - processed=false; + Processed=false; + receivedall=false; + receivedpercent=0; day=Day; month=Month; pktcnt=Packetcount; @@ -40,41 +41,45 @@ void cGlobalInfosatdata::Init(char *File, int Day, int Month, int Packetcount) int cGlobalInfosatdata::Save(int fd) { if (fd==-1) return -1; - ssize_t ret=write(fd,&ready,sizeof(ready)); - if (ret!=sizeof(ready)) return -1; - ret=write(fd,&processed,sizeof(processed)); - if (ret!=sizeof(processed)) return -1; - ret=write(fd,&day,sizeof(day)); + ssize_t ret=write(fd,&receivedall,sizeof(receivedall)); + if (ret!=sizeof(receivedall)) return -1; + ret=write(fd,&receivedpercent,sizeof(receivedpercent)); + if (ret!=sizeof(receivedpercent)) return -1; + ret=write(fd,&Processed,sizeof(Processed)); + if (ret!=sizeof(Processed)) return -1; + ret=write (fd,&day,sizeof (day)); if (ret!=sizeof(day)) return -1; - ret=write(fd,&month,sizeof(month)); - if (ret!=sizeof(month)) return -1; - ret=write(fd,&pktcnt,sizeof(pktcnt)); - if (ret!=sizeof(pktcnt)) return -1; - ret=write(fd,&bitfield,sizeof(bitfield)); - if (ret!=sizeof(bitfield)) return -1; - ret=write(fd,&file,sizeof(file)); - if (ret!=sizeof(file)) return -1; + ret=write (fd,&month,sizeof (month)); + if (ret!=sizeof (month)) return -1; + ret=write (fd,&pktcnt,sizeof (pktcnt)); + if (ret!=sizeof (pktcnt)) return -1; + ret=write (fd,&bitfield,sizeof (bitfield)); + if (ret!=sizeof (bitfield)) return -1; + ret=write (fd,&file,sizeof (file)); + if (ret!=sizeof (file)) return -1; return ret; } int cGlobalInfosatdata::Load(int fd) { if (fd==-1) return -1; - ssize_t ret=read(fd,&ready,sizeof(ready)); - if (ret!=sizeof(ready)) return -1; - ret=read(fd,&processed,sizeof(processed)); - if (ret!=sizeof(processed)) return -1; - ret=read(fd,&day,sizeof(day)); - if (ret!=sizeof(day)) return -1; - ret=read(fd,&month,sizeof(month)); - if (ret!=sizeof(month)) return -1; - ret=read(fd,&pktcnt,sizeof(pktcnt)); - if (ret!=sizeof(pktcnt)) return -1; - ret=read(fd,&bitfield,sizeof(bitfield)); - if (ret!=sizeof(bitfield)) return -1; - ret=read(fd,&file,sizeof(file)); - if (ret!=sizeof(file)) return -1; - dsyslog("infosatepg: loaded file=*%s*",file); + ssize_t ret=read (fd,&receivedall,sizeof (receivedall)); + if (ret!=sizeof (receivedall)) return -1; + ret=read (fd,&receivedpercent,sizeof(receivedpercent)); + if (ret!=sizeof (receivedpercent)) return -1; + ret=read (fd,&Processed,sizeof (Processed)); + if (ret!=sizeof (Processed)) return -1; + ret=read (fd,&day,sizeof (day)); + if (ret!=sizeof (day)) return -1; + ret=read (fd,&month,sizeof (month)); + if (ret!=sizeof (month)) return -1; + ret=read (fd,&pktcnt,sizeof (pktcnt)); + if (ret!=sizeof (pktcnt)) return -1; + ret=read (fd,&bitfield,sizeof (bitfield)); + if (ret!=sizeof (bitfield)) return -1; + ret=read (fd,&file,sizeof (file)); + if (ret!=sizeof (file)) return -1; + dsyslog ("infosatepg: loaded file=%s",file); return ret; } @@ -82,38 +87,42 @@ int cGlobalInfosatdata::Load(int fd) void cGlobalInfosatdata::Debug(const char *Directory) { char file[1024]; - snprintf(file,sizeof(file),"%s/infosatepg9999_999.dat",Directory); - Init(file,99,99,999); + snprintf (file,sizeof (file),"%s/infosatepg9999_999.dat",Directory); + Init (file,99,99,999); ready=true; } #endif -int cGlobalInfosatdata::ReceivedPercent() +bool cGlobalInfosatdata::CheckReceivedAll() { - if (pktcnt==0) return 0; int donecnt=0; - for (int i=0; i<pktcnt; i++) - { - if (GetBit(i)==true) donecnt++; - } - return ((donecnt*100)/pktcnt); -} - -bool cGlobalInfosatdata::ReceivedAll() -{ + receivedpercent=0; if (pktcnt==0) return false; + bool retval=true; for (int i=0; i<pktcnt; i++) { - if (GetBit(i)==false) return false; + if (GetBit(i)==true) donecnt++; + else retval=false; } - ready=true; - return true; + receivedpercent=((donecnt*100)/pktcnt); + if (retval==true) receivedall=true; + return retval; } // --- cGlobalInfosatepg ----------------------------------------------------- cGlobalInfosatepg::cGlobalInfosatepg() { // set default values + // set private member + switched=false; + directory=NULL; + infosatchannels=NULL; + this_day=-1; + this_month=-1; + numinfosatchannels=0; + wakeuptime=-1; + // set public member + LastCurrentChannel=-1; Pid=1809; EventTimeDiff=480; // default 8 minutes Channel=1; @@ -123,14 +132,8 @@ cGlobalInfosatepg::cGlobalInfosatepg() MAC[3]=0x02; MAC[4]=0x02; WaitTime=10; // default 10 seconds - Switched=false; - directory=NULL; - SetDirectory("/tmp"); - infosatchannels=NULL; - numinfosatchannels=0; - WakeupTime=0; - this_day=-1; - this_month=-1; + SetDirectory ("/tmp"); + ProcessedAll=false; } cGlobalInfosatepg::~cGlobalInfosatepg() @@ -141,18 +144,18 @@ cGlobalInfosatepg::~cGlobalInfosatepg() bool cGlobalInfosatepg::SetDirectory(const char *Directory) { - if (access(Directory,W_OK | R_OK | X_OK)==-1) + if (access (Directory,W_OK | R_OK | X_OK) ==-1) { // cannot access, maybe create? - if (mkdir(Directory,0775)==-1) + if (mkdir (Directory,0775) ==-1) { // even if the Directory exists, we cannot access return false; } - if (access(Directory,W_OK | R_OK| X_OK)==-1) return false; + if (access (Directory,W_OK | R_OK| X_OK) ==-1) return false; } - free((void *) directory); - directory = Directory ? strdup(Directory) : NULL; + free ((void *) directory); + directory = Directory ? strdup (Directory) : NULL; return true; } @@ -173,14 +176,27 @@ bool cGlobalInfosatepg::CheckMAC(struct ethhdr *eth_hdr) void cGlobalInfosatepg::AddChannel(tChannelID ChannelID,int Usage) { - infosatchannels=(struct infosatchannels *) realloc(infosatchannels, - (numinfosatchannels+1)*sizeof(struct infosatchannels)); + infosatchannels= (struct infosatchannels *) realloc (infosatchannels, + (numinfosatchannels+1) *sizeof (struct infosatchannels)); if (!infosatchannels) return; infosatchannels[numinfosatchannels].ChannelID=ChannelID; infosatchannels[numinfosatchannels].Usage=Usage; numinfosatchannels++; } +void cGlobalInfosatepg::RemoveChannel(int Index) +{ + if ((Index<0) || (Index>numinfosatchannels)) return; + int i; + for (i=Index; i<(numinfosatchannels-1); i++) + { + infosatchannels[i].ChannelID=infosatchannels[i+1].ChannelID; + infosatchannels[i].Usage=infosatchannels[i+1].Usage; + } + //infosatchannels[numinfosatchannels].Usage=0; + numinfosatchannels--; +} + tChannelID cGlobalInfosatepg::GetChannelID(int Index) { if (numinfosatchannels==0) return tChannelID::InvalidID; @@ -224,14 +240,14 @@ int cGlobalInfosatepg::GetChannelUse(int Index) int cGlobalInfosatepg::Save() { char file[1024]; - snprintf(file,sizeof(file),"%s/infosatepg.dat",directory); + snprintf (file,sizeof (file),"%s/infosatepg.dat",directory); - int f=open(file,O_RDWR|O_CREAT|O_TRUNC,0664); + int f=open (file,O_RDWR|O_CREAT|O_TRUNC,0664); if (f==-1) { if (errno!=ENOSPC) { - esyslog("infosatepg: unable to create file '%s'", file); + esyslog ("infosatepg: unable to create file '%s'", file); } return -1; } @@ -239,97 +255,140 @@ int cGlobalInfosatepg::Save() int ret; for (int mac=EPG_FIRST_DAY_MAC; mac<=EPG_LAST_DAY_MAC; mac++) { - ret=Infosatdata[mac].Save(f); + ret=Infosatdata[mac].Save (f); if (ret==-1) break; } if (ret!=-1) { - ret=write(f,&this_day,sizeof(this_day)); - if (ret!=sizeof(this_day)) ret=-1; + ret=write (f,&this_day,sizeof(this_day)); + if (ret!=sizeof (this_day)) ret=-1; } if (ret!=-1) { - ret=write(f,&this_month,sizeof(this_month)); - if (ret!=sizeof(this_month)) ret=-1; + ret=write (f,&this_month,sizeof(this_month)); + if (ret!=sizeof (this_month)) ret=-1; + } + if (ret!=-1) + { + ret=write (f,&wakeuptime,sizeof(wakeuptime)); + if (ret!=sizeof (wakeuptime)) ret=-1; } - close(f); - if (ret==-1) unlink(file); + close (f); + if (ret==-1) unlink (file); return ret; } int cGlobalInfosatepg::Load() { char file[1024]; - snprintf(file,sizeof(file),"%s/infosatepg.dat",directory); + snprintf (file,sizeof (file),"%s/infosatepg.dat",directory); - int f=open(file,O_RDONLY); + int f=open (file,O_RDONLY); if (f==-1) return 0; // it's ok if the file doesn't exist int ret; for (int mac=EPG_FIRST_DAY_MAC; mac<=EPG_LAST_DAY_MAC; mac++) { - ret=Infosatdata[mac].Load(f); + ret=Infosatdata[mac].Load (f); if (ret==-1) break; } if (ret!=-1) { - ret=read(f,&this_day,sizeof(this_day)); - if (ret!=sizeof(this_day)) ret=-1; + ret=read (f,&this_day,sizeof (this_day)); + if (ret!=sizeof (this_day)) ret=-1; } if (ret!=-1) { - ret=read(f,&this_month,sizeof(this_month)); - if (ret!=sizeof(this_month)) ret=-1; + ret=read (f,&this_month,sizeof (this_month)); + if (ret!=sizeof (this_month)) ret=-1; + } + if (ret!=-1) + { + ret=read (f,&wakeuptime,sizeof (wakeuptime)); + if (ret!=sizeof (wakeuptime)) ret=-1; } - close(f); + close (f); if (ret==-1) { - unlink(file); // but it's not ok if the read failed! - for (int mac=EPG_FIRST_DAY_MAC; mac<=EPG_LAST_DAY_MAC; mac++) - { - Infosatdata[mac].Init(NULL,0,0,0); - } - + unlink (file); // but it's not ok if the read failed! + ResetReceivedAll(); } return ret; } -void cGlobalInfosatepg::ResetProcessedFlags(void) +void cGlobalInfosatepg::ResetReceivedAll(void) +{ + for (int mac=EPG_FIRST_DAY_MAC; mac<=EPG_LAST_DAY_MAC; mac++) + { + Infosatdata[mac].ResetReceivedAll(); + } + wakeuptime=-1; +} + +void cGlobalInfosatepg::ResetProcessed (void) { - dsyslog("infosatepg: reprocess files (later)"); for (int mac=EPG_FIRST_DAY_MAC; mac<=EPG_LAST_DAY_MAC; mac++) { - Infosatdata[mac].ResetProcessed(); + Infosatdata[mac].Processed=false; } + wakeuptime=-1; + ProcessedAll=false; } -void cGlobalInfosatepg::Lock(time_t Now) +bool cGlobalInfosatepg::ReceivedAll(int *Day, int *Month) { + bool res=false; + time_t Now=time (NULL); struct tm tm; - if (!localtime_r(&Now,&tm)) + if (!localtime_r (&Now,&tm)) return false; + + // First check if we have received all data + int numReceived=0; + for (int mac=EPG_FIRST_DAY_MAC; mac<=EPG_LAST_DAY_MAC; mac++) { - this_day=-1; - this_month=-1; + if (Infosatdata[mac].ReceivedAll()) numReceived++; } - else + // All days fully received + if (numReceived==EPG_DAYS) { - if ((tm.tm_mday!=this_day) || ((tm.tm_mon+1)!=this_month)) - isyslog("infosatepg: all data processed"); - this_day=tm.tm_mday; - this_month=tm.tm_mon+1; + // First entry from today? + if ((Infosatdata[EPG_FIRST_DAY_MAC].Day() ==tm.tm_mday) && + (Infosatdata[EPG_FIRST_DAY_MAC].Month() ==tm.tm_mon+1)) + { + // Yes + if ((this_day!=tm.tm_mday) || (this_month!=tm.tm_mon+1)) + { + isyslog ("infosatepg: all data received"); + this_day=tm.tm_mday; + this_month=tm.tm_mon+1; + } + res=true; + } + else + { + // New day, but new data is ready only after wakeup-time + time_t Now = time(NULL); + time_t Time = cTimer::SetTime(Now,cTimer::TimeToInt(WakeupTime())); + if (Now>=Time) + { + // new day and new data should be available + ResetReceivedAll(); + res=false; + } + else + { + // wait till we are after wakeuptime + res=true; + } + + } } -} -bool cGlobalInfosatepg::isLocked(int *Day, int *Month) -{ if (Day) *Day=this_day; if (Month) *Month=this_month; - time_t Now=time(NULL); - struct tm tm; - if (!localtime_r(&Now,&tm)) return false; - if ((tm.tm_mday==this_day) && ((tm.tm_mon+1)==this_month)) return true; - return false; + + return res; } |