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

Manages the synchronization process and reports its state. More...

#include <syncmanager.h>

+ Inheritance diagram for QtDataSync::SyncManager:

Public Types

enum  SyncState {
  Initializing, Downloading, Uploading, Synchronized,
  Error, Disconnected
}
 The possible states the sync engine can be in. More...
 

Public Slots

void setSyncEnabled (bool syncEnabled)
 WRITE accessor for syncEnabled.
 
void synchronize ()
 Triggers a synchronization. More...
 
void reconnect ()
 Tries to reconnect to the remote. More...
 

Signals

QT_DATASYNC_REVISION_2 void setupNameChanged (const QString &setupName, QPrivateSignal)
 NOTIFY accessor for AccountManager::setupName.
 
void syncEnabledChanged (bool syncEnabled, QPrivateSignal)
 NOTIFY accessor for syncEnabled.
 
void syncStateChanged (QtDataSync::SyncManager::SyncState syncState, QPrivateSignal)
 NOTIFY accessor for syncState.
 
void syncProgressChanged (qreal syncProgress, QPrivateSignal)
 NOTIFY accessor for syncProgress.
 
void lastErrorChanged (const QString &lastError, QPrivateSignal)
 NOTIFY accessor for lastError.
 

Public Member Functions

 SyncManager (QObject *parent=nullptr)
 Default constructor, uses the default setup. More...
 
 SyncManager (const QString &setupName, QObject *parent=nullptr)
 Constructor with an explicit setup. More...
 
 SyncManager (QRemoteObjectNode *node, QObject *parent=nullptr)
 Constructor with a remote object node to connect to. More...
 
Q_INVOKABLE QRemoteObjectReplicareplica () const
 The internal replica used to connect to the engine. More...
 
QString setupName () const
 READ accessor for AccountManager::setupName.
 
bool isSyncEnabled () const
 READ accessor for syncEnabled.
 
SyncState syncState () const
 READ accessor for syncState.
 
qreal syncProgress () const
 READ accessor for syncProgress.
 
QString lastError () const
 READ accessor for lastError.
 
void runOnDownloaded (const std::function< void(SyncState)> &resultFn, bool triggerSync=true)
 Performs an operation once all changes have been downloaded. More...
 
void runOnSynchronized (const std::function< void(SyncState)> &resultFn, bool triggerSync=true)
 Performs an operation once all changes have been synchronized (both directions) More...
 
- Public Member Functions inherited from QObject
virtual const QMetaObjectmetaObject () const const
 
virtual void * qt_metacast (const char *)
 
virtual int qt_metacall (QMetaObject::Call, int, void **)
 
 QObject (QObject *parent)
 
virtual bool event (QEvent *e)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
QString objectName () const const
 
void setObjectName (const QString &name)
 
bool isWidgetType () const const
 
bool isWindowType () const const
 
bool signalsBlocked () const const
 
bool blockSignals (bool block)
 
QThreadthread () const const
 
void moveToThread (QThread *targetThread)
 
int startTimer (int interval, Qt::TimerType timerType)
 
int startTimer (std::chrono::milliseconds time, Qt::TimerType timerType)
 
void killTimer (int id)
 
findChild (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegExp &regExp, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const
 
const QObjectList & children () const const
 
void setParent (QObject *parent)
 
void installEventFilter (QObject *filterObj)
 
void removeEventFilter (QObject *obj)
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const
 
bool disconnect (const char *signal, const QObject *receiver, const char *method) const const
 
bool disconnect (const QObject *receiver, const char *method) const const
 
void dumpObjectTree ()
 
void dumpObjectInfo ()
 
void dumpObjectTree () const const
 
void dumpObjectInfo () const const
 
bool setProperty (const char *name, const QVariant &value)
 
QVariant property (const char *name) const const
 
QList< QByteArraydynamicPropertyNames () const const
 
void destroyed (QObject *obj)
 
void objectNameChanged (const QString &objectName)
 
QObjectparent () const const
 
bool inherits (const char *className) const const
 
void deleteLater ()
 

Properties

QString setupName
 Holds the name of the setup this manager operates on. More...
 
bool syncEnabled
 Specifies whether synchronization is currently enabled or disabled. More...
 
SyncState syncState
 Holds the current synchronization state. More...
 
qreal syncProgress
 Holds the progress of the current sync operation. More...
 
QString lastError
 Holds a description of the last internal error. More...
 
- Properties inherited from QObject
 objectName
 

Additional Inherited Members

- Static Public Member Functions inherited from QObject
QString tr (const char *sourceText, const char *disambiguation, int n)
 
QString trUtf8 (const char *sourceText, const char *disambiguation, int n)
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, Functor functor)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type)
 
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
bool disconnect (const QMetaObject::Connection &connection)
 
