- work on actions
[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         eDVBFrontendParametersSatellite fesat;
64                 
65         fesat.frequency = 11817000; // 12070000;
66         fesat.symbol_rate = 27500000;
67         fesat.polarisation = eDVBFrontendParametersSatellite::Polarisation::Vertical;
68         fesat.fec = eDVBFrontendParametersSatellite::FEC::f3_4;
69         fesat.inversion = eDVBFrontendParametersSatellite::Inversion::Off;
70         fesat.orbital_position = 192;
71
72         eDVBFrontendParameters *fe = new eDVBFrontendParameters();
73         
74         fe->setDVBS(fesat);
75         
76         ePtr<iDVBChannel> channel;
77
78         if (mgr->allocateRawChannel(channel))
79                 eDebug("scan: allocating raw channel failed!");
80
81         std::list<ePtr<iDVBFrontendParameters> > list;
82                 
83         list.push_back(fe);
84         
85         m_scan = new eDVBScan(channel);
86         m_scan->connectEvent(slot(*this, &eComponentScan::scanEvent), m_scan_event_connection);
87         m_scan->start(list);
88
89         return 0;
90 }
91
92 int eComponentScan::getProgress()
93 {
94         if (!m_scan)
95                 return 0;
96         int done, total, services;
97         m_scan->getStats(done, total, services);
98         if (!total)
99                 return 0;
100         return done * 100 / total;
101 }
102
103 int eComponentScan::getNumServices()
104 {
105         if (!m_scan)
106                 return 0;
107         int done, total, services;
108         m_scan->getStats(done, total, services);
109         return services;
110 }
111
112 int eComponentScan::isDone()
113 {
114         return m_done;
115 }