some small fixes
[enigma2.git] / lib / components / scan.cpp
index ad2e4d1aff2446e5422bde8422fffe3dce51b364..c027fe6bb4dbc062d5aa8af55bb9414b594283ef 100644 (file)
@@ -8,37 +8,44 @@ DEFINE_REF(eComponentScan);
 
 void eComponentScan::scanEvent(int evt)
 {
-       eDebug("scan event %d!", evt);
+//     eDebug("scan event %d!", evt);
        
-       if (evt == eDVBScan::evtFinish)
+       switch(evt)
        {
-               m_done = 1;
-               ePtr<iDVBChannelList> db;
-               ePtr<eDVBResourceManager> res;
-               
-               int err;
-               if ((err = eDVBResourceManager::getInstance(res)) != 0)
-               {
-                       eDebug("no resource manager");
-                       m_failed = 2;
-               } else if ((err = res->getChannelList(db)) != 0)
-               {
-                       m_failed = 3;
-                       eDebug("no channel list");
-               } else
+               case eDVBScan::evtFinish:
                {
-                       m_scan->insertInto(db);
-                       eDebug("scan done!");
+                       m_done = 1;
+                       ePtr<iDVBChannelList> db;
+                       ePtr<eDVBResourceManager> res;
+                       
+                       int err;
+                       if ((err = eDVBResourceManager::getInstance(res)) != 0)
+                       {
+                               eDebug("no resource manager");
+                               m_failed = 2;
+                       } else if ((err = res->getChannelList(db)) != 0)
+                       {
+                               m_failed = 3;
+                               eDebug("no channel list");
+                       } else
+                       {
+                               m_scan->insertInto(db);
+                               db->flush();
+                               eDebug("scan done!");
+                       }
+                       break;
                }
+               case eDVBScan::evtNewService:
+                       newService();
+                       return;
+               case eDVBScan::evtFail:
+                       eDebug("scan failed.");
+                       m_failed = 1;
+                       m_done = 1;
+                       break;
+               case eDVBScan::evtUpdate:
+                       break;
        }
-       
-       if (evt == eDVBScan::evtFail)
-       {
-               eDebug("scan failed.");
-               m_failed = 1;
-               m_done = 1;
-       }
-       
        statusChanged();
 }
 
@@ -50,8 +57,38 @@ eComponentScan::~eComponentScan()
 {
 }
 
