From edb01ec8c65ef7b52c7a321864ee448752316ba3 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sat, 3 Jan 2009 16:05:04 +0100 Subject: [PATCH] Integration: Thread/sync, GUI-Plugin invoked in separate thread --- src/common/guifacade.cpp | 14 +++++++++----- src/common/subsystem-runner.hpp | 1 + src/gui/guifacade.hpp | 4 ++-- src/gui/guistart.cpp | 7 +++---- src/lib/thread-wrapper.hpp | 15 ++++++--------- tests/lib/subsystem-runner-test.cpp | 1 + tests/lib/thread-wrapper-test.cpp | 8 ++++---- 7 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/common/guifacade.cpp b/src/common/guifacade.cpp index c95e069a1..d803cecc3 100644 --- a/src/common/guifacade.cpp +++ b/src/common/guifacade.cpp @@ -27,6 +27,7 @@ #include "lib/error.hpp" #include "lib/singleton.hpp" #include "lib/functorutil.hpp" +#include "lib/thread-wrapper.hpp" #include "common/instancehandle.hpp" #include @@ -45,6 +46,7 @@ namespace gui { using util::dispatchSequenced; using lib::Sync; using lib::RecursiveLock_NoWait; + using lib::Thread; @@ -60,17 +62,18 @@ namespace gui { : theGUI_("lumieraorg_Gui", 1, 1, "lumieraorg_GuiStarterPlugin") // load GuiStarterPlugin { ASSERT (theGUI_); - if (!kickOff (terminationHandle)) + Thread ("GUI-Main", bind (&GuiRunner::kickOff, this, terminationHandle)); + + if (lumiera_error_peek()) throw lumiera::error::Fatal("failed to bring up GUI",lumiera_error()); } ~GuiRunner () { } - bool kickOff (Subsys::SigTerm& terminationHandle) + void kickOff (Subsys::SigTerm& terminationHandle) { - return theGUI_->kickOff (reinterpret_cast (&terminationHandle)) - && !lumiera_error_peek(); + theGUI_->kickOff (reinterpret_cast (&terminationHandle)); } }; @@ -81,6 +84,7 @@ namespace gui { scoped_ptr facade (0); + class GuiSubsysDescriptor : public lumiera::Subsys, public Sync @@ -123,10 +127,10 @@ namespace gui { bool checkRunningState () throw() { - Lock guard (this); return (facade); } + void closeGuiModule (lumiera::Error *) { diff --git a/src/common/subsystem-runner.hpp b/src/common/subsystem-runner.hpp index 1e7deb32f..f46168cd7 100644 --- a/src/common/subsystem-runner.hpp +++ b/src/common/subsystem-runner.hpp @@ -177,6 +177,7 @@ namespace lumiera { ASSERT (susy); Lock sync (this); triggerEmergency(problem); + INFO (operate, "Subsystem '%s' terminated.", cStr(*susy)); ERROR_IF (susy->isRunning(), lumiera, "Subsystem '%s' signals termination, " "without resetting running state", cStr(*susy)); removeall (running_, susy); diff --git a/src/gui/guifacade.hpp b/src/gui/guifacade.hpp index 677ef4711..5afa230f0 100644 --- a/src/gui/guifacade.hpp +++ b/src/gui/guifacade.hpp @@ -91,7 +91,7 @@ namespace gui { * @internal this function is invoked automatically during the GUI * loading and startup process. Don't call it manually. */ - virtual bool kickOff (lumiera::Subsys::SigTerm&) =0; + virtual void kickOff (lumiera::Subsys::SigTerm&) =0; protected: @@ -100,7 +100,7 @@ namespace gui { /** interface of the GuiStarterPlugin */ LUMIERA_INTERFACE_DECLARE (lumieraorg_Gui, 1, - LUMIERA_INTERFACE_SLOT (bool, kickOff, (void*)) + LUMIERA_INTERFACE_SLOT (void, kickOff, (void*)) ); diff --git a/src/gui/guistart.cpp b/src/gui/guistart.cpp index 360cba90f..cca023ac9 100644 --- a/src/gui/guistart.cpp +++ b/src/gui/guistart.cpp @@ -75,7 +75,7 @@ namespace gui { : public GuiFacade { - bool kickOff (Subsys::SigTerm& terminationHandle) + void kickOff (Subsys::SigTerm& terminationHandle) { cout << " *** Ha Ha Ha\n" << " this is the GuiStarterPlugin speaking!\n" @@ -83,7 +83,6 @@ namespace gui { << " but actually nothing happens!!!!!!!!!!!!!!\n\n"; terminationHandle(0); // signal immediate shutdown without error - return false; } }; @@ -179,9 +178,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", - bool, (void* termSig), + void, (void* termSig), { - return gui::facade_().kickOff ( + gui::facade_().kickOff ( *reinterpret_cast (termSig)); } ) diff --git a/src/lib/thread-wrapper.hpp b/src/lib/thread-wrapper.hpp index b927f3d51..3c60cda09 100644 --- a/src/lib/thread-wrapper.hpp +++ b/src/lib/thread-wrapper.hpp @@ -21,8 +21,8 @@ */ -#ifndef LUMIERA_THREADWRAPPER_H -#define LUMIERA_THREADWRAPPER_H +#ifndef LIB_THREADWRAPPER_H +#define LIB_THREADWRAPPER_H #include "include/nobugcfg.h" @@ -36,14 +36,11 @@ extern "C" { #include -namespace lumiera { +namespace lib { using std::tr1::bind; using std::tr1::function; - using std::tr1::placeholders::_1; - - using lib::Sync; - using lib::NonrecursiveLock_Waitable; + using lumiera::Literal; /** @@ -106,7 +103,7 @@ namespace lumiera { ); if (!res) - throw error::State("failed to create new thread."); + throw lumiera::error::State("failed to create new thread."); // make sure the new thread had the opportunity to take the Operation // prior to leaving and thereby possibly destroying this local context @@ -116,5 +113,5 @@ namespace lumiera { - } // namespace lumiera + } // namespace lib #endif diff --git a/tests/lib/subsystem-runner-test.cpp b/tests/lib/subsystem-runner-test.cpp index c1391a26c..2f6d65454 100644 --- a/tests/lib/subsystem-runner-test.cpp +++ b/tests/lib/subsystem-runner-test.cpp @@ -43,6 +43,7 @@ using util::cStr; using test::Test; using lib::Sync; using lib::RecursiveLock_Waitable; +using lib::Thread; namespace lumiera { diff --git a/tests/lib/thread-wrapper-test.cpp b/tests/lib/thread-wrapper-test.cpp index 30bd1e24c..52ec2bb14 100644 --- a/tests/lib/thread-wrapper-test.cpp +++ b/tests/lib/thread-wrapper-test.cpp @@ -34,8 +34,8 @@ using test::Test; -namespace lumiera { - namespace test { +namespace lib { + namespace test { namespace { // private test classes and data... @@ -86,7 +86,7 @@ namespace lumiera { * lumiera::Thread wrapper for binding to an arbitrary operation * and passing the appropriate context. * - * @see lumiera::Thread + * @see lib::Thread * @see threads.h */ class ThreadWrapper_test : public Test @@ -114,4 +114,4 @@ namespace lumiera { } // namespace test -} // namespace lumiera +} // namespace lib