diff --git a/CMakeLists.txt b/CMakeLists.txt index e8f7d11..2a3cf7b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,14 +16,11 @@ find_package(yaml-cpp REQUIRED) set(EXEC_NAME "jay") -add_executable(${EXEC_NAME} - main.cpp - jay.cpp - logger.cpp - config.cpp -) +add_executable(${EXEC_NAME} main.cpp jay.cpp) -add_subdirectory(handlers) +add_subdirectory(component) +add_subdirectory(handler) +add_subdirectory(module) target_include_directories(${EXEC_NAME} PRIVATE ${GLOOX_INCLUDE_DIRS}) target_include_directories(${EXEC_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/component/CMakeLists.txt b/component/CMakeLists.txt new file mode 100644 index 0000000..fa0c995 --- /dev/null +++ b/component/CMakeLists.txt @@ -0,0 +1,13 @@ +set(SOURCES + config.cpp + logger.cpp + actor.cpp +) + +set(HEADERS + config.h + logger.h + actor.h +) + +target_sources(${EXEC_NAME} PRIVATE ${SOURCES}) diff --git a/component/actor.cpp b/component/actor.cpp new file mode 100644 index 0000000..7c21387 --- /dev/null +++ b/component/actor.cpp @@ -0,0 +1,4 @@ +// SPDX-FileCopyrightText: 2024 Yury Gubich +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "actor.h" diff --git a/component/actor.h b/component/actor.h new file mode 100644 index 0000000..7f0ecd6 --- /dev/null +++ b/component/actor.h @@ -0,0 +1,7 @@ +// SPDX-FileCopyrightText: 2024 Yury Gubich +// SPDX-License-Identifier: GPL-3.0-or-later + +#pragma once + +class Actor { +}; diff --git a/config.cpp b/component/config.cpp similarity index 100% rename from config.cpp rename to component/config.cpp diff --git a/config.h b/component/config.h similarity index 100% rename from config.h rename to component/config.h diff --git a/logger.cpp b/component/logger.cpp similarity index 100% rename from logger.cpp rename to component/logger.cpp diff --git a/logger.h b/component/logger.h similarity index 100% rename from logger.h rename to component/logger.h diff --git a/handlers/CMakeLists.txt b/handler/CMakeLists.txt similarity index 100% rename from handlers/CMakeLists.txt rename to handler/CMakeLists.txt diff --git a/handlers/connection.cpp b/handler/connection.cpp similarity index 100% rename from handlers/connection.cpp rename to handler/connection.cpp diff --git a/handlers/connection.h b/handler/connection.h similarity index 95% rename from handlers/connection.h rename to handler/connection.h index c67a48a..ef6ee38 100644 --- a/handlers/connection.h +++ b/handler/connection.h @@ -8,7 +8,7 @@ #include "gloox/client.h" #include "gloox/connectionlistener.h" -#include "config.h" +#include "component/config.h" class Connection : public gloox::ConnectionListener { public: diff --git a/handlers/message.cpp b/handler/message.cpp similarity index 100% rename from handlers/message.cpp rename to handler/message.cpp diff --git a/handlers/message.h b/handler/message.h similarity index 95% rename from handlers/message.h rename to handler/message.h index e44172a..2784394 100644 --- a/handlers/message.h +++ b/handler/message.h @@ -9,7 +9,7 @@ #include #include -#include "config.h" +#include "component/config.h" class Message : public gloox::MessageHandler { public: diff --git a/jay.cpp b/jay.cpp index 48774bc..e445857 100644 --- a/jay.cpp +++ b/jay.cpp @@ -9,7 +9,8 @@ Jay::Jay(const std::string& configPath): client(), messageHandler(), connectionHandler(), - loggers() + loggers(), + actors() {} Jay::~Jay() {} @@ -53,6 +54,14 @@ void Jay::createClient() { client->setStreamManagement(true, true); } +void Jay::createActors() { + for (const std::string& jid : config->getOwners()) { + Actors::const_iterator act = actors.find(jid); + if (act == actors.end()) + actors.emplace(jid, std::make_unique()); + } +} + void Jay::addLogger(gloox::LogLevel level) { loggers.emplace_back(std::make_unique(client->logInstance(), level)); diff --git a/jay.h b/jay.h index e35f353..afcd02c 100644 --- a/jay.h +++ b/jay.h @@ -13,10 +13,11 @@ #include #include -#include "logger.h" -#include "config.h" -#include "handlers/message.h" -#include "handlers/connection.h" +#include "component/logger.h" +#include "component/config.h" +#include "component/actor.h" +#include "handler/message.h" +#include "handler/connection.h" class Jay { public: @@ -31,12 +32,16 @@ private: void addLogger(gloox::LogLevel level); void initialize(); void createClient(); + void createActors(); private: + typedef std::map> Actors; + std::mutex runMutex; std::shared_ptr config; std::shared_ptr client; std::unique_ptr messageHandler; std::unique_ptr connectionHandler; std::vector> loggers; + Actors actors; }; diff --git a/main.cpp b/main.cpp index a6c1e7d..a7d92ec 100644 --- a/main.cpp +++ b/main.cpp @@ -2,7 +2,6 @@ // SPDX-License-Identifier: GPL-3.0-or-later #include "jay.h" -#include "logger.h" #include #include diff --git a/module/CMakeLists.txt b/module/CMakeLists.txt new file mode 100644 index 0000000..4d98992 --- /dev/null +++ b/module/CMakeLists.txt @@ -0,0 +1,11 @@ +set(SOURCES + module.cpp + owner.cpp +) + +set(HEADERS + module.h + owner.h +) + +target_sources(${EXEC_NAME} PRIVATE ${SOURCES}) diff --git a/module/module.cpp b/module/module.cpp new file mode 100644 index 0000000..f9bb1a1 --- /dev/null +++ b/module/module.cpp @@ -0,0 +1,9 @@ +// SPDX-FileCopyrightText: 2024 Yury Gubich +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "module.h" + +Module::Module() +{} + +Module::~Module() noexcept {} diff --git a/module/module.h b/module/module.h new file mode 100644 index 0000000..9c4e3ad --- /dev/null +++ b/module/module.h @@ -0,0 +1,12 @@ +// SPDX-FileCopyrightText: 2024 Yury Gubich +// SPDX-License-Identifier: GPL-3.0-or-later + +#pragma once + +class Module { +protected: + Module(); + +public: + virtual ~Module() noexcept; +}; diff --git a/module/owner.cpp b/module/owner.cpp new file mode 100644 index 0000000..339d082 --- /dev/null +++ b/module/owner.cpp @@ -0,0 +1,10 @@ +// SPDX-FileCopyrightText: 2024 Yury Gubich +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "owner.h" + +Owner::Owner(): + Module() +{} + +Owner::~Owner() noexcept {} diff --git a/module/owner.h b/module/owner.h new file mode 100644 index 0000000..c6401eb --- /dev/null +++ b/module/owner.h @@ -0,0 +1,12 @@ +// SPDX-FileCopyrightText: 2024 Yury Gubich +// SPDX-License-Identifier: GPL-3.0-or-later + +#pragma once + +#include "module.h" + +class Owner : public Module { +public: + Owner(); + ~Owner() noexcept; +};