synchronizer.h
/*
* This file is part of buteo-syncfw package
*
* Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
* Copyright (C) 2014-2019 Jolla Ltd.
* Copyright (C) 2020 Open Mobile Platform LLC.
*
* Contact: Sateesh Kavuri <sateesh.kavuri@nokia.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2.1 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
#ifndef SYNCHRONIZER_H
#define SYNCHRONIZER_H
#include "SyncDBusInterface.h"
#include "SyncQueue.h"
#include "StorageBooker.h"
#include "SyncScheduler.h"
#include "SyncBackup.h"
#include "SyncOnChange.h"
#include "SyncOnChangeScheduler.h"
#include "SyncCommonDefs.h"
#include "ProfileManager.h"
#include "PluginManager.h"
#include "PluginCbInterface.h"
#include "ClientPlugin.h"
#include <QVector>
#include <QMutex>
#include <QCoreApplication>
#include <QMap>
#include <QString>
#include <QDBusInterface>
#include <QScopedPointer>
#include <QTimer>
struct _GSettings;
namespace Buteo {
class PluginManager;
class ServerPluginRunner;
class NetworkManager;
class TransportTracker;
class ServerActivator;
class AccountsHelper;
class BatteryInfo;
class Synchronizer : public SyncDBusInterface, // Derived from QObject
public PluginCbInterface
{
Q_OBJECT
public:
Synchronizer(QCoreApplication *aApplication);
virtual ~Synchronizer();
bool initialize();
void close();
// From PluginCbInterface
// ---------------------------------------------------------------------------
virtual bool requestStorage(const QString &aStorageName,
const SyncPluginBase *aCaller);
virtual void releaseStorage(const QString &aStorageName,
const SyncPluginBase *aCaller);
virtual StoragePlugin *createStorage(const QString &aPluginName);
virtual void destroyStorage(StoragePlugin *aStorage);
virtual bool isConnectivityAvailable(Sync::ConnectivityType aType);
virtual Profile *getSyncProfileByRemoteAddress(const QString &aAddress);
virtual QString getValue(const QString &aAddress, const QString &aKey);
// From SyncDBusInterface
// --------------------------------------------------------------------------
public slots:
virtual bool startSync(QString aProfileName);
virtual void abortSync(QString aProfileName);
virtual bool removeProfile(QString aProfileAsXml);
virtual bool updateProfile(QString aProfileAsXml);
virtual bool requestStorages(QStringList aStorageNames);
virtual void releaseStorages(QStringList aStorageNames);
virtual QStringList runningSyncs();
virtual bool setSyncSchedule(QString aProfileId, QString aScheduleAsXml);
virtual bool saveSyncResults(QString aProfileId, QString aSyncResults);
virtual QString createSyncProfileForAccount(uint aAccountId);
virtual QString getLastSyncResult(const QString &aProfileId);
virtual QStringList allVisibleSyncProfiles();
virtual QString syncProfile(const QString &aProfileId);
virtual QStringList syncProfilesByKey(const QString &aKey, const QString &aValue);
virtual QStringList syncProfilesByType(const QString &aType);
virtual QStringList profilesByType(const QString &aType) override;
// --------------------------------------------------------------------------
bool startScheduledSync(QString aProfileName);
void backupStarts();
void backupFinished();
void restoreStarts();
void restoreFinished();
virtual bool getBackUpRestoreState();
void start(unsigned int aAccountId);
void stop(unsigned int aAccountId);
QList<unsigned int> syncingAccounts();
int status(unsigned int aAccountId, int &aFailedReason, qlonglong &aPrevSyncTime, qlonglong &aNextSyncTime);
void isSyncedExternally(unsigned int aAccountId, const QString aClientProfileName);
signals:
void storageReleased();
void syncDone(const QString &aProfileName);
private slots:
void onStorageReleased();
void onTransferProgress(const QString &aProfileName,
Sync::TransferDatabase aDatabase, Sync::TransferType aType,
const QString &aMimeType, int aCommittedItems);
void onSessionFinished(const QString &aProfileName,
Sync::SyncStatus aStatus, const QString &aMessage,
SyncResults::MinorCode aErrorCode);
void onStorageAccquired(const QString &aProfileName, const QString &aMimeType);
void onSyncProgressDetail(const QString &aProfileName, int aProgressDetail);
void onServerDone();
void onNewSession(const QString &aDestination);
void slotProfileChanged(QString aProfileName, int aChangeType, QString aProfileAsXml);
void startServer(const QString &aProfileName);
void stopServer(const QString &aProfileName);
void onNetworkStateChanged(bool aState, Sync::InternetConnectionType type);
void enableSOCSlot(const QString &aProfileName);
void reschedule(const QString &aProfileName);
void slotSyncStatus(QString aProfileName, int aStatus,
QString aMessage, int aMoreDetails);
void removeScheduledSync(const QString &aProfileName);
void reportExternalSyncStatus(const QString &aProfileName, bool force);
void profileChangeTriggerTimeout();
private:
bool startSync(const QString &aProfileName, bool aScheduled);
bool startSyncNow(SyncSession *aSession);
bool startNextSync();
void cleanupSession(SyncSession *aSession, Sync::SyncStatus aStatus);
void startServers(bool resume = false);
void stopServers(bool suspend = false);
void backupRestoreStarts();
void backupRestoreFinished();
void initializeScheduler();
bool isBackupRestoreInProgress();
bool cleanupProfile(const QString &profileId);
bool clientProfileActive(const QString &clientProfileName);
void removeExternalSyncStatus(const SyncProfile *aProfile);
bool acceptScheduledSync(bool aConnected, Sync::InternetConnectionType aType, SyncProfile *profile) const;
void reportExternalSyncStatus(const SyncProfile *aProfile, bool force = false);
QMap<QString, SyncSession *> iActiveSessions;
QMap<QString, bool> iExternalSyncProfileStatus;
QList<QString> iProfilesToRemove;
QMap<QString, ServerPluginRunner *> iServers;
QList<QString> iWaitingOnlineSyncs;
NetworkManager *iNetworkManager;
QMap<QString, int> iCountersStorage;
PluginManager iPluginManager;
ProfileManager iProfileManager;
SyncQueue iSyncQueue;
StorageBooker iStorageBooker;
SyncScheduler *iSyncScheduler;
SyncBackup *iSyncBackup;
TransportTracker *iTransportTracker;
ServerActivator *iServerActivator;
AccountsHelper *iAccounts;
bool iClosing;
SyncOnChange iSyncOnChange;
SyncOnChangeScheduler iSyncOnChangeScheduler;
void saveProfileCounter(const SyncProfile *aProfile);
void restoreProfileCounter(SyncProfile *aProfile);
bool iSOCEnabled;
QString iUUID;
QString iRemoteName;
/*
* Temporary, until we can clean up Buteo and properly implement the SyncOnChange
* queue to handle all of the required changes (account + profile + connectivity)
* in a sane manner (also taking into account BackupRestore status).
* However, that change will be far more invasive, so for now this is much simpler.
*/
QList<QPair<QString, ProfileManager::ProfileChangeType> > iProfileChangeTriggerQueue;
QTimer iProfileChangeTriggerTimer;
#ifdef SYNCFW_UNIT_TESTS
friend class SynchronizerTest;
#endif
QDBusInterface *iSyncUIInterface;
_GSettings *iSettings;
BatteryInfo *iBatteryInfo;
};
}
#endif // SYNCHRONIZER_H
Buteo::AccountsHelper
Helper Class towards Accounts::Manager and various SSO related operations.
Definition AccountsHelper.h:42
Buteo::NetworkManager
Class for managing network sessions.
Definition NetworkManager.h:44
Buteo::PluginCbInterface
Interface which client and server plugins can use to communicate with synchronization daemon.
Definition PluginCbInterface.h:39
Buteo::PluginManager
Manages plugins.
Definition PluginManager.h:56
Buteo::ProfileManager
ProfileManager is responsible for storing and retrieving the profiles.
Definition ProfileManager.h:47
Buteo::Profile
This class represents a single profile, a collection of settings or data releated to some entity.
Definition Profile.h:53
Buteo::ServerActivator
Keeps track of which server plug-ins should be enabled.
Definition ServerActivator.h:48
Buteo::ServerPluginRunner
Class for running server sync plug-ins.
Definition ServerPluginRunner.h:39
Buteo::StorageBooker
A helper class for managing storage reservations.
Definition StorageBooker.h:37
Buteo::StoragePlugin
Base class for storage plugins.
Definition StoragePlugin.h:39
Buteo::SyncBackup
Handles Sync requirements towards Backup.
Definition SyncBackup.h:38
Buteo::SyncDBusInterface
Defines a D-Bus interface for the sync daemon.
Definition msyncd/SyncDBusInterface.h:42
Buteo::SyncOnChangeScheduler
Definition SyncOnChangeScheduler.h:15
Buteo::SyncOnChange
this class initiates a sync if there are changes in storage(s) it's asked to monitor
Definition SyncOnChange.h:18
Buteo::SyncPluginBase
Base class for client and server plugins.
Definition SyncPluginBase.h:46
Buteo::SyncProfile
A top level synchronization profile.
Definition SyncProfile.h:49
Buteo::SyncQueue
Class for queuing sync sessions.
Definition SyncQueue.h:38
Buteo::SyncResults::MinorCode
MinorCode
enum value
Definition SyncResults.h:93
Buteo::SyncScheduler
SyncScheduler Object to be used to set Schedule via the framework.
Definition SyncScheduler.h:58
Buteo::SyncSession
Class representing a single sync session.
Definition SyncSession.h:44
Buteo::Synchronizer::abortSync
virtual void abortSync(QString aProfileName)
Definition synchronizer.cpp:789
Buteo::Synchronizer::releaseStorages
virtual void releaseStorages(QStringList aStorageNames)
Definition synchronizer.cpp:956
Buteo::Synchronizer::getSyncProfileByRemoteAddress
virtual Profile * getSyncProfileByRemoteAddress(const QString &aAddress)
Definition synchronizer.cpp:1877
Buteo::Synchronizer::createSyncProfileForAccount
virtual QString createSyncProfileForAccount(uint aAccountId)
Definition synchronizer.cpp:379
Buteo::Synchronizer::~Synchronizer
virtual ~Synchronizer()
Destructor.
Definition synchronizer.cpp:114
Buteo::Synchronizer::allVisibleSyncProfiles
virtual QStringList allVisibleSyncProfiles()
Gets all visible sync profiles.
Definition synchronizer.cpp:1749
Buteo::Synchronizer::syncDone
void syncDone(const QString &aProfileName)
emit this signal when the sync session is completed, this is useful when the session status is not im...
Buteo::Synchronizer::restoreFinished
void restoreFinished()
Called when backup is restored.
Definition synchronizer.cpp:1608
Buteo::Synchronizer::initialize
bool initialize()
registers the dbus service and creates handlers for various tasks of the synchronizer
Definition synchronizer.cpp:123
Buteo::Synchronizer::startScheduledSync
bool startScheduledSync(QString aProfileName)
Called starts a schedule sync.
Definition synchronizer.cpp:298
Buteo::Synchronizer::stop
void stop(unsigned int aAccountId)
Stops sync for all profiles matching the given account ID.
Definition synchronizer.cpp:1633
Buteo::Synchronizer::backupStarts
void backupStarts()
Called when backup starts.
Definition synchronizer.cpp:1587
Buteo::Synchronizer::restoreStarts
void restoreStarts()
Called when starting to restore a backup.
Definition synchronizer.cpp:1601
Buteo::Synchronizer::close
void close()
stops the daemon and unregisters the dbus object
Definition synchronizer.cpp:250
Buteo::Synchronizer::destroyStorage
virtual void destroyStorage(StoragePlugin *aStorage)
Definition synchronizer.cpp:1083
Buteo::Synchronizer::isConnectivityAvailable
virtual bool isConnectivityAvailable(Sync::ConnectivityType aType)
Definition synchronizer.cpp:1090
Buteo::Synchronizer::status
int status(unsigned int aAccountId, int &aFailedReason, qlonglong &aPrevSyncTime, qlonglong &aNextSyncTime)
Returns the status of the sync for the given account Id.
Definition synchronizer.cpp:1645
Buteo::Synchronizer::isSyncedExternally
void isSyncedExternally(unsigned int aAccountId, const QString aClientProfileName)
Queries the sync externally status of a given account, 'syncedExternallyStatus' signal is emitted wit...
Definition synchronizer.cpp:2048
Buteo::Synchronizer::storageReleased
void storageReleased()
emitted by releaseStorages call
Buteo::Synchronizer::getLastSyncResult
virtual QString getLastSyncResult(const QString &aProfileId)
To get lastSyncResult.
Definition synchronizer.cpp:1726
Buteo::Synchronizer::getValue
virtual QString getValue(const QString &aAddress, const QString &aKey)
Definition synchronizer.cpp:1899
Buteo::Synchronizer::createStorage
virtual StoragePlugin * createStorage(const QString &aPluginName)
Definition synchronizer.cpp:1047
Buteo::Synchronizer::startSync
virtual bool startSync(QString aProfileName)
Definition synchronizer.cpp:290
Buteo::Synchronizer::Synchronizer
Synchronizer(QCoreApplication *aApplication)
The contructor.
Definition synchronizer.cpp:93
Buteo::Synchronizer::syncProfile
virtual QString syncProfile(const QString &aProfileId)
Gets a sync profile.
Definition synchronizer.cpp:1769
Buteo::Synchronizer::removeProfile
virtual bool removeProfile(QString aProfileAsXml)
Definition synchronizer.cpp:880
Buteo::Synchronizer::backupFinished
void backupFinished()
Called when backup is completed.
Definition synchronizer.cpp:1594
Buteo::Synchronizer::syncingAccounts
QList< unsigned int > syncingAccounts()
Returns the list of account IDs for which sync is ongoing.
Definition synchronizer.cpp:1696
Buteo::Synchronizer::updateProfile
virtual bool updateProfile(QString aProfileAsXml)
Definition synchronizer.cpp:899
Buteo::Synchronizer::requestStorages
virtual bool requestStorages(QStringList aStorageNames)
Definition synchronizer.cpp:949
Buteo::Synchronizer::requestStorage
virtual bool requestStorage(const QString &aStorageName, const SyncPluginBase *aCaller)
Definition synchronizer.cpp:1029
Buteo::Synchronizer::runningSyncs
virtual QStringList runningSyncs()
Definition synchronizer.cpp:964
Buteo::Synchronizer::releaseStorage
virtual void releaseStorage(const QString &aStorageName, const SyncPluginBase *aCaller)
Definition synchronizer.cpp:1038
Buteo::Synchronizer::setSyncSchedule
virtual bool setSyncSchedule(QString aProfileId, QString aScheduleAsXml)
Definition synchronizer.cpp:355
Buteo::Synchronizer::saveSyncResults
virtual bool saveSyncResults(QString aProfileId, QString aSyncResults)
Definition synchronizer.cpp:365
Buteo::Synchronizer::getBackUpRestoreState
virtual bool getBackUpRestoreState()
Called to get the current backup/restore state.
Definition synchronizer.cpp:1615
Buteo::TransportTracker
Class for tracking transport states.
Definition TransportTracker.h:49
QList
Definition SyncBackupAdaptor.h:40
QMap
Definition SyncBackupAdaptor.h:41