code cleanup
[enigma2.git] / lib / dvb / epgcache.cpp
index a744655a2b253511acb411a9c8fe380fcee3771f..1867eb9732ae147e9cbc68d37d48ecc3c9cabd0b 100644 (file)
@@ -286,7 +286,7 @@ void eEPGCache::DVBChannelStateChanged(iDVBChannel *chan)
                                {
                                        eDebug("[eEPGCache] remove channel %p", chan);
                                        messages.send(Message(Message::leaveChannel, chan));
-                                       while(!it->second->can_delete)
+                                       while(!it->second->canDelete())
                                                usleep(1000);
                                        delete it->second;
                                        m_knownChannels.erase(it);
@@ -384,7 +384,7 @@ void eEPGCache::sectionRead(const __u8 *data, int source, channel_data *channel)
        int duration;
 
        time_t TM = parseDVBtime( eit_event->start_time_1, eit_event->start_time_2,     eit_event->start_time_3, eit_event->start_time_4, eit_event->start_time_5);
-       time_t now = time(0)+eDVBLocalTimeHandler::getInstance()->difference();
+       time_t now = eDVBLocalTimeHandler::getInstance()->nowTime();
 
        if ( TM != 3599 && TM > -1)
                channel->haveData |= source;
@@ -629,7 +629,7 @@ void eEPGCache::cleanLoop()
        {
                eDebug("[EPGC] start cleanloop");
 
-               time_t now = time(0)+eDVBLocalTimeHandler::getInstance()->difference();
+               time_t now = eDVBLocalTimeHandler::getInstance()->nowTime();
 
                for (eventCache::iterator DBIt = eventDB.begin(); DBIt != eventDB.end(); DBIt++)
                {
@@ -744,7 +744,7 @@ void eEPGCache::gotMessage( const Message &msg )
                                        data->m_PrivatePid = msg.pid;
                                        data->m_PrivateService = msg.service;
                                        updateMap::iterator It = channelLastUpdated.find( channel->getChannelID() );
-                                       int update = ( It != channelLastUpdated.end() ? ( UPDATE_INTERVAL - ( (time(0)+eDVBLocalTimeHandler::getInstance()->difference()-It->second) * 1000 ) ) : ZAP_DELAY );
+                                       int update = ( It != channelLastUpdated.end() ? ( UPDATE_INTERVAL - ( (eDVBLocalTimeHandler::getInstance()->nowTime()-It->second) * 1000 ) ) : ZAP_DELAY );
                                        if (update < ZAP_DELAY)
                                                update = ZAP_DELAY;
                                        data->startPrivateTimer.start(update, 1);
@@ -983,7 +983,7 @@ void eEPGCache::save()
 eEPGCache::channel_data::channel_data(eEPGCache *ml)
        :cache(ml)
        ,abortTimer(ml), zapTimer(ml),state(0)
-       ,isRunning(0), haveData(0), can_delete(1)
+       ,isRunning(0), haveData(0)
        ,startPrivateTimer(ml)
 {
        CONNECT(zapTimer.timeout, eEPGCache::channel_data::startEPG);
@@ -995,7 +995,7 @@ bool eEPGCache::channel_data::finishEPG()
 {
        if (!isRunning)  // epg ready
        {
-               eDebug("[EPGC] stop caching events(%ld)", time(0)+eDVBLocalTimeHandler::getInstance()->difference());
+               eDebug("[EPGC] stop caching events(%ld)", eDVBLocalTimeHandler::getInstance()->nowTime());
                zapTimer.start(UPDATE_INTERVAL, 1);
                eDebug("[EPGC] next update in %i min", UPDATE_INTERVAL / 60000);
                for (int i=0; i < 3; ++i)
@@ -1004,11 +1004,7 @@ bool eEPGCache::channel_data::finishEPG()
                        calcedSections[i].clear();
                }
                singleLock l(cache->cache_lock);
-               cache->channelLastUpdated[channel->getChannelID()] = time(0)+eDVBLocalTimeHandler::getInstance()->difference();
-#ifdef ENABLE_PRIVATE_EPG
-               if (seenPrivateSections.empty())
-#endif
-               can_delete=1;
+               cache->channelLastUpdated[channel->getChannelID()] = eDVBLocalTimeHandler::getInstance()->nowTime();
                return true;
        }
        return false;
@@ -1016,10 +1012,9 @@ bool eEPGCache::channel_data::finishEPG()
 
 void eEPGCache::channel_data::startEPG()
 {
-       eDebug("[EPGC] start caching events(%ld)", eDVBLocalTimeHandler::getInstance()->difference()+time(0));
+       eDebug("[EPGC] start caching events(%ld)", eDVBLocalTimeHandler::getInstance()->nowTime());
        state=0;
        haveData=0;
-       can_delete=0;
        for (int i=0; i < 3; ++i)
        {
                seenSections[i].clear();
@@ -1056,21 +1051,21 @@ void eEPGCache::channel_data::abortNonAvail()
 {
        if (!state)
        {
-               if ( !(haveData&eEPGCache::NOWNEXT) && (isRunning&eEPGCache::NOWNEXT) )
+               if ( !(haveData&NOWNEXT) && (isRunning&NOWNEXT) )
                {
                        eDebug("[EPGC] abort non avail nownext reading");
-                       isRunning &= ~eEPGCache::NOWNEXT;
+                       isRunning &= ~NOWNEXT;
                        m_NowNextReader->stop();
                        m_NowNextConn=0;
                }
-               if ( !(haveData&eEPGCache::SCHEDULE) && (isRunning&eEPGCache::SCHEDULE) )
+               if ( !(haveData&SCHEDULE) && (isRunning&SCHEDULE) )
                {
                        eDebug("[EPGC] abort non avail schedule reading");
                        isRunning &= ~SCHEDULE;
                        m_ScheduleReader->stop();
                        m_ScheduleConn=0;
                }
-               if ( !(haveData&eEPGCache::SCHEDULE_OTHER) && (isRunning&eEPGCache::SCHEDULE_OTHER) )
+               if ( !(haveData&SCHEDULE_OTHER) && (isRunning&SCHEDULE_OTHER) )
                {
                        eDebug("[EPGC] abort non avail schedule_other reading");
                        isRunning &= ~SCHEDULE_OTHER;
@@ -1087,10 +1082,6 @@ void eEPGCache::channel_data::abortNonAvail()
                                seenSections[i].clear();
                                calcedSections[i].clear();
                        }
-#ifdef ENABLE_PRIVATE_EPG
-                       if (seenPrivateSections.empty())
-#endif
-                       can_delete=1;
                }
        }
        ++state;
@@ -1100,7 +1091,7 @@ void eEPGCache::channel_data::startChannel()
 {
        updateMap::iterator It = cache->channelLastUpdated.find( channel->getChannelID() );
 
-       int update = ( It != cache->channelLastUpdated.end() ? ( UPDATE_INTERVAL - ( (time(0)+eDVBLocalTimeHandler::getInstance()->difference()-It->second) * 1000 ) ) : ZAP_DELAY );
+       int update = ( It != cache->channelLastUpdated.end() ? ( UPDATE_INTERVAL - ( (eDVBLocalTimeHandler::getInstance()->nowTime()-It->second) * 1000 ) ) : ZAP_DELAY );
 
        if (update < ZAP_DELAY)
                update = ZAP_DELAY;
@@ -1124,21 +1115,21 @@ void eEPGCache::channel_data::abortEPG()
        if (isRunning)
        {
                eDebug("[EPGC] abort caching events !!");
-               if (isRunning & eEPGCache::SCHEDULE)
+               if (isRunning & SCHEDULE)
                {
-                       isRunning &= ~eEPGCache::SCHEDULE;
+                       isRunning &= ~SCHEDULE;
                        m_ScheduleReader->stop();
                        m_ScheduleConn=0;
                }
-               if (isRunning & eEPGCache::NOWNEXT)
+               if (isRunning & NOWNEXT)
                {
-                       isRunning &= ~eEPGCache::NOWNEXT;
+                       isRunning &= ~NOWNEXT;
                        m_NowNextReader->stop();
                        m_NowNextConn=0;
                }
                if (isRunning & SCHEDULE_OTHER)
                {
-                       isRunning &= ~eEPGCache::SCHEDULE_OTHER;
+                       isRunning &= ~SCHEDULE_OTHER;
                        m_ScheduleOtherReader->stop();
                        m_ScheduleOtherConn=0;
                }
@@ -1149,7 +1140,6 @@ void eEPGCache::channel_data::abortEPG()
        if (m_PrivateConn)
                m_PrivateConn=0;
 #endif
-       can_delete=1;
 }
 
 void eEPGCache::channel_data::readData( const __u8 *data)
@@ -1165,17 +1155,17 @@ void eEPGCache::channel_data::readData( const __u8 *data)
                {
                        case 0x4E ... 0x4F:
                                reader=m_NowNextReader;
-                               source=eEPGCache::NOWNEXT;
+                               source=NOWNEXT;
                                map=0;
                                break;
                        case 0x50 ... 0x5F:
                                reader=m_ScheduleReader;
-                               source=eEPGCache::SCHEDULE;
+                               source=SCHEDULE;
                                map=1;
                                break;
                        case 0x60 ... 0x6F:
                                reader=m_ScheduleOtherReader;
-                               source=eEPGCache::SCHEDULE_OTHER;
+                               source=SCHEDULE_OTHER;
                                map=2;
                                break;
                        default:
@@ -1189,21 +1179,21 @@ void eEPGCache::channel_data::readData( const __u8 *data)
                        eDebugNoNewLine("[EPGC] ");
                        switch (source)
                        {
-                               case eEPGCache::NOWNEXT:
+                               case NOWNEXT:
                                        m_NowNextConn=0;
                                        eDebugNoNewLine("nownext");
                                        break;
-                               case eEPGCache::SCHEDULE:
+                               case SCHEDULE:
                                        m_ScheduleConn=0;
                                        eDebugNoNewLine("schedule");
                                        break;
-                               case eEPGCache::SCHEDULE_OTHER:
+                               case SCHEDULE_OTHER:
                                        m_ScheduleOtherConn=0;
                                        eDebugNoNewLine("schedule other");
                                        break;
                                default: eDebugNoNewLine("unknown");break;
                        }
-                       eDebug(" finished(%ld)", time(0)+eDVBLocalTimeHandler::getInstance()->difference());
+                       eDebug(" finished(%ld)", eDVBLocalTimeHandler::getInstance()->nowTime());
                        if ( reader )
                                reader->stop();
                        isRunning &= ~source;
@@ -1254,7 +1244,7 @@ RESULT eEPGCache::lookupEventTime(const eServiceReference &service, time_t t, co
        if ( It != eventDB.end() && !It->second.first.empty() ) // entrys cached ?
        {
                if (t==-1)
-                       t = time(0)+eDVBLocalTimeHandler::getInstance()->difference();
+                       t = eDVBLocalTimeHandler::getInstance()->nowTime();
                timeMap::iterator i = direction <= 0 ? It->second.second.lower_bound(t) :  // find > or equal
                        It->second.second.upper_bound(t); // just >
                if ( i != It->second.second.end() )
@@ -1605,7 +1595,7 @@ PyObject *eEPGCache::lookupEvent(PyObject *list, PyObject *convertFunc)
        }
 
        PyObject *nowTime = strchr(argstring, 'C') ?
-               PyLong_FromLong(time(0)+eDVBLocalTimeHandler::getInstance()->difference()) :
+               PyLong_FromLong(eDVBLocalTimeHandler::getInstance()->nowTime()) :
                NULL;
 
        bool must_get_service_name = strchr(argstring, 'N') ? true : false;
@@ -2384,7 +2374,7 @@ void eEPGCache::privateSectionRead(const uniqueEPGKey &current_service, const __
                event[0] = (event_id & 0xFF00) >> 8;
                event[1] = (event_id & 0xFF);
                time_event_map[it->first.tm]=std::pair<time_t, __u16>(stime, event_id);
-               eventData *d = new eventData( ev_struct, bptr, eEPGCache::PRIVATE );
+               eventData *d = new eventData( ev_struct, bptr, PRIVATE );
                evMap[event_id] = d;
                tmMap[stime] = d;
        }
@@ -2406,7 +2396,8 @@ void eEPGCache::channel_data::startPrivateReader()
                mask.mode[3] = 0x3E;
        }
        seenPrivateSections.clear();
-       m_PrivateReader->connectRead(slot(*this, &eEPGCache::channel_data::readPrivateData), m_PrivateConn);
+       if (!m_PrivateConn)
+               m_PrivateReader->connectRead(slot(*this, &eEPGCache::channel_data::readPrivateData), m_PrivateConn);
        m_PrivateReader->start(mask);
 }
 
@@ -2418,28 +2409,12 @@ void eEPGCache::channel_data::readPrivateData( const __u8 *data)
        {
                if ( seenPrivateSections.find( data[6] ) == seenPrivateSections.end() )
                {
-#ifdef NEED_DEMUX_WORKAROUND
-                       int version = data[5];
-                       version = ((version & 0x3E) >> 1);
-                       can_delete = 0;
-                       if ( m_PrevVersion != version )
-                       {
-                               cache->privateSectionRead(m_PrivateService, data);
-                               seenPrivateSections.insert(data[6]);
-                       }
-                       else
-                               eDebug("ignore");
-#else
-                       can_delete = 0;
                        cache->privateSectionRead(m_PrivateService, data);
                        seenPrivateSections.insert(data[6]);
-#endif
                }
                if ( seenPrivateSections.size() == (unsigned int)(data[7] + 1) )
                {
                        eDebug("[EPGC] private finished");
-                       if (!isRunning)
-                               can_delete = 1;
                        m_PrevVersion = (data[5] & 0x3E) >> 1;
                        startPrivateReader();
                }