jay/jay.cpp

60 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"
static const std::map<
std::string,
std::function<
std::shared_ptr<Module::Module>(
const std::shared_ptr<Core>&,
const std::shared_ptr<Connection>&
)
>
> moduleNames = {
{"actor", [](const std::shared_ptr<Core>& core, const std::shared_ptr<Connection>& connection) { return std::make_shared<Module::Actor>(core, connection); }}
};
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() {
connection->initiialize();
createModules();
createActors();
}
void Jay::createActors() {
for (const std::pair<const std::string, std::string>& pair : core->config.getActors())
core->router.registerActor(pair.first, pair.second);
}
void Jay::createModules() {
for (const auto& pair : moduleNames) {
Config::Module conf = core->config.getModuleConfig(pair.first);
if (!conf.enabled)
continue;
modules.emplace_back(pair.second(core, connection));
core->router.registerModule(pair.first, modules.back());
}
}