diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2021-02-21 22:16:21 +0100 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2021-02-23 22:12:41 +0100 |
commit | c3d6046b25ef0786b8d2919dfa9db4eb05114501 (patch) | |
tree | 19af178d6305c3a83859b7d5b07dbc9b1af3aea5 /include | |
parent | 52db636c108ab0a16ba0ccf8df55cf28142a230c (diff) |
Sync service
Diffstat (limited to 'include')
-rw-r--r-- | include/erebos/service.h | 2 | ||||
-rw-r--r-- | include/erebos/state.h | 5 | ||||
-rw-r--r-- | include/erebos/storage.h | 8 | ||||
-rw-r--r-- | include/erebos/sync.h | 32 |
4 files changed, 44 insertions, 3 deletions
diff --git a/include/erebos/service.h b/include/erebos/service.h index cec5ea0..ba06495 100644 --- a/include/erebos/service.h +++ b/include/erebos/service.h @@ -32,6 +32,8 @@ public: virtual UUID uuid() const = 0; virtual void handle(Context &) = 0; + + virtual void serverStarted(const class Server &); }; } diff --git a/include/erebos/state.h b/include/erebos/state.h index 543e03c..b1567b0 100644 --- a/include/erebos/state.h +++ b/include/erebos/state.h @@ -29,6 +29,9 @@ public: template<class T> LocalState shared(const Storage & st, const T & x) { return updateShared(T::sharedTypeId, x.store(st)); } + vector<Ref> sharedRefs() const; + LocalState sharedRefAdd(const Ref &) const; + private: vector<Ref> lookupShared(UUID) const; LocalState updateShared(UUID, const vector<Ref> &) const; @@ -47,7 +50,7 @@ template<class T> LocalState LocalState::shared(const vector<Stored<T>> & v) const { vector<Ref> refs; - for (const auto x : v) + for (const auto & x : v) refs.push_back(x.ref()); return updateShared(T::sharedTypeId, refs); } diff --git a/include/erebos/storage.h b/include/erebos/storage.h index 75b8139..7ec73ab 100644 --- a/include/erebos/storage.h +++ b/include/erebos/storage.h @@ -507,12 +507,16 @@ class WatchedHead : public Head<T> friend class Head<T>; WatchedHead(const Head<T> & h, int watcherId): Head<T>(h), watcherId(watcherId) {} + int watcherId; + +public: WatchedHead(WatchedHead<T> && h): Head<T>(h), watcherId(h.watcherId) { h.watcherId = -1; } - int watcherId; -public: + WatchedHead<T> & operator=(WatchedHead<T> && h) + { watcherId = h.watcherId; h.watcherId = -1; return *this; } + WatchedHead<T> & operator=(const Head<T> & h) { if (Head<T>::id() != h.id()) throw std::runtime_error("WatchedHead ID mismatch"); diff --git a/include/erebos/sync.h b/include/erebos/sync.h new file mode 100644 index 0000000..0b9ed9a --- /dev/null +++ b/include/erebos/sync.h @@ -0,0 +1,32 @@ +#pragma once + +#include <erebos/service.h> +#include <erebos/state.h> +#include <erebos/storage.h> + +#include <optional> +#include <mutex> + +namespace erebos { + +class SyncService : public Service +{ +public: + SyncService(); + virtual ~SyncService(); + + UUID uuid() const override; + void handle(Context &) override; + + void serverStarted(const class Server &) override; + +private: + void peerWatcher(size_t, const class Peer *); + void localStateWatcher(const Head<LocalState> &); + + const class Server * server; + std::mutex headMutex; + std::optional<WatchedHead<LocalState>> watchedHead; +}; + +} |