From 86293ff20d9f8625615e855d98249175e8cd5cd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sun, 18 Dec 2022 18:56:19 +0100 Subject: Contact service and contacts using stored set --- include/erebos/contact.h | 65 ++++++++++++++++++++++++++++++++++++++++++------ include/erebos/set.h | 12 ++++++--- 2 files changed, 66 insertions(+), 11 deletions(-) (limited to 'include') 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 #include +#include +#include #include #include @@ -17,31 +19,80 @@ using std::shared_ptr; using std::string; using std::vector; +struct ContactData; + class Contact { public: + Contact(vector> data); Contact(const Contact &) = default; Contact(Contact &&) = default; Contact & operator=(const Contact &) = default; Contact & operator=(Contact &&) = default; - static List prepend(const Storage &, Identity, List); - - Identity identity() const; - optional name() const; + optional identity() const; + optional customName() const; + string name() const; bool operator==(const Contact &) const; bool operator!=(const Contact &) const; - static List loadList(const vector &); - vector refs() const; + vector> data() const; private: struct Priv; shared_ptr p; Contact(shared_ptr p): p(p) {} + + friend class ContactService; +}; + +DECLARE_SHARED_TYPE(Set) + +struct ContactData +{ + static ContactData load(const Ref &); + Ref store(const Storage &) const; + + vector> prev; + vector>> identity; + optional name; +}; + +template<> struct Mergeable +{ + using Component = ContactData; + static vector> components(const Contact & c) { return c.data(); } + static Contact merge(vector> x) { return Contact(move(x)); } +}; + +struct ContactAccepted; + +class ContactService : public PairingService +{ +public: + ContactService(); + virtual ~ContactService(); + + UUID uuid() const override; + + void serverStarted(const class Server &) override; + + void request(const Peer &); + +protected: + virtual Stored handlePairingComplete(const Peer &) override; + virtual void handlePairingResult(Context &, Stored) override; + + const class Server * server; }; -DECLARE_SHARED_TYPE(List) +template 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 &); SetBase(shared_ptr); - - shared_ptr add(Storage &, const vector &) const; + + shared_ptr add(const Storage &, const vector &) const; vector> toList() const; public: + bool operator==(const SetBase &) const; + bool operator!=(const SetBase &) const; + vector digests() const; + vector store() const; protected: shared_ptr p; @@ -43,7 +47,7 @@ public: static Set load(const vector & refs) { return Set(move(refs)); } - Set add(Storage &, const T &) const; + Set add(const Storage &, const T &) const; template SetView view(F && cmp) const; @@ -64,7 +68,7 @@ private: }; template -Set Set::add(Storage & st, const T & x) const +Set Set::add(const Storage & st, const T & x) const { return Set(SetBase::add(st, storedRefs(Mergeable::components(x)))); } -- cgit v1.2.3