Ditto 4.7.4
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
76
97
112 std::string peer_metadata_json_string() const;
113
133 void set_peer_metadata_json_string(std::string json_string);
134
161 ConnectionRequestHandler connection_request_handler);
162
167 void set_connection_request_handler(std::nullptr_t);
168
169private:
170 Presence(std::shared_ptr<DittoHandleWrapper> ditto_handle_wrapper);
171 friend struct PresenceInternal;
172
178 void on_presence(PresenceGraph presence_graph);
179
180 std::shared_ptr<DittoHandleWrapper> ditto_handle_wrapper;
181 std::vector<PresenceObserverInternal> observers;
182 bool registered;
183
184 static void
185 on_connecting(Arc<ConnectionRequestHandler> const &handler,
186 dittoffi_connection_request_t *ffi_connection_request);
187};
188} // namespace ditto
189#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:141
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
basic_json<> json
default JSON class
Definition json.hpp:2933
Privacy hack.
Definition Presence.cpp:50