diff options
Diffstat (limited to 'include/erebos')
-rw-r--r-- | include/erebos/network.h | 4 | ||||
-rw-r--r-- | include/erebos/storage.h | 10 |
2 files changed, 12 insertions, 2 deletions
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 <erebos/identity.h> #include <erebos/service.h> +#include <erebos/state.h> #include <functional> #include <typeinfo> @@ -11,7 +11,7 @@ namespace erebos { class Server { public: - Server(const Identity &, std::vector<std::unique_ptr<Service>> &&); + Server(const Head<LocalState> &, std::vector<std::unique_ptr<Service>> &&); ~Server(); template<class S> 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<Ref> updateHead(UUID type, UUID id, const Ref & old, const std::function<Ref(const Ref &)> &); + void watchHead(UUID type, UUID id, const std::function<void(const Ref &)>) const; }; class Digest @@ -482,6 +483,7 @@ public: const Ref & ref() const { return mstored.ref(); } std::optional<Head<T>> update(const std::function<Stored<T>(const Stored<T> &)> &) const; + void watch(const std::function<void(const Head<T> &)> &) const; private: UUID mid; @@ -536,6 +538,14 @@ std::optional<Head<T>> Head<T>::update(const std::function<Stored<T>(const Store return Head<T>(mid, *res); } +template<typename T> +void Head<T>::watch(const std::function<void(const Head<T> &)> & watcher) const +{ + stored().ref().storage().watchHead(T::headTypeId, id(), [id = id(), watcher] (const Ref & ref) { + watcher(Head<T>(id, ref)); + }); +} + } namespace std |