// SPDX-FileCopyrightText: 2024 Yury Gubich // SPDX-License-Identifier: GPL-3.0-or-later #include "jay.h" #include "module/actor.h" #include "module/publish.h" static const std::map< std::string, std::function< std::shared_ptr( const std::shared_ptr&, const Config::Module& conf ) > > moduleNames = { {"actor", []( const std::shared_ptr& core, const Config::Module& conf ) { return std::make_shared(core, conf); }}, {"publish", []( const std::shared_ptr& core, const Config::Module& conf ) { return std::make_shared(core, conf); }} }; Jay::Jay(const std::string& configPath): core(std::make_shared(configPath)), connection(std::make_shared(core)), modules() {} Jay::~Jay() { connection->deinitialize(); } bool Jay::isConfigValid() const { return core->config.isValid(); } void Jay::run() { initialize(); connection->connect(); } void Jay::initialize() { createModules(); core->initialize(connection); connection->initialize(); } void Jay::createModules() { for (const Config::Module& conf : core->config.getModules()) { if (!conf.enabled) continue; auto itr = moduleNames.find(conf.type); if (itr == moduleNames.end()) continue; modules.emplace_back(itr->second(core, conf)); core->router.registerModule(modules.back()); } }