Ditto 3.0.11
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Member Functions | List of all members
ditto::Ditto Class Reference

The entrypoint to the Ditto SDK. More...

#include <Ditto.hpp>

Classes

class  Fields
 

Public Member Functions

 Ditto (std::shared_ptr< Identity > identity=Identity::OfflinePlayground(), std::string persistence_dir="")
 Initializes a new Ditto instance.
 
 Ditto (Ditto const &other)=delete
 
 Ditto (Ditto &&other) noexcept
 
Dittooperator= (Ditto const &other)=delete
 
Dittooperator= (Ditto &&other) noexcept
 
std::shared_ptr< Authenticatorget_auth () const
 Provides access to authentication information and methods for logging on to Ditto Cloud.
 
Storeget_store () const
 Provides access to the SDK's store functionality.
 
Presenceget_presence () const
 Provides access to the SDK's presence functionality.
 
DiskUsageget_disk_usage () const
 Provides access to the SDK's disk usage.
 
TransportConfig get_transport_config () const
 Returns the current transport config.
 
bool get_is_sync_active () const
 Returns a flag indicating whether or not sync is active. Use start_sync to activate sync and stop_sync to deactivate sync.
 
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 (OfflinePlayground, Manual or SharedKey) Ditto instance before you have activated it.
 
void start_sync () const
 Starts the network transports. Ditto will connect to other devices and sync with them where appropriate.
 
void stop_sync () const
 Stops all network transports.
 
void disable_sync_with_v2 () const
 Explicitly opt-in to disabling the ability to sync with Ditto peers running any version of the SDK in the v2 series of releases.
 
void set_transport_config (TransportConfig config)
 Assign a new transports configuration.
 
void update_transport_config (std::function< void(TransportConfig &config)> lambda)
 Convenience method to update the current transport config of the receiver.
 
void run_garbage_collection () const
 Removes all sync metadata for any remote peers which aren't currently connected.
 
std::string get_app_id () const
 Get the Ditto application Id.
 
std::string get_persistence_directory () const
 Get the persistence directory used by Ditto to persist data.
 
PresenceObserver observe_peers (PresenceCallback cb)
 TODO.
 
void close ()
 Shut down Ditto and release all resources. Must be called before recreating a Ditto instance that uses the same persistence directory.
 

Static Public Member Functions

static std::string get_sdk_version ()
 Returns a string identifying the version of the Ditto SDK.
 
static bool get_logging_enabled ()
 Gets whether or not logging is enabled for Ditto.
 
static void set_logging_enabled (bool enabled)
 Sets whether or not logging is enabled for Ditto.
 
static bool get_emoji_log_level_headings_enabled ()
 Gets whether or not emoji log level headings are enabled for Ditto.
 
static void set_emoji_log_level_headings_enabled (bool enabled)
 Sets whether or not emoji log level headings are enabled for Ditto.
 
static LogLevel get_minimum_log_level ()
 Gets the minimum log level at which logs will be emitted for Ditto.
 
static void set_minimum_log_level (LogLevel log_level)
 Sets the minimum log level at which logs should be emitted for Ditto.
 

Detailed Description

The entrypoint to the Ditto SDK.

For a Ditto instance to continue to connect to other devices it must be kept in scope.

Constructor & Destructor Documentation

◆ Ditto()

ditto::Ditto::Ditto ( std::shared_ptr< Identity identity = Identity::OfflinePlayground(),
std::string  persistence_dir = "" 
)
explicit

Initializes a new Ditto instance.

Parameters
[in]identitythe identity of the entity that will be interacting with Ditto.
[in]directorythe directory that will be used to persist Ditto data.

Member Function Documentation

◆ disable_sync_with_v2()

void ditto::Ditto::disable_sync_with_v2 ( ) const

Explicitly opt-in to disabling the ability to sync with Ditto peers running any version of the SDK in the v2 series of releases.

Assuming this succeeds then this peer will only be able to sync with other peers using SDKs in the v3 series of releases. Note that this disabling of sync spreads to peers that sync with a peer that has disabled, or has (transitively) had disabled, syncing with v2 SDK peers.

Exceptions
DittoErrorthrown if the operation fails.

◆ get_app_id()

std::string ditto::Ditto::get_app_id ( ) const

Get the Ditto application Id.

Returns
the Ditto application Id.

◆ get_auth()

std::shared_ptr< Authenticator > ditto::Ditto::get_auth ( ) const

Provides access to authentication information and methods for logging on to Ditto Cloud.

Returns
a shared pointer to an Authenticator.

◆ get_disk_usage()

DiskUsage & ditto::Ditto::get_disk_usage ( ) const

Provides access to the SDK's disk usage.

Returns
a DiskUsage object.

◆ get_emoji_log_level_headings_enabled()

