summaryrefslogtreecommitdiff
path: root/include/erebos/pairing.h
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2023-05-06 17:09:32 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2023-05-06 18:54:24 +0200
commit25a1ba71e3cf4250489291f688423963aa603498 (patch)
treefb1e23060b810237316f4cde6524c0b1a66d5d0e /include/erebos/pairing.h
parent07f61b1ad6363cd471b7dab3f94c3160636fd6a0 (diff)
Server and services configuration using separate objects
Diffstat (limited to 'include/erebos/pairing.h')
-rw-r--r--include/erebos/pairing.h41
1 files changed, 26 insertions, 15 deletions
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<void(const Peer &)> RequestInitHook;
- void onRequestInit(RequestInitHook);
-
enum class Outcome
{
Success,
@@ -44,12 +39,28 @@ public:
Stale,
};
- typedef function<future<bool>(const Peer &, string, future<Outcome> &&)> ConfirmHook;
- void onResponse(ConfirmHook);
- void onRequest(ConfirmHook);
+ using RequestInitHook = function<void(const Peer &)>;
+ using ConfirmHook = function<future<bool>(const Peer &, string, future<Outcome> &&)>;
+ using RequestNonceFailedHook = function<void(const Peer &)>;
+
+ 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<void(const Peer &)> RequestNonceFailedHook;
- void onRequestNonceFailed(RequestNonceFailedHook);
+ PairingServiceBase(Config &&);
+ virtual ~PairingServiceBase();
protected:
void requestPairing(UUID serviceId, const Peer & peer);
@@ -62,11 +73,7 @@ private:
const vector<uint8_t> & nonce1, const vector<uint8_t> & nonce2);
static string confirmationNumber(const vector<uint8_t> &);
- RequestInitHook requestInitHook;
- ConfirmHook responseHook;
- ConfirmHook requestHook;
- RequestNonceFailedHook requestNonceFailedHook;
-
+ const Config config;
optional<Ref> result;
enum class StatePhase {
@@ -99,6 +106,10 @@ private:
template<class Result>
class PairingService : public PairingServiceBase
{
+public:
+ PairingService(Config && config):
+ PairingServiceBase(move(config)) {}
+
protected:
virtual Stored<Result> handlePairingComplete(const Peer &) = 0;
virtual void handlePairingResult(Context &, Stored<Result>) = 0;