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/pairing.h | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) (limited to 'include/erebos/pairing.h') diff --git a/include/erebos/pairing.h b/include/erebos/pairing.h index ea349a9..71c9288 100644 --- a/include/erebos/pairing.h +++ b/include/erebos/pairing.h @@ -29,11 +29,6 @@ using std::vector; class PairingServiceBase : public Service { public: - virtual ~PairingServiceBase(); - - typedef function RequestInitHook; - void onRequestInit(RequestInitHook); - enum class Outcome { Success, @@ -44,12 +39,28 @@ public: Stale, }; - typedef function(const Peer &, string, future &&)> ConfirmHook; - void onResponse(ConfirmHook); - void onRequest(ConfirmHook); + using RequestInitHook = function; + using ConfirmHook = function(const Peer &, string, future &&)>; + using RequestNonceFailedHook = function; + + class Config + { + public: + Config & onRequestInit(RequestInitHook); + Config & onResponse(PairingServiceBase::ConfirmHook); + Config & onRequest(PairingServiceBase::ConfirmHook); + Config & onRequestNonceFailed(RequestNonceFailedHook); + + private: + friend class PairingServiceBase; + RequestInitHook requestInitHook; + ConfirmHook responseHook; + ConfirmHook requestHook; + RequestNonceFailedHook requestNonceFailedHook; + }; - typedef function RequestNonceFailedHook; - void onRequestNonceFailed(RequestNonceFailedHook); + PairingServiceBase(Config &&); + virtual ~PairingServiceBase(); protected: void requestPairing(UUID serviceId, const Peer & peer); @@ -62,11 +73,7 @@ private: const vector & nonce1, const vector & nonce2); static string confirmationNumber(const vector &); - RequestInitHook requestInitHook; - ConfirmHook responseHook; - ConfirmHook requestHook; - RequestNonceFailedHook requestNonceFailedHook; - + const Config config; optional result; enum class StatePhase { @@ -99,6 +106,10 @@ private: template class PairingService : public PairingServiceBase { +public: + PairingService(Config && config): + PairingServiceBase(move(config)) {} + protected: virtual Stored handlePairingComplete(const Peer &) = 0; virtual void handlePairingResult(Context &, Stored) = 0; -- cgit v1.2.3