diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2022-12-18 18:56:19 +0100 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2022-12-18 21:37:11 +0100 |
commit | 86293ff20d9f8625615e855d98249175e8cd5cd3 (patch) | |
tree | 7eb1fe3a34ce1d6a24a9338f3dd3008b500fffe0 /include | |
parent | 77fc16d21158c6542addcbaaff47b801d3b5f5c7 (diff) |
Contact service and contacts using stored set
Diffstat (limited to 'include')
-rw-r--r-- | include/erebos/contact.h | 65 | ||||
-rw-r--r-- | include/erebos/set.h | 12 |
2 files changed, 66 insertions, 11 deletions
diff --git a/include/erebos/contact.h b/include/erebos/contact.h index e56346a..ef9c3b6 100644 --- a/include/erebos/contact.h +++ b/include/erebos/contact.h @@ -2,6 +2,8 @@ #include <erebos/identity.h> #include <erebos/list.h> +#include <erebos/pairing.h> +#include <erebos/set.h> #include <erebos/state.h> #include <erebos/storage.h> @@ -17,31 +19,80 @@ using std::shared_ptr; using std::string; using std::vector; +struct ContactData; + class Contact { public: + Contact(vector<Stored<ContactData>> data); Contact(const Contact &) = default; Contact(Contact &&) = default; Contact & operator=(const Contact &) = default; Contact & operator=(Contact &&) = default; - static List<Contact> prepend(const Storage &, Identity, List<Contact>); - - Identity identity() const; - optional<string> name() const; + optional<Identity> identity() const; + optional<string> customName() const; + string name() const; bool operator==(const Contact &) const; bool operator!=(const Contact &) const; - static List<Contact> loadList(const vector<Ref> &); - vector<Ref> refs() const; + vector<Stored<ContactData>> data() const; private: struct Priv; shared_ptr<Priv> p; Contact(shared_ptr<Priv> p): p(p) {} + + friend class ContactService; +}; + +DECLARE_SHARED_TYPE(Set<Contact>) + +struct ContactData +{ + static ContactData load(const Ref &); + Ref store(const Storage &) const; + + vector<Stored<ContactData>> prev; + vector<Stored<Signed<IdentityData>>> identity; + optional<string> name; +}; + +template<> struct Mergeable<Contact> +{ + using Component = ContactData; + static vector<Stored<ContactData>> components(const Contact & c) { return c.data(); } + static Contact merge(vector<Stored<ContactData>> x) { return Contact(move(x)); } +}; + +struct ContactAccepted; + +class ContactService : public PairingService<ContactAccepted> +{ +public: + ContactService(); + virtual ~ContactService(); + + UUID uuid() const override; + + void serverStarted(const class Server &) override; + + void request(const Peer &); + +protected: + virtual Stored<ContactAccepted> handlePairingComplete(const Peer &) override; + virtual void handlePairingResult(Context &, Stored<ContactAccepted>) override; + + const class Server * server; }; -DECLARE_SHARED_TYPE(List<Contact>) +template<class T> class Signed; + +struct ContactAccepted +{ + static ContactAccepted load(const Ref &); + Ref store(const Storage &) const; +}; } diff --git a/include/erebos/set.h b/include/erebos/set.h index f625cb0..539ffa0 100644 --- a/include/erebos/set.h +++ b/include/erebos/set.h @@ -17,13 +17,17 @@ protected: SetBase(); SetBase(const vector<Ref> &); SetBase(shared_ptr<const Priv>); - - shared_ptr<const Priv> add(Storage &, const vector<Ref> &) const; + + shared_ptr<const Priv> add(const Storage &, const vector<Ref> &) const; vector<vector<Ref>> toList() const; public: + bool operator==(const SetBase &) const; + bool operator!=(const SetBase &) const; + vector<Digest> digests() const; + vector<Ref> store() const; protected: shared_ptr<const Priv> p; @@ -43,7 +47,7 @@ public: static Set<T> load(const vector<Ref> & refs) { return Set<T>(move(refs)); } - Set<T> add(Storage &, const T &) const; + Set<T> add(const Storage &, const T &) const; template<class F> SetView<T> view(F && cmp) const; @@ -64,7 +68,7 @@ private: }; template<class T> -Set<T> Set<T>::add(Storage & st, const T & x) const +Set<T> Set<T>::add(const Storage & st, const T & x) const { return Set<T>(SetBase::add(st, storedRefs(Mergeable<T>::components(x)))); } |