fix for memleak check
[enigma2.git] / main / enigma.cpp
1 #ifdef WITH_SDL
2 #define SDLDC
3 #endif
4
5 #include <stdio.h>
6 #include <unistd.h>
7 #include <libsig_comp.h>
8
9 #include <lib/actions/action.h>
10 #include <lib/driver/rc.h>
11 #include <lib/base/ebase.h>
12 #include <lib/base/eerror.h>
13 #include <lib/base/init.h>
14 #include <lib/base/init_num.h>
15 #include <lib/gdi/gfbdc.h>
16 #include <lib/gdi/glcddc.h>
17 #include <lib/gdi/grc.h>
18 #ifdef WITH_SDL
19 #include <lib/gdi/sdl.h>
20 #endif
21 #include <lib/gdi/epng.h>
22 #include <lib/gdi/font.h> 
23 #include <lib/gui/ebutton.h>
24 #include <lib/gui/elabel.h>
25 #include <lib/gui/elistboxcontent.h>
26 #include <lib/gui/ewidget.h>
27 #include <lib/gui/ewidgetdesktop.h>
28 #include <lib/gui/ewindow.h>
29 #include <lib/python/connections.h>
30 #include <lib/python/python.h>
31
32 #include "bsod.h" 
33
34 #ifdef HAVE_GSTREAMER
35 #include <gst/gst.h>
36 #endif
37
38 #ifdef OBJECT_DEBUG
39 int object_total_remaining;
40
41 void object_dump()
42 {
43         printf("%d items left\n", object_total_remaining);
44 }
45 #endif
46
47 static eWidgetDesktop *wdsk, *lcddsk;
48
49 PSignal1<void,int> keyPressed;
50
51 PSignal1<void,int> &keyPressedSignal()
52 {
53         return keyPressed;
54 }
55
56 void keyEvent(const eRCKey &key)
57 {
58         ePtr<eActionMap> ptr;
59         eActionMap::getInstance(ptr);
60         ptr->keyPressed(0, key.code, key.flags);
61 //      if (!key.flags)
62 //              keyPressed(key.code);
63 }
64
65 /************************************************/
66 #include <unistd.h>
67 #include <lib/components/scan.h>
68 #include <lib/dvb/idvb.h>
69 #include <lib/dvb/dvb.h>
70 #include <lib/dvb/db.h>
71 #include <lib/dvb/dvbtime.h>
72 #include <lib/dvb/epgcache.h>
73
74 class eMain: public eApplication, public Object
75 {
76         eInit init;
77         
78         ePtr<eDVBResourceManager> m_mgr;
79         ePtr<eDVBDB> m_dvbdb;
80         ePtr<eDVBLocalTimeHandler> m_locale_time_handler;
81         ePtr<eComponentScan> m_scan;
82         ePtr<eEPGCache> m_epgcache;
83
84 public:
85         eMain()
86         {
87                 init.setRunlevel(eAutoInitNumbers::main);
88
89                                 /* TODO: put into init */
90                 m_dvbdb = new eDVBDB();
91                 m_mgr = new eDVBResourceManager();
92                 m_locale_time_handler = new eDVBLocalTimeHandler();
93                 m_epgcache = new eEPGCache();
94                 m_mgr->setChannelList(m_dvbdb);
95         }
96         
97         ~eMain()
98         {
99                 m_dvbdb->saveServicelist();
100                 m_scan = 0;
101         }
102 };
103
104 int exit_code;
105
106 int main(int argc, char **argv)
107 {
108 #ifdef MEMLEAK_CHECK
109         atexit(DumpUnfreed);
110 #endif
111
112 #ifdef OBJECT_DEBUG
113         atexit(object_dump);
114 #endif
115
116 #ifdef HAVE_GSTREAMER
117         gst_init(&argc, &argv);
118 #endif
119
120         // set pythonpath if unset
121         setenv("PYTHONPATH", LIBDIR "/enigma2/python", 0);
122         printf("PYTHONPATH: %s\n", getenv("PYTHONPATH"));
123         
124         bsodLogInit();
125
126         ePython python;
127         eMain main;
128         
129 #if 1
130 #ifdef SDLDC
131         ePtr<gSDLDC> my_dc;
132         gSDLDC::getInstance(my_dc);
133 #else
134         ePtr<gFBDC> my_dc;
135         gFBDC::getInstance(my_dc);
136         
137         int double_buffer = my_dc->haveDoubleBuffering();
138 #endif
139
140         ePtr<gLCDDC> my_lcd_dc;
141         gLCDDC::getInstance(my_lcd_dc);
142
143         fontRenderClass::getInstance()->AddFont(FONTDIR "/md_khmurabi_10.ttf", "Regular", 100);
144         fontRenderClass::getInstance()->AddFont(FONTDIR "/ae_AlMateen.ttf", "Replacement", 90);
145         eTextPara::setReplacementFont("Replacement");
146         
147                         /* some characters are wrong in the regular font, force them to use the replacement font */
148         for (int i = 0x60c; i <= 0x66d; ++i)
149                 eTextPara::forceReplacementGlyph(i);
150         eTextPara::forceReplacementGlyph(0xfdf2);
151         for (int i = 0xfe80; i < 0xff00; ++i)
152                 eTextPara::forceReplacementGlyph(i);
153         
154
155         eWidgetDesktop dsk(eSize(720, 576));
156         eWidgetDesktop dsk_lcd(eSize(132, 64));
157         
158 /*      if (double_buffer)
159         {
160                 eDebug(" - double buffering found, enable buffered graphics mode.");
161                 dsk.setCompositionMode(eWidgetDesktop::cmBuffered);
162         } */
163         
164         wdsk = &dsk;
165         lcddsk = &dsk_lcd;
166
167         dsk.setDC(my_dc);
168         dsk_lcd.setDC(my_lcd_dc);
169
170         ePtr<gPixmap> m_pm;
171         loadPNG(m_pm, DATADIR "/enigma2/pal.png");
172         if (!m_pm)
173         {
174                 eFatal("pal.png not found!");
175         } else
176                 dsk.setPalette(*m_pm);
177
178         dsk.setBackgroundColor(gRGB(0,0,0,0xFF));
179 #endif
180
181                 /* redrawing is done in an idle-timer, so we have to set the context */
182         dsk.setRedrawTask(main);
183         dsk_lcd.setRedrawTask(main);
184
185         eRCInput::getInstance()->keyEvent.connect(slot(keyEvent));
186         
187         printf("executing main\n");
188         
189         bsodCatchSignals();
190         
191         python.execute("mytest", "__main__");
192         
193         if (exit_code == 5) /* python crash */
194                 bsodFatal();
195         
196         dsk.paint();
197         dsk_lcd.paint();
198
199         {
200                 gPainter p(my_lcd_dc);
201                 p.resetClip(eRect(0, 0, 132, 64));
202                 p.clear();
203                 p.flush();
204         }
205
206         return exit_code;
207 }
208
209 eWidgetDesktop *getDesktop(int which)
210 {
211         return which ? lcddsk : wdsk;
212 }
213
214 eApplication *getApplication()
215 {
216         return eApp;
217 }
218
219 void runMainloop()
220 {
221         eApp->runLoop();
222 }
223
224 void quitMainloop(int exitCode)
225 {
226         exit_code = exitCode;
227         eApp->quit(0);
228 }