8#if !defined(ALIB_C20_MODULES) || ((ALIB_C20_MODULES != 0) && (ALIB_C20_MODULES != 1))
9# error "Configuration MACRO ALIB_C20_MODULES has to be given to the compiler as either 0 or 1"
26 import ALib.EnumRecords;
27 import ALib.EnumRecords.Bootstrap;
28 import ALib.Variables;
48 "A second instance of the App-singleton was created, which is forbidden.")
54 { States::SetCamps , &App::onBsSetCamps },
55 { States::PrepareResources , &App::onBsPrepareResources },
56 { States::SetNameVersionAndInfo , &App::onBsSetNameVersionAndInfo },
57 { States::PrepareConfig , &App::onBsPrepareConfig },
58 { States::PreloadVariables , &App::onBsPreloadVariables },
59 { States::ImportConfig , &App::onBsImportConfig },
60 { States::FinalizeBootstrap , &App::onBsFinalizeBootstrap },
61 { States::SetupALox , &App::onBsSetupALox },
62 { States::RunStart , &App::onRunStart },
63 { States::Run , &App::onRun },
64 { States::RunEnd , &App::onRunEnd },
65 { States::AnnounceShutdown , &App::onSdAnnounceShutdown },
66 { States::CleanALox , &App::onSdCleanALox },
67 { States::ExportConfig , &App::onSdExportConfig },
68 { States::Output , &App::onSdOutput },
69 { States::FinalizeShutdown , &App::onSdFinalizeShutdown },
75int App::Main(
int argc,
const char** argv,
const wchar_t** argvw ) {
103 "Exceptions::ControlledEarlyExit thrown while not in States::Run")
105 "Exceptions::ControlledEarlyExit thrown without having exit code set")
113 catch( std::runtime_error& e ) {
114 cErr->Add(
"Unhandled system exception: ", e.what());
119 "This should be done by the user of class ALib App.")
133 return machine.GetExitCode().Integral<
int>();
163 "<- Exceptions::ControlledEarlyExit was trown here!" );
164 machine.DbgDumpFurtherExitCodes(target);
174 cErr->Add(
"Exception occurred when executing command:\n"
176 "Exception details ({} item{}):",
177 cmdLine, exception.
Size(), (exception.
Size() > 1 ?
"s" :
"") )
179 .Add( exception.
Format() )
183 cErr->Add(
"Application exit-code will be: ",
machine.GetExitCode() );
186 machine.DbgDumpFurtherExitCodes(target);
194 if ( !
files.size() ) {
200 p.
Add(
"Configuration file: {!ATab}:1\n", fileInfo.Pathname );
201 p.
Add(
" Existed: {!ATab}\n", fileInfo.WasEmpty ?
"no" :
"yes" );
203 if ( fileInfo.Exports.IsNotEmpty() ) {
206 p.
Add(
" Exports: {!ATab}\n" , tok.
Next() );
216 String128 resourceName(
"CFGF_NAME_"); resourceName << (cnt+1);
220 files.emplace_back();
221 files.at(cnt).Pathname= name;
228 if ( fInfo.Comment.IsEmpty() ) {
229 String128 resourceName(
"CFGF_CMT_"); resourceName << (cnt+1);
230 fInfo.Comment=
appCamp->TryResource( resourceName );
238 String128 resourceName(
"CFGF_EXP_"); resourceName << (cnt+1);
239 fInfo.Exports=
appCamp->TryResource( resourceName );
247 String128 resourceName(
"CFGF_EXP_"); resourceName << (cnt+1);
249 if (exports.IsNull() )
251 additionalExports <<
',' << exports;
257 "Config-exports {!Q} found, but no config-file is created by the application",
272 if (fileInfo.Pathname.IsEmpty() || fileInfo.Pathname.IsAbsolute())
275 Path backup(fileInfo.Pathname);
276 if (fileInfo.Pathname.CharAtStart() ==
'.')
277 fileInfo.Pathname.Change( SystemFolders::Current, backup );
279 fileInfo.Pathname.Change( SystemFolders::HomeConfig, backup );
285 while (
files.size() &&
files.back().Pathname.IsEmpty())
301 #if ALIB_DEBUG_RESOURCES
310 if(
cOut->LineWidth == 0) {
343 for (
size_t fileNo= 0; fileNo <
files.size() ; ++fileNo ) {
366 "DEBUG_LOGGER already created. Obviously logging was used "
367 "prior to the invocation of bs30SetupALox. This can cause issues" )
398 pacl->SetVerbosityExport(&
LOG_LOX,
true );
423 if (fileInfo.Pathname.IsEmpty())
434 auto& tok= tknzr.
Next();
435 int changes= iniFileFeeder.
ExportSubTree( tok, tok.Equals(
"/") );
437 cntChanges+= changes;
443 && fileInfo.Comment.IsNotEmpty() ) {
448 .RemoveLastNewLine();
449 iniFile.FileComments.Allocate(iniFile.Allocator, buf);
459 if( cntChanges > 0 ) iniFileFeeder.
ExportEnd( fileInfo.Pathname );
467 if (
cOut->Buffer.IsNotEmpty() ) {
468 std::cout <<
cOut->Buffer;
470 std::cout << std::endl;
471 cOut->Buffer.Reset();
475 if (
cErr->Buffer.IsNotEmpty() ) {
476 std::cerr <<
cErr->Buffer;
478 std::cerr << std::endl;
479 cErr->Buffer.Reset();
487 "Debug logging used somewhere, although the flag UseReleaseLoggerForDebugLogging is set." )
491 #if ALIB_DEBUG_RESOURCES
492 std::cout << std::endl;
493 std::cout <<
"---------------- Resource Pool Dump ----------------" << std::endl;
494 auto resourceList= mainCamp->GetResourcePool().DbgGetList();
496 std::cout <<
"---------------- Resource Pool Dump (end) ----------" << std::endl;
500 #if ALIB_DEBUG_BOXING
501 std::cout << std::endl;
502 std::cout <<
"---------------- Debug Boxing ----------------" << std::endl;
506 std::cout <<
"---------------- Debug Boxing (end) ----------" << std::endl;
#define ALIB_WARNING(domain,...)
#define ALIB_LOCK_RECURSIVE_WITH(lock)
#define ALIB_ASSERT_ERROR(cond, domain,...)
#define Log_GetLogger(identifier, name)
#define Lox_RemoveLogger(logger)
#define Lox_SetVerbosity(...)
virtual void onBsImportConfig()
virtual void onBsPreloadVariables()
virtual void onBsSetNameVersionAndInfo()
@ FinalizeBootstrap
Invokes the virtual method onBsFinalizeBootstrap.
@ FinalizeShutdown
Invokes the virtual method onSdFinalizeShutdown.
@ Run
Invokes the virtual method onRun.
@ ImportConfig
Invokes the virtual method onBsImportConfig.
virtual void onSdFinalizeShutdown()
virtual void onBsSetCamps()
StateMachine machine
The state-machine singleton.
virtual int Main(int argc, const char **argv, const wchar_t **argvw=nullptr)
virtual void onSdOutput()
virtual void getConfigFilePathsFromResources(StdVectorMA< ConfigFileDescriptor > &files)
virtual void onBsPrepareConfig()
virtual ~App()
Virtual destructor.
virtual Enum exceptionToExitCode(alib::Exception &exception)
@ UseReleaseLoggerForDebugLogging
@ ALoxVerbosityExportAllAndWriteBackDbgLogger
@ ALoxVerbosityExportAllAndWriteBackRelLogger
virtual void onSdCleanALox()
virtual void onBsPrepareResources()
virtual void printConfigFileInfo(Paragraphs &target)
virtual void exceptionDisplay(Exception &exception, AString &target)
virtual void onBsSetupALox()
Flags flags
Various boolean flags used to configure the application.
virtual void onSdAnnounceShutdown()
virtual void getConfigFilePaths(StdVectorMA< ConfigFileDescriptor > &files)
virtual void getConfigFilePathsMakeAbsolutePaths(StdVectorMA< ConfigFileDescriptor > &files)
lox::textlogger::TextLogger * releaseLogger
@ ErrUnknown
An unknown exception occurred.
@ ErrConfigFileNotWritable
The configuration file(s) could not be written.
virtual void onBsFinalizeBootstrap()
Paragraphs * cErr
Same as cOut, but used for stream std::err.
virtual void onSdExportConfig()
AString & Format(AString &target) const
const Enum & Type() const
static textlogger::TextLogger * DEBUG_LOGGER
The debug logger created by AddDebugLogger.
static void SetALibAssertionPlugin(Lox *lox)
static textlogger::TextLogger * CreateConsoleLogger(const NString &name=nullptr)
static std::ostream * DbgResourceLoadObserver
TAString & InsertAt(const TString< TChar > &src, integer pos)
TAString & DeleteStart(integer regionLength)
constexpr bool IsEmpty() const
void Allocate(TAllocator &allocator, const TString< TChar > ©)
constexpr bool IsNotEmpty() const
TSubstring< TChar > & Next(lang::Whitespaces trimming=lang::Whitespaces::Trim, TChar newDelim='\0')
static int GetWidth(bool forceRedetect=false, int defaultWidth=80)
static const ProcessInfo & Current()
void ExportEnd()
Closes and deletes the internal iniFile instance without writing an opened INI-file.
int AddResourcedSectionComments(ResourcePool &resourcePool, const NString &resourceCategory, const NString &resourceNamePrefix)
int ExportSubTree(Configuration::Cursor cursor, bool directChildrenOnly=false)
int ImportStart(const system::Path &path)
bool DidNotExistOrWasEmpty
void ImportEnd()
Closes and deletes the internal iniFile instance.
int ExportStart(const system::Path &path)
void Raise(const lang::CallerInfo &ci, int type, std::string_view domain, TArgs &&... args)
std::vector< std::pair< const std::type_info *, uinteger > > GetKnownFunctionTypes()
AString DumpFunctions(const std::vector< std::pair< const std::type_info *, uinteger > > &input, const String &headline, const String &indent)
AString DumpVTables(bool staticVtables, bool includeFunctions)
RecursiveLock GLOBAL_ALLOCATOR_LOCK
TMonoAllocator< lang::HeapAllocator > GLOBAL_ALLOCATOR
AString DbgDump(std::vector< std::tuple< NString, NString, String, integer > > &list, const NString &catFilter, const String &format)
@ ErrorWritingFile
An error occurred writing the file .
@ ErrorOpeningFile
File not found when reading.
ListMA< camp::Camp * > CAMPS
void BootstrapAddDefaultCamps()
void Bootstrap(BootstrapPhases targetPhase, camp::Camp *targetCamp, int alibVersion, int alibRevision, TCompilationFlags compilationFlags)
strings::util::TTokenizer< character > Tokenizer
Type alias in namespace alib.
constexpr CString NEW_LINE
A zero-terminated string containing the new-line character sequence.
lox::ALoxCamp ALOX
The singleton instance of ALib Camp class #"ALoxCamp".
monomem::TLocalAllocator< 2 > LocalAllocator2K
Type alias in namespace alib. Allocates 2kB of stack memory.
LocalString< 4096 > String4K
Type alias name for #"TLocalString;TLocalString<character,4096>".
strings::TString< character > String
Type alias in namespace alib.
system::Path Path
Type alias in namespace alib.
camp::Basecamp BASECAMP
The singleton instance of ALib Camp class #"Basecamp".
LocalString< 1024 > String1K
Type alias name for #"TLocalString;TLocalString<character,1024>".
exceptions::Exception Exception
Type alias in namespace alib.
strings::util::CalendarDateTime CalendarDateTime
Type alias in namespace alib.
LocalString< 128 > String128
Type alias name for #"TLocalString;TLocalString<character,128>".
strings::TAString< character, lang::HeapAllocator > AString
Type alias in namespace alib.
format::Paragraphs Paragraphs
Type alias in namespace alib.
std::vector< T, StdMA< T > > StdVectorMA
Type alias in namespace alib.
strings::TStringLengthResetter< character,lang::HeapAllocator > StringLengthResetter
Type alias in namespace alib.
time::DateTime DateTime
Type alias in namespace alib.
boxing::Enum Enum
Type alias in namespace alib.
LocalString< 512 > String512
Type alias name for #"TLocalString;TLocalString<character,512>".
variables::IniFileFeeder IniFileFeeder
Type alias in namespace alib.
Path Pathname
The resolved full path to the file.
bool WasEmpty
If set, the file did not exist or was empty at the start of the application.
A struct denoting the next state and the corresponding method to execute.
CallerInfo CI
The source code location that this message relates to.
void(* Custom)(App &)
A pointer to a method of a custom derived type.
void(App::* BuiltIn)()
A pointer to a virtual method of class App.