Ditto 4.9.4
 
Loading...
Searching...
No Matches
Ditto.hpp
1#ifndef _DITTO_DITTO_
2#define _DITTO_DITTO_
3
4#include "DiskUsage.hpp"
5#include "Identity.hpp"
6#include "LogLevel.hpp"
7#include "Presence.hpp"
8#include "SmallPeerInfo.hpp"
9
10#include "TransportConfig.hpp"
11
12#include "Helpers.hpp"
13
14#include <memory>
15
16#ifdef __ANDROID__
17#include <jni.h>
18#endif /* __ANDROID__ */
19
20namespace ditto {
21class Authenticator;
22class Store;
23class StoreObserver;
24class Sync;
32class Ditto {
33 friend class AttachmentFetcher;
34 friend class AttachmentFetcherCtx;
35 friend class Authenticator;
36 friend class Collection;
37 friend class Store;
38 friend class StoreObserver;
39 friend class Sync;
40 friend class SyncSubscription;
41 friend class ValidityListener;
42
43public:
51 explicit Ditto(
52 std::shared_ptr<Identity> identity = Identity::OfflinePlayground(),
53 std::string persistence_dir = "");
54
55 Ditto(Ditto const &other) = delete;
56 Ditto(Ditto &&other) noexcept;
57 Ditto &operator=(Ditto const &other) = delete;
58 Ditto &operator=(Ditto &&other) noexcept;
59 ~Ditto();
60
67 std::shared_ptr<Authenticator> get_auth() const;
68
74 Store &get_store() const;
75
82
87 Sync &sync() const;
88
94 Presence &get_presence() const;
95
101 DiskUsage &get_disk_usage() const;
102
109
116 bool get_is_sync_active() const;
117
127 void set_offline_only_license_token(std::string license_token);
128
141 void set_device_name(std::string const &name);
142
160 void start_sync() const;
161
168 void stop_sync() const;
169
187 void disable_sync_with_v3() const;
188
199
211 void
212 update_transport_config(std::function<void(TransportConfig &config)> lambda);
213
219 static std::string get_sdk_version();
220
226 static bool get_logging_enabled();
227
234 static void set_logging_enabled(bool enabled);
235
243
250 static void set_emoji_log_level_headings_enabled(bool enabled);
251
257 static LogLevel get_minimum_log_level();
258
266 static void set_minimum_log_level(LogLevel log_level);
267
282 void run_garbage_collection() const;
283
288 std::string get_app_id() const;
289
303 std::string get_persistence_directory() const;
304
316 PresenceObserver observe_peers(PresenceCallback cb);
317
322 void close();
323#ifdef __ANDROID__
337 void set_android_context(JNIEnv *env, jobject context);
338
356 std::vector<std::string> missing_permissions() const;
357
372 jobjectArray missing_permissions_jni_array() const;
373#endif
374
375private:
376 struct Fields;
377 std::shared_ptr<Fields> fields;
378 bool is_closable;
379
380 explicit Ditto(std::shared_ptr<Fields> fields);
381
382 void validity_updated(bool web_valid, bool x509_valid) const;
383 void set_is_closable(bool is_closable);
384 std::shared_ptr<DittoHandleWrapper> get_handle_wrapper();
385
386 friend struct ValidityListenerCtx;
387 friend struct StoreObserverCtx;
388};
389} // namespace ditto
390
391#endif
Provides access to authentication information and methods for logging on to Ditto Cloud....
Definition Authenticator.hpp:27
Provides an interface to be able to monitor local files.
Definition DiskUsage.hpp:66
static bool get_logging_enabled()
Gets whether or not logging is enabled for Ditto.
Definition Ditto.cpp:347
TransportConfig get_transport_config() const
Returns the current transport config.
Definition Ditto.cpp:274
void stop_sync() const
Stops all network transports.
Definition Ditto.cpp:304
static void set_minimum_log_level(LogLevel log_level)
Sets the minimum log level at which logs should be emitted for Ditto.
Definition Ditto.cpp:363
void set_transport_config(TransportConfig config)
Assign a new transports configuration.
Definition Ditto.cpp:319
void run_garbage_collection() const
Removes all sync metadata for any remote peers which aren't currently connected.
Definition Ditto.cpp:367
void disable_sync_with_v3() const
Disable sync with peers running version 3 or lower of the Ditto SDK.
Definition Ditto.cpp:314
jobjectArray missing_permissions_jni_array() const
Calculates which permissions are missing that Ditto needs to operate. The returned strings should be ...
Definition Ditto.cpp:396
bool get_is_sync_active() const
Returns a flag indicating whether or not sync is active. Use start_sync to activate sync and stop_syn...
Definition Ditto.cpp:278
static void set_logging_enabled(bool enabled)
Sets whether or not logging is enabled for Ditto.
Definition Ditto.cpp:349
std::string get_app_id() const
Get the Ditto application Id.
Definition Ditto.cpp:418
static bool get_emoji_log_level_headings_enabled()
Gets whether or not emoji log level headings are enabled for Ditto.
Definition Ditto.cpp:353
Sync & sync() const
Provides access to the SDK's sync functionality.
Definition Ditto.cpp:270
void set_device_name(std::string const &name)
Set a custom identifier for the current device.
Definition Ditto.cpp:258
void set_android_context(JNIEnv *env, jobject context)
Definition Ditto.cpp:373
DiskUsage & get_disk_usage() const
Provides access to the SDK's disk usage.
Definition Ditto.cpp:272
Presence & get_presence() const
Provides access to the SDK's presence functionality.
Definition Ditto.cpp:416
SmallPeerInfo & get_small_peer_info() const
Provides access to the SDK's Small Peer Info functionality.
Definition Ditto.cpp:266
PresenceObserver observe_peers(PresenceCallback cb)
Request information about Ditto peers in range of this device.
Ditto(std::shared_ptr< Identity > identity=Identity::OfflinePlayground(), std::string persistence_dir="")
Initializes a new Ditto instance.
Definition Ditto.cpp:120
void update_transport_config(std::function< void(TransportConfig &config)> lambda)
Convenience method to update the current transport config of the receiver.
Definition Ditto.cpp:332
void set_offline_only_license_token(std::string license_token)
Activate an offline Ditto instance by setting a license token. You cannot initiate sync on an offline...
Definition Ditto.cpp:237
void close()
Shut down Ditto and release all resources. Must be called before recreating a Ditto instance that use...
Definition Ditto.cpp:441
static LogLevel get_minimum_log_level()
Gets the minimum log level at which logs will be emitted for Ditto.
Definition Ditto.cpp:361
Store & get_store() const
Provides access to the SDK's store functionality.
Definition Ditto.cpp:264
void start_sync() const
Starts the network transports. Ditto will connect to other devices and sync with them where appropria...
Definition Ditto.cpp:280
std::shared_ptr< Authenticator > get_auth() const
Provides access to authentication information and methods for logging on to Ditto Cloud.
Definition Ditto.cpp:262
std::string get_persistence_directory() const
The persistence directory used by Ditto to persist data.
Definition Ditto.cpp:426
static void set_emoji_log_level_headings_enabled(bool enabled)
Sets whether or not emoji log level headings are enabled for Ditto.
Definition Ditto.cpp:357
std::vector< std::string > missing_permissions() const
Calculates which permissions are missing that Ditto needs to operate. The returned strings should be ...
Definition Ditto.cpp:383
static std::string get_sdk_version()
Returns a string identifying the version of the Ditto SDK.
Definition Ditto.cpp:339
static std::shared_ptr< OfflinePlaygroundIdentity > OfflinePlayground(std::string app_id="", uint64_t site_id=0)
Construct a new OfflinePlaygroundIdentity.
Definition Identity.cpp:25
Definition Presence.hpp:34
The entrypoint for small peer user info collection.
Definition SmallPeerInfo.hpp:18
Provides access to Collections and a write transaction API.
Definition Store.hpp:29
Definition StoreObserver.hpp:44
Definition Sync.hpp:14
A sync subscription configures Ditto to receive updates from remote peers about documents matching th...
Definition SyncSubscription.hpp:20
A configuration object specifying which network transports Ditto should use to sync data.
Definition TransportConfig.hpp:374
Definition Ditto.cpp:48