]> git.vomp.tv Git - vompclient-marten.git/commitdiff
Handle crashes better
authorChris Tallon <chris@vomp.tv>
Wed, 7 Nov 2007 02:01:35 +0000 (02:01 +0000)
committerChris Tallon <chris@vomp.tv>
Wed, 7 Nov 2007 02:01:35 +0000 (02:01 +0000)
command.cc
command.h
log.cc
main.cc
vinfo.cc
vinfo.h

index 413f304d451514196e172f73f7a8adf767c5b032..6600b2ed7b5732cdbba640fd70b5fcff73faebc2 100644 (file)
@@ -62,6 +62,7 @@ Command::Command()
   isStandby = 0;
   firstBoot = 1;
   connLost = NULL;
+  crashed = false;
 }
 
 Command::~Command()
@@ -74,10 +75,11 @@ Command* Command::getInstance()
   return instance;
 }
 
-int Command::init()
+int Command::init(bool tcrashed)
 {
   if (initted) return 0;
   initted = 1;
+  crashed = tcrashed;
 
   logger = Log::getInstance();
   boxstack = BoxStack::getInstance();
@@ -172,9 +174,16 @@ void Command::run()
 #endif
   //logger->log("Command", Log::DEBUG, "LOCKED");
 
-  VConnect* vconnect = new VConnect();
-  boxstack->add(vconnect);
-  vconnect->run();
+  if (crashed)
+  {
+    buildCrashedBox();
+  }
+  else
+  {
+    VConnect* vconnect = new VConnect();
+    boxstack->add(vconnect);
+    vconnect->run();
+  }
 
   // Start method 2 of getting commands in...
   udp.run(this);
@@ -398,7 +407,13 @@ void Command::processMessage(Message* m)
       }
       case Message::LAST_VIEW_CLOSE:
       {
-//        not currently used
+        // Shouldn't be done like this. Some generic message pass back from vinfo perhaps
+        if (crashed)
+        {
+          crashed = false;
+          doFromTheTop(false);        
+        }
+      
 //        VWelcome* vw = new VWelcome();
 //        vw->draw();
 //        boxstack->add(vw);
@@ -449,6 +464,7 @@ void Command::handleCommand(int button)
     }
     case Remote::OK:
     {
+      // FIXME
       if (!connLost) return; // if connLost, handle Remote::OK
       doFromTheTop(false);
       return;
@@ -546,6 +562,25 @@ void Command::connectionLost()
   postMessageNoLock(m);
 }
 
+void Command::buildCrashedBox()
+{
+  VInfo* crash = new VInfo();
+  crash->setSize(360, 250);
+  crash->createBuffer();
+  if (Video::getInstance()->getFormat() == Video::PAL)
+    crash->setPosition(190, 146);
+  else
+    crash->setPosition(180, 96);
+  crash->setMainText("Oops, vomp crashed.. :(\nPlease report this crash to the author, with as much detail as possible about what you were doing at the time that might have caused the crash.");
+  crash->setBorderOn(1);
+  crash->setTitleBarColour(Colour::DANGER);
+  crash->okButton();
+  crash->setExitable();
+  crash->draw();
+  boxstack->add(crash);
+  boxstack->update(crash);
+}
+
 void Command::doJustConnected(VConnect* vconnect)
 {
   I18n::initialize();
index e07dda2a265a3dd6f9d86e718df8a30d74daa8a7..96078edb90002508bcf08dccc3ce4f67e65db72f 100644 (file)
--- a/command.h
+++ b/command.h
@@ -54,7 +54,7 @@ class Command : public MessageQueue
     ~Command();
     static Command* getInstance();
 
-    int init();
+    int init(bool crashed = false);
     int shutdown();
     void run();
     void stop();
@@ -72,6 +72,7 @@ class Command : public MessageQueue
     void doJustConnected(VConnect* vconnect);
     void doWallpaper();
     void doFromTheTop(bool which);  // true - show vinfo,wait. false - del vinfo,restart
+    void buildCrashedBox();
 
     static Command* instance;
 #ifndef WIN32
@@ -91,7 +92,8 @@ class Command : public MessageQueue
     Remote* remote;
     Boxx* wallpaper;
     VInfo* connLost;
-    
+    bool crashed;
+        
     UDP udp;
 
     void processMessage(Message* m);
diff --git a/log.cc b/log.cc
index 5fd37bcc36ec54a93127e425aa784edb522151a0..3c844caa7eb8b2f42c8bcee2a63c325c17f2c474 100644 (file)
--- a/log.cc
+++ b/log.cc
@@ -83,7 +83,7 @@ int Log::init(int startLogLevel, char* fileName, int tenabled)
 int Log::shutdown()
 {
   if (!initted) return 1;
-  if (logfile) fclose(logfile);
+  if (enabled) fclose(logfile);
   return 1;
 }
 
diff --git a/main.cc b/main.cc
index bf1910be0b5cfd97c385a526aea09a1aa9189da4..e241026b8b7c723b4e888f7cc8f8e82d0050e9fc 100644 (file)
--- a/main.cc
+++ b/main.cc
@@ -54,7 +54,6 @@ extern "C"
 }
 
 // Global variables --------------------------------------------------------------------------------------------------