bool disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method)
 
- Protected Member Functions inherited from QObject
QObjectsender () const const
 
int senderSignalIndex () const const
 
int receivers (const char *signal) const const
 
bool isSignalConnected (const QMetaMethod &signal) const const
 
virtual void timerEvent (QTimerEvent *event)
 
virtual void childEvent (QChildEvent *event)
 
virtual void customEvent (QEvent *event)
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 

Detailed Description

Manages the synchronization process and reports its state.

The manager connects to the engine via a QRemoteObjectNode. Internally the class holds a replica of a source that is part of the datasync engine which is created by the setup. Typically, this node is managed by the setup too, but you can specify your own node in the constructor. In order to increase security and performance a special remote object connection is used that utilizes events to deliver messages within the same process only. See Threaded remote objects for details.

See also
Threaded remote objects, Setup::remoteObjectHost

Definition at line 20 of file syncmanager.h.

Member Enumeration Documentation

◆ SyncState

The possible states the sync engine can be in.

Enumerator
Initializing 

Initializing internal stuff and connecting to a remote.

Downloading 

Downloading changes from the remote.

Uploading 

Uploading changes to the remote.

Synchronized 

All changes have been synchronized. The engine is idle.

Error 

An internal error occured. Synchronization is paused until reconnect() is called.

Disconnected 

The remote is not available or sync has been disabled and the engine thus is disconnected.

Definition at line 37 of file syncmanager.h.

Constructor & Destructor Documentation

◆ SyncManager() [1/3]

QtDataSync::SyncManager::SyncManager ( QObject parent = nullptr)
explicit

Default constructor, uses the default setup.

Parameters
parentThe parent object
Exceptions
SetupDoesNotExistExceptionThrown if the default setup was not created yet

◆ SyncManager() [2/3]

QtDataSync::SyncManager::SyncManager ( const QString setupName,
QObject parent = nullptr 
)
explicit

Constructor with an explicit setup.

Parameters
setupNameThe name of the setup to connect to
parentThe parent object
Exceptions
SetupDoesNotExistExceptionThrown if the given setup was not created yet

◆ SyncManager() [3/3]

QtDataSync::SyncManager::SyncManager ( QRemoteObjectNode node,
QObject parent = nullptr 
)
explicit

Constructor with a remote object node to connect to.

Parameters
nodeThe remote object node used to connect to the source objects
parentThe parent object

Member Function Documentation

◆ reconnect

QtDataSync::SyncManager::reconnect ( )
slot

Tries to reconnect to the remote.

Completely reconnects to the remote. If currently connected, the remote is first disconnected, then reconnected. Can also be used to leave the SyncManager::Error state and go back to the normal operational mode. If no remote is defined or the synchronization is disabled, reconnecting will not have any effect.

Note
If the engine is disconnected, but a remote is defined and sync enabled, it will automatically reconnect peridically. There is no need to explicitly reconnect in such a case.
See also
SyncManager::syncState, SyncManager::synchronize

◆ replica()

QtDataSync::SyncManager::replica ( ) const

The internal replica used to connect to the engine.

Returns
A pointer to the interal replica object

Returns a reference to the internally used replica which connects to the engine. The replica is only valid as long as the SyncManager exists. You can use the replica reference to get information about it's state etc.

◆ runOnDownloaded()

QtDataSync::SyncManager::runOnDownloaded ( const std::function< void(SyncState)> &  resultFn,
bool  triggerSync = true 
)

Performs an operation once all changes have been downloaded.

Parameters
resultFnThe function to be called as soon as a target state is reached
triggerSyncTrigger a synchronisation in case the engine is currently synchronized

Semantics of the resultFn:

  • Parameter 1: The state reached that triggered this callback

This method behaves just like runOnSynchronized(), but with the one difference that the SyncManager::Uploading state will also trigger the callback (in both phases). This method can be used to only wait for all changes to be downloaded from the remote, instead of waiting for the uploads as well.

See also
SyncManager::runOnSynchronized

◆ runOnSynchronized()

