- fixed dvb scan
[enigma2.git] / main / enigma.cpp
1 #include <stdio.h>
2 #include <libsig_comp.h>
3 #include <lib/base/ebase.h>
4 #include <lib/base/eerror.h>
5 #include <lib/base/init.h>
6 #include <lib/base/init_num.h>
7
8 #include <unistd.h>
9
10 #include <lib/gdi/grc.h>
11 #include <lib/gdi/gfbdc.h>
12 #include <lib/gdi/font.h> 
13
14 #include <lib/gui/ewidget.h>
15 #include <lib/gui/ewidgetdesktop.h>
16 #include <lib/gui/elabel.h>
17 #include <lib/gui/ebutton.h>
18
19 #include <lib/gui/ewindow.h>
20
21 #include <lib/python/python.h>
22 #include <lib/python/connections.h>
23
24 #include <lib/gui/elistboxcontent.h>
25
26 #include <lib/driver/rc.h>
27
28 #ifdef OBJECT_DEBUG
29 int object_total_remaining;
30
31 void object_dump()
32 {
33         printf("%d items left\n", object_total_remaining);
34 }
35 #endif
36
37 void dumpRegion(const gRegion &region)
38 {
39         fprintf(stderr, "extends: %d %d -> %d %d (%d rects)\n", 
40                 region.extends.left(), region.extends.top(),
41                 region.extends.right(), region.extends.bottom(), region.rects.size());
42         for (int y=0; y<region.extends.bottom(); ++y)
43         {
44                 for (int x=0; x<region.extends.right(); ++x)
45                 {
46                         unsigned char res = ' ';
47                         for (unsigned int i=0; i < region.rects.size(); ++i)
48                                 if (region.rects[i].contains(ePoint(x, y)))
49                                         res = '0' + i;
50                         fprintf(stderr, "%c", res);
51                 }
52                 fprintf(stderr, "\n");
53         }
54 }
55
56 eWidgetDesktop *wdsk;
57
58 // typedef struct _object PyObject;
59
60 void print(int i)
61 {
62         printf("C++ says: it's a %d!!!\n", i);
63 }
64
65 PSignal1<void,int> keyPressed;
66
67 PSignal1<void,int> &keyPressedSignal()
68 {
69         return keyPressed;
70 }
71
72 void keyEvent(const eRCKey &key)
73 {
74         if (!key.flags)
75                 keyPressed(key.code);
76 }
77
78 /************************************************/
79 #include <lib/dvb/dvb.h>
80 #include <lib/dvb/db.h>
81 #include <lib/dvb/isection.h>
82 #include <lib/dvb/esection.h>
83 #include <lib/dvb_si/pmt.h>
84 #include <lib/dvb/scan.h>
85 #include <unistd.h>
86
87 class eMain: public eApplication, public Object
88 {
89         eInit init;
90         
91         ePtr<eDVBScan> m_scan;
92
93         ePtr<eDVBResourceManager> m_mgr;
94         ePtr<iDVBChannel> m_channel;
95         ePtr<eDVBDB> m_dvbdb;
96
97         void scanEvent(int evt)
98         {
99                 eDebug("scan event %d!", evt);
100                 if (evt == eDVBScan::evtFinish)
101                 {
102                         m_scan->insertInto(m_dvbdb);
103                         quit(0);
104                 }
105         }
106         ePtr<eConnection> m_scan_event_connection;
107 public:
108         eMain()
109         {
110                 init.setRunlevel(eAutoInitNumbers::main);
111
112 #if 0
113                 m_dvbdb = new eDVBDB();
114                 m_mgr = new eDVBResourceManager();
115
116                 eDVBFrontendParametersSatellite fesat;
117                 
118                 fesat.frequency = 11817000; // 12070000;
119                 fesat.symbol_rate = 27500000;
120                 fesat.polarisation = eDVBFrontendParametersSatellite::Polarisation::Vertical;
121                 fesat.fec = eDVBFrontendParametersSatellite::FEC::f3_4;
122                 fesat.inversion = eDVBFrontendParametersSatellite::Inversion::Off;
123                 fesat.orbital_position = 192;
124
125                 eDVBFrontendParameters *fe = new eDVBFrontendParameters();
126                 
127                 fe->setDVBS(fesat);
128
129                 if (m_mgr->allocateRawChannel(m_channel))
130                         eDebug("shit it failed!");
131
132                 eDebug("starting scan...");
133                 
134                 std::list<ePtr<iDVBFrontendParameters> > list;
135                 
136                 list.push_back(fe);
137                 
138                 m_scan = new eDVBScan(m_channel);
139                 m_scan->start(list);
140                 m_scan->connectEvent(slot(*this, &eMain::scanEvent), m_scan_event_connection);
141 #endif
142         }
143         
144         ~eMain()
145         {
146                 m_scan = 0;
147         }
148 };
149
150 /************************************************/
151
152
153 int main(int argc, char **argv)
154 {
155 #ifdef OBJECT_DEBUG
156         atexit(object_dump);
157 #endif
158
159
160         ePython python;
161         eMain main;
162
163 #if 1
164         ePtr<gFBDC> my_dc;
165         gFBDC::getInstance(my_dc);
166
167         gPainter p(my_dc);
168         
169         gRGB pal[256];
170         pal[0] = 0;
171         pal[1] = 0xff00ff;
172         pal[2] = 0xffFFff;
173         pal[3] = 0x00ff00;
174         
175         for (int a=0; a<0x10; ++a)
176                 pal[a | 0x10] = 0x111111 * a;
177         for (int a=0; a<0x10; ++a)
178                 pal[a | 0x20] = (0x111100 * a) | 0xFF;
179         for (int a=0; a<0x10; ++a)
180                 pal[a | 0x30] = (0x110011 * a) | 0xFF00;
181         for (int a=0; a<0x10; ++a)
182                 pal[a | 0x40] = (0x001111 * a) | 0xFF0000;
183         p.setPalette(pal, 0, 256);
184
185         fontRenderClass::getInstance()->AddFont("/dbox2/cdkroot/share/fonts/arial.ttf", "Arial", 100);
186
187         eWidgetDesktop dsk(eSize(720, 576));
188         
189         wdsk = &dsk;
190         dsk.setBackgroundColor(gColor(0));
191         dsk.setDC(my_dc);
192 #endif
193
194                 /* redrawing is done in an idle-timer, so we have to set the context */
195         dsk.setRedrawTask(main);
196         
197         eRCInput::getInstance()->keyEvent.connect(slot(keyEvent));
198         
199         printf("executing main\n");
200         python.execute("mytest", "__main__");
201
202 //      eApp->exec();
203
204         return 0;
205 }
206
207 eWidgetDesktop *getDesktop()
208 {
209         return wdsk;
210 }
211
212 void runMainloop()
213 {
214         eApp->exec();
215 }