diff options
Diffstat (limited to 'eit.c')
-rw-r--r-- | eit.c | 80 |
1 files changed, 28 insertions, 52 deletions
@@ -16,7 +16,7 @@ * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * - * $Id: eit.c 1.54 2002/10/06 10:31:38 kls Exp $ + * $Id: eit.c 1.55 2002/10/07 16:24:04 kls Exp $ ***************************************************************************/ #include "eit.h" @@ -629,50 +629,26 @@ cEventInfo *cSchedule::AddEvent(cEventInfo *EventInfo) return EventInfo; } -/** */ -const cEventInfo * cSchedule::GetPresentEvent() const +const cEventInfo *cSchedule::GetPresentEvent(void) const { - // checking temporal sanity of present event (kls 2000-11-01) - time_t now = time(NULL); -//XXX if (pPresent && !(pPresent->GetTime() <= now && now <= pPresent->GetTime() + pPresent->GetDuration())) - { - cEventInfo *pe = Events.First(); - while (pe != NULL) - { - if (pe->GetTime() <= now && now <= pe->GetTime() + pe->GetDuration()) - return pe; - pe = Events.Next(pe); - } - } - return NULL;//XXX - return pPresent; + return GetEventAround(time(NULL)); } -/** */ -const cEventInfo * cSchedule::GetFollowingEvent() const + +const cEventInfo *cSchedule::GetFollowingEvent(void) const { - // checking temporal sanity of following event (kls 2000-11-01) - time_t now = time(NULL); - const cEventInfo *pr = GetPresentEvent(); // must have it verified! -if (pr)//XXX if (pFollowing && !(pr && pr->GetTime() + pr->GetDuration() <= pFollowing->GetTime())) - { - int minDt = INT_MAX; - cEventInfo *pe = Events.First(), *pf = NULL; - while (pe != NULL) - { - int dt = pe->GetTime() - now; - if (dt > 0 && dt < minDt) - { - minDt = dt; - pf = pe; + const cEventInfo *pe = NULL; + time_t now = time(NULL); + time_t delta = INT_MAX; + for (cEventInfo *p = Events.First(); p; p = Events.Next(p)) { + time_t dt = p->GetTime() - now; + if (dt > 0 && dt < delta) { + delta = dt; + pe = p; } - pe = Events.Next(pe); } - return pf; - } - return NULL;//XXX - return pFollowing; + return pe; } -/** */ + void cSchedule::SetServiceID(unsigned short servid) { uServiceID = servid; @@ -701,21 +677,21 @@ const cEventInfo * cSchedule::GetEvent(unsigned short uEventID, time_t tTime) co return pt; } -/** */ -const cEventInfo * cSchedule::GetEventAround(time_t tTime) const -{ - cEventInfo *pe = Events.First(); - while (pe != NULL) - { - if (pe->GetTime() <= tTime && tTime <= pe->GetTime() + pe->GetDuration()) - return pe; - - pe = Events.Next(pe); - } - return NULL; +const cEventInfo *cSchedule::GetEventAround(time_t Time) const +{ + const cEventInfo *pe = NULL; + time_t delta = INT_MAX; + for (cEventInfo *p = Events.First(); p; p = Events.Next(p)) { + time_t dt = Time - p->GetTime(); + if (dt >= 0 && dt < delta && p->GetTime() + p->GetDuration() >= Time) { + delta = dt; + pe = p; + } + } + return pe; } -/** */ + bool cSchedule::SetPresentEvent(cEventInfo *pEvent) { if (pPresent != NULL) |