QtDataSync::SyncManager::runOnSynchronized ( const std::function< void(SyncState)> &  resultFn,
bool  triggerSync = true 
)

Performs an operation once all changes have been synchronized (both directions)

Parameters
resultFnThe function to be called as soon as a target state is reached
triggerSyncTrigger a synchronisation in case the engine is currently synchronized

Semantics of the resultFn:

  • Parameter 1: The state reached that triggered this callback

This method will pass a callback to the engine that is called as soon as a "stable" state is reached. The logic is as follows:

If the engine is in the SyncManager::Error or SyncManager::Disconnected state, the callback is immediatly called. If it is SyncManager::Synchronized, and triggerSync is false, it will be called too. If it is true a new synchronization is triggered and the method is not called yet. For all other states, nothing happens yet.

If the method was not directly called, the engine will instead call it as soon as one of the SyncManager::Synchronized, SyncManager::Error or SyncManager::Disconnected states is reached.

The state that triggerd the function to be called is the one that is passed to the callback.

See also
SyncManager::runOnDownloaded

◆ synchronize

QtDataSync::SyncManager::synchronize ( )
slot

Triggers a synchronization.

This method will only work if the engine is currently in the SyncManager::Synchronized state. In all other cases it does nothing. To leave the error state, use reconnect() instead.

See also
SyncManager::syncState, SyncManager::reconnect

Property Documentation

◆ lastError

QtDataSync::SyncManager::lastError
read

Holds a description of the last internal error.

Default: empty

When the engine is in the SyncManager::Error state, this property contains a localized error string to be displayed to the user. As long as it stays in the error state this property keeps the string. As soon as the engine enters another state, the error gets cleared. To leave the error state, one must reconnect the engine explicitly by calling the reconnect() method.

Accessors
READlastError()
NOTIFYlastErrorChanged()
See also
SyncManager::syncState

Definition at line 33 of file syncmanager.h.

◆ setupName

QtDataSync::SyncManager::setupName
read

Holds the name of the setup this manager operates on.

Default: QtDataSync::DefaultSetup

The setup name is the name that was passed to the Setup::create method to create the datasync instance this manager is refering to.

Accessors
READsetupName()
NOTIFYsetupNameChanged()
REVISION2
See also
QtDataSync::DefaultSetup, Setup::create

Definition at line 25 of file syncmanager.h.

◆ syncEnabled

QtDataSync::SyncManager::syncEnabled
readwrite

Specifies whether synchronization is currently enabled or disabled.

Default: true

Changing this property will asynchronously trigger the specific operation in the engine, i.e. either disconnect it to disable sync, or start initializing in order to synchronize again. Whether the engine can actually connect to a remote can be monitored via SyncManager::syncState.

Accessors
READisSyncEnabled()
WRITEsetSyncEnabled()
NOTIFYsyncEnabledChanged()
See also
SyncManager::syncState

Definition at line 27 of file syncmanager.h.

◆ syncProgress

QtDataSync::SyncManager::syncProgress
read

Holds the progress of the current sync operation.

Default: -1.0

When in the SyncManager::Downloading or SyncManager::Uploading state, this property will provide a progress of that operation. The possible progress values range from 0.0 to 1.0. If there is currently no active progress (i.e. because the engine is in a state different from those two), the progress is set to -1.0, meaning that there is no progress to show.

Accessors
READsyncProgress()
NOTIFYsyncProgressChanged()
See also
SyncManager::syncState

Definition at line 31 of file syncmanager.h.

◆ syncState

QtDataSync::SyncManager::syncState
read

Holds the current synchronization state.

Default: SyncManager::Initializing

The sync state is simply forwareded form the engine. When in Downloading or Uploading state, the SyncManager::syncProgress property can be used to monitor the progress of each of those operations. When in the Error state, SyncManager::lastError holds the error string, and the engine disconnects from the remote. It will stay in the error state until it is explicitly cleared by calling reconnect(). When disconnected, the engine automatically tries to reconnect to the remote periodically, unless no remote is defined or synchronization has been disabled. Explicit tries to connect can by made by reconnect().

Accessors
READsyncState()
NOTIFYsyncStateChanged()
See also
SyncManager::SyncState, SyncManager::syncEnabled, SyncManager::syncProgress, SyncManager::lastError, SyncManager::synchronize, SyncManager::reconnect

Definition at line 29 of file syncmanager.h.


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