Skip to content

Commit 7fc1814

Browse files
committed
Updates related to enabling modules.
1 parent 336d95e commit 7fc1814

File tree

5 files changed

+66
-18
lines changed

5 files changed

+66
-18
lines changed

input/element.config.txt

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
1-
/ Parameters that use default values are commented out.
1+
/ CONFIGURATION PARAMETERS.
2+
/
3+
/ This file contains key-value pairs, one pair per line. A line with a /
4+
/ in the first column is treated as a comment.
5+
/
6+
/ Legal characters in a key are A-Z, a-z, 0-9 and period (.), hyphen (-),
7+
/ and underscore (_). Leading blanks on a line are ignored, after which the
8+
/ key is the first string containing those legal characters.
9+
/
10+
/ The rest of the characters on the line are taken as the value after erasing
11+
/ leading and trailing blanks. Legal characters in a value are those in a
12+
/ key, plus colon (:), slash (/), backslash (\), and internal space ( ).
13+
/
14+
/ Parameters that use default values have been commented out.
215
/
316
BreakEnabled T
417
CheckStack T
@@ -31,7 +44,7 @@ NullifyObjectData T
3144
/ NumOfSmallBuffers 1
3245
/ NumOfTimers 1
3346
/ NumOfTinyBuffers 1
34-
OptionalModules an sn ct
47+
OptionalModules nt an sn ct
3548
ReinitOnSchedTimeout F
3649
/ RtcInterval 60
3750
/ RtcLimit 6

src/app/rscapp.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
// (a) create its module in CreateModules, below;
6868
// (b) have its module pass a symbol to the base Module constructor; and
6969
// (c) add that symbol to the OptionalModules configuration parameter in
70-
// the configuration file rsc/input/element.config.txt
70+
// the configuration file (by default, rsc/input/element.config.txt)
7171
// (d) remove a symbol from OptionalModules if you don't create its module
7272
//
7373
//& #include "AnModule.h"

src/nb/Module.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,16 @@ void Module::Display(ostream& stream,
8888

8989
//------------------------------------------------------------------------------
9090

91+
fn_name Module_Enable = "Module.Enable";
92+
9193
void Module::Enable()
9294
{
93-
Debug::ft("Module.Enable");
95+
Debug::ft(Module_Enable);
9496

95-
enabled_ = true;
97+
if(Restart::GetLevel() == RestartReboot)
98+
enabled_ = true;
99+
else
100+
Debug::SwLog(Module_Enable, "reboot not in progress", 0);
96101
}
97102

98103
//------------------------------------------------------------------------------

src/nb/Module.h

+36-13
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,14 @@
3333

3434
namespace NodeBase
3535
{
36+
// The purpose of modules is to avoid the type of totally unstructured
37+
// main() that plagues so many systems.
38+
//
3639
// A module--the term as used here predates C++20 and is unrelated to its
3740
// usage--consists of interrelated software that provides some logical
38-
// capability. It is implemented within its own namespace, which should
39-
// consist of a separate .h/.cpp pair for each major class. One of these
40-
// pairs is a Module subclass that is invoked during restarts. The term
41+
// capability. The capability is often implemented in its own namespace
42+
// and should have a separate .h/.cpp pair for each major class. One such
43+
// pair is a Module subclass that is invoked during restarts. The term
4144
// "restart" refers to both system initialization (when the executable is
4245
// first launched) and reinitialization (to recover from a serious error).
4346
//
@@ -51,7 +54,7 @@ namespace NodeBase
5154
// private:
5255
// SomeModule() : Module()
5356
// {
54-
// // Modules 1 to N are the ones on which this module depends.
57+
// // Modules 1 to N are the ones that this module requires.
5558
// // Creating their singletons ensures that they will exist in
5659
// // the module registry when the system initializes. Because
5760
// // each module creates the modules on which it depends before
@@ -65,17 +68,27 @@ namespace NodeBase
6568
// }
6669
//
6770
// ~SomeModule() = default;
71+
//
72+
// void Enable() override
73+
// {
74+
// // Enable the modules that this one requires, followed by this
75+
// // module. This must be public if other modules require this
76+
// // one. The outline is similar to the constructor.
77+
// //
78+
// Singleton<Module1>::Instance()->Enable();
79+
// // ...
80+
// Singleton<ModuleN>::Instance()->Enable();
81+
// Module::Enable();
82+
// }
83+
//
6884
// void Startup(RestartLevel level) override;
6985
// void Shutdown(RestartLevel level) override;
7086
// };
7187
//
72-
// Later during initialization, ModuleRegistry::Startup handles most of
73-
// the system's initialization by invoking Startup on each module. The
74-
// Startup function initializes the data required by the module when
75-
// the system starts to run.
76-
//
77-
// The purpose of modules is to avoid the type of totally unstructured
78-
// main() that plagues so many systems.
88+
// Later during initialization, ModuleRegistry::Startup handles most of the
89+
// system's initialization by invoking Startup on each module that has been
90+
// enabled (see the Enable function, below). A Startup function initializes
91+
// the data required by its module when the system initializes or restarts.
7992
//
8093
class Module : public Immutable
8194
{
@@ -95,8 +108,18 @@ class Module : public Immutable
95108
static const ModuleId MaxId;
96109

97110
// Enables the module. Overridden to invoke this function on modules
98-
// that this one requires, after which this version must be invoked.
99-
// May only be invoked during a RestartReboot (first initialization).
111+
// that this one requires (the same ones that its constructor created),
112+
// after which this version must be invoked. Only invoked during a
113+
// RestartReboot (initial launch), when NodeBase (the lowest layer)
114+
// has initialized. This function is invoked on each module whose
115+
// Symbol() appears in the configuration parameter OptionalModules,
116+
// which in turn causes it to enable the modules that it requires.
117+
// If a module is not enabled as the result of this procedure, its
118+
// Startup function is not invoked. This allows a single executable
119+
// with various optiona capabilities to be built, and a subset of those
120+
// capabilities to be enabled by the OptionalModules parameter. The
121+
// executable's capabilities can later be modified by editing that
122+
// parameter in the configuration file and performing a reboot restart.
100123
//
101124
virtual void Enable();
102125

src/nb/ModuleRegistry.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "Memory.h"
4444
#include "Module.h"
4545
#include "NbLogs.h"
46+
#include "NbModule.h"
4647
#include "NbSignals.h"
4748
#include "Restart.h"
4849
#include "RootThread.h"
@@ -332,6 +333,12 @@ void ModuleRegistry::EnableModules() const
332333

333334
if(Restart::GetLevel() != RestartReboot) return;
334335

336+
// NbModule is enabled by default, and its Startup function actually
337+
// invokes us. Enable it explicitly for cosmetic purposes, so that
338+
// it will be marked enabled in the output of the >modules command.
339+
//
340+
Singleton<NbModule>::Instance()->Enable();
341+
335342
string enabled = modulesCfg_->CurrValue();
336343

337344
for(auto sym = GetSymbol(enabled); !sym.empty(); sym = GetSymbol(enabled))

0 commit comments

Comments
 (0)