summaryrefslogtreecommitdiff
path: root/src/network.cpp
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2021-01-06 21:52:53 +0100
committerRoman Smrž <roman.smrz@seznam.cz>2021-01-06 21:52:53 +0100
commit381b6505b5afaacc9194168697f6bc93c43d2775 (patch)
tree1190917b6ee40d6f4a74bf724466b3062ab86f4f /src/network.cpp
parent96eb8471d11667a56466a6f701d1d23fa64c2225 (diff)
Access services via Server object
Diffstat (limited to 'src/network.cpp')
-rw-r--r--src/network.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/network.cpp b/src/network.cpp
index 91f1923..4b79dcb 100644
--- a/src/network.cpp
+++ b/src/network.cpp
@@ -6,6 +6,7 @@
#include <algorithm>
#include <cstring>
#include <iostream>
+#include <stdexcept>
#include <arpa/inet.h>
#include <ifaddrs.h>
@@ -13,6 +14,7 @@
#include <unistd.h>
using std::holds_alternative;
+using std::runtime_error;
using std::scoped_lock;
using std::to_string;
using std::unique_lock;
@@ -26,6 +28,14 @@ Server::Server(const Identity & self, vector<unique_ptr<Service>> && svcs):
Server::~Server() = default;
+Service & Server::svcHelper(const std::type_info & tinfo)
+{
+ for (auto & s : p->services)
+ if (typeid(*s) == tinfo)
+ return *s;
+ throw runtime_error("service not found");
+}
+
PeerList & Server::peerList() const
{
return p->plist;