Merge branch 'bug_624_change_handylike_char_input' into experimental
[enigma2.git] / main / enigma.cpp
index 64088cb5f225a98809f2d465edf8906468382290..1cdd867ba9e2b9a20250e36b762168300862f0f0 100644 (file)
@@ -1,26 +1,23 @@
-#ifdef WITH_SDL
-#define SDLDC
-#endif
-
-#include <stdio.h>
 #include <unistd.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/ioctl.h>
 #include <libsig_comp.h>
 
 #include <lib/actions/action.h>
 #include <lib/driver/rc.h>
 #include <lib/base/ioprio.h>
 #include <lib/base/ebase.h>
+#include <lib/base/eenv.h>
 #include <lib/base/eerror.h>
 #include <lib/base/init.h>
 #include <lib/base/init_num.h>
-#include <lib/gdi/gfbdc.h>
+#include <lib/gdi/gmaindc.h>
 #include <lib/gdi/glcddc.h>
 #include <lib/gdi/grc.h>
-#ifdef WITH_SDL
-#include <lib/gdi/sdl.h>
-#endif
 #include <lib/gdi/epng.h>
-#include <lib/gdi/font.h> 
+#include <lib/gdi/font.h>
 #include <lib/gui/ebutton.h>
 #include <lib/gui/elabel.h>
 #include <lib/gui/elistboxcontent.h>
 #include <lib/python/connections.h>
 #include <lib/python/python.h>
 
-#include "bsod.h" 
+#include "bsod.h"
+#include "version_info.h"
 
-#ifdef HAVE_GSTREAMER
 #include <gst/gst.h>
-#endif
 
 #ifdef OBJECT_DEBUG
 int object_total_remaining;
@@ -99,19 +95,17 @@ void keyEvent(const eRCKey &key)
 class eMain: public eApplication, public Object
 {
        eInit init;
-       
-       ePtr<eDVBResourceManager> m_mgr;
+
        ePtr<eDVBDB> m_dvbdb;
+       ePtr<eDVBResourceManager> m_mgr;
        ePtr<eDVBLocalTimeHandler> m_locale_time_handler;
-       ePtr<eComponentScan> m_scan;
        ePtr<eEPGCache> m_epgcache;
 
 public:
        eMain()
        {
                init.setRunlevel(eAutoInitNumbers::main);
-
-                               /* TODO: put into init */
+               /* TODO: put into init */
                m_dvbdb = new eDVBDB();
                m_mgr = new eDVBResourceManager();
                m_locale_time_handler = new eDVBLocalTimeHandler();
@@ -122,7 +116,7 @@ public:
        ~eMain()
        {
                m_dvbdb->saveServicelist();
-               m_scan = 0;
+               m_mgr->releaseCachedChannel();
        }
 };
 
@@ -138,29 +132,22 @@ int main(int argc, char **argv)
        atexit(object_dump);
 #endif
 
-#ifdef HAVE_GSTREAMER
        gst_init(&argc, &argv);
-#endif
 
        // set pythonpath if unset
-       setenv("PYTHONPATH", LIBDIR "/enigma2/python", 0);
+       setenv("PYTHONPATH", eEnv::resolve("${libdir}/enigma2/python").c_str(), 0);
        printf("PYTHONPATH: %s\n", getenv("PYTHONPATH"));
        
        bsodLogInit();
 
        ePython python;
        eMain main;
-       
+
 #if 1
-#ifdef SDLDC
-       ePtr<gSDLDC> my_dc;
-       gSDLDC::getInstance(my_dc);
-#else
-       ePtr<gFBDC> my_dc;
-       gFBDC::getInstance(my_dc);
+       ePtr<gMainDC> my_dc;
+       gMainDC::getInstance(my_dc);
        
-       int double_buffer = my_dc->haveDoubleBuffering();
-#endif
+       //int double_buffer = my_dc->haveDoubleBuffering();
 
        ePtr<gLCDDC> my_lcd_dc;
        gLCDDC::getInstance(my_lcd_dc);
@@ -175,11 +162,11 @@ int main(int argc, char **argv)
                eTextPara::forceReplacementGlyph(i);
 
        eWidgetDesktop dsk(eSize(720, 576));
-       eWidgetDesktop dsk_lcd(eSize(132, 64));
-       
+       eWidgetDesktop dsk_lcd(my_lcd_dc->size());
+
        dsk.setStyleID(0);
-       dsk_lcd.setStyleID(1);
-       
+       dsk_lcd.setStyleID(my_lcd_dc->size().width() == 96 ? 2 : 1);
+
 /*     if (double_buffer)
        {
                eDebug(" - double buffering found, enable buffered graphics mode.");
@@ -193,7 +180,7 @@ int main(int argc, char **argv)
        dsk_lcd.setDC(my_lcd_dc);
 
        ePtr<gPixmap> m_pm;
-       loadPNG(m_pm, DATADIR "/enigma2/pal.png");
+       loadPNG(m_pm, eEnv::resolve("${datadir}/enigma2/skin_default/pal.png").c_str());
        if (!m_pm)
        {
                eFatal("pal.png not found!");
@@ -216,14 +203,16 @@ int main(int argc, char **argv)
                ePtr<gPixmap> wait[MAX_SPINNER];
                for (i=0; i<MAX_SPINNER; ++i)
                {
-                       char filename[strlen(DATADIR) + 20];
-                       sprintf(filename, DATADIR "/enigma2/wait%d.png", i + 1);
-                       loadPNG(wait[i], filename);
+                       char filename[64];
+                       std::string rfilename;
+                       snprintf(filename, sizeof(filename), "${datadir}/enigma2/skin_default/spinner/wait%d.png", i + 1);
+                       rfilename = eEnv::resolve(filename);
+                       loadPNG(wait[i], rfilename.c_str());
                        
                        if (!wait[i])
                        {
                                if (!i)
-                                       eDebug("failed to load %s! (%m)", filename);
+                                       eDebug("failed to load %s! (%m)", rfilename.c_str());
                                else
                                        eDebug("found %d spinner!\n", i);
                                break;
@@ -245,10 +234,17 @@ int main(int argc, char **argv)
 
        setIoPrio(IOPRIO_CLASS_BE, 3);
 
-       python.execute("mytest", "__main__");
-       
+//     python.execute("mytest", "__main__");
+       python.execFile(eEnv::resolve("${libdir}/enigma2/python/mytest.py").c_str());
+
+       extern void setFullsize(); // definend in lib/gui/evideo.cpp
+       setFullsize();
+
        if (exit_code == 5) /* python crash */
-               bsodFatal();
+       {
+               eDebug("(exit code 5)");
+               bsodFatal(0);
+       }
        
        dsk.paint();
        dsk_lcd.paint();
@@ -257,7 +253,6 @@ int main(int argc, char **argv)
                gPainter p(my_lcd_dc);
                p.resetClip(eRect(0, 0, 132, 64));
                p.clear();
-               p.flush();
        }
 
        return exit_code;
@@ -273,13 +268,61 @@ eApplication *getApplication()
        return eApp;
 }
 
+void quitMainloop(int exitCode)
+{
+       FILE *f = fopen("/proc/stb/fp/was_timer_wakeup", "w");
+       if (f)
+       {
+               fprintf(f, "%d", 0);
+               fclose(f);
+       }
+       else
+       {
+               int fd = open("/dev/dbox/fp0", O_WRONLY);
+               if (fd >= 0)
+               {
+                       if (ioctl(fd, 10 /*FP_CLEAR_WAKEUP_TIMER*/) < 0)
+                               eDebug("FP_CLEAR_WAKEUP_TIMER failed (%m)");
+                       close(fd);
+               }
+               else
+                       eDebug("open /dev/dbox/fp0 for wakeup timer clear failed!(%m)");
+       }
+       exit_code = exitCode;
+       eApp->quit(0);
+}
+
+static void sigterm_handler(int num)
+{
+       quitMainloop(128 + num);
+}
+
 void runMainloop()
 {
+       struct sigaction act;
+
+       act.sa_handler = sigterm_handler;
+       act.sa_flags = SA_RESTART;
+
+       if (sigemptyset(&act.sa_mask) == -1)
+               perror("sigemptyset");
+       if (sigaction(SIGTERM, &act, 0) == -1)
+               perror("SIGTERM");
+
        eApp->runLoop();
 }
 
-void quitMainloop(int exitCode)
+const char *getEnigmaVersionString()
 {
-       exit_code = exitCode;
-       eApp->quit(0);
+       std::string date = enigma2_date;
+       std::string branch = enigma2_branch;
+       return std::string(date + '-' + branch).c_str();
+}
+
+#include <malloc.h>
+
+void dump_malloc_stats(void)
+{
+       struct mallinfo mi = mallinfo();
+       eDebug("MALLOC: %d total", mi.uordblks);
 }