summaryrefslogtreecommitdiff
path: root/include/erebos
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2021-01-17 21:59:46 +0100
committerRoman Smrž <roman.smrz@seznam.cz>2021-01-19 21:44:22 +0100
commit2abd6593c8b047d3fd579aa6cc0058bbebe266f8 (patch)
tree44af7148f648538846ef64bed0f8560f77de7e5d /include/erebos
parent1466751256580d8b0e6eea46a8028dcab9742f6b (diff)
Server watching local state head
Diffstat (limited to 'include/erebos')
-rw-r--r--include/erebos/network.h4
-rw-r--r--include/erebos/storage.h10
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