Ditto 4.11.1
 
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#include "TransportConfig.hpp"
10
11#include "Helpers.hpp"
12
13#include <memory>
14
15#ifdef __ANDROID__
16#include <jni.h>
17#endif /* __ANDROID__ */
18
19namespace ditto {
20class AuthenticationStatusHandler;
21class Authenticator;
22class Store;
23class StoreObserver;
24class Sync;
32class Ditto {
33 friend class AttachmentFetcher;
34 friend class AttachmentFetcherCtx;
35 friend class AuthenticationStatusHandler;
36 friend class AuthenticationStatusHandlerCtx;
37 friend class Authenticator;
38 friend class Collection;
39 friend class Store;
40 friend class StoreObserver;
41 friend class Sync;
42 friend class SyncSubscription;
43
44public:
53#ifdef __ANDROID__
54 Ditto(jobject android_context,
55 std::shared_ptr<Identity> identity = Identity::OfflinePlayground(),
56 std::string persistence_dir = "");
57#else
58 explicit Ditto(
59 std::shared_ptr<Identity> identity = Identity::OfflinePlayground(),
60 std::string persistence_dir = "");
61#endif
62
63 Ditto(Ditto const &other) = delete;
64 Ditto(Ditto &&other) noexcept;
65 Ditto &operator=(Ditto const &other) = delete;
66 Ditto &operator=(Ditto &&other) noexcept;
67 ~Ditto();
68
75 std::shared_ptr<Authenticator> get_auth() const;
76
82 Store &get_store() const;
83
90
95 Sync &get_sync() const;
96
102 DITTO_DEPRECATED Sync &sync() const;
103
109 Presence &get_presence() const;
110
116 DiskUsage &get_disk_usage() const;
117
124
131 bool get_is_sync_active() const;
132
144 bool get_is_activated() const;
145
155 void set_offline_only_license_token(std::string license_token);
156
169 void set_device_name(std::string const &name);
170
189 void start_sync() const;
190
197 void stop_sync() const;
198
216 void disable_sync_with_v3() const;
217
228
240 void
241 update_transport_config(std::function<void(TransportConfig &config)> lambda);
242
248 static std::string get_sdk_version();
249
255 static bool get_logging_enabled();
256
263 static void set_logging_enabled(bool enabled);
264
272
279 static void set_emoji_log_level_headings_enabled(bool enabled);
280
286 static LogLevel get_minimum_log_level();
287
295 static void set_minimum_log_level(LogLevel log_level);
296
311 void run_garbage_collection() const;
312
317 std::string get_app_id() const;
318
332 std::string get_persistence_directory() const;
333
345 PresenceObserver observe_peers(PresenceCallback cb);
346
351 void close();
352
353#ifdef __ANDROID__
373 "Use the Ditto constructor's `android_context` parameter instead")
374 void set_android_context(JNIEnv *env, jobject context);
375
393 std::vector<std::string> missing_permissions() const;
394
409 jobjectArray missing_permissions_jni_array() const;
410#endif
411
412private:
413 struct Fields;
414 std::shared_ptr<Fields> fields;
415 bool is_closable;
416
417 explicit Ditto(std::shared_ptr<Fields> fields);
418
419 void set_is_closable(bool is_closable);
420 std::shared_ptr<DittoHandleWrapper> get_handle_wrapper();
421
422 friend struct StoreObserverCtx;
423};
424} // namespace ditto
425
426#endif
Provides access to authentication information and methods for logging on to Ditto Cloud....
Definition Authenticator.hpp:28
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:376
Sync & get_sync() const
Provides access to the SDK's sync functionality.
Definition Ditto.cpp:291
TransportConfig get_transport_config() const
Returns the current transport config.
Definition Ditto.cpp:297
void stop_sync() const
Stops all network transports.
Definition Ditto.cpp:341
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:392
void set_transport_config(TransportConfig config)
Assign a new transports configuration.
Definition Ditto.cpp:350
void run_garbage_collection() const
Removes all sync metadata for any remote peers which aren't currently connected.
Definition Ditto.cpp:396
void disable_sync_with_v3() const
Disable sync with peers running version 3 or lower of the Ditto SDK.
Definition Ditto.cpp:345
jobjectArray missing_permissions_jni_array() const
Calculates which permissions are missing that Ditto needs to operate. The returned strings should be ...
Definition Ditto.cpp:426
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:306
static void set_logging_enabled(bool enabled)
Sets whether or not logging is enabled for Ditto.
Definition Ditto.cpp:378
std::string get_app_id() const
Get the Ditto application Id.
Definition Ditto.cpp:434
static bool get_emoji_log_level_headings_enabled()
Gets whether or not emoji log level headings are enabled for Ditto.
Definition Ditto.cpp:382
DITTO_DEPRECATED Sync & sync() const
Provides access to the SDK's sync functionality.
Definition Ditto.cpp:293
void set_device_name(std::string const &name)
Set a custom identifier for the current device.
Definition Ditto.cpp:279
DiskUsage & get_disk_usage() const
Provides access to the SDK's disk usage.
Definition Ditto.cpp:295
Presence & get_presence() const
Provides access to the SDK's presence functionality.
Definition Ditto.cpp:432
SmallPeerInfo & get_small_peer_info() const
Provides access to the SDK's Small Peer Info functionality.
Definition Ditto.cpp:287
PresenceObserver observe_peers(PresenceCallback cb)
Request information about Ditto peers in range of this device.
void update_transport_config(std::function< void(TransportConfig &config)> lambda)
Convenience method to update the current transport config of the receiver.
Definition Ditto.cpp:361
DITTO_DEPRECATED_BECAUSE("Use the Ditto constructor's `android_context` parameter instead") void set_android_context(JNIEnv *env
Set a Context to be used to access Android system resources.
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:258
void close()
Shut down Ditto and release all resources. Must be called before recreating a Ditto instance that use...
Definition Ditto.cpp:457
static LogLevel get_minimum_log_level()
Gets the minimum log level at which logs will be emitted for Ditto.
Definition Ditto.cpp:390
Store & get_store() const
Provides access to the SDK's store functionality.
Definition Ditto.cpp:285
void start_sync() const
Starts the network transports. Ditto will connect to other devices and sync with them where appropria...
Definition Ditto.cpp:314
std::shared_ptr< Authenticator > get_auth() const
Provides access to authentication information and methods for logging on to Ditto Cloud.
Definition Ditto.cpp:283
bool get_is_activated() const
Returns a flag indicating whether or not the Ditto instance has been activated by a successful call t...
Definition Ditto.cpp:310
std::string get_persistence_directory() const
The persistence directory used by Ditto to persist data.
Definition Ditto.cpp:442
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:386
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:413
Ditto(jobject android_context, std::shared_ptr< Identity > identity=Identity::OfflinePlayground(), std::string persistence_dir="")
Initializes a new Ditto instance.
Definition Ditto.cpp:119
static std::string get_sdk_version()
Returns a string identifying the version of the Ditto SDK.
Definition Ditto.cpp:368
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 transaction API.
Definition Store.hpp:63
Definition StoreObserver.hpp:44
Definition Sync.hpp:15
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:63