diff options
author | horchi <vdr@jwendel.de> | 2017-05-05 18:02:06 +0200 |
---|---|---|
committer | horchi <vdr@jwendel.de> | 2017-05-05 18:02:06 +0200 |
commit | 65ef548b3b1e80d37da6db48e0648fc4485d14c7 (patch) | |
tree | 2b65dfcecf2c551b4b51179aa64aec9090248ab0 /update.c | |
parent | 9e720f23bafea648ce3f7496c8369d90a553383d (diff) | |
download | vdr-plugin-epg2vdr-65ef548b3b1e80d37da6db48e0648fc4485d14c7.tar.gz vdr-plugin-epg2vdr-65ef548b3b1e80d37da6db48e0648fc4485d14c7.tar.bz2 |
2017-05-05 version 1.1.59 (horchi)\n - bugfix: Fixed crash on missing cahnnels\n\n1.1.59
Diffstat (limited to 'update.c')
-rw-r--r-- | update.c | 169 |
1 files changed, 92 insertions, 77 deletions
@@ -1359,6 +1359,38 @@ void clearEpg() } //*************************************************************************** +// Get Schedule Of +//*************************************************************************** + +cSchedule* getScheduleOf(tChannelID channelId, const cSchedules* schedules) +{ + cChannel* channel = 0; + cSchedule* s = 0; + + // get channels lock + +#if defined (APIVERSNUM) && (APIVERSNUM >= 20301) + cStateKey channelsKey; + cChannels* channels = cChannels::GetChannelsWrite(channelsKey, 10); +#else + cChannels* channels = &Channels; +#endif + + // get channel and schedule of channel + + if (channel = channels->GetByChannelID(channelId, true)) + s = (cSchedule*)schedules->GetSchedule(channel, true); + else + tell(0, "Error: Channel with ID '%s' don't exist on this VDR", (const char*)channelId.ToString()); + +#if defined (APIVERSNUM) && (APIVERSNUM >= 20301) + channelsKey.Remove(); +#endif + + return s; +} + +//*************************************************************************** // Refresh Epg //*************************************************************************** @@ -1432,17 +1464,6 @@ int cUpdate::refreshEpg(const char* forChannelId, int maxTries) cTimers* timers = &Timers; #endif - // get channles lock - -#if defined (APIVERSNUM) && (APIVERSNUM >= 20301) - cStateKey channelsKey; - tell(3, "-> Try to get channels lock"); - cChannels* channels = cChannels::GetChannelsWrite(channelsKey, 10); - tell(3, "channels LOCK (refreshEpg)"); -#else - cChannels* channels = &Channels; -#endif - // get schedules lock #if defined (APIVERSNUM) && (APIVERSNUM >= 20301) @@ -1455,13 +1476,12 @@ int cUpdate::refreshEpg(const char* forChannelId, int maxTries) tell(3, "LOCK (refreshEpg)"); #endif - if (!schedules || !timers || !channels) + if (!schedules || !timers) { - tell(3, "Info: Can't get write lock on '%s'", !schedules ? "schedules" : !channels ? "channels" : "timers"); + tell(3, "Info: Can't get write lock on '%s'", !schedules ? "schedules" : "timers"); #if defined (APIVERSNUM) && (APIVERSNUM >= 20301) if (schedules) schedulesKey.Remove(); - if (channels) channelsKey.Remove(); if (timers) timersKey.Remove(); #else delete schedulesLock; @@ -1482,99 +1502,94 @@ int cUpdate::refreshEpg(const char* forChannelId, int maxTries) tries = 0; - // get schedule of channel + // lookup schedules object - cChannel* channel = channels->GetByChannelID(channelId, true); - s = (cSchedule*)schedules->GetSchedule(channel, true); + if (s = getScheduleOf(channelId, schedules)) + { + // ----------------------------------------- + // iterate over all events of this schedule - // if (!(s = (cSchedule*)schedules->GetSchedule(channelId))) - // s = schedules->AddSchedule(channelId); + for (int found = selectUpdEvents->find(); found && dbConnected(); found = selectUpdEvents->fetch()) + { + cTimer* timer = 0; + char updFlg = toupper(eventsDb->getStrValue("UPDFLG")[0]); - // ----------------------------------------- - // iterate over all events of this channel + updFlg = updFlg == 0 ? 'P' : updFlg; // fix missing flag - for (int found = selectUpdEvents->find(); found && dbConnected(); found = selectUpdEvents->fetch()) - { - cTimer* timer = 0; - char updFlg = toupper(eventsDb->getStrValue("UPDFLG")[0]); + // ignore unneded event rows .. - updFlg = updFlg == 0 ? 'P' : updFlg; // fix missing flag + if (!Us::isNeeded(updFlg)) + continue; - // ignore unneded event rows .. + // get event / timer - if (!Us::isNeeded(updFlg)) - continue; + if ((event = s->GetEvent(eventsDb->getIntValue("USEID")))) + { + if (Us::isRemove(updFlg)) + tell(2, "Remove event %uld of channel '%s' due to updflg %c", + event->EventID(), (const char*)event->ChannelID().ToString(), updFlg); - // get event / timer + if (event->HasTimer()) + { + for (timer = timers->First(); timer; timer = timers->Next(timer)) + if (timer->Event() == event) + break; + } - if ((event = s->GetEvent(eventsDb->getIntValue("USEID")))) - { - if (Us::isRemove(updFlg)) - tell(2, "Remove event %uld of channel '%s' due to updflg %c", - event->EventID(), (const char*)event->ChannelID().ToString(), updFlg); + if (timer) + timer->SetEvent(0); - if (event->HasTimer()) - { - for (timer = timers->First(); timer; timer = timers->Next(timer)) - if (timer->Event() == event) - break; + s->DelEvent((cEvent*)event); } - if (timer) - timer->SetEvent(0); + if (!Us::isRemove(updFlg)) + event = s->AddEvent(createEventFromRow(eventsDb->getRow())); + else if (event) + { + event = 0; + dels++; + } - s->DelEvent((cEvent*)event); - } + if (timer && event) + { + timer->SetEvent(event); + timer->Matches(event); + timerChanges++; + } + else if (timer) + { + tell(0, "Info: Timer '%s', has no event anymore", *timer->ToDescr()); + } - if (!Us::isRemove(updFlg)) - event = s->AddEvent(createEventFromRow(eventsDb->getRow())); - else if (event) - { - event = 0; - dels++; + count++; } - if (timer && event) - { - timer->SetEvent(event); - timer->Matches(event); - timerChanges++; - } - else if (timer) - { - tell(0, "Info: Timer '%s', has no event anymore", *timer->ToDescr()); - } + selectUpdEvents->freeResult(); - count++; - } + // Kanal fertig machen .. - selectUpdEvents->freeResult(); + s->Sort(); + s->SetModified(); - // Kanal fertig machen .. + tell(2, "Processed channel '%s' - '%s' with %d updates", + eventsDb->getStrValue("CHANNELID"), + mapDb->getStrValue("CHANNELNAME"), + count); - s->Sort(); - s->SetModified(); + total += count; + } // schedules lock freigeben #if defined (APIVERSNUM) && (APIVERSNUM >= 20301) schedulesKey.Remove(); tell(3, "-> Released schedules lock"); - channelsKey.Remove(); - tell(3, "-> Released channels lock"); timersKey.Remove(); tell(3, "-> Released timers lock"); #else tell(3, "LOCK free (refreshEpg)"); delete schedulesLock; #endif - - tell(2, "Processed channel '%s' - '%s' with %d updates", - eventsDb->getStrValue("ChannelId"), - mapDb->getStrValue("ChannelName"), - count); - - total += count; } select->freeResult(); @@ -1591,12 +1606,12 @@ int cUpdate::refreshEpg(const char* forChannelId, int maxTries) } if (lastEventsUpdateAt) - tell(2, "Updated changes since '%s'; %d channels, " + tell(1, "Updated changes since '%s'; %d channels, " "%d events (%d deletions) in %s", forChannelId ? "-" : l2pTime(lastEventsUpdateAt).c_str(), channels, total, dels, ms2Dur(cTimeMs::Now()-start).c_str()); else - tell(2, "Updated all %d channels, %d events (%d deletions) in %s", + tell(1, "Updated all %d channels, %d events (%d deletions) in %s", channels, total, dels, ms2Dur(cTimeMs::Now()-start).c_str()); return dbConnected(yes) ? success : fail; |