38 #ifndef LUMIERA_SUBSYSTEMRUNNER_H 39 #define LUMIERA_SUBSYSTEMRUNNER_H 55 using lib::RecursiveLock_Waitable;
56 using std::chrono_literals::operator
""s;
110 :
public Sync<RecursiveLock_Waitable>
113 volatile bool emergency_;
114 vector<Subsys*> running_;
116 bool isEmergency() {
return emergency_; }
117 bool allDead(){
return isnil (running_); }
132 triggerStartup (&susy);
143 triggerEmergency (
bool cond)
146 if (cond) emergency_=
true;
152 Lock blocking{
this, [&]{
return allDead() or isEmergency(); }};
156 return isEmergency();
163 triggerStartup (
Subsys* susy)
166 auto triggerStart = [
this](
Subsys* susy){ triggerStartup(susy); };
167 auto termCallback = [
this,susy]
173 if (isRunning(susy))
return;
175 INFO (subsystem,
"Triggering startup of subsystem \"%s\"",
cStr(*susy));
177 for_each (susy->getPrerequisites(), triggerStart );
178 bool started = susy->
start (opts_, termCallback);
183 running_.push_back (susy);
188 if (not and_all (susy->getPrerequisites(), isRunning ))
191 throw error::State(
_Fmt{
"Unable to start all prerequisites of Subsystem %s"} % *susy);
199 triggerEmergency(not isnil (problem));
200 INFO (subsystem,
"Subsystem '%s' terminated.",
cStr(*susy));
201 WARN_IF (not isnil(problem), subsystem,
"Irregular shutdown caused by: %s",
cStr(*problem));
202 ERROR_IF (susy->
isRunning(), subsystem,
"Subsystem '%s' signals termination, " 203 "without resetting running state",
cStr(*susy));
204 removeall (running_, susy);
Facility for monitor object based locking.
Dependencies and lifecycle of a partially independent Subsystem of the Application.
void sigTerm(Subsys *susy, string *problem)
CStr cStr(std::string const &rendered)
convenience shortcut: forced conversion to c-String via string.
scoped guard to control the actual locking.
bool and_all(CON const &elements, FUN function, P1 &&bind1, ARGS &&...args)
Accept binding for arbitrary function arguments.
Frontend for handling the Lumiera application commandline arguments.
virtual bool start(lumiera::Option &options, SigTerm)=0
attempt to bring up this subsystem up.
A front-end for using printf-style formatting.
Object Monitor based synchronisation.
Derived specific exceptions within Lumiera's exception hierarchy.
virtual void triggerShutdown() noexcept=0
initiate termination of this subsystem.
Implementation helper for managing execution of a collection of subsystems, which may depend on one a...
Describing dependencies and lifecycle of the application's primary parts.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
void for_each(CON const &elements, FUN function, P1 &&bind1, ARGS &&...args)
Accept binding for arbitrary function arguments.
bool isRunning() noexcept
Lumiera error handling (C++ interface).
Lumiera public interface.
virtual bool shouldStart(lumiera::Option &)=0
query application option state to determine if this subsystem should be activated.
const auto EMERGENCY_STOP
limited wait period for unwinding of remaining subsystems in case of an emergency shutdown...
SEQ::iterator removeall(SEQ &coll, typename SEQ::value_type const &val)
shortcut for removing all copies of an Element in any sequential collection
Perform operations "for each element" of a collection.