jay/jay.cpp
2025-03-31 13:02:45 +03:00

66 lines
1.5 KiB
C++

// SPDX-FileCopyrightText: 2024 Yury Gubich <blue@macaw.me>
// 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<Module::Module>(
const std::shared_ptr<Core>&,
const Config::Module& conf
)
>
> moduleNames = {
{"actor", [](
const std::shared_ptr<Core>& core,
const Config::Module& conf
) { return std::make_shared<Module::Actor>(core, conf); }},
{"publish", [](
const std::shared_ptr<Core>& core,
const Config::Module& conf
) { return std::make_shared<Module::Publish>(core, conf); }}
};
Jay::Jay(const std::string& configPath):
core(std::make_shared<Core>(configPath)),
connection(std::make_shared<Connection>(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());
}
}