-int eComponentScan::start()
+void eComponentScan::clear()
 {
+       m_initial.clear();
+}
+
+void eComponentScan::addInitial(const eDVBFrontendParametersSatellite &p)
+{
+       ePtr<eDVBFrontendParameters> parm = new eDVBFrontendParameters();
+       parm->setDVBS(p);
+       m_initial.push_back(parm);
+}
+
+void eComponentScan::addInitial(const eDVBFrontendParametersCable &p)
+{
+       ePtr<eDVBFrontendParameters> parm = new eDVBFrontendParameters();
+       parm->setDVBC(p);
+       m_initial.push_back(parm);
+}
+
+void eComponentScan::addInitial(const eDVBFrontendParametersTerrestrial &p)
+{
+       ePtr<eDVBFrontendParameters> parm = new eDVBFrontendParameters();
+       parm->setDVBT(p);
+       m_initial.push_back(parm);
+}
+
+
+int eComponentScan::start(int feid, int flags)
+{
+       if (m_initial.empty())
+               return -2;
+
        if (m_done != -1)
                return -1;
        
@@ -60,48 +97,57 @@ int eComponentScan::start()
        
        eDVBResourceManager::getInstance(mgr);
 
-       eDVBFrontendParameters *fe = new eDVBFrontendParameters();
-#if 0  
-       eDVBFrontendParametersSatellite fesat;
-               
-       fesat.frequency = 11817000; // 12070000;
-       fesat.symbol_rate = 27500000;
-       fesat.polarisation = eDVBFrontendParametersSatellite::Polarisation::Vertical;
-       fesat.fec = eDVBFrontendParametersSatellite::FEC::f3_4;
-       fesat.inversion = eDVBFrontendParametersSatellite::Inversion::Off;
-       fesat.orbital_position = 192;
-
-       
-       fe->setDVBS(fesat);
-#endif
-
-       eDVBFrontendParametersTerrestrial fet;
-       fet.frequency = 626000000;
-       fet.inversion = eDVBFrontendParametersTerrestrial::Inversion::Unknown;
-       fet.bandwidth = eDVBFrontendParametersTerrestrial::Bandwidth::Bw8MHz;
-       fet.code_rate_HP = fet.code_rate_LP = eDVBFrontendParametersTerrestrial::FEC::fAuto;
-       fet.modulation = eDVBFrontendParametersTerrestrial::Modulation::QAM16;
-       fet.transmission_mode = eDVBFrontendParametersTerrestrial::TransmissionMode::TM8k;
-       fet.guard_interval = eDVBFrontendParametersTerrestrial::GuardInterval::GI_1_32;
-       fet.hierarchy = eDVBFrontendParametersTerrestrial::Hierarchy::HNone;
-       fe->setDVBT(fet);
-       
-       ePtr<iDVBChannel> channel;
+       eUsePtr<iDVBChannel> channel;
 
-       if (mgr->allocateRawChannel(channel))
+       if (mgr->allocateRawChannel(channel, feid))
        {
-               eDebug("scan: allocating raw channel failed!");
+               eDebug("scan: allocating raw channel (on frontend %d) failed!", feid);
                return -1;
        }
 
        std::list<ePtr<iDVBFrontendParameters> > list;
-               
-       list.push_back(fe);
-       
        m_scan = new eDVBScan(channel);
        m_scan->connectEvent(slot(*this, &eComponentScan::scanEvent), m_scan_event_connection);
-       m_scan->start(list);
-       
+
+       if (!(flags & scanRemoveServices))
+       {
+               ePtr<iDVBChannelList> db;
+               ePtr<eDVBResourceManager> res;
+               int err;
+               if ((err = eDVBResourceManager::getInstance(res)) != 0)
+                       eDebug("no resource manager");
+               else if ((err = res->getChannelList(db)) != 0)
+                       eDebug("no channel list");
+               else
+               {
+                       if (m_initial.size() > 1)
+                       {
+                               ePtr<iDVBFrontendParameters> tp = m_initial.first();
+                               int type;
+                               if (tp && !tp->getSystem(type))
+                               {
+                                       switch(type)
+                                       {
+                                               case iDVBFrontend::feSatellite:
+                                               {
+                                                       eDVBFrontendParametersSatellite parm;
+                                                       tp->getDVBS(parm);
+                                                       db->removeFlags(eDVBService::dxNewFound, -1, -1, -1, parm.orbital_position);
+                                                       break;
+                                               }
+                                               case iDVBFrontend::feCable:
+                                                       db->removeFlags(eDVBService::dxNewFound, 0xFFFF0000, -1, -1, -1);
+                                                       break;
+                                               case iDVBFrontend::feTerrestrial:
+                                                       db->removeFlags(eDVBService::dxNewFound, 0xEEEE0000, -1, -1, -1);
+                                                       break;
+                                       }
+                               }
+                       }
+               }
+       }
+       m_scan->start(m_initial, flags);
+
        return 0;
 }
 
@@ -134,3 +180,27 @@ int eComponentScan::getError()
 {
        return m_failed;
 }
+
+void eComponentScan::getLastServiceName(std::string &string)
+{
+       if (!m_scan)
+               return;
+       m_scan->getLastServiceName(string);
+}
+
+RESULT eComponentScan::getFrontend(ePtr<iDVBFrontend> &fe)
+{
+       if (m_scan)
+               return m_scan->getFrontend(fe);
+       fe = 0;
+       return -1;
+}
+
+RESULT eComponentScan::getCurrentTransponder(ePtr<iDVBFrontendParameters> &tp)
+{
+       if (m_scan)
+               return m_scan->getCurrentTransponder(tp);
+       tp = 0;
+       return -1;
+}
+