Ditto 4.7.2-rc.2
Loading...
Searching...
No Matches
Store.hpp
1#ifndef _DITTO_STORE_
2#define _DITTO_STORE_
3
4#include "Attachment.hpp"
5#include "AttachmentFetchEvent.hpp"
6#include "AttachmentFetcher.hpp"
7#include "AttachmentToken.hpp"
8#include "Collection.hpp"
9#include "DiskUsage.hpp"
10#include "Ditto.hpp"
11#include "PendingCollectionsOperation.hpp"
12#include "QueryResult.hpp"
13#include "StoreObserver.hpp"
14#include "WriteTransaction.hpp"
15#include "WriteTransactionResult.hpp"
16
17#include <functional>
18#include <memory>
19#include <mutex>
20#include <set>
21#include <string>
22#include <vector>
23
24namespace ditto {
25class DittoHandleWrapper;
29class Store {
30 friend class AttachmentFetcher;
31 friend class Ditto;
32 friend class StoreObserver;
33
34 static bool finalize_attachment_fetcher(
35 std::shared_ptr<AttachmentFetcher> const &attachment_fetcher,
36 std::shared_ptr<std::set<std::shared_ptr<AttachmentFetcher>>> const
37 &attachment_fetchers,
38 std::lock_guard<std::mutex> const &lock);
39
40 std::shared_ptr<DittoHandleWrapper> ditto_handle_wrapper;
41 DiskUsage disk_usage;
42 Store(std::shared_ptr<DittoHandleWrapper> ditto_handle_wrapper);
43 void set_weak_ditto_fields(std::weak_ptr<Ditto::Fields> weak_ditto_fields);
44 std::weak_ptr<Ditto::Fields> weak_ditto_fields;
45
46 // Lock responsible for synchronizing access to the attachment_fetchers set.
47 std::shared_ptr<std::mutex> attachment_fetchers_lock;
48 mutable std::shared_ptr<std::set<std::shared_ptr<AttachmentFetcher>>>
49 attachment_fetchers;
50
51 bool unregister_observer(std::shared_ptr<StoreObserver>);
52
53public:
54 Store();
55
59 std::set<std::shared_ptr<StoreObserver>> observers;
60
64 std::set<std::shared_ptr<AttachmentFetcher>> get_attachment_fetchers() const;
65
77 Collection collection(std::string name) const;
78
88 std::vector<std::unique_ptr<WriteTransactionResult>>
89 write(std::function<void(WriteTransaction &)> fn) const;
90
99
106
120 QueryResult execute(std::string query, nlohmann::json query_args = nullptr);
121
135 std::shared_ptr<StoreObserver>
136 register_observer(std::string query, StoreObservationHandler change_handler);
137
154 std::shared_ptr<StoreObserver>
155 register_observer(std::string query, nlohmann::json query_args,
156 StoreObservationHandler change_handler);
157
169 std::shared_ptr<StoreObserver>
170 register_observer(std::string query,
171 StoreObservationHandlerWithNextSignal change_handler);
172
187 std::shared_ptr<StoreObserver>
188 register_observer(std::string query, nlohmann::json query_args,
189 StoreObservationHandlerWithNextSignal change_handler);
190
226 Attachment new_attachment(std::string path,
227 std::map<std::string, std::string> metadata =
228 std::map<std::string, std::string>()) const;
229
260 std::shared_ptr<AttachmentFetcher>
261 fetch_attachment(std::shared_ptr<AttachmentToken> token,
263
294 std::shared_ptr<AttachmentFetcher>
295 fetch_attachment(std::unordered_map<std::string, any> map,
297};
298} // namespace ditto
299#endif
These objects are returned by calls to Store::fetch_attachment.
Definition AttachmentFetcher.hpp:28
Represents an attachment and can be used to insert the associated attachment into a document at a spe...
Definition Attachment.hpp:22
A reference to a collection in a Store.
Definition Collection.hpp:27
Provides an interface to be able to monitor local files.
Definition DiskUsage.hpp:66
The entrypoint to the Ditto SDK.
Definition Ditto.hpp:32
These objects are returned when calling collections() on Store objects.
Definition PendingCollectionsOperation.hpp:58
Represents the returned results when executing a DQL query, containing a QueryResultItem for each mat...
Definition QueryResult.hpp:104
Provides access to Collections and a write transaction API.
Definition Store.hpp:29
Attachment new_attachment(std::string path, std::map< std::string, std::string > metadata=std::map< std::string, std::string >()) const
Creates a new attachment, which can then be inserted into a document.
Definition Store.cpp:114
DiskUsage get_disk_usage() const
Provides access to the Store's disk usage.
Definition Store.cpp:49
std::vector< std::unique_ptr< WriteTransactionResult > > write(std::function< void(WriteTransaction &)> fn) const
Allows you to group multiple operations together that affect multiple documents, potentially across m...
Definition Store.cpp:52
std::set< std::shared_ptr< AttachmentFetcher > > get_attachment_fetchers() const
Returns a copy of all currently active attachment fetchers.
Definition Store.cpp:190
PendingCollectionsOperation collections() const
Returns an object that lets you fetch or observe the collections in the store.
Definition Store.cpp:45
std::shared_ptr< StoreObserver > register_observer(std::string query, StoreObservationHandler change_handler)
Installs and returns a change observer for a query, configuring Ditto to call the provided change han...
Definition Store.cpp:83
std::set< std::shared_ptr< StoreObserver > > observers
Returns a copy of all currently active store observers.
Definition Store.hpp:59
std::shared_ptr< StoreObserver > register_observer(std::string query, nlohmann::json query_args, StoreObservationHandlerWithNextSignal change_handler)
Installs and returns a change observer for a query, configuring Ditto to call the provided change han...
QueryResult execute(std::string query, nlohmann::json query_args=nullptr)
Executes a DQL query and returns matching items as a query result.
Definition Store.cpp:64
std::shared_ptr< AttachmentFetcher > fetch_attachment(std::shared_ptr< AttachmentToken > token, AttachmentFetcherEventHandler event_handler) const
Trigger an attachment to be downloaded locally to the device and observe its progress as it does so.
Definition Store.cpp:140
Collection collection(std::string name) const
Returns a Collection with the provided name.
Definition Store.cpp:41
std::shared_ptr< StoreObserver > register_observer(std::string query, nlohmann::json query_args, StoreObservationHandler change_handler)
Installs and returns a change observer for a query, configuring Ditto to call the provided in change ...
Definition StoreObserver.hpp:44
WriteTransaction exposes functionality that allows you to perform multiple operations on the store wi...
Definition WriteTransaction.hpp:25
basic_json<> json
default JSON class
Definition json.hpp:2933
Definition Arc.hpp:11
A thin wrapper around a function that will get called when there are updates relating to an attempt t...
Definition AttachmentFetcher.hpp:19