Switch basic Application initialisation to the rewritten DependencyFactory

this is the classic case of a singleton object
This commit is contained in:
Fischlurch 2018-04-02 02:56:08 +02:00
parent 4669260cd1
commit 6460ff8344
6 changed files with 86 additions and 60 deletions

View file

@ -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<AppState> theApp_;
if (!theApp_) theApp_.reset (new AppState ());
return *theApp_;
}
/** storage for the Appstate Singleton instance */
lib::Depend<AppState> AppState::instance;
string
@ -120,7 +102,7 @@ namespace lumiera {
// ===== Implementation startup and shutdown sequence for main() ========
#define _THROW_IF \
#define _MAYBE_THROW_ \
maybeThrow<error::Fatal> ("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

View file

@ -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<AppState>;
friend class lib::DependencyFactory<AppState>;
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<AppState> 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<SubsystemRunner>;

View file

@ -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);
}

View file

@ -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() +":";

View file

@ -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<LifecycleRegistry>`,
* 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);

View file

@ -28328,8 +28328,8 @@
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1522033564057" ID="ID_1294295502" MODIFIED="1522033567713" TEXT="Nacharbeiten">
<icon BUILTIN="flag-yellow"/>
<node BACKGROUND_COLOR="#fdfdcf" COLOR="#ff0000" CREATED="1522454023039" ID="ID_1828121921" MODIFIED="1522454031095" TEXT="Folge-Probleme">
<icon BUILTIN="flag-pink"/>
<node COLOR="#338800" CREATED="1522454023039" ID="ID_1828121921" MODIFIED="1522630470765" TEXT="Folge-Probleme">
<icon BUILTIN="button_ok"/>
<node CREATED="1522454040500" ID="ID_1674154774" MODIFIED="1522454043160" TEXT="Architektur">
<node CREATED="1522454061873" ID="ID_1012349550" MODIFIED="1522454068316" TEXT="unklare statische Abh&#xe4;ngigkeiten">
<node CREATED="1522454074760" ID="ID_1884600051" MODIFIED="1522457273211" TEXT="ClassLock">
@ -28362,8 +28362,8 @@
<icon BUILTIN="button_ok"/>
</node>
</node>
<node CREATED="1522454146645" ID="ID_818640049" MODIFIED="1522557422822" TEXT="Advice-System">
<linktarget COLOR="#7a8fa9" DESTINATION="ID_818640049" ENDARROW="Default" ENDINCLINATION="-384;-20;" ID="Arrow_ID_1167388040" SOURCE="ID_1527905225" STARTARROW="None" STARTINCLINATION="288;-115;"/>
<node CREATED="1522454146645" ID="ID_818640049" MODIFIED="1522628482100" TEXT="Advice-System">
<linktarget COLOR="#7a8fa9" DESTINATION="ID_818640049" ENDARROW="Default" ENDINCLINATION="-384;-20;" ID="Arrow_ID_1167388040" SOURCE="ID_1527905225" STARTARROW="None" STARTINCLINATION="309;-116;"/>
<icon BUILTIN="info"/>
<node CREATED="1522454318558" ID="ID_65008261" MODIFIED="1522454338494" TEXT="braucht sicht selbst beim Runterfahren">
<icon BUILTIN="smiley-oh"/>
@ -28507,8 +28507,8 @@
<node CREATED="1522454162939" ID="ID_867445269" MODIFIED="1522454175102" TEXT="Subklassen-Konfig">
<node CREATED="1522454176426" ID="ID_964380935" MODIFIED="1522454188772" TEXT="mu&#xdf; jetzt in den Provider-Scope"/>
<node CREATED="1522454189359" ID="ID_1178508604" MODIFIED="1522454200306" TEXT="dieser ist meist nicht so offensichtlich klar"/>
<node COLOR="#338800" CREATED="1522454200902" ID="ID_1367664577" MODIFIED="1522628368155" TEXT="ConfigRules">
<linktarget COLOR="#8fbeb3" DESTINATION="ID_1367664577" ENDARROW="Default" ENDINCLINATION="-183;5;" ID="Arrow_ID_1637829369" SOURCE="ID_1789329281" STARTARROW="None" STARTINCLINATION="26;-32;"/>
<node COLOR="#338800" CREATED="1522454200902" ID="ID_1367664577" MODIFIED="1522628490770" TEXT="ConfigRules">
<linktarget COLOR="#8fbeb3" DESTINATION="ID_1367664577" ENDARROW="Default" ENDINCLINATION="-268;0;" ID="Arrow_ID_1637829369" SOURCE="ID_1789329281" STARTARROW="None" STARTINCLINATION="26;-32;"/>
<icon BUILTIN="button_ok"/>
<node CREATED="1522454211157" ID="ID_1826864875" MODIFIED="1522454217672" TEXT="Subclass MockConfigRules"/>
<node CREATED="1522454218267" ID="ID_1085608506" MODIFIED="1522628399085" TEXT="in die ConfigManager-Implementierung verelgt"/>
@ -28516,11 +28516,47 @@
</node>
</node>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1522018567685" ID="ID_1619059123" MODIFIED="1522018578992" TEXT="Frage: was ist mit AppState?">
<node COLOR="#338800" CREATED="1522018567685" ID="ID_1619059123" MODIFIED="1522630290145" TEXT="Frage: was ist mit AppState?">
<icon BUILTIN="help"/>
<node CREATED="1522018581283" ID="ID_132446315" MODIFIED="1522018592182" TEXT="macht es Sinn, das via Depend zug&#xe4;nglich zu machen?"/>
<node CREATED="1522018581283" ID="ID_132446315" MODIFIED="1522630357153" TEXT="macht es Sinn, das via Depend zug&#xe4;nglich zu machen?">
<icon BUILTIN="forward"/>
<node CREATED="1522630308841" ID="ID_1688145864" MODIFIED="1522630349227" TEXT="Ja">
<icon BUILTIN="ksmiletris"/>
</node>
<node CREATED="1522630312898" ID="ID_23962719" MODIFIED="1522630325291" TEXT="Wird zwar von lumiera::Config hochgezogen"/>
<node CREATED="1522630325999" ID="ID_976681959" MODIFIED="1522630344624" TEXT="...welches aber selber schon per lib::Depend instantiiert wird"/>
</node>
<node CREATED="1522018593697" ID="ID_1730197219" MODIFIED="1522018623361" TEXT="ist bisher ein Meyer&apos;s Singleton"/>
<node CREATED="1522018623861" ID="ID_1923633930" MODIFIED="1522018631776" TEXT="aber lebt bereits im globalen Speicher"/>
<node CREATED="1522630364690" ID="ID_1442746804" MODIFIED="1522630460073" TEXT="ABER: LifecycleRegistry mu&#xdf; Meyer&apos;s Singleton bleiben">
<richcontent TYPE="NOTE"><html>
<head>
</head>
<body>
<p>
...weil Nobug-Init ON_BASIC_INIT braucht,
</p>
<p>
und lib::Depend wiederum von Nobug-Init abh&#228;ngig ist.
</p>
<p>
</p>
<p>
Also w&#252;rde DependencyFactory&lt;LifecycleRegistry&gt; aufgerufen,
</p>
<p>
bevor es statisch initialisiert sein kann...
</p>
</body>
</html>
</richcontent>
<icon BUILTIN="clanbomber"/>
</node>
<node COLOR="#338800" CREATED="1522630297899" ID="ID_365546675" MODIFIED="1522630305978" TEXT="umgestellt auf lib::Depend">
<icon BUILTIN="button_ok"/>
</node>
</node>
<node COLOR="#338800" CREATED="1521433694233" ID="ID_1951071885" MODIFIED="1522557016686" STYLE="fork" TEXT="Nebenbei: Schwartz-Counter in ClassLock abl&#xf6;sen">
<arrowlink COLOR="#735d7e" DESTINATION="ID_715588139" ENDARROW="Default" ENDINCLINATION="1087;0;" ID="Arrow_ID_1384015103" STARTARROW="None" STARTINCLINATION="-84;86;"/>
@ -28583,11 +28619,15 @@
<node COLOR="#338800" CREATED="1522457377743" ID="ID_157728376" MODIFIED="1522628243174" TEXT="DefsManager_test">
<icon BUILTIN="button_ok"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1522630494375" ID="ID_787599487" MODIFIED="1522630496224" TEXT="PlacementHierarchy_test">
<icon BUILTIN="flag-yellow"/>
</node>
</node>
<node CREATED="1522457303466" ID="ID_28369083" MODIFIED="1522597732907" TEXT="Advice-System verpfuscht">
<icon BUILTIN="button_cancel"/>
<node CREATED="1522457315568" ID="ID_1527905225" MODIFIED="1522457337194" TEXT="Policy-Verletzung">
<arrowlink COLOR="#7a8fa9" DESTINATION="ID_818640049" ENDARROW="Default" ENDINCLINATION="-384;-20;" ID="Arrow_ID_1167388040" STARTARROW="None" STARTINCLINATION="288;-115;"/>
<node CREATED="1522457315568" ID="ID_1527905225" MODIFIED="1522628482100" TEXT="Policy-Verletzung">
<arrowlink COLOR="#7a8fa9" DESTINATION="ID_818640049" ENDARROW="Default" ENDINCLINATION="-384;-20;" ID="Arrow_ID_1167388040" STARTARROW="None" STARTINCLINATION="309;-116;"/>
<icon BUILTIN="messagebox_warning"/>
</node>
<node COLOR="#338800" CREATED="1522597569180" ID="ID_602663488" MODIFIED="1522597663372" TEXT="naja... nicht sch&#xf6;n aber OK">
<richcontent TYPE="NOTE"><html>
@ -28621,8 +28661,8 @@
<node CREATED="1522457406523" ID="ID_715525481" MODIFIED="1522628426366" TEXT="wer ist schuld?">
<icon BUILTIN="help"/>
</node>
<node COLOR="#338800" CREATED="1522628298319" ID="ID_1789329281" MODIFIED="1522628438825" TEXT="ein Nebeneffekt der Konfiguration f&#xfc;r ConfigResolver">
<arrowlink COLOR="#8fbeb3" DESTINATION="ID_1367664577" ENDARROW="Default" ENDINCLINATION="-183;5;" ID="Arrow_ID_1637829369" STARTARROW="None" STARTINCLINATION="26;-32;"/>
<node COLOR="#338800" CREATED="1522628298319" ID="ID_1789329281" MODIFIED="1522628490770" TEXT="ein Nebeneffekt der Konfiguration f&#xfc;r ConfigResolver">
<arrowlink COLOR="#8fbeb3" DESTINATION="ID_1367664577" ENDARROW="Default" ENDINCLINATION="-268;0;" ID="Arrow_ID_1637829369" STARTARROW="None" STARTINCLINATION="26;-32;"/>
<icon BUILTIN="info"/>
</node>
</node>