Ditto 5.0.0
Loading...
Searching...
No Matches
Public Member Functions | List of all members
ditto::Sync Class Reference

Provides access to sync related functionality of Ditto. More...

Public Member Functions

 Sync (const Sync &other)=default
 
 Sync (Sync &&other)=default
 
Syncoperator= (const Sync &other)=default
 
Syncoperator= (Sync &&other)=default
 
void start () const
 Starts the network transports. Ditto will connect to other devices and sync with them where appropriate.
 
void stop () const
 Stops all network transports.
 
bool is_active () const
 Returns a flag indicating whether or not sync is active. Use start to activate sync and stop to deactivate sync.
 
std::shared_ptr< SyncSubscriptionregister_subscription (std::string query, nlohmann::json query_arguments=nullptr)
 Installs and returns a sync subscription for a query, configuring Ditto to receive updates from other peers for documents matching that query. The provided query must be a SELECT query.
 
SyncSubscriptionSet get_subscriptions () const
 Returns a snapshot of all active subscriptions.
 

Detailed Description

Provides access to sync related functionality of Ditto.

Member Function Documentation

◆ is_active()

bool ditto::Sync::is_active ( ) const

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

Returns
a flag indicating whether or not sync is active.

◆ register_subscription()

std::shared_ptr< SyncSubscription > ditto::Sync::register_subscription ( std::string  query,
nlohmann::json  query_arguments = nullptr 
)

Installs and returns a sync subscription for a query, configuring Ditto to receive updates from other peers for documents matching that query. The provided query must be a SELECT query.

Parameters
querya string containing a valid query expressed in DQL.
query_argumentsa dictionary of values keyed by the placeholder name without the leading :. Example: {{"mileage", 123}}.
Returns
An active SyncSubscription for the provided query and arguments. You'll have to keep it to be able to cancel the replication subscription, i.e. remove it from the store again. Otherwise it will remain active until the Ditto instance goes out of scope.

◆ start()

void ditto::Sync::start ( ) 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 default network configuration can be modified with update_transport_config or replaced with set_transport_config.

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

◆ stop()

void ditto::Sync::stop ( ) const

Stops all network transports.

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