Files
salmanoff/main.cpp
T
hayodea bffc32519b ComponentThreads: now basics are working.
Next step is to get the unified event loops working generically
and then we can begin region-splitting up the data in harikoff.

We'll assign all the global resource managers to Marionette and
then assign the Mind components to the respective component threads.
2025-01-11 04:35:11 -04:00

99 lines
2.3 KiB
C++

#include <iostream>
#include <exception>
#include <thread>
#include <mutex>
#include <unordered_map>
#include <condition_variable>
#include <boost/asio.hpp>
#include <opts.h>
#include <mind.h>
#include <deviceManager/deviceManager.h>
#include <senseApis/senseApiManager.h>
#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;
// Validate thread IDs
hk::ComponentThread::validateThreadIds();
int ret = hk::initializeHarikoff(argc, argv, envp);
if (ret != 0) {
return ret;
}
// Signal all threads
for (const auto& [id, componentThread]
: hk::ComponentThread::componentThreads) {
hk::ComponentThread::signalThread(id);
}
// Infinite loop calling yield
while (true) {
std::this_thread::yield();
}
}
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);
}
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;
}
std::cout << options.stringifyOptions() << std::endl;
DeviceManager::getInstance().collateAllDeviceSpecs();
DeviceManager::getInstance().parseAllDeviceSpecs();
std::cout << DeviceManager::stringifyDeviceSpecs() << std::endl;
sense_api::SenseApiManager::getInstance().loadAllSenseApiLibsFromOptions();
/* Start the threads */
std::cout << __func__ << ": Exiting" << std::endl;
return 0;
}
} // namespace hk