Ditto  3.0.4
Presence.hpp
1 #ifndef _DITTO_PRESENCE_MANAGER_
2 #define _DITTO_PRESENCE_MANAGER_
3 
4 #include "DittoHandleWrapper.hpp"
5 #include "PresenceGraph.hpp"
6 
7 #include <memory>
8 #include <string>
9 
10 namespace ditto {
11 class DittoHandleWrapper;
12 
17 typedef std::function<void(PresenceGraph)> PresenceCallback;
18 
19 typedef std::weak_ptr<PresenceCallback> PresenceObserverInternal;
20 typedef std::shared_ptr<PresenceCallback> PresenceObserver;
21 
25 class Presence {
26  friend class Ditto;
27 
28 public:
35  PresenceObserver observe(PresenceCallback presence_cb);
42 
43 private:
44  Presence(std::shared_ptr<DittoHandleWrapper> ditto_handle_wrapper);
50  static void on_event(void *ctx, const char *graph);
51 
57  void on_presence(PresenceGraph presence_graph);
58 
59  std::shared_ptr<DittoHandleWrapper> ditto_handle_wrapper;
60  std::vector<PresenceObserverInternal> observers;
61  bool registered;
62 };
63 } // namespace ditto
64 #endif
The entrypoint to the Ditto SDK.
Definition: Ditto.hpp:28
Represents local peer and local peers.
Definition: PresenceGraph.hpp:62
Definition: Presence.hpp:25
PresenceGraph exec()
Return an immediate representation of known peers.
Definition: Presence.cpp:63
PresenceObserver observe(PresenceCallback presence_cb)
This will run the provided callback when peers are updated.
Definition: Presence.cpp:41