Mrntt: initializeSalmanoff exceptions handled in outermode catch block
We don't post a message to the event loop telling it to execute initializeSalmanoff anymore. We now execute it in the main control flow. Also, we've unified the logic to call finalizeReq() in response to exceptions in the outermost try block.
This commit is contained in:
@@ -39,6 +39,7 @@ void ComponentThread::marionetteMain(ComponentThread& self)
|
||||
self.initializeTls();
|
||||
mrntt::exitCode = EXIT_SUCCESS;
|
||||
static boost::asio::signal_set signals(self.getIoService(), SIGINT);
|
||||
bool callFinalizeReq = false;
|
||||
|
||||
try {
|
||||
// Register SIGINT (Ctrl+C) handler to request user shutdown
|
||||
@@ -67,9 +68,9 @@ void ComponentThread::marionetteMain(ComponentThread& self)
|
||||
throw JustPrintUsageNoError(options);
|
||||
}
|
||||
|
||||
initializeSalmanoff();
|
||||
self.getIoService().post([]()
|
||||
{
|
||||
initializeSalmanoff();
|
||||
mind.initialize();
|
||||
});
|
||||
|
||||
@@ -110,42 +111,46 @@ void ComponentThread::marionetteMain(ComponentThread& self)
|
||||
}
|
||||
|
||||
std::cout << __func__ << ": Exited event loop" << "\n";
|
||||
shutdownSalmanoff();
|
||||
}
|
||||
catch (const OptionParser::Exception& e)
|
||||
{
|
||||
std::ostream &out = std::cout;
|
||||
std::ostream *out = &std::cout;
|
||||
std::string outUsageMsg;
|
||||
|
||||
if (typeid(e) == typeid(OptionsParserError))
|
||||
{
|
||||
mrntt::exitCode = EXIT_FAILURE;
|
||||
out = &std::cerr;
|
||||
outUsageMsg = std::string(__func__) + ": ";
|
||||
}
|
||||
|
||||
out << outUsageMsg << e.what() << std::endl;
|
||||
mind.finalizeReq([]{
|
||||
mrntt::mrntt->getIoService().stop();
|
||||
});
|
||||
self.getIoService().reset();
|
||||
self.getIoService().run();
|
||||
return;
|
||||
*out << outUsageMsg << e.what() << std::endl;
|
||||
callFinalizeReq = true;
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
std::cerr << __func__ << ": Exception occurred: " << e.what()
|
||||
<< std::endl;
|
||||
mrntt::exitCode = EXIT_FAILURE;
|
||||
return;
|
||||
callFinalizeReq = true;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::cerr << __func__ << ": Unknown exception occurred" << std::endl;
|
||||
mrntt::exitCode = EXIT_FAILURE;
|
||||
return;
|
||||
callFinalizeReq = true;
|
||||
}
|
||||
|
||||
std::cout << __func__ << ": Exiting normally" << std::endl;
|
||||
if (callFinalizeReq)
|
||||
{
|
||||
mind.finalizeReq([]{
|
||||
mrntt::mrntt->getIoService().stop();
|
||||
});
|
||||
self.getIoService().reset();
|
||||
self.getIoService().run();
|
||||
}
|
||||
|
||||
shutdownSalmanoff();
|
||||
}
|
||||
|
||||
} // namespace smo
|
||||
|
||||
Reference in New Issue
Block a user