bool ditto::Ditto::get_emoji_log_level_headings_enabled ( )
static

Gets whether or not emoji log level headings are enabled for Ditto.

Returns
a bool representing whether or not emoji log level headings are enabled for Ditto.

◆ get_is_sync_active()

bool ditto::Ditto::get_is_sync_active ( ) const

Returns a flag indicating whether or not sync is active. Use start_sync to activate sync and stop_sync to deactivate sync.

Returns
a flag indicating whether or not sync is active.

◆ get_logging_enabled()

bool ditto::Ditto::get_logging_enabled ( )
static

Gets whether or not logging is enabled for Ditto.

Returns
a bool representing whether or not logging is enabled for Ditto.

◆ get_minimum_log_level()

LogLevel ditto::Ditto::get_minimum_log_level ( )
static

Gets the minimum log level at which logs will be emitted for Ditto.

Returns
the minimum log level at which logs will be emitted for Ditto.

◆ get_persistence_directory()

std::string ditto::Ditto::get_persistence_directory ( ) const

Get the persistence directory used by Ditto to persist data.

Returns
the path of directory used by Ditto to persist data.

◆ get_presence()

Presence & ditto::Ditto::get_presence ( ) const

Provides access to the SDK's presence functionality.

Returns
a Presence object.

◆ get_sdk_version()

std::string ditto::Ditto::get_sdk_version ( )
static

Returns a string identifying the version of the Ditto SDK.

Returns
a string identifying the version of the Ditto SDK.

◆ get_store()

Store & ditto::Ditto::get_store ( ) const

Provides access to the SDK's store functionality.

Returns
a Store object.

◆ get_transport_config()

TransportConfig ditto::Ditto::get_transport_config ( ) const

Returns the current transport config.

Returns
the current transport config.

◆ observe_peers()

PresenceObserver ditto::Ditto::observe_peers ( PresenceCallback  cb)

TODO.

Parameters
cb
Returns
PresenceObserver

◆ run_garbage_collection()

void ditto::Ditto::run_garbage_collection ( ) const

Removes all sync metadata for any remote peers which aren't currently connected.

This method shouldn't usually be called. Manually running garbage collection often will result in slower sync times. Ditto automatically runs a garbage a collection process in the background at optimal times.

Manually running garbage collection is typically only useful during testing if large amounts of data are being generated. Alternatively, if an entire data set is to be evicted and it's clear that maintaining this metadata isn't necessary, then garbage collection could be run after evicting the old data.

◆ set_emoji_log_level_headings_enabled()

void ditto::Ditto::set_emoji_log_level_headings_enabled ( bool  enabled)
static

Sets whether or not emoji log level headings are enabled for Ditto.

Parameters
[in]enableda bool representing whether or not emoji log level headings are enabled for Ditto.

◆ set_logging_enabled()

void ditto::Ditto::set_logging_enabled ( bool  enabled)
static

Sets whether or not logging is enabled for Ditto.

Parameters
[in]enableda bool representing whether or not logging is enabled for Ditto.

◆ set_minimum_log_level()

void ditto::Ditto::set_minimum_log_level ( LogLevel  log_level)
static

Sets the minimum log level at which logs should be emitted for Ditto.

Parameters
[in]log_levelthe minimum log level at which logs should be emitted for Ditto.

◆ set_offline_only_license_token()

void ditto::Ditto::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 (OfflinePlayground, Manual or SharedKey) Ditto instance before you have activated it.

Parameters
[in]license_strthe license token to activate the Ditto instance with, which you can find on the Ditto portal (https://portal.ditto.live).

◆ set_transport_config()

void ditto::Ditto::set_transport_config ( TransportConfig  config)

Assign a new transports configuration.

By default peer-to-peer transports (Bluetooth and WiFi, where available) are enabled.

You may use this method to alter the configuration at any time. Sync will not begin until start_sync is called.

◆ start_sync()

void ditto::Ditto::start_sync ( ) const

Starts the network transports. Ditto will connect to other devices and sync with them where appropriate.

By default Ditto will enable all peer-to-peer transport types. The network configuration can be customized using set_transport_config.

Exceptions
DittoErrorthrown if the Ditto instance hasn't been activated by a successful call to set_license_token. If running on Android, throws if a Context has not been provided via set_android_context.

◆ stop_sync()

void ditto::Ditto::stop_sync ( ) const

Stops all network transports.

You may continue to use the database locally but no data will sync to or from other devices.

◆ update_transport_config()

void ditto::Ditto::update_transport_config ( std::function< void(TransportConfig &config)>  lambda)

Convenience method to update the current transport config of the receiver.

Invokes the block with a mutable copy of the current transport config which you can alter to your liking. The updated transport config is then set on the receiver.

You may use this method to alter the configuration at any time. Sync will not begin until start_sync is invoked.