#include #include #include #include #include #include #include #include #include #include #include #include "componentThread.h" namespace hk { static int initializeHarikoff(int argc, char **argv, char **envp); } // namespace hk int main(int argc, char **argv, char **envp) { try { std::cout << __func__ << ": Entering main()" << std::endl; boost::asio::io_service mrntLoop; boost::asio::io_service::work work(mrntLoop); // Validate thread IDs hk::ComponentThread::validateThreadIds(); // Post initializeHarikoff to mrntLoop mrntLoop.post([&]() { int ret = hk::initializeHarikoff(argc, argv, envp); if (ret != 0) { std::cerr << "Initialization failed with code: " << ret << std::endl; std::exit(ret); } }); mrntLoop.run(); } catch (const std::exception& e) { std::cerr << __func__ << ": Exception occurred: " << e.what() << std::endl; return EXIT_FAILURE; } catch (...) { std::cerr << __func__ << ": Unknown exception occurred" << std::endl; return EXIT_FAILURE; } std::cout << __func__ << ": Exiting normally" << std::endl; return 0; } namespace hk { static int initializeHarikoff(int argc, char **argv, char **envp) { std::cout << __func__ << ": Entering" << std::endl; using namespace hk; OptionParser &options = OptionParser::getOptions(); hk::Mind mind; std::cout << PACKAGE_NAME << " " << PACKAGE_VERSION << std::endl; try { options.parseArguments(argc, argv, envp); std::cout << options.stringifyOptions() << std::endl; } catch (const std::invalid_argument& e) { std::cerr << __func__ << ": Exception occurred: " << e.what() << '\n' << options.getUsage() << '\n'; return EXIT_FAILURE; } if (options.printUsage) { std::cout << options.getUsage() << std::endl; return EXIT_SUCCESS; } DeviceManager::getInstance().collateAllDeviceSpecs(); DeviceManager::getInstance().parseAllDeviceSpecs(); std::cout << DeviceManager::stringifyDeviceSpecs() << std::endl; sense_api::SenseApiManager::getInstance().loadAllSenseApiLibsFromOptions(); /* Start the threads */ for (const auto& [id, componentThread] : hk::ComponentThread::componentThreads) { hk::ComponentThread::signalThread(id); } std::cout << __func__ << ": Exiting" << std::endl; return 0; } } // namespace hk