Some further achitecture thoguhts
This commit is contained in:
parent
ac8db32552
commit
b997972ec1
@ -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})
|
||||
|
13
component/CMakeLists.txt
Normal file
13
component/CMakeLists.txt
Normal file
@ -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})
|
4
component/actor.cpp
Normal file
4
component/actor.cpp
Normal file
@ -0,0 +1,4 @@
|
||||
// SPDX-FileCopyrightText: 2024 Yury Gubich <blue@macaw.me>
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "actor.h"
|
7
component/actor.h
Normal file
7
component/actor.h
Normal file
@ -0,0 +1,7 @@
|
||||
// SPDX-FileCopyrightText: 2024 Yury Gubich <blue@macaw.me>
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
class Actor {
|
||||
};
|
@ -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:
|
@ -9,7 +9,7 @@
|
||||
#include <gloox/messagehandler.h>
|
||||
#include <gloox/message.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "component/config.h"
|
||||
|
||||
class Message : public gloox::MessageHandler {
|
||||
public:
|
11
jay.cpp
11
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<Actor>());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Jay::addLogger(gloox::LogLevel level) {
|
||||
loggers.emplace_back(std::make_unique<Logger>(client->logInstance(), level));
|
||||
|
13
jay.h
13
jay.h
@ -13,10 +13,11 @@
|
||||
#include <gloox/disco.h>
|
||||
#include <gloox/connectionlistener.h>
|
||||
|
||||
#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<std::string, std::unique_ptr<Actor>> Actors;
|
||||
|
||||
std::mutex runMutex;
|
||||
std::shared_ptr<Config> config;
|
||||
std::shared_ptr<gloox::Client> client;
|
||||
std::unique_ptr<Message> messageHandler;
|
||||
std::unique_ptr<Connection> connectionHandler;
|
||||
std::vector<std::unique_ptr<Logger>> loggers;
|
||||
Actors actors;
|
||||
};
|
||||
|
1
main.cpp
1
main.cpp
@ -2,7 +2,6 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "jay.h"
|
||||
#include "logger.h"
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
11
module/CMakeLists.txt
Normal file
11
module/CMakeLists.txt
Normal file
@ -0,0 +1,11 @@
|
||||
set(SOURCES
|
||||
module.cpp
|
||||
owner.cpp
|
||||
)
|
||||
|
||||
set(HEADERS
|
||||
module.h
|
||||
owner.h
|
||||
)
|
||||
|
||||
target_sources(${EXEC_NAME} PRIVATE ${SOURCES})
|
9
module/module.cpp
Normal file
9
module/module.cpp
Normal file
@ -0,0 +1,9 @@
|
||||
// SPDX-FileCopyrightText: 2024 Yury Gubich <blue@macaw.me>
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "module.h"
|
||||
|
||||
Module::Module()
|
||||
{}
|
||||
|
||||
Module::~Module() noexcept {}
|
12
module/module.h
Normal file
12
module/module.h
Normal file
@ -0,0 +1,12 @@
|
||||
// SPDX-FileCopyrightText: 2024 Yury Gubich <blue@macaw.me>
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
class Module {
|
||||
protected:
|
||||
Module();
|
||||
|
||||
public:
|
||||
virtual ~Module() noexcept;
|
||||
};
|
10
module/owner.cpp
Normal file
10
module/owner.cpp
Normal file
@ -0,0 +1,10 @@
|
||||
// SPDX-FileCopyrightText: 2024 Yury Gubich <blue@macaw.me>
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "owner.h"
|
||||
|
||||
Owner::Owner():
|
||||
Module()
|
||||
{}
|
||||
|
||||
Owner::~Owner() noexcept {}
|
12
module/owner.h
Normal file
12
module/owner.h
Normal file
@ -0,0 +1,12 @@
|
||||
// SPDX-FileCopyrightText: 2024 Yury Gubich <blue@macaw.me>
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "module.h"
|
||||
|
||||
class Owner : public Module {
|
||||
public:
|
||||
Owner();
|
||||
~Owner() noexcept;
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user