From 054c652571cffb32429df2767f337dc5cd31dc30 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Thu, 15 Jan 2009 15:16:45 +0100 Subject: [PATCH] improve error handling when starting the GUI thread --- src/common/guifacade.cpp | 8 ++++---- src/gui/guifacade.hpp | 7 +++++-- src/gui/guistart.cpp | 23 ++++++++++++++++++----- src/lib/exception.cpp | 2 +- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/common/guifacade.cpp b/src/common/guifacade.cpp index 408c7b1d0..4adb83d47 100644 --- a/src/common/guifacade.cpp +++ b/src/common/guifacade.cpp @@ -60,18 +60,18 @@ namespace gui { : theGUI_("lumieraorg_Gui", 1, 1, "lumieraorg_GuiStarterPlugin") // load GuiStarterPlugin { ASSERT (theGUI_); - this->kickOff (terminationHandle); + bool res = this->kickOff (terminationHandle); - if (lumiera_error_peek()) + if (!res || lumiera_error_peek()) throw lumiera::error::Fatal("failed to bring up GUI",lumiera_error()); } ~GuiRunner () { } - void kickOff (Subsys::SigTerm& terminationHandle) + bool kickOff (Subsys::SigTerm& terminationHandle) { - theGUI_->kickOff (reinterpret_cast (&terminationHandle)); + return theGUI_->kickOff (reinterpret_cast (&terminationHandle)); } }; diff --git a/src/gui/guifacade.hpp b/src/gui/guifacade.hpp index 5afa230f0..212a62b47 100644 --- a/src/gui/guifacade.hpp +++ b/src/gui/guifacade.hpp @@ -44,6 +44,8 @@ extern "C" { #include "common/interface.h" } +#include + namespace gui { @@ -69,6 +71,7 @@ namespace gui { * */ class GuiFacade + : boost::noncopyable { public: @@ -91,7 +94,7 @@ namespace gui { * @internal this function is invoked automatically during the GUI * loading and startup process. Don't call it manually. */ - virtual void kickOff (lumiera::Subsys::SigTerm&) =0; + virtual bool kickOff (lumiera::Subsys::SigTerm&) =0; protected: @@ -100,7 +103,7 @@ namespace gui { /** interface of the GuiStarterPlugin */ LUMIERA_INTERFACE_DECLARE (lumieraorg_Gui, 1, - LUMIERA_INTERFACE_SLOT (void, kickOff, (void*)) + LUMIERA_INTERFACE_SLOT (bool, kickOff, (void*)) ); diff --git a/src/gui/guistart.cpp b/src/gui/guistart.cpp index e0e3b2930..08311797c 100644 --- a/src/gui/guistart.cpp +++ b/src/gui/guistart.cpp @@ -70,6 +70,7 @@ using std::string; using lib::Thread; using std::tr1::bind; using lumiera::Subsys; +using lumiera::error::LUMIERA_ERROR_STATE; using gui::LUMIERA_INTERFACE_INAME(lumieraorg_Gui, 1); @@ -77,7 +78,7 @@ namespace gui { namespace { // implementation details - /** + /****************************************************************************** * Implement the necessary steps for actually making the Lumiera Gui available. * Open the business interface(s) and start up the GTK GUI main event loop. */ @@ -133,10 +134,22 @@ namespace gui { } // (End) impl details - void + + + bool kickOff (Subsys::SigTerm& terminationHandle) { - Thread ("GUI-Main", bind (&runGUI, terminationHandle)); + try + { + Thread ("GUI-Main", bind (&runGUI, terminationHandle)); + return true; // if we reach this line... + } + catch(...) + { + if (!lumiera_error_peek()) + LUMIERA_ERROR_SET (gui, STATE, "unexpected error when starting the GUI thread"); + return false; + } } } // namespace gui @@ -226,9 +239,9 @@ extern "C" { /* ================== define an lumieraorg_Gui instance =========== , NULL /* on open */ , NULL /* on close */ , LUMIERA_INTERFACE_INLINE (kickOff, "\255\142\006\244\057\170\152\312\301\372\220\323\230\026\200\065", - void, (void* termSig), + bool, (void* termSig), { - gui::kickOff (*reinterpret_cast (termSig)); + return gui::kickOff (*reinterpret_cast (termSig)); } ) ) diff --git a/src/lib/exception.cpp b/src/lib/exception.cpp index d59928025..091319110 100644 --- a/src/lib/exception.cpp +++ b/src/lib/exception.cpp @@ -79,7 +79,7 @@ namespace lumiera { desc_ (description), cause_ ("") { - lumiera_error_set (this->id_, description.c_str ()); + lumiera_error_set (this->id_, description.c_str ()); }