Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
appstate.cpp
Go to the documentation of this file.
1/*
2 AppState - application initialisation and behaviour
3
4 Copyright (C)
5 2008, Hermann Vosseler <Ichthyostega@web.de>
6
7  **Lumiera** is free software; you can redistribute it and/or modify it
8  under the terms of the GNU General Public License as published by the
9  Free Software Foundation; either version 2 of the License, or (at your
10  option) any later version. See the file COPYING for further details.
11
12* *****************************************************************/
13
14
26#include "lib/error.hpp"
27#include "common/appstate.hpp"
29
30extern "C" {
32
33#include "common/interface.h"
35#include "common/plugin.h"
36}
37
38#include "lib/symbol.hpp"
39#include "lib/util.hpp"
40
41
42using lib::Literal;
43using std::unique_ptr;
44
45
46
47namespace lumiera {
48
49 namespace { // implementation details
50
51 inline void
53 {
54 if (lumiera_err errorstate = lumiera_error ())
55 ALERT (common, "*** Unexpected error: %s\n Triggering emergency exit.", errorstate);
56 }
57 }
58
59
60
61
73 , subsystems_{}
74 , emergency_{false}
75 , core_up_{false}
76 { }
77
80
81
82 string
84 {
85 return setup_.get(key).as<string>();
86 }
87
88
89
90
91
92 // ===== Implementation startup and shutdown sequence for main() ========
93
94
95#define _MAYBE_THROW_ \
96 maybeThrow<error::Fatal> ("internal failure while initialising the "\
97 "Lumiera application framework");
98
99
100
101 void
103 {
104 TRACE (common, "initialising application core...");
105
108
111
114
115 core_up_= true;
118
119
120 subsystems_.reset (new SubsystemRunner (options));
121 TRACE (common, "Lumiera core started successfully.");
122 }
123
124
125
126 void
128 {
129 TRACE (common, "maybe startup %s...?", cStr(subsys));
130 REQUIRE (subsystems_);
131 subsystems_->maybeRun (subsys);
132 }
133
134
135
137
138
153 {
154 if (subsystems_)
155 {
156 emergency_ |= subsystems_->wait();
157 subsystems_.reset(0);
158 }
159
160 NOTICE (common, "Shutting down Lumiera...");
161
162 if (emergency_)
163 {
164 ALERT (common, "Triggering emergency exit...");
167 }
168 else
169 {
171 return NORMAL_EXIT;
172 }
173 }
174
175
176
179 {
180
181 ERROR (common, "Aborting Lumiera after unhandled error: %s", cStr(problem.what()));
182
183 log_and_clear_unexpected_errorstate();
184
185 try
186 {
187 if (subsystems_)
188 {
189 subsystems_->triggerEmergency(true);
190 subsystems_->shutdownAll();
191 }
192 return maybeWait ();
193 }
194 catch (...)
195 {
196 return abort();
197 }
198 }
199
200
201
203 AppState::abort () noexcept
204 {
205 log_and_clear_unexpected_errorstate();
206
207 if (emergency_)
208 {
211 }
212 else
213 {
216 }
217 }
218
219
220
221
228 {
229 if (core_up_)
230 try
231 {
232 TRACE (common, "shutting down basic application layer...");
235 }
236 catch (...)
237 {
238 log_and_clear_unexpected_errorstate();
239 } }
240
241
242
243
244} // namespace lumiera
#define _MAYBE_THROW_
Definition appstate.cpp:95
Registering and managing primary application-global services.
#define LUMIERA_LOCATION_OF_BOOTSTRAP_INI
"bootstrapIni" : the basic setup configuration to load
Access point to singletons and other kinds of dependencies designated by type.
Definition depend.hpp:281
Inline string literal.
Definition symbol.hpp:78
~AppState()
anything which should be closed as late as possible and after the normal shutdown sequence can be pla...
Definition appstate.cpp:227
string fetchSetupValue(lib::Literal key)
access basic application setup values (from setup.ini)
Definition appstate.cpp:83
void init(lumiera::Option &options)
evaluate the result of option parsing and maybe additional configuration such as to be able to determ...
Definition appstate.cpp:102
ExitCode abort() noexcept
initiate an fatal emergency shutdown, caused by an unforeseen error condition
Definition appstate.cpp:203
ExitCode maybeWait()
put the main thread of the application into a wait state, as long as some subsystem(s) registered wit...
Definition appstate.cpp:152
static lib::Depend< AppState > instance
get the (single) AppState instance.
Definition appstate.hpp:74
BasicSetup setup_
Definition appstate.hpp:126
void maybeStart(lumiera::Subsys &)
building on the state determined by init, decide if the given Subsys needs to be pulled up and,...
Definition appstate.cpp:127
AppState()
perform initialisation triggered on first access.
Definition appstate.cpp:71
opt::variable_value const & get(lib::Literal key) const
Interface and Base definition for all Lumiera Exceptions.
Definition error.hpp:65
virtual CStr what() const noexcept override
std::exception interface : yield a diagnostic message
static void trigger(Symbol eventLabel)
trigger lifecycle callbacks registered under the given label
Definition lifecycle.cpp:72
Frontend for handling the Lumiera application commandline arguments.
Definition option.hpp:70
Dependencies and lifecycle of a partially independent Subsystem of the Application.
Definition subsys.hpp:63
Implementation helper for managing execution of a collection of subsystems, which may depend on one a...
void lumiera_config_interface_destroy(void)
void lumiera_config_interface_init(void)
External interface to the lumiera configuration system.
lumiera_err lumiera_error(void)
Get and clear current error state.
const char * lumiera_err
Definition error.h:48
Lumiera error handling (C++ interface).
Lumiera interface macros and structures.
void lumiera_interfaceregistry_init(void)
Initialise the interface registry.
void lumiera_interfaceregistry_destroy(void)
Global registry for interfaces (extension points).
Lumiera public interface.
Definition advice.hpp:102
CStr ON_GLOBAL_INIT
to be triggered in main()
CStr ON_GLOBAL_SHUTDOWN
to be triggered at the end of main()
CStr ON_EMERGENCY
activated on shutdown after premature failure of a subsystem
AppState::ExitCode ExitCode
Definition appstate.cpp:136
LumieraPlugin lumiera_plugin_load(const char *plugin)
Tries to load a plugin Creates a new plugin structure and tries to load and initialise the plugin.
Definition plugin.c:241
int lumiera_plugin_register(LumieraPlugin plugin)
Register a plugin and its interfaces.
Definition plugin.c:260
int lumiera_plugin_discover(LumieraPlugin(*callback_load)(const char *plugin), int(*callback_register)(LumieraPlugin))
discover new plugins traverses the configured plugin paths and calls the callback_load function for a...
Definition plugin.c:187
Lumiera plugins define 'interfaces' as shown in interface.h, the plugin system handles the loading of...
Manage execution of the independent Subsystems of the Lumiera application.
Marker types to indicate a literal string and a Symbol.
CStr cStr(std::string const &rendered)
convenience shortcut: forced conversion to c-String via string.
Definition symbol.hpp:60
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...