Ditto 4.13.1
 
Loading...
Searching...
No Matches
Sync.hpp
1#ifndef DITTO_SYNC_H
2#define DITTO_SYNC_H
3
4#include "Ditto.hpp"
5
6#include "json.hpp"
7#include <mutex>
8#include <set>
9
10namespace ditto {
11
12class DittoHandleWrapper;
14
15class Sync {
16 friend class Ditto;
17
18 explicit Sync(std::shared_ptr<DittoHandleWrapper> ditto_handle_wrapper);
19
20 std::shared_ptr<DittoHandleWrapper> ditto_handle_wrapper;
21 void set_weak_ditto_fields(std::weak_ptr<Ditto::Fields> weak_ditto_fields);
22 std::weak_ptr<Ditto::Fields> weak_ditto_fields;
23
24 // This mutex synchronizes access to the `subscriptions` set.
25 std::shared_ptr<std::mutex> synchronized;
26
27 friend class SyncSubscription;
32 bool unregister_subscription(std::shared_ptr<SyncSubscription> subscription);
33
34 void remove_subscription(std::shared_ptr<SyncSubscription> subscription);
35
36public:
37 // Disable the deprecation warnings for the special member functions which
38 // implicitly copy or move deprecated members.
39#pragma GCC diagnostic push
40#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
41 Sync(const Sync &other) = default;
42 Sync(Sync &&other) = default;
43 Sync &operator=(const Sync &other) = default;
44 Sync &operator=(Sync &&other) = default;
45 ~Sync() = default;
46#pragma GCC diagnostic pop
47
57 // NOLINTNEXTLINE
58 DITTO_DEPRECATED std::set<std::shared_ptr<SyncSubscription>> subscriptions;
59
75 std::shared_ptr<SyncSubscription>
76 register_subscription(std::string query, nlohmann::json query_args = nullptr);
77
81 std::set<std::shared_ptr<SyncSubscription>> get_subscriptions() const;
82};
83
84} // namespace ditto
85
86#endif
std::set< std::shared_ptr< SyncSubscription > > subscriptions
Set of active subscriptions.
Definition Sync.hpp:58
std::shared_ptr< SyncSubscription > register_subscription(std::string query, nlohmann::json query_args=nullptr)
Installs and returns a sync subscription for a query, configuring Ditto to receive updates from other...
std::set< std::shared_ptr< SyncSubscription > > get_subscriptions() const
Returns a snapshot of all active subscriptions.
A sync subscription configures Ditto to receive updates from remote peers about documents matching th...
Definition SyncSubscription.hpp:20
Namespace for the Ditto C++ SDK types and functions.
Definition AbstractDocumentPath.hpp:19