diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2023-05-06 17:09:32 +0200 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2023-05-06 18:54:24 +0200 |
commit | 25a1ba71e3cf4250489291f688423963aa603498 (patch) | |
tree | fb1e23060b810237316f4cde6524c0b1a66d5d0e /src/network.cpp | |
parent | 07f61b1ad6363cd471b7dab3f94c3160636fd6a0 (diff) |
Server and services configuration using separate objects
Diffstat (limited to 'src/network.cpp')
-rw-r--r-- | src/network.cpp | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/network.cpp b/src/network.cpp index dafab67..5c268ae 100644 --- a/src/network.cpp +++ b/src/network.cpp @@ -24,11 +24,12 @@ using std::unique_lock; using namespace erebos; -Server::Server(const Head<LocalState> & head, vector<unique_ptr<Service>> && svcs): - p(new Priv(head, *head->identity(), std::move(svcs))) +Server::Server(const Head<LocalState> & head, ServerConfig && config): + p(new Priv(head, *head->identity())) { - for (const auto & s : p->services) - s->serverStarted(*this); + p->services.reserve(config.services.size()); + for (const auto & ctor : config.services) + p->services.emplace_back(ctor(*this)); } Server:: Server(const std::shared_ptr<Priv> & ptr): @@ -223,13 +224,11 @@ void PeerList::onUpdate(function<void(size_t, const Peer *)> w) } -Server::Priv::Priv(const Head<LocalState> & local, const Identity & self, - vector<unique_ptr<Service>> && svcs): +Server::Priv::Priv(const Head<LocalState> & local, const Identity & self): self(self), // Watching needs to start after self is initialized localState(local.behavior()), - localHead(local.watch(std::bind(&Priv::handleLocalHeadChange, this, std::placeholders::_1))), - services(std::move(svcs)) + localHead(local.watch(std::bind(&Priv::handleLocalHeadChange, this, std::placeholders::_1))) { struct ifaddrs * raddrs; if (getifaddrs(&raddrs) < 0) |