Ditto 4.13.1
 
Loading...
Searching...
No Matches
Presence.hpp
1#ifndef DITTO_PRESENCE_MANAGER_H
2#define DITTO_PRESENCE_MANAGER_H
3
4#include "Arc.hpp"
5#include "ConnectionRequest.hpp"
6#include "DittoHandleWrapper.hpp"
7#include "PresenceGraph.hpp"
8#include "any.hpp"
9
10#include <cstddef>
11#include <memory>
12#include <string>
13
14using dittoffi_connection_request_t = struct dittoffi_connection_request;
15
16namespace ditto {
17
18struct OnConnectingWrapper;
19
20class DittoHandleWrapper;
21
26using PresenceCallback = std::function<void(PresenceGraph)>;
27using PresenceObserverInternal = std::weak_ptr<PresenceCallback>;
28using PresenceObserver = std::shared_ptr<PresenceCallback>;
29
33class Presence {
34 friend class Ditto;
35
36public:
43 PresenceObserver observe(PresenceCallback presence_cb);
44
50 DITTO_DEPRECATED PresenceGraph exec();
51
58
72 nlohmann::json peer_metadata() const;
73
93 void set_peer_metadata(nlohmann::json const &peer_metadata);
94
107 std::string peer_metadata_json_string() const;
108
128 void set_peer_metadata_json_string(std::string json_string);
129
156 ConnectionRequestHandler connection_request_handler);
157
162 void set_connection_request_handler(std::nullptr_t);
163
164private:
165 explicit Presence(std::shared_ptr<DittoHandleWrapper> ditto_handle_wrapper);
166 friend struct PresenceInternal;
167
173 void on_presence(PresenceGraph presence_graph);
174
175 std::shared_ptr<DittoHandleWrapper> ditto_handle_wrapper;
176 std::vector<PresenceObserverInternal> observers;
177 bool registered;
178
179 static void
180 on_connecting(Arc<ConnectionRequestHandler> const &handler,
181 dittoffi_connection_request_t *ffi_connection_request);
182};
183} // namespace ditto
184#endif
A structure that holds the value and the strong reference count for an Arc.
Definition Arc.hpp:40
Represents the Ditto mesh network of peers and their connections between each other....
Definition PresenceGraph.hpp:211
void set_connection_request_handler(std::nullptr_t)
Unset the connection request handler, if one was previously set, replacing it with the default all-al...
void set_peer_metadata_json_string(std::string json_string)
Set arbitrary metadata formatted as JSON to be associated with the current peer.
void set_connection_request_handler(ConnectionRequestHandler connection_request_handler)
Set this handler to control which peers in a Ditto mesh can connect to the current peer.
nlohmann::json peer_metadata() const
Metadata associated with the current peer.
void set_peer_metadata(nlohmann::json const &peer_metadata)
Set arbitrary metadata to be associated with the current peer.
PresenceGraph exec()
Deprecated alias of graph()
PresenceObserver observe(PresenceCallback presence_cb)
This will run the provided callback when peers are updated.
std::string peer_metadata_json_string() const
Metadata associated with the current peer as a JSON string.
PresenceGraph graph()
Return an immediate representation of known peers.
Namespace for the Ditto C++ SDK types and functions.
Definition AbstractDocumentPath.hpp:19
std::function< void(PresenceGraph)> PresenceCallback
A type representing a callback that will get called when there are updates relating to presence.
Definition Presence.hpp:26
std::function< ConnectionRequestAuthorization(ConnectionRequest)> ConnectionRequestHandler
Definition ConnectionRequest.hpp:107