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 --- include/erebos/network.h | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'include/erebos/network.h') diff --git a/include/erebos/network.h b/include/erebos/network.h index b47efee..c211fbf 100644 --- a/include/erebos/network.h +++ b/include/erebos/network.h @@ -10,11 +10,16 @@ struct sockaddr_in; namespace erebos { +using std::vector; +using std::unique_ptr; + +class ServerConfig; + class Server { struct Priv; public: - Server(const Head &, std::vector> &&); + Server(const Head &, ServerConfig &&); Server(const std::shared_ptr &); ~Server(); @@ -36,12 +41,42 @@ private: const std::shared_ptr p; }; +class ServerConfig +{ +public: + ServerConfig() = default; + ServerConfig(const ServerConfig &) = delete; + ServerConfig(ServerConfig &&) = default; + ServerConfig & operator=(const ServerConfig &) = delete; + ServerConfig & operator=(ServerConfig &&) = default; + + template + typename S::Config & service(); + +private: + friend class Server; + vector(const Server &)>> services; +}; + template S & Server::svc() { return dynamic_cast(svcHelper(typeid(S))); } +template +typename S::Config & ServerConfig::service() +{ + auto config = make_shared(); + auto & configRef = *config; + + services.push_back([config = move(config)](const Server & server) { + return make_unique(move(*config), server); + }); + + return configRef; +} + class Peer { public: -- cgit v1.2.3