Mind: Implement initialize/finalizeBodyReq()

We've done a lot of general work on the init sequencing.
This commit is contained in:
2025-09-12 16:09:26 -04:00
parent b99b147959
commit 25a9721f92
10 changed files with 294 additions and 163 deletions
+23 -37
View File
@@ -47,7 +47,7 @@ void ComponentThread::marionetteMain(ComponentThread& self)
self.initializeTls();
mrntt::exitCode = EXIT_SUCCESS;
static boost::asio::signal_set signals(self.getIoService(), SIGINT);
bool callFinalizeReq = false, callShutdownSalmanoffReq = false;
bool callFinalizeReq = false, callShutdownSalmanoff = false;
try {
// Register SIGINT (Ctrl+C) and SIGSEGV handlers
@@ -88,6 +88,9 @@ void ComponentThread::marionetteMain(ComponentThread& self)
throw JustPrintUsageNoError(options);
}
initializeSalmanoff();
callShutdownSalmanoff = true;
self.getIoService().post([]()
{
/** EXPLANATION:
@@ -109,22 +112,17 @@ void ComponentThread::marionetteMain(ComponentThread& self)
* easier to implement.
*/
globalMind->initializeReq(
[](bool success)
[](bool success)
{
if (!success)
{
if (success) {
initializeSalmanoff([](bool success) {
if (!success) {
std::cerr << "Failed to initialize "
"Salmanoff" << '\n';
}
});
}
else {
std::cerr << "Failed to initialize Mind object "
"(threads)" << '\n';
}
std::cerr << "Failed to initialize Mind object "
"(threads)" << '\n';
}
);
std::cout << "Mrntt: Mind object (threads) initialized."
<< '\n';
});
});
std::cout << __func__ << ": Entering event loop" << "\n";
@@ -188,43 +186,26 @@ void ComponentThread::marionetteMain(ComponentThread& self)
}
*out << outUsageMsg << e.what() << std::endl;
callShutdownSalmanoffReq = callFinalizeReq = true;
callFinalizeReq = true;
}
catch (const std::exception& e)
{
std::cerr << __func__ << ": Exception occurred: " << e.what()
<< std::endl;
mrntt::exitCode = EXIT_FAILURE;
callShutdownSalmanoffReq = callFinalizeReq = true;
callShutdownSalmanoff = callFinalizeReq = true;
}
catch (...)
{
std::cerr << __func__ << ": Unknown exception occurred" << std::endl;
mrntt::exitCode = EXIT_FAILURE;
callShutdownSalmanoffReq = callFinalizeReq = true;
}
if (callShutdownSalmanoffReq)
{
shutdownSalmanoff(
[](bool success)
{
if (success) {
std::cout << "Salmanoff shutdown completed successfully"
<< std::endl;
} else {
std::cerr << "Salmanoff shutdown failed" << std::endl;
}
mrntt::mrntt->getIoService().stop();
}
);
self.getIoService().reset();
self.getIoService().run();
callShutdownSalmanoff = callFinalizeReq = true;
}
if (callFinalizeReq)
{
globalMind->finalizeReq([](bool success) {
globalMind->finalizeReq([](bool success)
{
if (!success) {
std::cerr << "Failed to finalize Mind object (threads)" << '\n';
}
@@ -233,6 +214,11 @@ void ComponentThread::marionetteMain(ComponentThread& self)
self.getIoService().reset();
self.getIoService().run();
}
if (callShutdownSalmanoff) {
shutdownSalmanoff();
}
}
} // namespace smo