Some more thoughts
This commit is contained in:
parent
b997972ec1
commit
bc2dc9bf07
18 changed files with 146 additions and 42 deletions
|
@ -2,12 +2,14 @@ set(SOURCES
|
|||
config.cpp
|
||||
logger.cpp
|
||||
actor.cpp
|
||||
router.cpp
|
||||
)
|
||||
|
||||
set(HEADERS
|
||||
config.h
|
||||
logger.h
|
||||
actor.h
|
||||
router.h
|
||||
)
|
||||
|
||||
target_sources(${EXEC_NAME} PRIVATE ${SOURCES})
|
||||
|
|
|
@ -2,3 +2,11 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "actor.h"
|
||||
|
||||
Actor::Actor(const std::string& group) :
|
||||
group(group)
|
||||
{}
|
||||
|
||||
void Actor::setGroup(const std::string& newGroup) {
|
||||
group = newGroup;
|
||||
}
|
||||
|
|
|
@ -3,5 +3,14 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
class Actor {
|
||||
public:
|
||||
Actor(const std::string& group);
|
||||
|
||||
void setGroup(const std::string& newGroup);
|
||||
|
||||
private:
|
||||
std::string group;
|
||||
};
|
||||
|
|
|
@ -46,14 +46,14 @@ gloox::TLSPolicy Config::getTLSPolicy() const {
|
|||
}
|
||||
|
||||
|
||||
std::set<std::string> Config::getOwners() const {
|
||||
std::set<std::string> result;
|
||||
YAML::Node owners = root["resource"];
|
||||
if (!owners.IsSequence())
|
||||
std::map<std::string, std::string> Config::getOwners() const {
|
||||
std::map<std::string, std::string> result;
|
||||
YAML::Node owners = root["actors"];
|
||||
if (!owners.IsMap())
|
||||
return result;
|
||||
|
||||
for (const YAML::Node& node : owners)
|
||||
result.insert(node.as<std::string>());
|
||||
for (const auto& node : owners)
|
||||
result.emplace(node.first.as<std::string>(), node.second.as<std::string>());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <set>
|
||||
#include <map>
|
||||
|
||||
#include "gloox/gloox.h"
|
||||
|
||||
|
@ -20,7 +20,7 @@ public:
|
|||
std::string getFullJID() const;
|
||||
std::string getPassword() const;
|
||||
std::string getResource() const;
|
||||
std::set<std::string> getOwners() const;
|
||||
std::map<std::string, std::string> getOwners() const;
|
||||
gloox::LogLevel getLogLevel() const;
|
||||
gloox::TLSPolicy getTLSPolicy() const;
|
||||
|
||||
|
|
30
component/router.cpp
Normal file
30
component/router.cpp
Normal file
|
@ -0,0 +1,30 @@
|
|||
// SPDX-FileCopyrightText: 2024 Yury Gubich <blue@macaw.me>
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "router.h"
|
||||
|
||||
Router::Router():
|
||||
actors(),
|
||||
defaultGroup("Stranger")
|
||||
{}
|
||||
|
||||
void Router::registerModule(const std::string& key, const std::shared_ptr<Module::Module>& module) {
|
||||
modules[key] = module;
|
||||
}
|
||||
|
||||
|
||||
void Router::registerActor(const std::string& key, const std::string& group) {
|
||||
if (key == "default") {
|
||||
defaultGroup = group;
|
||||
return;
|
||||
}
|
||||
|
||||
Actors::iterator act = actors.find(key);
|
||||
if (act == actors.end())
|
||||
actors.emplace(key, group);
|
||||
else
|
||||
act->second.setGroup(group);
|
||||
}
|
||||
|
||||
void Router::routeMessage(const std::string& sender, const std::string& body) {
|
||||
}
|
28
component/router.h
Normal file
28
component/router.h
Normal file
|
@ -0,0 +1,28 @@
|
|||
// SPDX-FileCopyrightText: 2024 Yury Gubich <blue@macaw.me>
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
|
||||
#include "actor.h"
|
||||
#include "module/module.h"
|
||||
|
||||
class Router {
|
||||
public:
|
||||
Router();
|
||||
|
||||
void registerModule(const std::string& key, const std::shared_ptr<Module::Module>& module);
|
||||
void registerActor(const std::string& key, const std::string& group);
|
||||
void routeMessage(const std::string& sender, const std::string& body);
|
||||
|
||||
private:
|
||||
typedef std::map<std::string, std::weak_ptr<Module::Module>> Modules;
|
||||
typedef std::map<std::string, Actor> Actors;
|
||||
|
||||
Modules modules;
|
||||
Actors actors;
|
||||
std::string defaultGroup;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue