47 #ifndef LUMIERA_SUBSYSTEMRUNNER_H 48 #define LUMIERA_SUBSYSTEMRUNNER_H 64 using lib::RecursiveLock_Waitable;
65 using std::chrono_literals::operator
""s;
119 :
public Sync<RecursiveLock_Waitable>
122 volatile bool emergency_;
123 vector<Subsys*> running_;
125 bool isEmergency() {
return emergency_; }
126 bool allDead(){
return isnil (running_); }
141 triggerStartup (&susy);
152 triggerEmergency (
bool cond)
155 if (cond) emergency_=
true;
161 Lock blocking{
this, [&]{
return allDead() or isEmergency(); }};
165 return isEmergency();
172 triggerStartup (
Subsys* susy)
175 auto triggerStart = [
this](
Subsys* susy){ triggerStartup(susy); };
176 auto termCallback = [
this,susy]
182 if (isRunning(susy))
return;
184 INFO (subsystem,
"Triggering startup of subsystem \"%s\"",
cStr(*susy));
186 for_each (susy->getPrerequisites(), triggerStart );
187 bool started = susy->
start (opts_, termCallback);
192 running_.push_back (susy);
197 if (not and_all (susy->getPrerequisites(), isRunning ))
200 throw error::State(
_Fmt{
"Unable to start all prerequisites of Subsystem %s"} % *susy);
208 triggerEmergency(not isnil (problem));
209 INFO (subsystem,
"Subsystem '%s' terminated.",
cStr(*susy));
210 WARN_IF (not isnil(problem), subsystem,
"Irregular shutdown caused by: %s",
cStr(*problem));
211 ERROR_IF (susy->
isRunning(), subsystem,
"Subsystem '%s' signals termination, " 212 "without resetting running state",
cStr(*susy));
213 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.