Files
salmanoff/smocore/marionette/marionette.cpp
T

111 lines
2.8 KiB
C++
Raw Normal View History

#include <config.h>
#include <cstdlib>
#include <iostream>
#include <exception>
#include <opts.h>
#include <componentThread.h>
#include <marionette/marionette.h>
namespace smo {
CrtCommandLineArgs crtCommandLineArgs(0, nullptr, nullptr);
void CrtCommandLineArgs::set(int argc, char *argv[], char *envp[])
{
crtCommandLineArgs = CrtCommandLineArgs(argc, argv, envp);
}
2025-07-22 02:03:09 -04:00
namespace mrntt {
std::atomic<int> exitCode;
}
2025-07-22 02:03:09 -04:00
void ComponentThread::marionetteMain(ComponentThread& self)
2025-07-22 02:03:09 -04:00
{
// Wait for CRT's main() to post us the command line args.
std::cout << __func__ << ": Waiting for command line JOLT" << std::endl;
self.getIoService().run();
self.initializeTls();
mrntt::exitCode = 0;
try {
OptionParser &options = OptionParser::getOptions();
std::cout << __func__ << ": " << PACKAGE_NAME << " " << PACKAGE_VERSION
<< std::endl;
try {
options.parseArguments(
crtCommandLineArgs.argc, crtCommandLineArgs.argv,
crtCommandLineArgs.envp);
std::cout << __func__ << ": " << options.stringifyOptions()
<< std::endl;
}
catch (const std::invalid_argument& e)
{
std::cerr << __func__ << ": Exception occurred: " << e.what()
<< '\n' << options.getUsage() << '\n';
mrntt::exitCode = EXIT_FAILURE;
return;
}
if (options.printUsage)
{
std::cout << __func__ << ": " << options.getUsage() << std::endl;
mrntt::exitCode = EXIT_SUCCESS;
return;
}
int ret = smo::initializeSalmanoff();
if (ret != 0)
{
std::cerr << __func__ << ": Initialization failed with code: "
<< ret << std::endl;
mrntt::exitCode = ret;
return;
}
/* Start the threads */
for (auto& componentThread : smo::ComponentThread::componentThreads)
{
// Post startThread() to the event loop of all threads except MRNTT.
if (componentThread->id == ComponentThread::MRNTT) { continue; }
// JOLT the thread.
componentThread->getIoService().post([componentThread]()
{ componentThread->getIoService().stop(); }
);
// Now tell it to execute its initialization sequence.
componentThread->startThreadReq();
}
body::body->getIoService().post([]{
throw std::runtime_error("test exception");
});
std::cout << __func__ << ": Entering event loop" << "\n";
self.getIoService().reset();
self.getIoService().run();
}
catch (const std::exception& e)
{
std::cerr << __func__ << ": Exception occurred: " << e.what()
<< std::endl;
mrntt::exitCode = EXIT_FAILURE;
return;
}
catch (...)
{
std::cerr << __func__ << ": Unknown exception occurred" << std::endl;
mrntt::exitCode = EXIT_FAILURE;
return;
}
std::cout << __func__ << ": Exiting normally" << std::endl;
2025-07-22 02:03:09 -04:00
}
} // namespace smo