Ditto 4.6.0
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
38 static bool finalize_attachment_fetcher(
39 std::shared_ptr<AttachmentFetcher> const &,
40 std::shared_ptr<std::set<std::shared_ptr<AttachmentFetcher>>> const
41 &attachment_fetchers);
42
43 std::shared_ptr<DittoHandleWrapper> ditto_handle_wrapper;
44 DiskUsage disk_usage;
45 Store(std::shared_ptr<DittoHandleWrapper> ditto_handle_wrapper);
46 void set_weak_ditto_fields(std::weak_ptr<Ditto::Fields> weak_ditto_fields);
47 std::weak_ptr<Ditto::Fields> weak_ditto_fields;
48
49 // Lock responsible for synchronizing access to the attachment_fetchers set.
50 std::shared_ptr<std::mutex> attachment_fetchers_lock;
51 mutable std::shared_ptr<std::set<std::shared_ptr<AttachmentFetcher>>>
52 attachment_fetchers;
53
54 bool unregister_observer(std::shared_ptr<StoreObserver>);
55
56public:
57 Store();
58
62 std::set<std::shared_ptr<StoreObserver>> observers;
63
67 std::set<std::shared_ptr<AttachmentFetcher>> get_attachment_fetchers() const;
68
80 Collection collection(std::string name) const;
81
91 std::vector<std::unique_ptr<WriteTransactionResult>>
92 write(std::function<void(WriteTransaction &)> fn) const;
93
102
109
123 QueryResult execute(std::string query, nlohmann::json query_args = nullptr);
124
138 std::shared_ptr<StoreObserver>
139 register_observer(std::string query, StoreObservationHandler change_handler);
140
157 std::shared_ptr<StoreObserver>
158 register_observer(std::string query, nlohmann::json query_args,
159 StoreObservationHandler change_handler);
160
172 std::shared_ptr<StoreObserver>
173 register_observer(std::string query,
174 StoreObservationHandlerWithNextSignal change_handler);
175
190 std::shared_ptr<StoreObserver>
191 register_observer(std::string query, nlohmann::json query_args,
192 StoreObservationHandlerWithNextSignal change_handler);
193
229 Attachment new_attachment(std::string path,
230 std::map<std::string, std::string> metadata =
231 std::map<std::string, std::string>()) const;
232
263 std::shared_ptr<AttachmentFetcher>
264 fetch_attachment(std::shared_ptr<AttachmentToken> token,
266
297 std::shared_ptr<AttachmentFetcher>
298 fetch_attachment(std::unordered_map<std::string, any> map,
300};
301} // namespace ditto
302#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:65
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:62
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:10
A thin wrapper around a function that will get called when there are updates relating to an attempt t...
Definition AttachmentFetcher.hpp:19