the scan should now work for scanning dish network .. they use the SDT OTHER
[enigma2.git] / lib / components / scan.cpp
1 #include <lib/dvb/dvb.h>
2 #include <lib/dvb/db.h>
3 #include <lib/components/scan.h>
4 #include <lib/base/eerror.h>
5 #include <lib/dvb/scan.h>
6
7 DEFINE_REF(eComponentScan);
8
9 void eComponentScan::scanEvent(int evt)
10 {
11 //      eDebug("scan event %d!", evt);
12         
13         if (evt == eDVBScan::evtFinish)
14         {
15                 m_done = 1;
16                 ePtr<iDVBChannelList> db;
17                 ePtr<eDVBResourceManager> res;
18                 
19                 int err;
20                 if ((err = eDVBResourceManager::getInstance(res)) != 0)
21                 {
22                         eDebug("no resource manager");
23                         m_failed = 2;
24                 } else if ((err = res->getChannelList(db)) != 0)
25                 {
26                         m_failed = 3;
27                         eDebug("no channel list");
28                 } else
29                 {
30                         m_scan->insertInto(db);
31                         db->flush();
32                         eDebug("scan done!");
33                 }
34         }
35         
36         if (evt == eDVBScan::evtNewService)
37         {
38                 newService();
39                 return;
40         }
41         
42         if (evt == eDVBScan::evtFail)
43         {
44                 eDebug("scan failed.");
45                 m_failed = 1;
46                 m_done = 1;
47         }
48         
49         statusChanged();
50 }
51
52 eComponentScan::eComponentScan(): m_done(-1), m_failed(0)
53 {
54 }
55
56 eComponentScan::~eComponentScan()
57 {
58 }
59
60 void eComponentScan::clear()
61 {
62         m_initial.clear();
63 }
64
65 void eComponentScan::addInitial(const eDVBFrontendParametersSatellite &p)
66 {
67         ePtr<eDVBFrontendParameters> parm = new eDVBFrontendParameters();
68         parm->setDVBS(p);
69         m_initial.push_back(parm);
70 }
71
72 void eComponentScan::addInitial(const eDVBFrontendParametersCable &p)
73 {
74         ePtr<eDVBFrontendParameters> parm = new eDVBFrontendParameters();
75         parm->setDVBC(p);
76         m_initial.push_back(parm);
77 }
78
79 void eComponentScan::addInitial(const eDVBFrontendParametersTerrestrial &p)
80 {
81         ePtr<eDVBFrontendParameters> parm = new eDVBFrontendParameters();
82         parm->setDVBT(p);
83         m_initial.push_back(parm);
84 }
85
86
87 int eComponentScan::start(int feid, int flags)
88 {
89         if (m_initial.empty())
90                 return -2;
91
92         if (m_done != -1)
93                 return -1;
94         
95         m_done = 0;
96         ePtr<eDVBResourceManager> mgr;
97         
98         eDVBResourceManager::getInstance(mgr);
99
100         eUsePtr<iDVBChannel> channel;
101
102         if (mgr->allocateRawChannel(channel, feid))
103         {
104                 eDebug("scan: allocating raw channel (on frontend %d) failed!", feid);
105                 return -1;
106         }
107
108         std::list<ePtr<iDVBFrontendParameters> > list;
109
110         m_scan = new eDVBScan(channel);
111         m_scan->connectEvent(slot(*this, &eComponentScan::scanEvent), m_scan_event_connection);
112         m_scan->start(m_initial, flags);
113         
114         return 0;
115 }
116
117 int eComponentScan::getProgress()
118 {
119         if (!m_scan)
120                 return 0;
121         int done, total, services;
122         m_scan->getStats(done, total, services);
123         if (!total)
124                 return 0;
125         return done * 100 / total;
126 }
127
128 int eComponentScan::getNumServices()
129 {
130         if (!m_scan)
131                 return 0;
132         int done, total, services;
133         m_scan->getStats(done, total, services);
134         return services;
135 }
136
137 int eComponentScan::isDone()
138 {
139         return m_done;
140 }
141
142 int eComponentScan::getError()
143 {
144         return m_failed;
145 }
146
147 void eComponentScan::getLastServiceName(std::string &string)
148 {
149         if (!m_scan)
150                 return;
151         m_scan->getLastServiceName(string);
152 }