64 lines
1.6 KiB
C++
64 lines
1.6 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 Shared::Permissions& permissions
|
|
)
|
|
>
|
|
> moduleNames = {
|
|
{"actor", [](
|
|
const std::shared_ptr<Core>& core,
|
|
const Shared::Permissions& permissions
|
|
) { return std::make_shared<Module::Actor>(core, permissions); }},
|
|
{"publish", [](
|
|
const std::shared_ptr<Core>& core,
|
|
const Shared::Permissions& permissions
|
|
) { return std::make_shared<Module::Publish>(core, permissions); }}
|
|
};
|
|
|
|
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 auto& pair : moduleNames) {
|
|
Config::Module conf = core->config.getModuleConfig(pair.first);
|
|
if (!conf.enabled)
|
|
continue;
|
|
|
|
core->logger.log(Shared::Logger::info, "enabling module " + pair.first, {"Jay"});
|
|
modules.emplace_back(pair.second(core, conf.permissions));
|
|
core->router.registerModule(pair.first, modules.back());
|
|
}
|
|
}
|