- add dvb resource management
[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                         eDebug("scan done!");
32                 }
33         }
34         
35         if (evt == eDVBScan::evtFail)
36         {
37                 eDebug("scan failed.");
38                 m_failed = 1;
39                 m_done = 1;
40         }
41         
42         statusChanged();
43 }
44
45 eComponentScan::eComponentScan(): m_done(-1), m_failed(0)
46 {
47 }
48
49 eComponentScan::~eComponentScan()
50 {
51 }
52
53 int eComponentScan::start()
54 {
55         if (m_done != -1)
56                 return -1;
57         
58         m_done = 0;
59         ePtr<eDVBResourceManager> mgr;
60         
61         eDVBResourceManager::getInstance(mgr);
62
63         eDVBFrontendParameters *fe = new eDVBFrontendParameters();
64 #if 1
65         eDVBFrontendParametersSatellite fesat;
66                 
67         fesat.frequency = 11817000; // 12070000;
68         fesat.symbol_rate = 27500000;
69         fesat.polarisation = eDVBFrontendParametersSatellite::Polarisation::Vertical;
70         fesat.fec = eDVBFrontendParametersSatellite::FEC::f3_4;
71         fesat.inversion = eDVBFrontendParametersSatellite::Inversion::Off;
72         fesat.orbital_position = 192;
73
74         
75         fe->setDVBS(fesat);
76
77 #else
78         eDVBFrontendParametersTerrestrial fet;
79         fet.frequency = 626000000;
80         fet.inversion = eDVBFrontendParametersTerrestrial::Inversion::Unknown;
81         fet.bandwidth = eDVBFrontendParametersTerrestrial::Bandwidth::Bw8MHz;
82         fet.code_rate_HP = fet.code_rate_LP = eDVBFrontendParametersTerrestrial::FEC::fAuto;
83         fet.modulation = eDVBFrontendParametersTerrestrial::Modulation::QAM16;
84         fet.transmission_mode = eDVBFrontendParametersTerrestrial::TransmissionMode::TM8k;
85         fet.guard_interval = eDVBFrontendParametersTerrestrial::GuardInterval::GI_1_32;
86         fet.hierarchy = eDVBFrontendParametersTerrestrial::Hierarchy::HNone;
87         fe->setDVBT(fet);
88 #endif
89         ePtr<iDVBChannel> channel;
90
91         if (mgr->allocateRawChannel(channel))
92         {
93                 eDebug("scan: allocating raw channel failed!");
94                 return -1;
95         }
96
97         std::list<ePtr<iDVBFrontendParameters> > list;
98                 
99         list.push_back(fe);
100         
101         m_scan = new eDVBScan(channel);
102         m_scan->connectEvent(slot(*this, &eComponentScan::scanEvent), m_scan_event_connection);
103         m_scan->start(list);
104         
105         return 0;
106 }
107
108 int eComponentScan::getProgress()
109 {
110         if (!m_scan)
111                 return 0;
112         int done, total, services;
113         m_scan->getStats(done, total, services);
114         if (!total)
115                 return 0;
116         return done * 100 / total;
117 }
118
119 int eComponentScan::getNumServices()
120 {
121         if (!m_scan)
122                 return 0;
123         int done, total, services;
124         m_scan->getStats(done, total, services);
125         return services;
126 }
127
128 int eComponentScan::isDone()
129 {
130         return m_done;
131 }
132
133 int eComponentScan::getError()
134 {
135         return m_failed;
136 }