QtDataSync  4.2.0
A simple offline-first synchronisation framework, to synchronize data of Qt applications between devices
Public Types | Public Member Functions | Static Public Member Functions | List of all members
QtDataSync::Defaults Class Reference

A helper class to get defaults per datasync instance (threadsafe) More...

#include <defaults.h>

Public Types

enum  PropertyKey {
  CacheSize, PersistDeleted, ConflictPolicy, SslConfiguration,
  RemoteConfiguration, KeyStoreProvider, SignScheme, SignKeyParam,
  CryptScheme, CryptKeyParam, SymScheme, SymKeyParam,
  EventLoggingMode
}
 The keys of special properties set on the defaults. More...
 

Public Member Functions

 Defaults ()
 Default constructor. Constructs an invalid defaults object.
 
 Defaults (const Defaults &other)
 Copy constructor.
 
 Defaults (Defaults &&other) noexcept
 Move constructor.
 
Defaultsoperator= (const Defaults &other)
 Copy assignment operator.
 
Defaultsoperator= (Defaults &&other) noexcept
 Move assignment operator.
 
bool isValid () const
 Checks if the current defaults are valid. Default constructed defaults are invalid.
 
void drop ()
 Drops the reference to the defaults early.
 
LoggercreateLogger (const QByteArray &subCategory, QObject *parent=nullptr) const
 Create a new logger instance. More...
 
QString setupName () const
 Returns the name of the current setup.
 
QDir storageDir () const
 Returns the storage directory. More...
 
QUrl remoteAddress () const
 Returns the url to use for the remote object connection. More...
 
QRemoteObjectNoderemoteNode () const
 Returns the remote object node for the current thread to connect to the engine. More...
 
QSettingscreateSettings (QObject *parent=nullptr, const QString &group={}) const
 Returns a new instance of QSettings for this setup. More...
 
const QJsonSerializerserializer () const
 Returns the serializer of the current setup. More...
 
const ConflictResolverconflictResolver () const
 Returns the conflict resolver of the current setup. More...
 
QVariant property (PropertyKey key) const
 Returns the extra property defined by the given key. More...
 
DatabaseRef aquireDatabase (QObject *object) const
 Aquire a reference to the standard sqlite database. More...
 

Static Public Member Functions

static QVariant defaultParam (Setup::SignatureScheme scheme)
 Returns the standard key parameter for the given signature scheme. More...
 
static QVariant defaultParam (Setup::EncryptionScheme scheme)
 Returns the standard key parameter for the given encryption scheme. More...
 

Detailed Description

A helper class to get defaults per datasync instance (threadsafe)

This class is internally used to easily get "defaults" that vary between different setups. Unless you are extending data sync with a custom implementation, this class has no relevance for you. The things you can access from the defaults are all defined by the Setup.

Using this defaults provides save storage locations, settings, logging and more, that won't interfere with other instances of data sync. If you need to store files, settings or do some logging, you should use this defaults to do so.

See also
Setup

Definition at line 61 of file defaults.h.

Member Enumeration Documentation

◆ PropertyKey

The keys of special properties set on the defaults.

For a more details explanation, see property()

See also
Defaults::property
Enumerator
CacheSize 

The size of the internal database cache, in bytes.

PersistDeleted 

Specify whether deleted datasets should persist.

ConflictPolicy 

The policiy for how to handle conflicts.

SslConfiguration 

The ssl configuration to be used to connect to the remote.

RemoteConfiguration 

The configuration to be used to connect to the remote.

KeyStoreProvider 

The name of the preferred keystore provider.

SignScheme 

The algorithmic scheme to be used for new signature keys.

SignKeyParam 

The generation parameter for the signature key.

CryptScheme 

The algorithmic scheme to be used for new encryption keys.

CryptKeyParam 

The generation parameter for the encryption key.

SymScheme 

The algorithmic scheme to be used for new secret exchange keys (which are symmetric)

SymKeyParam 

The size in bytes for the secret exchange key (which is symmetric)

EventLoggingMode 

The logging mode for database change events.

Definition at line 68 of file defaults.h.

Member Function Documentation

◆ aquireDatabase()

QtDataSync::Defaults::aquireDatabase ( QObject object) const

Aquire a reference to the standard sqlite database.

Parameters
objectThe object the wants the reference.
Returns
An instance of the local sqlite database, wrapped in a database ref

If you are working with sqlite databases, you can use this function to get a reference to one. This allows multiple components to share one database, instead of create many. Of cause, this means will will have to be careful to not interfere with the data of other components. The database itself will be created inside the storage directory. Reference counting is used to automatically clean up connections. See the DatabaseRef documentation.

The object is used to install an event filter to detect if the object was moved to a different thread. This is needed, as a connection is only valid per thread, and thus changing a thread means creating a new connection. This is completly handeled internally, so it is save to move the databaseref to another thread via that object.

See also
DatabaseRef, Defaults::storageDir

◆ conflictResolver()

QtDataSync::Defaults::conflictResolver ( ) const

Returns the conflict resolver of the current setup.

Returns
The conflict resolver. Can be nullptr

An optional conflict resolver used to handle merge conflicts. Is null by default, but can be set by the setup.

Attention
This instance is shared across the whole setup, do not delete or change it, use it only to resolve conflicts. Please do not const_cast it ;)
See also
Setup::conflictResolver, ConflictResolver

◆ createLogger()

