Ditto 4.13.1
 
Loading...
Searching...
No Matches
Ditto.hpp
1#ifndef DITTO_DITTO_H
2#define DITTO_DITTO_H
3
4#include "DiskUsage.hpp"
5#include "DittoConfig.hpp"
6#include "Identity.hpp"
7#include "LogLevel.hpp"
8#include "Presence.hpp"
9#include "SmallPeerInfo.hpp"
10#include "TransportConfig.hpp"
11
12#include "Helpers.hpp"
13
14#include <future>
15#include <memory>
16
17#ifdef __ANDROID__
18#include <jni.h>
19#endif /* __ANDROID__ */
20
21namespace ditto {
22class AuthenticationStatusHandler;
23class Authenticator;
24class Store;
25class StoreObserver;
26class Sync;
28
29namespace internal {
30struct DittoUnitTest;
31} // namespace internal
32
39class Ditto {
40 friend class AttachmentFetcher;
41 friend class AttachmentFetcherCtx;
42 friend class AuthenticationStatusHandler;
43 friend class AuthenticationStatusHandlerCtx;
44 friend class Authenticator;
45 friend class Collection;
46 friend class Store;
47 friend class StoreObserver;
48 friend class Sync;
49 friend class SyncSubscription;
50
51public:
56 static std::shared_ptr<Ditto>
58
68 static std::future<std::shared_ptr<Ditto>>
70
81#ifdef __ANDROID__
82 Ditto(jobject android_context,
83 std::shared_ptr<Identity> identity = Identity::OfflinePlayground(),
84 std::string persistence_dir = "");
85#else
86 explicit Ditto(
87 std::shared_ptr<Identity> identity = Identity::OfflinePlayground(),
88 std::string persistence_dir = "");
89#endif
90
91 Ditto(Ditto const &other) = delete;
92 Ditto(Ditto &&other) noexcept;
93 Ditto &operator=(Ditto const &other) = delete;
98 DITTO_DEPRECATED_BECAUSE("Assigning one Ditto instance to another is not "
99 "supported. Create a new instance instead.")
100 Ditto &operator=(Ditto &&other) noexcept;
101 ~Ditto();
102
109 std::shared_ptr<Authenticator> get_auth() const;
110
116 Store &get_store() const;
117
124
129 Sync &get_sync() const;
130
136 DITTO_DEPRECATED_BECAUSE("Use get_sync() instead") Sync &sync() const;
137
144
151
158
165 bool get_is_sync_active() const;
166
178 bool get_is_activated() const;
179
189 void set_offline_only_license_token(std::string license_token);
190
203 void set_device_name(std::string const &name);
204
223 void start_sync() const;
224
231 void stop_sync() const;
232
252
263
275 void
276 update_transport_config(std::function<void(TransportConfig &config)> lambda);
277
283 static std::string get_sdk_version();
284
303#ifdef __ANDROID__
304 static std::string default_root_directory(JNIEnv *env, jobject context);
305#else
306 static std::string default_root_directory();
307#endif
308
314 static bool get_logging_enabled();
315
322 static void set_logging_enabled(bool enabled);
323
331
338 static void set_emoji_log_level_headings_enabled(bool enabled);
339
346
354 static void set_minimum_log_level(LogLevel log_level);
355
371
376 std::string get_app_id() const;
377
395
409 std::string get_persistence_directory() const;
410
443
455 PresenceObserver observe_peers(PresenceCallback cb);
456
461 void close();
462
463#ifdef __ANDROID__
482 DITTO_DEPRECATED_BECAUSE(
483 "Use the Ditto constructor's `android_context` parameter instead")
484 void set_android_context(JNIEnv *env, jobject context);
485
503 std::vector<std::string> missing_permissions() const;
504
519 jobjectArray missing_permissions_jni_array() const;
520#endif
521
522private:
523 // Private Ditto::Fields structure contains the state of a Ditto instance.
524 struct Fields;
525 std::shared_ptr<Fields> fields;
526
527 // TODO(v5) Remove is_closable
528 bool is_closable;
529
530 explicit Ditto(std::shared_ptr<Fields> fields);
531
532 void set_is_closable(bool is_closable);
533 std::shared_ptr<DittoHandleWrapper> get_handle_wrapper();
534
535 friend struct StoreObserverCtx;
536 friend struct ::ditto::internal::DittoUnitTest;
537
538 static std::shared_ptr<Ditto> open_ditto_with_config(DittoConfig config);
539};
540} // namespace ditto
541
542#endif
Provides access to authentication information and methods for logging on to Ditto Cloud....
Definition Authenticator.hpp:34
Provides an interface to be able to monitor local files.
Definition DiskUsage.hpp:66
Sync & get_sync() const
Provides access to the SDK's sync functionality.
TransportConfig get_transport_config() const
Returns the current transport config.
void stop_sync() const
Stops all network transports.
DittoConfig get_config() const
Returns the configuration used to initialize this Ditto instance.
void set_transport_config(TransportConfig config)
Assign a new transports configuration.
void run_garbage_collection() const
Removes all sync metadata for any remote peers which aren't currently connected.
void disable_sync_with_v3() const
Disable sync with peers running version 3 or lower of the Ditto SDK.
static std::string default_root_directory()
Returns the default root directory where Ditto stores its data.
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...
static bool get_emoji_log_level_headings_enabled()
Gets whether or not emoji log level headings are enabled for Ditto.
std::string get_app_id() const
Get the Ditto application Id.
Sync & sync() const
Provides access to the SDK's sync functionality.
void set_device_name(std::string const &name)
Set a custom identifier for the current device.
static bool get_logging_enabled()
Gets whether or not logging is enabled for Ditto.
DiskUsage & get_disk_usage() const
Provides access to the SDK's disk usage.
static std::string get_sdk_version()
Returns a string identifying the version of the Ditto SDK.
Presence & get_presence() const
Provides access to the SDK's presence functionality.
static std::shared_ptr< Ditto > open(DittoConfig config=DittoConfig::default_config())
Create a new Ditto instance.
static void set_logging_enabled(bool enabled)
Sets whether or not logging is enabled for Ditto.
SmallPeerInfo & get_small_peer_info() const
Provides access to the SDK's Small Peer Info functionality.
PresenceObserver observe_peers(PresenceCallback cb)
Request information about Ditto peers in range of this device.
static LogLevel get_minimum_log_level()
Gets the minimum log level at which logs will be emitted for Ditto.
Ditto(std::shared_ptr< Identity > identity=Identity::OfflinePlayground(), std::string persistence_dir="")
Initializes a new Ditto instance.
void update_transport_config(std::function< void(TransportConfig &config)> lambda)
Convenience method to update the current transport config of the receiver.
static std::future< std::shared_ptr< Ditto > > open_async(DittoConfig config=DittoConfig::default_config())
Create a new Ditto instance asynchronously.
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...
void close()
Shut down Ditto and release all resources. Must be called before recreating a Ditto instance that use...
Store & get_store() const
Provides access to the SDK's store functionality.
void start_sync() const
Starts the network transports. Ditto will connect to other devices and sync with them where appropria...
static void set_emoji_log_level_headings_enabled(bool enabled)
Sets whether or not emoji log level headings are enabled for Ditto.
std::shared_ptr< Authenticator > get_auth() const
Provides access to authentication information and methods for logging on to Ditto Cloud.
bool get_is_activated() const
Returns a flag indicating whether or not the Ditto instance has been activated by a successful call t...
std::string get_absolute_persistence_directory() const
The absolute path to the persistence directory used by Ditto to persist data.
std::string get_persistence_directory() const
The persistence directory used by Ditto to persist data.
static void set_minimum_log_level(LogLevel log_level)
Sets the minimum log level at which logs should be emitted for Ditto.
static std::shared_ptr< OfflinePlaygroundIdentity > OfflinePlayground(std::string app_id="")
Construct a new OfflinePlaygroundIdentity.
Definition Presence.hpp:33
The entrypoint for small peer user info collection.
Definition SmallPeerInfo.hpp:30
Provides access to Collections and a transaction API.
Definition Store.hpp:65
Definition StoreObserver.hpp:43
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
Namespace for internal Ditto SDK functionality.
Definition Ditto.hpp:29
Namespace for the Ditto C++ SDK types and functions.
Definition AbstractDocumentPath.hpp:19
LogLevel
The log levels that the Ditto SDK supports.
Definition LogLevel.hpp:9
std::function< void(PresenceGraph)> PresenceCallback
A type representing a callback that will get called when there are updates relating to presence.
Definition Presence.hpp:26
Configuration options for initializing a Ditto instance.
Definition DittoConfig.hpp:30
static DittoConfig default_config()
Get a usable default configuration.