From 381b6505b5afaacc9194168697f6bc93c43d2775 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Wed, 6 Jan 2021 21:52:53 +0100 Subject: Access services via Server object --- include/erebos/message.h | 10 +++++++--- include/erebos/network.h | 11 +++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/erebos/message.h b/include/erebos/message.h index c94e8c3..66d221c 100644 --- a/include/erebos/message.h +++ b/include/erebos/message.h @@ -4,11 +4,14 @@ #include #include +#include #include #include namespace erebos { +using std::unique_ptr; + class Identity; class DirectMessage @@ -78,13 +81,14 @@ public: void handle(Context &) const override; typedef std::function ThreadWatcher; - static void onUpdate(ThreadWatcher); - static DirectMessageThread thread(const Identity &); + void onUpdate(ThreadWatcher); + DirectMessageThread thread(const Identity &); - static DirectMessage send(const Identity &, const Peer &, const std::string &); + DirectMessage send(const Identity &, const Peer &, const std::string &); private: struct Priv; + unique_ptr p; }; } diff --git a/include/erebos/network.h b/include/erebos/network.h index d730fb5..a2f989e 100644 --- a/include/erebos/network.h +++ b/include/erebos/network.h @@ -4,6 +4,7 @@ #include #include +#include namespace erebos { @@ -13,14 +14,24 @@ public: Server(const Identity &, std::vector> &&); ~Server(); + template S & svc(); + class PeerList & peerList() const; struct Peer; private: + Service & svcHelper(const std::type_info &); + struct Priv; const std::shared_ptr p; }; +template +S & Server::svc() +{ + return dynamic_cast(svcHelper(typeid(S))); +} + class Peer { public: -- cgit v1.2.3