From 066c0f5a84af1da01a5520014b1d3d7bbf32e243 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Wed, 7 Nov 2007 02:01:35 +0000 Subject: [PATCH] Handle crashes better --- command.cc | 45 ++++++++++++++++++++++++++++++++++++++++----- command.h | 6 ++++-- log.cc | 2 +- main.cc | 34 ++++++++++++++++++++++++++++------ vinfo.cc | 19 ++++--------------- vinfo.h | 3 ++- 6 files changed, 79 insertions(+), 30 deletions(-) diff --git a/command.cc b/command.cc index 413f304..6600b2e 100644 --- a/command.cc +++ b/command.cc @@ -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(); diff --git a/command.h b/command.h index e07dda2..96078ed 100644 --- 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 5fd37bc..3c844ca 100644 --- 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 bf1910b..e241026 100644 --- 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"); diff --git a/vinfo.cc b/vinfo.cc index eff47a0..8f8d87d 100644 --- 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 92deb06..2103760 100644 --- 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; -- 2.39.5