-void eEPGCache::pauseEPG()
-{
- if (!paused)
- {
- abortEPG();
- eDebug("[EPGC] paused]");
- paused=1;
- }
-}
-
-void eEPGCache::restartEPG()
-{
- if (paused)
- {
- isRunning=0;
- eDebug("[EPGC] restarted");
- paused--;
- if (paused)
- {
- paused = 0;
- startEPG(); // updateEPG
- }
- cleanLoop();
- }
-}
-
-void eEPGCache::startEPG()
-{
- if (paused) // called from the updateTimer during pause...
- {
- paused++;
- return;
- }
- if (eDVBLocalTimeHandler::getInstance()->ready())
- {
- Lock();
- temp.clear();
- Unlock();
- eDebug("[EPGC] start caching events");
- state=0;
- haveData=0;
-
- eDVBSectionFilterMask mask;
- memset(&mask, 0, sizeof(mask));
- mask.pid = 0x12;
- mask.flags = eDVBSectionFilterMask::rfCRC;
-
- mask.data[0] = 0x4E;
- mask.mask[0] = 0xFE;
- m_NowNextReader->start(mask);
- isRunning |= 1;
-
- mask.data[0] = 0x50;
- mask.mask[0] = 0xF0;
- m_ScheduleReader->start(mask);
- isRunning |= 2;
-
- mask.data[0] = 0x60;
- mask.mask[0] = 0xF0;
- m_ScheduleOtherReader->start(mask);
- isRunning |= 4;
-
- abortTimer.start(5000,true);
- }
- else
- {
- eDebug("[EPGC] wait for clock update");
- zapTimer.start(1000, 1); // restart Timer
- }
-}
-
-void eEPGCache::abortNonAvail()
-{
- if (!state)
- {
- if ( !(haveData&2) && (isRunning&2) )
- {
- eDebug("[EPGC] abort non avail nownext reading");
- isRunning &= ~2;
- if ( m_NowNextReader )
- m_NowNextReader->stop();
- }
- if ( !(haveData&1) && (isRunning&1) )
- {
- eDebug("[EPGC] abort non avail schedule reading");
- isRunning &= ~1;
- m_ScheduleReader->stop();
- }
- if ( !(haveData&4) && (isRunning&4) )
- {
- eDebug("[EPGC] abort non avail schedule_other reading");
- isRunning &= ~4;
- m_ScheduleOtherReader->stop();
- }
- abortTimer.start(20000, true);
- }
- ++state;
-}
-
-void eEPGCache::startCache(const eServiceReferenceDVB& ref)
-{
- if ( m_currentChannel )
- {
- next_service = ref;
- leaveChannel(m_currentChannel);
- return;
- }
- eDVBChannelID chid;
- ref.getChannelID( chid );
- ePtr<eDVBResourceManager> res_mgr;
- if ( eDVBResourceManager::getInstance( res_mgr ) )
- eDebug("[eEPGCache] no res manager!!");
- else
- {
- ePtr<iDVBDemux> demux;
-// res_mgr->allocateChannel(chid, m_currentChannel);
- if ( m_currentChannel->getDemux(demux) )
- {
- eDebug("[eEPGCache] no demux!!");
- goto error4;
- }
- else
- {
- RESULT res;
- m_NowNextReader = new eDVBSectionReader( demux, this, res );
- if ( res )
- {
- eDebug("[eEPGCache] couldnt initialize nownext reader!!");
- goto error3;
- }
- m_NowNextReader->connectRead(slot(*this, &eEPGCache::readNowNextData), m_NowNextConn);
- m_ScheduleReader = new eDVBSectionReader( demux, this, res );
- if ( res )
- {
- eDebug("[eEPGCache] couldnt initialize schedule reader!!");
- goto error2;
- }
- m_ScheduleReader->connectRead(slot(*this, &eEPGCache::readScheduleData), m_ScheduleConn);
- m_ScheduleOtherReader = new eDVBSectionReader( demux, this, res );
- if ( res )
- {
- eDebug("[eEPGCache] couldnt initialize schedule other reader!!");
- goto error1;
- }
- m_ScheduleOtherReader->connectRead(slot(*this, &eEPGCache::readScheduleOtherData), m_ScheduleOtherConn);
- messages.send(Message(Message::startService, ref));
- // -> gotMessage -> changedService
- }
- }
- return;
-error1:
- m_ScheduleOtherReader=0;
- m_ScheduleOtherConn=0;
-error2:
- m_ScheduleReader=0;
- m_ScheduleConn=0;
-error3:
- m_NowNextReader=0;
- m_NowNextConn=0;
-error4:
- m_currentChannel=0;
-}
-
-void eEPGCache::leaveChannel(iDVBChannel * chan)
-{
- if ( chan && chan == m_currentChannel )
- {
- messages.send(Message(Message::leaveChannel, chan));
- // -> gotMessage -> abortEPG
- }
-}
-
-void eEPGCache::changedService(const uniqueEPGKey &service)
-{
- current_service = service;
- updateMap::iterator It = serviceLastUpdated.find( current_service );
-
- int update;
-
-// check if this is a subservice and this is only a dbox2
-// then we dont start epgcache on subservice change..
-// ever and ever..
-
-// if ( !err || err == -ENOCASYS )
- {
- update = ( It != serviceLastUpdated.end() ? ( UPDATE_INTERVAL - ( (time(0)+eDVBLocalTimeHandler::getInstance()->difference()-It->second) * 1000 ) ) : ZAP_DELAY );
-
- if (update < ZAP_DELAY)
- update = ZAP_DELAY;
-
- zapTimer.start(update, 1);
- if (update >= 60000)
- eDebug("[EPGC] next update in %i min", update/60000);
- else if (update >= 1000)
- eDebug("[EPGC] next update in %i sec", update/1000);
- }
-
- Lock();
- bool empty=eventDB[current_service].first.empty();
- Unlock();
-
- if (!empty)
- {
- eDebug("[EPGC] yet cached");
- /*emit*/ EPGAvail(1);
- }
- else
- {
- eDebug("[EPGC] not cached yet");
- /*emit*/ EPGAvail(0);
- }
-}
-
-void eEPGCache::abortEPG()
-{
- abortTimer.stop();
- zapTimer.stop();
- if (isRunning)
- {
- if (isRunning & 1)
- {
- isRunning &= ~1;
- if ( m_ScheduleReader )
- m_ScheduleReader->stop();
- }
- if (isRunning & 2)
- {
- isRunning &= ~2;
- if ( m_NowNextReader )
- m_NowNextReader->stop();
- }
- if (isRunning & 4)
- {
- isRunning &= ~4;
- if ( m_ScheduleOtherReader )
- m_ScheduleOtherReader->stop();
- }
- eDebug("[EPGC] abort caching events !!");
- Lock();
- temp.clear();
- Unlock();
- }
-}
-