// SPDX-FileCopyrightText: 2024 Yury Gubich // SPDX-License-Identifier: GPL-3.0-or-later #include "core.h" #include "connection/connection.h" Core::Core(const std::string& configPath): config(configPath), logger(config.getLogLevel()), router(logger), initialized(false) {} void Core::send(const std::string& jid, const std::string& body) { std::shared_ptr cn = connection.lock(); if (!cn) { logger.log(Shared::Logger::warning, "Couldn't send a message to " + jid + ", connection is not available", {"Core"}); return; } cn->send(jid, body); } void Core::initialize(const std::shared_ptr& cn) { connection = cn; router.setConnection(cn); if (initialized) return; initializeActors(); initializeResponses(); initialized = true; } void Core::setGroup(const std::string& jid, const std::string& group) { router.registerActor(jid, group); std::map actors = router.getActors(); actors["default"] = router.getDefaultGroup(); config.setActors(actors); } void Core::initializeActors() { for (const std::pair& pair : config.getActors()) { logger.log(Shared::Logger::info, "registering actor " + pair.first + " as " + pair.second, {"Core"}); router.registerActor(pair.first, pair.second); } } void Core::initializeResponses() { for (const std::pair& pair : config.getResponses()) router.setResponses(pair.first, pair.second); }