summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2021-04-24 21:20:25 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2021-04-24 21:20:25 +0200
commita511d2d1ef5fa07dde601961fe9394b474aad5ae (patch)
tree9dd7321cba6303583d044cae95ea622e96b55d45 /include
parent9aaba1211c95dc7e08437a7cca73452181e296d6 (diff)
Behavior lens for shared refs from local state
Diffstat (limited to 'include')
-rw-r--r--include/erebos/frp.h28
-rw-r--r--include/erebos/state.h2
-rw-r--r--include/erebos/storage.h4
-rw-r--r--include/erebos/sync.h8
4 files changed, 36 insertions, 6 deletions
diff --git a/include/erebos/frp.h b/include/erebos/frp.h
index 587d2b6..b60b29f 100644
--- a/include/erebos/frp.h
+++ b/include/erebos/frp.h
@@ -4,7 +4,6 @@
#include <memory>
#include <optional>
#include <functional>
-#include <type_traits>
#include <tuple>
#include <variant>
@@ -115,6 +114,8 @@ public:
return impl->get(ctime, x);
}
+ template<typename C> BhvFun<A, C> lens() const;
+
const shared_ptr<BhvImpl<A, B>> impl;
};
@@ -135,6 +136,8 @@ public:
}
Watched<A> watch(function<void(const A &)>);
+ template<typename C> BhvFun<monostate, C> lens() const;
+
const shared_ptr<BhvSource<A>> impl;
};
@@ -227,4 +230,27 @@ BhvFun<A, C> operator>>(const BhvFun<A, B> & f, const BhvFun<B, C> & g)
return impl;
}
+
+template<typename A, typename B>
+class BhvLens : public BhvImpl<A, B>
+{
+public:
+ B get(const BhvCurTime &, const A & x) const override
+ { return A::template lens<B>(x); }
+};
+
+template<typename A, typename B>
+template<typename C>
+BhvFun<A, C> BhvFun<A, B>::lens() const
+{
+ return *this >> BhvFun<B, C>(make_shared<BhvLens<B, C>>());
+}
+
+template<typename A>
+template<typename C>
+BhvFun<monostate, C> BhvFun<monostate, A>::lens() const
+{
+ return *this >> BhvFun<A, C>(make_shared<BhvLens<A, C>>());
+}
+
}
diff --git a/include/erebos/state.h b/include/erebos/state.h
index b1567b0..7060f22 100644
--- a/include/erebos/state.h
+++ b/include/erebos/state.h
@@ -32,6 +32,8 @@ public:
vector<Ref> sharedRefs() const;
LocalState sharedRefAdd(const Ref &) const;
+ template<typename T> static T lens(const LocalState &);
+
private:
vector<Ref> lookupShared(UUID) const;
LocalState updateShared(UUID, const vector<Ref> &) const;
diff --git a/include/erebos/storage.h b/include/erebos/storage.h
index 2d00cc3..9d28ec7 100644
--- a/include/erebos/storage.h
+++ b/include/erebos/storage.h
@@ -182,8 +182,8 @@ public:
Ref & operator=(const Ref &) = default;
Ref & operator=(Ref &&) = default;
- bool operator==(const Ref &) = delete;
- bool operator!=(const Ref &) = delete;
+ bool operator==(const Ref &) const;
+ bool operator!=(const Ref &) const;
static std::optional<Ref> create(const Storage &, const Digest &);
static Ref zcreate(const Storage &);
diff --git a/include/erebos/sync.h b/include/erebos/sync.h
index 0b9ed9a..dad4e0e 100644
--- a/include/erebos/sync.h
+++ b/include/erebos/sync.h
@@ -6,9 +6,12 @@
#include <optional>
#include <mutex>
+#include <vector>
namespace erebos {
+using std::vector;
+
class SyncService : public Service
{
public:
@@ -22,11 +25,10 @@ public:
private:
void peerWatcher(size_t, const class Peer *);
- void localStateWatcher(const Head<LocalState> &);
+ void localStateWatcher(const vector<Ref> &);
const class Server * server;
- std::mutex headMutex;
- std::optional<WatchedHead<LocalState>> watchedHead;
+ std::optional<Watched<vector<Ref>>> watchedLocal;
};
}