QtDataSync
4.2.0
A simple offline-first synchronisation framework, to synchronize data of Qt applications between devices
|
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. | |
Defaults & | operator= (const Defaults &other) |
Copy assignment operator. | |
Defaults & | operator= (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. | |
Logger * | createLogger (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... | |
QRemoteObjectNode * | remoteNode () const |
Returns the remote object node for the current thread to connect to the engine. More... | |
QSettings * | createSettings (QObject *parent=nullptr, const QString &group={}) const |
Returns a new instance of QSettings for this setup. More... | |
const QJsonSerializer * | serializer () const |
Returns the serializer of the current setup. More... | |
const ConflictResolver * | conflictResolver () 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... | |
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.
Definition at line 61 of file defaults.h.
The keys of special properties set on the defaults.
For a more details explanation, see property()
Definition at line 68 of file defaults.h.
QtDataSync::Defaults::aquireDatabase | ( | QObject * | object | ) | const |
Aquire a reference to the standard sqlite database.
object | The object the wants the reference. |
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.
QtDataSync::Defaults::conflictResolver | ( | ) | const |
Returns the conflict resolver of the current setup.
nullptr
An optional conflict resolver used to handle merge conflicts. Is null by default, but can be set by the setup.
QtDataSync::Defaults::createLogger | ( | const QByteArray & | subCategory, |
QObject * | parent = nullptr |
||
) | const |
Create a new logger instance.
subCategory | The sub category, passed to the logger constructor |
parent | The object parent of the created 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.
QtDataSync::Defaults::createSettings | ( | QObject * | parent = nullptr , |
const QString & | group = {} |
||
) | const |
Returns a new instance of QSettings for this setup.
parent | The parent object for the settings |
group | A sub-group to use as root for the returned settings |
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.
|
static |
Returns the standard key parameter for the given signature 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.
|
static |
Returns the standard key parameter for the given encryption 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.
QtDataSync::Defaults::property | ( | PropertyKey | key | ) | const |
Returns the extra property defined by the given key.
key | The key of the property to be obtained |
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.
QtDataSync::Defaults::remoteAddress | ( | ) | const |
Returns the url to use for the remote object connection.
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.
QtDataSync::Defaults::remoteNode | ( | ) | const |
Returns the remote object node for the current thread to connect to the engine.
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().
QtDataSync::Defaults::serializer | ( | ) | const |
Returns the serializer of the current setup.
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.
QtDataSync::Defaults::storageDir | ( | ) | const |
Returns the 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.