main/enigma.cpp: use new defines for getEnigmaVersionString
[enigma2.git] / main / enigma.cpp
index 7b30f6b2534263827a7cb42eae32d7d5de8425ba..b5523d31bda5abfda22e2d9cdfa8840da4eeaddf 100644 (file)
+#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/eerror.h>
 #include <lib/base/init.h>
 #include <lib/base/init_num.h>
+#include <lib/gdi/gfbdc.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/gui/ebutton.h>
+#include <lib/gui/elabel.h>
+#include <lib/gui/elistboxcontent.h>
+#include <lib/gui/ewidget.h>
+#include <lib/gui/ewidgetdesktop.h>
+#include <lib/gui/ewindow.h>
+#include <lib/python/connections.h>
+#include <lib/python/python.h>
 
-#include <lib/dvb/dvb.h>
-#include <lib/dvb/db.h>
-#include <lib/dvb/isection.h>
-#include <lib/dvb/esection.h>
-#include <lib/dvb_si/pmt.h>
-#include <lib/dvb/scan.h>
-#include <unistd.h>
+#include "bsod.h"
+
+#ifdef HAVE_GSTREAMER
+#include <gst/gst.h>
+#endif
+
+#ifdef OBJECT_DEBUG
+int object_total_remaining;
+
+void object_dump()
+{
+       printf("%d items left\n", object_total_remaining);
+}
+#endif
 
-#include <lib/service/iservice.h>
-#include <lib/nav/core.h>
+static eWidgetDesktop *wdsk, *lcddsk;
 
-#include <main/cli.h>
+static int prev_ascii_code;
+
+int getPrevAsciiCode()
+{
+       int ret = prev_ascii_code;
+       prev_ascii_code = 0;
+       return ret;
+}
+
+void keyEvent(const eRCKey &key)
+{
+       static eRCKey last(0, 0, 0);
+       static int num_repeat;
+
+       ePtr<eActionMap> ptr;
+       eActionMap::getInstance(ptr);
+
+       if ((key.code == last.code) && (key.producer == last.producer) && key.flags & eRCKey::flagRepeat)
+               num_repeat++;
+       else
+       {
+               num_repeat = 0;
+               last = key;
+       }
+
+       if (num_repeat == 4)
+       {
+               ptr->keyPressed(key.producer->getIdentifier(), key.code, eRCKey::flagLong);
+               num_repeat++;
+       }
+
+       if (key.flags & eRCKey::flagAscii)
+       {
+               prev_ascii_code = key.code;
+               ptr->keyPressed(key.producer->getIdentifier(), 510 /* faked KEY_ASCII */, 0);
+       }
+       else
+               ptr->keyPressed(key.producer->getIdentifier(), key.code, key.flags);
+}
+
+/************************************************/
+#include <unistd.h>
+#include <lib/components/scan.h>
+#include <lib/dvb/idvb.h>
+#include <lib/dvb/dvb.h>
+#include <lib/dvb/db.h>
+#include <lib/dvb/dvbtime.h>
+#include <lib/dvb/epgcache.h>
 
 class eMain: public eApplication, public Object
 {
        eInit init;
-       
-       ePtr<eDVBResourceManager> m_mgr;
-       ePtr<iDVBChannel> m_channel;
+
        ePtr<eDVBDB> m_dvbdb;
+       ePtr<eDVBResourceManager> m_mgr;
+       ePtr<eDVBLocalTimeHandler> m_locale_time_handler;
+       ePtr<eEPGCache> m_epgcache;
 
-       ePtr<iPlayableService> m_playservice;
-       ePtr<eNavigation> m_nav;
-       ePtr<eConnection> m_conn_event;
-       ePtr<iServiceInformation> m_serviceInformation;
 public:
        eMain()
        {
                init.setRunlevel(eAutoInitNumbers::main);
+               /* TODO: put into init */
                m_dvbdb = new eDVBDB();
                m_mgr = new eDVBResourceManager();
+               m_locale_time_handler = new eDVBLocalTimeHandler();
+               m_epgcache = new eEPGCache();
                m_mgr->setChannelList(m_dvbdb);
-               
-               ePtr<eServiceCenter> service_center;
-               eServiceCenter::getInstance(service_center);
-
-               assert(service_center);
-               m_nav = new eNavigation(service_center);
-#if 0
-               if (service_center)
+       }
+       
+       ~eMain()
+       {
+               m_dvbdb->saveServicelist();
+               m_mgr->releaseCachedChannel();
+       }
+};
+
+int exit_code;
+
+int main(int argc, char **argv)
+{
+#ifdef MEMLEAK_CHECK
+       atexit(DumpUnfreed);
+#endif
+
+#ifdef OBJECT_DEBUG
+       atexit(object_dump);
+#endif
+
+#ifdef HAVE_GSTREAMER
+       gst_init(&argc, &argv);
+#endif
+
+       // set pythonpath if unset
+       setenv("PYTHONPATH", LIBDIR "/enigma2/python", 0);
+       printf("PYTHONPATH: %s\n", getenv("PYTHONPATH"));
+       
+       bsodLogInit();
+
+       ePython python;
+       eMain main;
+
+#if 1
+#ifdef WITH_SDL
+       ePtr<gSDLDC> my_dc;
+       gSDLDC::getInstance(my_dc);
+#else
+       ePtr<gFBDC> my_dc;
+       gFBDC::getInstance(my_dc);
+       
+       int double_buffer = my_dc->haveDoubleBuffering();
+#endif
+
+       ePtr<gLCDDC> my_lcd_dc;
+       gLCDDC::getInstance(my_lcd_dc);
+
+
+               /* ok, this is currently hardcoded for arabic. */
+                       /* some characters are wrong in the regular font, force them to use the replacement font */
+       for (int i = 0x60c; i <= 0x66d; ++i)
+               eTextPara::forceReplacementGlyph(i);
+       eTextPara::forceReplacementGlyph(0xfdf2);
+       for (int i = 0xfe80; i < 0xff00; ++i)
+               eTextPara::forceReplacementGlyph(i);
+
+       eWidgetDesktop dsk(eSize(720, 576));
+       eWidgetDesktop dsk_lcd(eSize(132, 64));
+       
+       dsk.setStyleID(0);
+       dsk_lcd.setStyleID(1);
+       
+/*     if (double_buffer)
+       {
+               eDebug(" - double buffering found, enable buffered graphics mode.");
+               dsk.setCompositionMode(eWidgetDesktop::cmBuffered);
+       } */
+       
+       wdsk = &dsk;
+       lcddsk = &dsk_lcd;
+
+       dsk.setDC(my_dc);
+       dsk_lcd.setDC(my_lcd_dc);
+
+       ePtr<gPixmap> m_pm;
+       loadPNG(m_pm, DATADIR "/enigma2/skin_default/pal.png");
+       if (!m_pm)
+       {
+               eFatal("pal.png not found!");
+       } else
+               dsk.setPalette(*m_pm);
+
+       dsk.setBackgroundColor(gRGB(0,0,0,0xFF));
+#endif
+
+               /* redrawing is done in an idle-timer, so we have to set the context */
+       dsk.setRedrawTask(main);
+       dsk_lcd.setRedrawTask(main);
+       
+       
+       eDebug("Loading spinners...");
+       
+       {
+               int i;
+#define MAX_SPINNER 64
+               ePtr<gPixmap> wait[MAX_SPINNER];
+               for (i=0; i<MAX_SPINNER; ++i)
                {
-                       eServiceReference ref("2:0:1:0:0:0:0:0:0:0:/");
-                       ePtr<iListableService> lst;
-                       if (service_center->list(ref, lst))
-                               eDebug("no list available!");
-                       else
+                       char filename[strlen(DATADIR) + 41];
+                       sprintf(filename, DATADIR "/enigma2/skin_default/spinner/wait%d.png", i + 1);
+                       loadPNG(wait[i], filename);
+                       
+                       if (!wait[i])
                        {
-                               std::list<eServiceReference> list;
-                               if (lst->getContent(list))
-                                       eDebug("list itself SUCKED AROUND!!!");
+                               if (!i)
+                                       eDebug("failed to load %s! (%m)", filename);
                                else
-                                       for (std::list<eServiceReference>::const_iterator i(list.begin());
-                                               i != list.end(); ++i)
-                                               eDebug("%s", i->toString().c_str());
+                                       eDebug("found %d spinner!\n", i);
+                               break;
                        }
                }
-#endif         
-               m_nav->connectEvent(slot(*this, &eMain::event), m_conn_event);
-               
-//             eServiceReference ref("1:0:1:6de2:44d:1:c00000:0:0:0:");
-               eServiceReference ref("4097:47:0:0:0:0:0:0:0:0:/sine_60s_100.mp3");
-               eServiceReference ref1("4097:47:0:0:0:0:0:0:0:0:/sine_60s_100.mp31");
-               eServiceReference ref2("4097:47:0:0:0:0:0:0:0:0:/sine_60s_100.mp32");
-               
-               if (m_nav->enqueueService(ref))
-                       eDebug("play sucked around!");
+               if (i)
+                       my_dc->setSpinner(eRect(ePoint(100, 100), wait[0]->size()), wait, i);
                else
-                       eDebug("play r00lz!");
-
-               m_nav->enqueueService(ref1);
-               m_nav->enqueueService(ref2);
-               m_nav->enqueueService(ref1);
+                       my_dc->setSpinner(eRect(100, 100, 0, 0), wait, 1);
        }
        
-       void event(eNavigation *nav, int ev)
+       gRC::getInstance()->setSpinnerDC(my_dc);
+
+       eRCInput::getInstance()->keyEvent.connect(slot(keyEvent));
+       
+       printf("executing main\n");
+       
+       bsodCatchSignals();
+
+       setIoPrio(IOPRIO_CLASS_BE, 3);
+
+//     python.execute("mytest", "__main__");
+       python.execFile("/usr/lib/enigma2/python/mytest.py");
+
+       extern void setFullsize(); // definend in lib/gui/evideo.cpp
+       setFullsize();
+
+       if (exit_code == 5) /* python crash */
        {
-               assert(nav);
-               
-               ePtr<ePlaylist> playlist;
-               nav->getPlaylist(playlist);
-               if (playlist)
-               {
-                       eDebug("PLAYLIST:");
-                       ePlaylist::iterator i;
-                       for (i=playlist->begin(); i != playlist->end(); ++i)
-                               eDebug("%s %s", i == playlist->m_current ? "-->" : "   ", i->toString().c_str());
-               }
-               
-               switch (ev)
-               {
-               case eNavigation::evStopService:
-                               /* very important: the old service should be deallocated, so clear *all* references to it */
-                       m_serviceInformation = 0;
-                       eDebug("STOP service!");
-                       break;
-               case eNavigation::evNewService:
-               {
-                       ePtr<iPlayableService> service;
-                       nav->getCurrentService(service);
-                       if (!service)
-                       {
-                               eDebug("no running service!");
-                               break;
-                       }
-                       if (service->getIServiceInformation(m_serviceInformation))
-                       {
-                               eDebug("failed to get iserviceinformation");
-                               break;
-                       }
-                       eString name;
-                       m_serviceInformation->getName(name);
-                       eDebug("NEW running service: %s", name.c_str());
-                       break;
-               }
-               case eNavigation::evPlayFailed:
-                       eDebug("play failed!");
-                       break;
-               case eNavigation::evPlaylistDone:
-                       eDebug("playlist done");
-                       quit();
-                       break;
-               default:
-                       eDebug("Navigation event %d", ev);
-                       break;
-               }
+               eDebug("(exit code 5)");
+               bsodFatal(0);
        }
        
-       ~eMain()
+       dsk.paint();
+       dsk_lcd.paint();
+
        {
+               gPainter p(my_lcd_dc);
+               p.resetClip(eRect(0, 0, 132, 64));
+               p.clear();
        }
-};
 
-#ifdef OBJECT_DEBUG
-int object_total_remaining;
+       return exit_code;
+}
 
-void object_dump()
+eWidgetDesktop *getDesktop(int which)
 {
-       printf("%d items left\n", object_total_remaining);
+       return which ? lcddsk : wdsk;
 }
-#endif
 
-int main()
+eApplication *getApplication()
 {
-#ifdef OBJECT_DEBUG
-       atexit(object_dump);
-#endif
+       return eApp;
+}
 
-#if 0
-       eCLI cli;
-       eString res;
-       
-       while (1)
+void runMainloop()
+{
+       eApp->runLoop();
+}
+
+void quitMainloop(int exitCode)
+{
+       FILE *f = fopen("/proc/stb/fp/was_timer_wakeup", "w");
+       if (f)
+       {
+               fprintf(f, "%d", 0);
+               fclose(f);
+       }
+       else
        {
-               char line[1024];
-               if (!fgets(line, 1024, stdin))
-                       break;
-               line[strlen(line)-1]=0;
-               int rn = cli.doCommand(res, line);
-               eDebug("%s%d", res.c_str(), rn);
+               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);
+}
+
+#include "version.h"
+
+const char *getEnigmaVersionString()
+{
+       std::string date =
+#ifdef ENIGMA2_LAST_CHANGE_DATE
+               ENIGMA2_LAST_CHANGE_DATE;
+#else
+               __DATE__;
+#endif
+       std::string branch =
+#ifdef ENIGMA2_BRANCH
+               ENIGMA2_BRANCH;
+#else
+               "HEAD"
 #endif
-       eMain app;
-       int res = app.exec();
-       eDebug("after exec");
+       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);
 }