From 6460ff83440fea582113b94711a52214a0cfc6d1 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Mon, 2 Apr 2018 02:56:08 +0200 Subject: [PATCH] Switch basic Application initialisation to the rewritten DependencyFactory this is the classic case of a singleton object --- src/common/appstate.cpp | 38 ++++++---------------- src/common/appstate.hpp | 13 ++++---- src/common/basic-setup.cpp | 6 ++-- src/common/configfacade.cpp | 12 +++---- src/lib/lifecycle.cpp | 13 +++++--- wiki/thinkPad.ichthyo.mm | 64 ++++++++++++++++++++++++++++++------- 6 files changed, 86 insertions(+), 60 deletions(-) diff --git a/src/common/appstate.cpp b/src/common/appstate.cpp index 2b7231265..6ba4bd20c 100644 --- a/src/common/appstate.cpp +++ b/src/common/appstate.cpp @@ -33,7 +33,6 @@ #include "lib/error.hpp" -#include "include/lifecycle.h" #include "common/appstate.hpp" #include "common/subsystem-runner.hpp" @@ -65,20 +64,12 @@ namespace lumiera { if (lumiera_err errorstate = lumiera_error ()) ALERT (common, "*** Unexpected error: %s\n Triggering emergency exit.", errorstate); } - - void - createAppStateInstance(){ - AppState::instance(); - } - - LifecycleHook schedule_ (ON_BASIC_INIT, &createAppStateInstance); - } - /** perform initialisation triggered on first access. + /** perform initialisation triggered on first access. * Will execute BasicSetup sequence to determine the location * of the executable and read in \c setup.ini -- * Since above a LifecycleHook is installed ON_BASIC_INIT, @@ -94,17 +85,8 @@ namespace lumiera { , core_up_{false} { } - - - - AppState& - AppState::instance() // Meyer's singleton - { - static unique_ptr theApp_; - if (!theApp_) theApp_.reset (new AppState ()); - return *theApp_; - } - + /** storage for the Appstate Singleton instance */ + lib::Depend AppState::instance; string @@ -120,7 +102,7 @@ namespace lumiera { // ===== Implementation startup and shutdown sequence for main() ======== -#define _THROW_IF \ +#define _MAYBE_THROW_ \ maybeThrow ("internal failure while initialising the "\ "Lumiera application framework"); @@ -132,17 +114,17 @@ namespace lumiera { TRACE (common, "initialising application core..."); lumiera_interfaceregistry_init (); - _THROW_IF + _MAYBE_THROW_ lumiera_plugin_discover (lumiera_plugin_load, lumiera_plugin_register); - _THROW_IF + _MAYBE_THROW_ lumiera_config_interface_init (); - _THROW_IF + _MAYBE_THROW_ core_up_= true; LifecycleHook::trigger (ON_GLOBAL_INIT); - _THROW_IF + _MAYBE_THROW_ subsystems_.reset (new SubsystemRunner (options)); @@ -174,7 +156,7 @@ namespace lumiera { * the termination of all other subsystems is initiated; when detecting this case, * the emergency exit sequence is called. Any error which can't be handled within * this scheme, should be thrown as exception, in which case the abort handler - * is activated. + * is activated. */ ExitCode AppState::maybeWait() @@ -269,6 +251,4 @@ namespace lumiera { - - } // namespace lumiera diff --git a/src/common/appstate.hpp b/src/common/appstate.hpp index 1490afcd7..d6fd3216f 100644 --- a/src/common/appstate.hpp +++ b/src/common/appstate.hpp @@ -42,6 +42,7 @@ #include "lib/symbol.hpp" #include "lib/nocopy.hpp" +#include "lib/depend.hpp" #include "common/option.hpp" #include "common/subsys.hpp" #include "common/basic-setup.hpp" @@ -62,7 +63,7 @@ namespace lumiera { /** * The Lumiera Application state and basic initialisation. * Singleton to hold global flags directing the overall application behaviour, - * for triggering lifecycle events and performing early initialisation tasks. + * responsible for triggering lifecycle events and performing early initialisation tasks. * AppState services are available already from static initialisation code. * @warning don't use AppState in destructors. */ @@ -73,13 +74,13 @@ namespace lumiera { AppState (); ~AppState (); - friend class std::default_delete; + friend class lib::DependencyFactory; public: - /** get the (single) AppState instance. + /** get the (single) AppState instance. * @warning don't use it after the end of main()! */ - static AppState& instance(); + static lib::Depend instance; /** evaluate the result of option parsing and maybe additional configuration @@ -111,7 +112,7 @@ namespace lumiera { * On termination of one of those components, tear down the remaining * components and initiate a normal or emergency shutdown of the * application, depending on the triggering component's - * mode of termination (exit or exception). + * mode of termination (exit or exception). * @return global application exit code */ ExitCode maybeWait(); @@ -127,7 +128,7 @@ namespace lumiera { ExitCode abort () throw(); - + private: using PSub = std::unique_ptr; diff --git a/src/common/basic-setup.cpp b/src/common/basic-setup.cpp index 16b9e2fe5..434c55086 100644 --- a/src/common/basic-setup.cpp +++ b/src/common/basic-setup.cpp @@ -75,9 +75,9 @@ namespace lumiera { /** * Creating the BasicSetup object performs the * initial self-configuration of the Lumiera Application. - * For this, the \c setup.ini file is located relative to the + * For this, the `setup.ini` file is located relative to the * current application executable, read in and parsed into a - * map of setup variables. + * map of setup variables. */ BasicSetup::BasicSetup (string bootstrapIni) : syntax("Lumiera installation and platform configuration") @@ -118,7 +118,7 @@ namespace lumiera { opt::parsed_options parsed = opt::parse_config_file (configIn, syntax); opt::store (parsed, settings); - opt::notify(settings); + opt::notify(settings); } diff --git a/src/common/configfacade.cpp b/src/common/configfacade.cpp index ac7500be5..3841f14eb 100644 --- a/src/common/configfacade.cpp +++ b/src/common/configfacade.cpp @@ -46,7 +46,7 @@ #include "lib/searchpath.hpp" #include "lib/util.hpp" -extern "C" { +extern "C" { #include "common/config.h" } @@ -61,7 +61,7 @@ extern "C" { /** Similarly, this key is used to fetch the configured default * plugin/module search path from the basic setup.ini * This patch is used by the plugin-loader to discover - * lumiera plugins and extensions. + * lumiera plugins and extensions. */ #define KEY_PLUGIN_PATH "Lumiera.modulepath" @@ -81,8 +81,8 @@ namespace lumiera { namespace { - void - pull_up_ConfigSystem () + void + pull_up_ConfigSystem () { TRACE (common, "booting up config system"); Config::instance(); @@ -139,7 +139,7 @@ extern "C" { /* ==== implementation C interface for accessing setup.ini ======= - const char* + const char* lumiera_get_plugin_path_default () { static string pathSpec; @@ -147,7 +147,7 @@ extern "C" { /* ==== implementation C interface for accessing setup.ini ======= { pathSpec += "plugin.path="; // syntax expected by lumiera_config_setdefault - // fetch plugin search path from setup.ini and expand any $ORIGIN token + // fetch plugin search path from setup.ini and expand any $ORIGIN token SearchPathSplitter pathElement(Config::get (KEY_PLUGIN_PATH)); while (pathElement) pathSpec += pathElement.next() +":"; diff --git a/src/lib/lifecycle.cpp b/src/lib/lifecycle.cpp index 1ac3f07ca..0a05d5eeb 100644 --- a/src/lib/lifecycle.cpp +++ b/src/lib/lifecycle.cpp @@ -40,15 +40,20 @@ namespace lumiera { // ==== implementation Lifecycle Registry ======= /** @remark since the LifecycleRegistry is used to implement - * the most basic initialisation, we need to ensure it is fully - * initialised and gets up on demand as early as possible. */ + * the most basic initialisation, we need to ensure it is fully initialised + * as early as possible. Especially we can not use lib::Depend for that purpose, + * since the latter needs the LifecycleRegistry to pull up the NoBug-Library. + * More specifically, if we `#include "lib/depend.hpp"`, on static initialisation + * the handle planted within that include would invoke `DependencyFactory`, + * which is defined later in the same header and thus not yet initialised. + */ LifecycleRegistry& LifecycleRegistry::instance() { static LifecycleRegistry theRegistry; return theRegistry; // Meyer's singleton } - + // ==== implementation LifecycleHook class ======= @@ -102,7 +107,7 @@ extern "C" { /* ==== implementation C interface for lifecycle hooks ======= */ - void + void lumiera_LifecycleHook_add (const char* eventLabel, void callbackFun(void)) { lumiera::LifecycleHook (eventLabel, callbackFun); diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index 5146bebf2..61ee974b6 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -28328,8 +28328,8 @@ - - + + @@ -28362,8 +28362,8 @@ - - + + @@ -28507,8 +28507,8 @@ - - + + @@ -28516,11 +28516,47 @@ - + - + + + + + + + + + + + + + + +

+ ...weil Nobug-Init ON_BASIC_INIT braucht, +

+

+ und lib::Depend wiederum von Nobug-Init abhängig ist. +

+

+ +

+

+ Also würde DependencyFactory<LifecycleRegistry> aufgerufen, +

+

+ bevor es statisch initialisiert sein kann... +

+ + +
+ +
+ + +
@@ -28583,11 +28619,15 @@ + + + - - + + + @@ -28621,8 +28661,8 @@ - - + +