Ditto 4.8.0-rc.2
Loading...
Searching...
No Matches
Presence.hpp
1#ifndef _DITTO_PRESENCE_MANAGER_
2#define _DITTO_PRESENCE_MANAGER_
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
14typedef struct dittoffi_connection_request dittoffi_connection_request_t;
15
16namespace ditto {
17
18struct OnConnectingWrapper;
19
20class DittoHandleWrapper;
21
26typedef std::function<void(PresenceGraph)> PresenceCallback;
27
28typedef std::weak_ptr<PresenceCallback> PresenceObserverInternal;
29typedef std::shared_ptr<PresenceCallback> PresenceObserver;
30
34class Presence {
35 friend class Ditto;
36
37public:
44 PresenceObserver observe(PresenceCallback presence_cb);
45
51 DITTO_DEPRECATED PresenceGraph exec();
52
59
73 nlohmann::json peer_metadata() const;
74
94 void set_peer_metadata(nlohmann::json const &peer_metadata);
95
108 std::string peer_metadata_json_string() const;
109
129 void set_peer_metadata_json_string(std::string json_string);
130
157 ConnectionRequestHandler connection_request_handler);
158
163 void set_connection_request_handler(std::nullptr_t);
164
165private:
166 Presence(std::shared_ptr<DittoHandleWrapper> ditto_handle_wrapper);
167 friend struct PresenceInternal;
168
174 void on_presence(PresenceGraph presence_graph);
175
176 std::shared_ptr<DittoHandleWrapper> ditto_handle_wrapper;
177 std::vector<PresenceObserverInternal> observers;
178 bool registered;
179
180 static void
181 on_connecting(Arc<ConnectionRequestHandler> const &handler,
182 dittoffi_connection_request_t *ffi_connection_request);
183};
184} // namespace ditto
185#endif
Definition Arc.hpp:19
The entrypoint to the Ditto SDK.
Definition Ditto.hpp:32
Represents the Ditto mesh network of peers and their connections between each other....
Definition PresenceGraph.hpp:184
Definition Presence.hpp:34
void set_peer_metadata_json_string(std::string json_string)
Set arbitrary metadata formatted as JSON to be associated with the current peer.
Definition Presence.cpp:114
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.
Definition Presence.cpp:181
nlohmann::json peer_metadata() const
Metadata associated with the current peer.
Definition Presence.cpp:110
void set_peer_metadata(nlohmann::json const &peer_metadata)
Set arbitrary metadata to be associated with the current peer.
Definition Presence.cpp:141
DITTO_DEPRECATED PresenceGraph exec()
Deprecated alias of graph()
Definition Presence.cpp:92
PresenceObserver observe(PresenceCallback presence_cb)
This will run the provided callback when peers are updated.
Definition Presence.cpp:72
std::string peer_metadata_json_string() const
Metadata associated with the current peer as a JSON string.
Definition Presence.cpp:102
PresenceGraph graph()
Return an immediate representation of known peers.
Definition Presence.cpp:94
Privacy hack.
Definition Presence.cpp:50