Buteo Synchronization Framework
synchronizer.h
1/*
2 * This file is part of buteo-syncfw package
3 *
4 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
5 * Copyright (C) 2014-2019 Jolla Ltd.
6 * Copyright (C) 2020 Open Mobile Platform LLC.
7 *
8 * Contact: Sateesh Kavuri <sateesh.kavuri@nokia.com>
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public License
12 * version 2.1 as published by the Free Software Foundation.
13 *
14 * This library is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22 * 02110-1301 USA
23 *
24 */
25#ifndef SYNCHRONIZER_H
26#define SYNCHRONIZER_H
27
28#include "SyncDBusInterface.h"
29#include "SyncQueue.h"
30#include "StorageBooker.h"
31#include "SyncScheduler.h"
32#include "SyncBackup.h"
33#include "SyncOnChange.h"
34#include "SyncOnChangeScheduler.h"
35
36#include "SyncCommonDefs.h"
37#include "ProfileManager.h"
38#include "PluginManager.h"
39#include "PluginCbInterface.h"
40#include "ClientPlugin.h"
41
42#include <QVector>
43#include <QMutex>
44#include <QCoreApplication>
45#include <QMap>
46#include <QString>
47#include <QDBusInterface>
48#include <QScopedPointer>
49#include <QTimer>
50
51struct _GSettings;
52
53namespace Buteo {
54
55class PluginManager;
56class ServerPluginRunner;
57class NetworkManager;
58class TransportTracker;
59class ServerActivator;
60class AccountsHelper;
61class BatteryInfo;
62
67class Synchronizer : public SyncDBusInterface, // Derived from QObject
69{
70 Q_OBJECT
71
72public:
74 Synchronizer(QCoreApplication *aApplication);
75
77 virtual ~Synchronizer();
78
81 bool initialize();
82
84 void close();
85
86
87// From PluginCbInterface
88// ---------------------------------------------------------------------------
90 virtual bool requestStorage(const QString &aStorageName,
91 const SyncPluginBase *aCaller);
92
94 virtual void releaseStorage(const QString &aStorageName,
95 const SyncPluginBase *aCaller);
96
98 virtual StoragePlugin *createStorage(const QString &aPluginName);
99
101 virtual void destroyStorage(StoragePlugin *aStorage);
102
104 virtual bool isConnectivityAvailable(Sync::ConnectivityType aType);
105
107 virtual Profile *getSyncProfileByRemoteAddress(const QString &aAddress);
108
110 virtual QString getValue(const QString &aAddress, const QString &aKey);
111
112
113// From SyncDBusInterface
114// --------------------------------------------------------------------------
115
116public slots:
118 virtual bool startSync(QString aProfileName);
119
121 virtual void abortSync(QString aProfileName);
122
124 virtual bool removeProfile(QString aProfileAsXml);
125
127 virtual bool updateProfile(QString aProfileAsXml);
128
130 virtual bool requestStorages(QStringList aStorageNames);
131
133 virtual void releaseStorages(QStringList aStorageNames);
134
136 virtual QStringList runningSyncs();
137
139 virtual bool setSyncSchedule(QString aProfileId, QString aScheduleAsXml);
140
142 virtual bool saveSyncResults(QString aProfileId, QString aSyncResults);
143
145 virtual QString createSyncProfileForAccount(uint aAccountId);
146
151 virtual QString getLastSyncResult(const QString &aProfileId);
152
159 virtual QStringList allVisibleSyncProfiles();
160
169 virtual QString syncProfile(const QString &aProfileId);
170 virtual QStringList syncProfilesByKey(const QString &aKey, const QString &aValue);
171 virtual QStringList syncProfilesByType(const QString &aType);
172 virtual QStringList profilesByType(const QString &aType) override;
173// --------------------------------------------------------------------------
174
176 bool startScheduledSync(QString aProfileName);
177
179 void backupStarts();
180
182 void backupFinished();
183
185 void restoreStarts();
186
188 void restoreFinished();
189
191 virtual bool getBackUpRestoreState();
192
193 void start(unsigned int aAccountId);
194
199 void stop(unsigned int aAccountId);
200
206
220 int status(unsigned int aAccountId, int &aFailedReason, qlonglong &aPrevSyncTime, qlonglong &aNextSyncTime);
221
230 void isSyncedExternally(unsigned int aAccountId, const QString aClientProfileName);
231
232signals:
234 void storageReleased();
235
241 void syncDone(const QString &aProfileName);
242
243private slots:
249 void onStorageReleased();
250
251 void onTransferProgress(const QString &aProfileName,
252 Sync::TransferDatabase aDatabase, Sync::TransferType aType,
253 const QString &aMimeType, int aCommittedItems);
254
255 void onSessionFinished(const QString &aProfileName,
256 Sync::SyncStatus aStatus, const QString &aMessage,
257 SyncResults::MinorCode aErrorCode);
258
259 void onStorageAccquired(const QString &aProfileName, const QString &aMimeType);
260
261 void onSyncProgressDetail(const QString &aProfileName, int aProgressDetail);
262
263 void onServerDone();
264
265 void onNewSession(const QString &aDestination);
266
267 void slotProfileChanged(QString aProfileName, int aChangeType, QString aProfileAsXml);
268
273 void startServer(const QString &aProfileName);
274
279 void stopServer(const QString &aProfileName);
280
281 void onNetworkStateChanged(bool aState, Sync::InternetConnectionType type);
282
289 void enableSOCSlot(const QString &aProfileName);
290
295 void reschedule(const QString &aProfileName);
296
304 void slotSyncStatus(QString aProfileName, int aStatus,
305 QString aMessage, int aMoreDetails);
306
311 void removeScheduledSync(const QString &aProfileName);
312
318 void reportExternalSyncStatus(const QString &aProfileName, bool force);
319
321 void profileChangeTriggerTimeout();
322
323private:
324 bool startSync(const QString &aProfileName, bool aScheduled);
325
331 bool startSyncNow(SyncSession *aSession);
332
339 bool startNextSync();
340
346 void cleanupSession(SyncSession *aSession, Sync::SyncStatus aStatus);
347
352 void startServers(bool resume = false);
353
358 void stopServers(bool suspend = false);
359
363 void backupRestoreStarts();
364
368 void backupRestoreFinished();
369
373 void initializeScheduler();
374
375 bool isBackupRestoreInProgress();
376
382 bool cleanupProfile(const QString &profileId);
383
384 bool clientProfileActive(const QString &clientProfileName);
385
391 void removeExternalSyncStatus(const SyncProfile *aProfile);
392
397 bool acceptScheduledSync(bool aConnected, Sync::InternetConnectionType aType, SyncProfile *profile) const;
398
406 void reportExternalSyncStatus(const SyncProfile *aProfile, bool force = false);
407
408 QMap<QString, SyncSession *> iActiveSessions;
409 QMap<QString, bool> iExternalSyncProfileStatus;
410 QList<QString> iProfilesToRemove;
412 QList<QString> iWaitingOnlineSyncs;
413 NetworkManager *iNetworkManager;
414 QMap<QString, int> iCountersStorage;
415 PluginManager iPluginManager;
416 ProfileManager iProfileManager;
417 SyncQueue iSyncQueue;
418 StorageBooker iStorageBooker;
419 SyncScheduler *iSyncScheduler;
420 SyncBackup *iSyncBackup;
421 TransportTracker *iTransportTracker;
422 ServerActivator *iServerActivator;
423 AccountsHelper *iAccounts;
424 bool iClosing;
425 SyncOnChange iSyncOnChange;
426 SyncOnChangeScheduler iSyncOnChangeScheduler;
427
432 void saveProfileCounter(const SyncProfile *aProfile);
433
438 void restoreProfileCounter(SyncProfile *aProfile);
439
440 bool iSOCEnabled;
441 QString iUUID;
442 QString iRemoteName;
443
444 /*
445 * Temporary, until we can clean up Buteo and properly implement the SyncOnChange
446 * queue to handle all of the required changes (account + profile + connectivity)
447 * in a sane manner (also taking into account BackupRestore status).
448 * However, that change will be far more invasive, so for now this is much simpler.
449 */
451 QTimer iProfileChangeTriggerTimer;
452
453#ifdef SYNCFW_UNIT_TESTS
454 friend class SynchronizerTest;
455#endif
456
457 QDBusInterface *iSyncUIInterface;
458 _GSettings *iSettings;
459 BatteryInfo *iBatteryInfo;
460};
461
462}
463
464#endif // SYNCHRONIZER_H
Helper Class towards Accounts::Manager and various SSO related operations.
Definition AccountsHelper.h:42
Class for managing network sessions.
Definition NetworkManager.h:43
Interface which client and server plugins can use to communicate with synchronization daemon.
Definition PluginCbInterface.h:39
Manages plugins.
Definition PluginManager.h:56
ProfileManager is responsible for storing and retrieving the profiles.
Definition ProfileManager.h:46
This class represents a single profile, a collection of settings or data releated to some entity.
Definition Profile.h:53
Keeps track of which server plug-ins should be enabled.
Definition ServerActivator.h:48
A helper class for managing storage reservations.
Definition StorageBooker.h:37
Base class for storage plugins.
Definition StoragePlugin.h:39
Handles Sync requirements towards Backup.
Definition SyncBackup.h:38
Defines a D-Bus interface for the sync daemon.
Definition msyncd/SyncDBusInterface.h:42
Definition SyncOnChangeScheduler.h:15
this class initiates a sync if there are changes in storage(s) it's asked to monitor
Definition SyncOnChange.h:19
Base class for client and server plugins.
Definition SyncPluginBase.h:46
A top level synchronization profile.
Definition SyncProfile.h:49
Class for queuing sync sessions.
Definition SyncQueue.h:38
MinorCode
enum value
Definition SyncResults.h:89
SyncScheduler Object to be used to set Schedule via the framework.
Definition SyncScheduler.h:55
Class representing a single sync session.
Definition SyncSession.h:44
The main entry point to the synchronization framework.
Definition synchronizer.h:69
virtual void abortSync(QString aProfileName)
Definition synchronizer.cpp:785
virtual void releaseStorages(QStringList aStorageNames)
Definition synchronizer.cpp:951
virtual Profile * getSyncProfileByRemoteAddress(const QString &aAddress)
Definition synchronizer.cpp:1870
virtual QString createSyncProfileForAccount(uint aAccountId)
Definition synchronizer.cpp:375
virtual ~Synchronizer()
Destructor.
Definition synchronizer.cpp:111
virtual QStringList allVisibleSyncProfiles()
Gets all visible sync profiles.
Definition synchronizer.cpp:1742
void syncDone(const QString &aProfileName)
emit this signal when the sync session is completed, this is useful when the session status is not im...
Definition moc_synchronizer.cpp:434
void restoreFinished()
Called when backup is restored.
Definition synchronizer.cpp:1604
bool initialize()
registers the dbus service and creates handlers for various tasks of the synchronizer
Definition synchronizer.cpp:120
bool startScheduledSync(QString aProfileName)
Called starts a schedule sync.
Definition synchronizer.cpp:294
void stop(unsigned int aAccountId)
Stops sync for all profiles matching the given account ID.
Definition synchronizer.cpp:1628
void backupStarts()
Called when backup starts.
Definition synchronizer.cpp:1583
void restoreStarts()
Called when starting to restore a backup.
Definition synchronizer.cpp:1597
void close()
stops the daemon and unregisters the dbus object
Definition synchronizer.cpp:246
virtual void destroyStorage(StoragePlugin *aStorage)
Definition synchronizer.cpp:1078
virtual bool isConnectivityAvailable(Sync::ConnectivityType aType)
Definition synchronizer.cpp:1085
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:1639
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:2031
void storageReleased()
emitted by releaseStorages call
Definition moc_synchronizer.cpp:428
virtual QString getLastSyncResult(const QString &aProfileId)
To get lastSyncResult.
Definition synchronizer.cpp:1718
virtual QString getValue(const QString &aAddress, const QString &aKey)
Definition synchronizer.cpp:1890
virtual StoragePlugin * createStorage(const QString &aPluginName)
Definition synchronizer.cpp:1042
virtual bool startSync(QString aProfileName)
Definition synchronizer.cpp:286
virtual QString syncProfile(const QString &aProfileId)
Gets a sync profile.
Definition synchronizer.cpp:1762
virtual bool removeProfile(QString aProfileAsXml)
Definition synchronizer.cpp:876
void backupFinished()
Called when backup is completed.
Definition synchronizer.cpp:1590
QList< unsigned int > syncingAccounts()
Returns the list of account IDs for which sync is ongoing.
Definition synchronizer.cpp:1689
virtual bool updateProfile(QString aProfileAsXml)
Definition synchronizer.cpp:894
virtual bool requestStorages(QStringList aStorageNames)
Definition synchronizer.cpp:944
virtual bool requestStorage(const QString &aStorageName, const SyncPluginBase *aCaller)
Definition synchronizer.cpp:1024
virtual QStringList runningSyncs()
Definition synchronizer.cpp:959
virtual void releaseStorage(const QString &aStorageName, const SyncPluginBase *aCaller)
Definition synchronizer.cpp:1033
virtual bool setSyncSchedule(QString aProfileId, QString aScheduleAsXml)
Definition synchronizer.cpp:351
virtual bool saveSyncResults(QString aProfileId, QString aSyncResults)
Definition synchronizer.cpp:361
virtual bool getBackUpRestoreState()
Called to get the current backup/restore state.
Definition synchronizer.cpp:1611
Class for tracking transport states.
Definition TransportTracker.h:50
Definition SyncBackupAdaptor.h:40
Definition SyncBackupAdaptor.h:41