QtDataSync::Defaults::createLogger ( const QByteArray subCategory,
QObject parent = nullptr 
) const

Create a new logger instance.

Parameters
subCategoryThe sub category, passed to the logger constructor
parentThe object parent of the created logger
Returns
A new created instance of a logger

Uses the setup this defaults belong to and the passed category to create a logger. Read the Logger documentation for more details. The returned logger is owner by the caller (or the parent) and will use the subCategory for the logging string.

See also
Logger

◆ createSettings()

QtDataSync::Defaults::createSettings ( QObject parent = nullptr,
const QString group = {} 
) const

Returns a new instance of QSettings for this setup.

Parameters
parentThe parent object for the settings
groupA sub-group to use as root for the returned settings
Returns
A newly created settings instance

Creates a QSettings instance that will persist data for this setup. The settings reside inside of the settings storage directory, and thus are not bound to the setup name. If you want to store data persistently, like usernames etc, use this settings.

Note
You should always pass a group that idenfifies your component. This keeps the settings clean and prevents naming conflicts with other components.
See also
Defaults::storageDir

◆ defaultParam() [1/2]

QtDataSync::Defaults::defaultParam ( Setup::SignatureScheme  scheme)
static

Returns the standard key parameter for the given signature scheme.

Returns
The default key parameter for the given scheme

If the Setup::signatureKeyParam is an invalid QVariant, this method can be used to obtain the default value for the corresponding signature scheme. For more details on what this parameter is for each scheme, check the setups key param documentation.

See also
Setup::signatureScheme, Setup::signatureKeyParam

◆ defaultParam() [2/2]

QtDataSync::Defaults::defaultParam ( Setup::EncryptionScheme  scheme)
static

Returns the standard key parameter for the given encryption scheme.

Returns
The default key parameter for the given scheme

If the Setup::encryptionKeyParam is an invalid QVariant, this method can be used to obtain the default value for the corresponding encryption scheme. For more details on what this parameter is for each scheme, check the setups key param documentation.

See also
Setup::encryptionScheme, Setup::encryptionKeyParam

◆ property()

QtDataSync::Defaults::property ( PropertyKey  key) const

Returns the extra property defined by the given key.

Parameters
keyThe key of the property to be obtained
Returns
The value of the stored property for that key.

This method is used instead of many direct methods to obtains various extra properties passed from the setup. The following table shows what these are. Please read the documentation of the corresponsing Setup properties for more details on what these properties mean in details and how they may be used internally.

Key Type Setup property
Defaults::CacheSize int Setup::cacheSize
Defaults::PersistDeleted bool Setup::persistDeletedVersion
Defaults::ConflictPolicy Setup::SyncPolicy Setup::syncPolicy
Defaults::SslConfiguration QSslConfiguration Setup::sslConfigurationn
Defaults::RemoteConfiguration RemoteConfig Setup::remoteConfiguration
Defaults::KeyStoreProvider QString Setup::keyStoreProvider
Defaults::SignScheme Setup::SignatureScheme Setup::signatureScheme
Defaults::SignKeyParam QVariant Setup::signatureKeyParam
Defaults::CryptScheme Setup::EncryptionScheme Setup::encryptionScheme
Defaults::CryptKeyParam QVariant Setup::encryptionKeyParam
Defaults::SymScheme Setup::CipherScheme Setup::cipherScheme
Defaults::SymKeyParam qint32 Setup::cipherKeySize
See also
Defaults::PropertyKey, Setup

◆ remoteAddress()

QtDataSync::Defaults::remoteAddress ( ) const

Returns the url to use for the remote object connection.

Returns
The url of the remote object host created by the engine

Use this address to create QRemoteObjectNode instances to connect to the engines host node. Typically you can use remoteNode() directly, as this one works threadsafe.

See also
Defaults::remoteNode, Setup::remoteObjectHost

◆ remoteNode()

QtDataSync::Defaults::remoteNode ( ) const

Returns the remote object node for the current thread to connect to the engine.

Returns
A remote node for the current thread connected to the engines host node

The method creates a node for each thread and cleans them up automatically. The returned node is connected to the engines host node, and thus can be immediatly used to obtain replicas. If you need the url used to connect, see remoteAddress().

Note
Even though this method is threadsafe, the returned node is not. If you need to switch the thread, call this method again on the new thread to obtain a new node for that thread. If you don't, replicas of the new thread will not work.
See also
Defaults::remoteAddress, Setup::remoteObjectHost

◆ serializer()

QtDataSync::Defaults::serializer ( ) const

Returns the serializer of the current setup.

Returns
The json serializer

The serializer is the one used by datasync internally. If you need to de/serializer data in your custom implementations, make shure to use this one.

Attention
This instance is shared across the whole setup, do not delete or change it, use it only to de/serializer data. Please do not const_cast it ;)
See also
Setup::serializer, QJsonSerializer

◆ storageDir()

QtDataSync::Defaults::storageDir ( ) const

Returns the storage directory.

Returns
The local storage directory

The storage directory contains everything regarding configuration and data, and thus basically identifies the datasync instance. It is also used for locking.

When implementing a part of qtdatasync, you may need to store data on the local file system. You should always store data inside this folder. Consider it your "root folder". Storing in different locations can lead to undefined behaviour. Of cause you can create subdirs etc inside this folder as you please. However, there are some special files, like the lock file or the settings you should not modify yourself.

See also
Defaults::createSettings, Setup::localDir

The documentation for this class was generated from the following files: