| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- #include "app.hpp"
- #include <smartbotic/microbit/common/config_loader.hpp>
- #include <smartbotic/microbit/common/logging.hpp>
- #include <spdlog/spdlog.h>
- #include <csignal>
- #include <filesystem>
- #include <iostream>
- namespace {
- std::atomic<bool> g_running{true};
- void signalHandler(int) { g_running = false; }
- }
- int main(int argc, char* argv[]) {
- std::filesystem::path configPath = "config/microbit.json";
- for (int i = 1; i < argc; ++i) {
- std::string arg = argv[i];
- if ((arg == "--config" || arg == "-c") && i + 1 < argc) {
- configPath = argv[++i];
- } else if (arg == "--help" || arg == "-h") {
- std::cout << "Usage: smartbotic-microbit [options]\n"
- << " --config, -c <path> Configuration file path (default: config/microbit.json)\n"
- << " --help, -h Show this help\n";
- return 0;
- }
- }
- try {
- auto config = smartbotic::microbit::ConfigLoader::loadFromFile(configPath);
- auto logLevel = spdlog::level::from_str(
- smartbotic::microbit::ConfigLoader::get<std::string>(config, "log_level", "info"));
- smartbotic::microbit::logging::init("microbit", logLevel);
- std::signal(SIGINT, signalHandler);
- std::signal(SIGTERM, signalHandler);
- std::signal(SIGPIPE, SIG_IGN);
- smartbotic::microbit::App app(config);
- app.start();
- while (g_running && app.isRunning()) {
- std::this_thread::sleep_for(std::chrono::milliseconds(100));
- }
- app.stop();
- } catch (const std::exception& e) {
- spdlog::error("Fatal error: {}", e.what());
- return 1;
- }
- return 0;
- }
|