From 25a1ba71e3cf4250489291f688423963aa603498 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sat, 6 May 2023 17:09:32 +0200 Subject: Server and services configuration using separate objects --- src/network.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src/network.cpp') 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 & head, vector> && svcs): - p(new Priv(head, *head->identity(), std::move(svcs))) +Server::Server(const Head & 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 & ptr): @@ -223,13 +224,11 @@ void PeerList::onUpdate(function w) } -Server::Priv::Priv(const Head & local, const Identity & self, - vector> && svcs): +Server::Priv::Priv(const Head & 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) -- cgit v1.2.3