From c815de3621d7e9349648d2f09ee0a09cb5ce61b4 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 16 Mar 2020 12:24:58 -0700 Subject: [PATCH] ircd::run: Rename level IDLE to LOAD; minor reorg. --- construct/construct.cc | 4 +-- include/ircd/run.h | 77 ++++++++++++++++++++---------------------- ircd/ircd.cc | 8 ++--- ircd/run.cc | 6 ++-- matrix/matrix.cc | 2 +- 5 files changed, 47 insertions(+), 50 deletions(-) diff --git a/construct/construct.cc b/construct/construct.cc index 4c2b7c2f4..5b0e37317 100644 --- a/construct/construct.cc +++ b/construct/construct.cc @@ -239,7 +239,7 @@ noexcept try // This object registers a callback for a specific event in libircd; the // closure is called from the main context (#1) running ircd::main(). - // after libircd is ready for service in runlevel IDLE but before entering + // after libircd is ready for service in runlevel LOAD but before entering // runlevel RUN. It is called again immediately after entering runlevel // QUIT, but before any functionality of libircd destructs. This cues us // to start and stop the homeserver. @@ -251,7 +251,7 @@ noexcept try // 2 This branch is taken the first time this function is called, // and not taken the second time. - if(level == ircd::run::level::IDLE && !context && !nomatrix) + if(level == ircd::run::level::LOAD && !context && !nomatrix) { // 3 Launch the homeserver context (asynchronous). context = { "matrix", ircd::context::POST, homeserver }; diff --git a/include/ircd/run.h b/include/ircd/run.h index 72a95cdff..9e68ffda9 100644 --- a/include/ircd/run.h +++ b/include/ircd/run.h @@ -36,6 +36,43 @@ namespace ircd::run extern const enum level &chadburn; } +/// The run::level allows all observers to know the coarse state of IRCd and to +/// react accordingly. This can be used by the embedder of libircd to know +/// when it's safe to use or delete libircd resources. It is also used +/// similarly by the library and its modules. Only one runlevel is active at +/// any time. +/// +/// * HALT is the off mode. Nothing is/will be running in libircd until +/// an invocation of ircd::init(); +/// +/// * READY is the state after calling ircd::init(). Leaving READY is done with +/// the user either calling their ios.run() to start executing tasks or calling +/// ircd::quit() to HALT again. +/// +/// * START indicates the daemon is executing its startup procedures. Leaving +/// the START state occurs internally when there is success or a fatal error. +/// +/// * RUN is the service mode. Full client and application functionality exists +/// in this mode. Leaving the RUN mode is done with ircd::quit(); +/// +/// * QUIT indicates the daemon is executing the shutdown procedures. This +/// will eventually return back to the HALT state. +/// +/// * FAULT is a special mode indicating something really bad. The exact +/// details of this mode are ambiguous. Users do not have to handle this. +/// +enum class ircd::run::level +:int +{ + FAULT = -1, ///< Unrecoverable fault. + HALT = 0, ///< x <-- IRCd Powered off. + READY = 1, ///< | | Ready for user to run ios event loop. + START = 2, ///< | | Starting internal subsystems. + LOAD = 3, ///< | | Load user application. + RUN = 4, ///< O | IRCd in service. + QUIT = 5, ///< --> ^ Clean shutdown in progress. +}; + /// An instance of this class registers itself to be called back when /// the ircd::run::level has changed. The context for this callback differs /// based on the level argument; not all invocations are on an ircd::ctx, etc. @@ -88,43 +125,3 @@ struct ircd::run::changed changed() noexcept; ~changed() noexcept; }; - -/// The run::level allows all observers to know the coarse state of IRCd and to -/// react accordingly. This can be used by the embedder of libircd to know -/// when it's safe to use or delete libircd resources. It is also used -/// similarly by the library and its modules. Only one runlevel is active at -/// any time. -/// -/// * HALT is the off mode. Nothing is/will be running in libircd until -/// an invocation of ircd::init(); -/// -/// * READY is the state after calling ircd::init(). Leaving READY is done with -/// the user either calling their ios.run() to start executing tasks or calling -/// ircd::quit() to HALT again. -/// -/// * START indicates the daemon is executing its startup procedures. Leaving -/// the START state occurs internally when there is success or a fatal error. -/// -/// * IDLE indicates the library is ready for use. The user can load their -/// application in this mode before transitioning to RUN. -/// -/// * RUN is the service mode. Full client and application functionality exists -/// in this mode. Leaving the RUN mode is done with ircd::quit(); -/// -/// * QUIT indicates the daemon is executing the shutdown procedures. This -/// will eventually return back to the HALT state. -/// -/// * FAULT is a special mode indicating something really bad. The exact -/// details of this mode are ambiguous. Users do not have to handle this. -/// -enum class ircd::run::level -:int -{ - FAULT = -1, ///< Unrecoverable fault. - HALT = 0, ///< x <-- IRCd Powered off. - READY = 1, ///< | | Ready for user to run ios event loop. - START = 2, ///< | | Starting internal subsystems. - IDLE = 3, ///< | | Ready for user to load application. - RUN = 4, ///< O | IRCd in service. - QUIT = 5, ///< --> ^ Clean shutdown in progress. -}; diff --git a/ircd/ircd.cc b/ircd/ircd.cc index 1a56405b1..92d270747 100644 --- a/ircd/ircd.cc +++ b/ircd/ircd.cc @@ -200,7 +200,7 @@ noexcept return true; } - case run::level::IDLE: + case run::level::LOAD: case run::level::START: { ctx::terminate(*main_context); @@ -251,7 +251,7 @@ noexcept case run::level::QUIT: return; - case run::level::IDLE: + case run::level::LOAD: case run::level::RUN: break; } @@ -318,9 +318,9 @@ noexcept try ircd::run::set(run::level::QUIT); }}; - // IRCd will now transition to the IDLE state allowing library user's to + // IRCd will now transition to the LOAD state allowing library user's to // load their applications using the run::changed callback. - run::set(run::level::IDLE); + run::set(run::level::LOAD); // IRCd will now transition to the RUN state indicating full functionality. run::set(run::level::RUN); diff --git a/ircd/run.cc b/ircd/run.cc index 47b8d88c4..3b7ef5749 100644 --- a/ircd/run.cc +++ b/ircd/run.cc @@ -123,7 +123,7 @@ try { case level::HALT: break; case level::QUIT: break; - case level::IDLE: throw; + case level::LOAD: throw; default: throw; } @@ -156,7 +156,7 @@ catch(const std::exception &e) { switch(new_level) { - case level::IDLE: throw; + case level::LOAD: throw; default: break; } @@ -178,7 +178,7 @@ ircd::run::reflect(const enum run::level &level) case level::HALT: return "HALT"; case level::READY: return "READY"; case level::START: return "START"; - case level::IDLE: return "IDLE"; + case level::LOAD: return "LOAD"; case level::RUN: return "RUN"; case level::QUIT: return "QUIT"; case level::FAULT: return "FAULT"; diff --git a/matrix/matrix.cc b/matrix/matrix.cc index af54a28d3..5494cf962 100644 --- a/matrix/matrix.cc +++ b/matrix/matrix.cc @@ -180,7 +180,7 @@ void ircd::m::on_load() try { - assert(ircd::run::level == run::level::IDLE); + assert(ircd::run::level == run::level::LOAD); } catch(const m::error &e) {