From 2abd6593c8b047d3fd579aa6cc0058bbebe266f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sun, 17 Jan 2021 21:59:46 +0100 Subject: Server watching local state head --- include/erebos/network.h | 4 ++-- include/erebos/storage.h | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/erebos/network.h b/include/erebos/network.h index a2f989e..8f3debe 100644 --- a/include/erebos/network.h +++ b/include/erebos/network.h @@ -1,7 +1,7 @@ #pragma once -#include #include +#include #include #include @@ -11,7 +11,7 @@ namespace erebos { class Server { public: - Server(const Identity &, std::vector> &&); + Server(const Head &, std::vector> &&); ~Server(); template S & svc(); diff --git a/include/erebos/storage.h b/include/erebos/storage.h index 34ed9df..29eaa8f 100644 --- a/include/erebos/storage.h +++ b/include/erebos/storage.h @@ -107,6 +107,7 @@ protected: static UUID storeHead(UUID type, const Ref & ref); static bool replaceHead(UUID type, UUID id, const Ref & old, const Ref & ref); static std::optional updateHead(UUID type, UUID id, const Ref & old, const std::function &); + void watchHead(UUID type, UUID id, const std::function) const; }; class Digest @@ -482,6 +483,7 @@ public: const Ref & ref() const { return mstored.ref(); } std::optional> update(const std::function(const Stored &)> &) const; + void watch(const std::function &)> &) const; private: UUID mid; @@ -536,6 +538,14 @@ std::optional> Head::update(const std::function(const Store return Head(mid, *res); } +template +void Head::watch(const std::function &)> & watcher) const +{ + stored().ref().storage().watchHead(T::headTypeId, id(), [id = id(), watcher] (const Ref & ref) { + watcher(Head(id, ref)); + }); +} + } namespace std -- cgit v1.2.3