-int debugEnabled = 0;
 Log* logger;
 Remote* remote;
 Mtd* mtd;
@@ -74,9 +73,32 @@ int main(int argc, char** argv)
 {
   if (strstr(argv[0], "ticonfig")) return ticonfig_main(argc, argv);
 
-  if ((argc > 1) && (!strcmp(argv[1], "-d"))) debugEnabled = 1;
-
+  bool daemonize = true;
+  bool debugEnabled = false;
+  bool crashed = false;
+  int c;
 
+  while ((c = getopt(argc, argv, "cdn")) != -1)
+  {
+    switch (c)
+    {
+      case 'c':
+        crashed = true;
+        break;
+      case 'd':
+        debugEnabled = true; // and...
+      case 'n':
+        daemonize = false;
+        break;        
+      case '?':
+        printf("Unknown option\n");
+        return 1;
+      default:
+        printf("Option error\n");
+        return 1;
+    }
+  }
+           
   // Init global vars ------------------------------------------------------------------------------------------------
 
   logger     = new Log();
@@ -100,7 +122,7 @@ int main(int argc, char** argv)
 
   // Get logging module started --------------------------------------------------------------------------------------
 
-  if (!logger->init(Log::DEBUG, "dummy", debugEnabled))
+  if (!logger->init(Log::DEBUG, "dummy", debugEnabled ? 1 : 0))
   {
     printf("Could not initialise log object. Aborting.\n");
     shutdown(1);
@@ -110,7 +132,7 @@ int main(int argc, char** argv)
 
   // Daemonize if not -d
 
-  if (!debugEnabled)
+  if (daemonize)
   {
     // Fork away
     pid_t forkTest = fork();
@@ -282,7 +304,7 @@ int main(int argc, char** argv)
     shutdown(1);
   }
 
-  success = command->init();
+  success = command->init(crashed);
   if (success)
   {
     logger->log("Core", Log::INFO, "Command module initialised");
index eff47a0b37da6541b415d9146a3a84ca9ea34766..8f8d87d117d91fb73e824004ad9758eedc19bf9a 100644 (file)
--- a/vinfo.cc
+++ b/vinfo.cc
@@ -22,7 +22,6 @@
 
 #include "remote.h"
 #include "colour.h"
-#include "wbutton.h"
 #include "i18n.h"
 #include "boxstack.h"
 
@@ -31,7 +30,6 @@ VInfo::VInfo()
   mainText = NULL;
   exitable = 0;
   dropThrough = 0;
-  okbutton = false;
 
   setTitleBarOn(1);
   setTitleBarColour(Colour::TITLEBARBACKGROUND);
@@ -85,18 +83,6 @@ void VInfo::draw()
       else drawTextCentre(mainText, area.w / 2, 55, Colour::LIGHTTEXT);
     }
   }
-
-  if (okbutton)
-  {
-/*
-    WButton button;
-    button.setPosition((area.w / 2) - 30, area.h - 50);
-    button.setText(tr("OK"));
-    button.setActive(1);
-    add(&button);
-    button.draw();
-*/
-  } // FIXME check
 }
 
 int VInfo::handleCommand(int command)
@@ -117,7 +103,10 @@ int VInfo::handleCommand(int command)
 
 void VInfo::okButton()
 {
-  okbutton = true;
+  okbutton.setPosition((area.w / 2) - 30, area.h - 50);
+  okbutton.setText(tr("OK"));
+  okbutton.setActive(1);
+  add(&okbutton);
 }
 
 void VInfo::processMessage(Message* m)
diff --git a/vinfo.h b/vinfo.h
index 92deb0684611e88df5fd1df597b7b93ecdfb6a16..2103760aebf9dd4a16abfff0b8136c1c326ecbde 100644 (file)
--- a/vinfo.h
+++ b/vinfo.h
@@ -26,6 +26,7 @@
 
 #include "tbboxx.h"
 #include "defines.h"
+#include "wbutton.h"
 
 class VInfo : public TBBoxx
 {
@@ -48,7 +49,7 @@ class VInfo : public TBBoxx
     UCHAR exitable;
     UCHAR dropThrough;
     UCHAR mainTextType;
-    bool okbutton;
+    WButton okbutton;
 
     const static UCHAR NORMAL = 1;
     const static UCHAR ONELINER = 2;