ButeoSynchronizationFramework
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-2015 Jolla Ltd
6  *
7  * Contact: Sateesh Kavuri <sateesh.kavuri@nokia.com>
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * version 2.1 as published by the Free Software Foundation.
12  *
13  * This library is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21  * 02110-1301 USA
22  *
23  */
24 #ifndef SYNCHRONIZER_H
25 #define SYNCHRONIZER_H
26 
27 #include "SyncDBusInterface.h"
28 #include "SyncQueue.h"
29 #include "StorageBooker.h"
30 #include "SyncScheduler.h"
31 #include "SyncBackup.h"
32 #include "SyncOnChange.h"
33 #include "SyncOnChangeScheduler.h"
34 
35 #include "SyncCommonDefs.h"
36 #include "ProfileManager.h"
37 #include "PluginManager.h"
38 #include "PluginCbInterface.h"
39 #include "ClientPlugin.h"
40 
41 #include <QVector>
42 #include <QMutex>
43 #include <QCoreApplication>
44 #include <QMap>
45 #include <QString>
46 #include <QDBusInterface>
47 #include <QScopedPointer>
48 
49 struct _GSettings;
50 
51 namespace Buteo {
52 
53 class PluginManager;
54 class ServerPluginRunner;
55 class NetworkManager;
56 class TransportTracker;
57 class ServerActivator;
58 class AccountsHelper;
59 
64 class Synchronizer : public SyncDBusInterface, // Derived from QObject
65  public PluginCbInterface
66 {
67  Q_OBJECT
68 public:
69 
71  Synchronizer(QCoreApplication *aApplication);
72 
74  virtual ~Synchronizer();
75 
78  bool initialize();
79 
81  void close();
82 
83 
84 // From PluginCbInterface
85 // ---------------------------------------------------------------------------
87  virtual bool requestStorage(const QString &aStorageName,
88  const SyncPluginBase *aCaller);
89 
91  virtual void releaseStorage(const QString &aStorageName,
92  const SyncPluginBase *aCaller);
93 
95  virtual StoragePlugin* createStorage(const QString &aPluginName);
96 
98  virtual void destroyStorage(StoragePlugin *aStorage);
99 
101  virtual bool isConnectivityAvailable( Sync::ConnectivityType aType );
102 
104  virtual Profile* getSyncProfileByRemoteAddress(const QString& aAddress);
105 
107  virtual QString getValue(const QString& aAddress, const QString& aKey);
108 
109 
110 // From SyncDBusInterface
111 // --------------------------------------------------------------------------
112 
113 public slots:
114 
116  virtual bool startSync(QString aProfileName);
117 
119  virtual void abortSync(QString aProfileName);
120 
122  virtual bool removeProfile(QString aProfileAsXml);
123 
125  virtual bool updateProfile(QString aProfileAsXml);
126 
128  virtual bool requestStorages(QStringList aStorageNames);
129 
131  virtual void releaseStorages(QStringList aStorageNames);
132 
134  virtual QStringList runningSyncs();
135 
137  virtual bool setSyncSchedule(QString aProfileId , QString aScheduleAsXml);
138 
140  virtual bool saveSyncResults(QString aProfileId,QString aSyncResults);
141 
143  virtual QString createSyncProfileForAccount(uint aAccountId);
144 
149  virtual QString getLastSyncResult(const QString &aProfileId);
150 
157  virtual QStringList allVisibleSyncProfiles();
158 
167  virtual QString syncProfile(const QString &aProfileId);
168  virtual QStringList syncProfilesByKey(const QString &aKey, const QString &aValue);
169  virtual QStringList syncProfilesByType(const QString &aType);
170 // --------------------------------------------------------------------------
171 
173  bool startScheduledSync(QString aProfileName);
174 
176  void backupStarts();
177 
179  void backupFinished();
180 
182  void restoreStarts();
183 
185  void restoreFinished();
186 
188  virtual bool getBackUpRestoreState();
189 
190  void start(unsigned int aAccountId);
191 
196  void stop(unsigned int aAccountId);
197 
203 
217  int status(unsigned int aAccountId, int &aFailedReason, qlonglong &aPrevSyncTime, qlonglong &aNextSyncTime);
218 
227  void isSyncedExternally(unsigned int aAccountId, const QString aClientProfileName);
228 
229 signals:
230 
232  void storageReleased();
233 
239  void syncDone(const QString &aProfileName);
240 
241 private slots:
242 
248  void onStorageReleased();
249 
250  void onTransferProgress( const QString &aProfileName,
251  Sync::TransferDatabase aDatabase, Sync::TransferType aType,
252  const QString &aMimeType, int aCommittedItems );
253 
254  void onSessionFinished( const QString &aProfileName,
255  Sync::SyncStatus aStatus, const QString &aMessage, int aErrorCode );
256 
257  void onStorageAccquired(const QString &aProfileName, const QString &aMimeType);
258 
259  void onSyncProgressDetail(const QString &aProfileName,int aProgressDetail);
260 
261  void onServerDone();
262 
263  void onNewSession(const QString &aDestination);
264 
265  void slotProfileChanged(QString aProfileName, int aChangeType , QString aProfileAsXml);
266 
271  void startServer(const QString &aProfileName);
272 
277  void stopServer(const QString &aProfileName);
278 
279  void onNetworkStateChanged(bool aState, Sync::InternetConnectionType type);
280 
287  void enableSOCSlot(const QString& aProfileName);
288 
293  void reschedule(const QString &aProfileName);
294 
302  void slotSyncStatus(QString aProfileName, int aStatus,
303  QString aMessage, int aMoreDetails);
304 
309  void removeScheduledSync(const QString &aProfileName);
310 
318  void externalSyncStatus(const SyncProfile *aProfile, bool aQuery=false);
319 
320 private:
321 
322  bool startSync(const QString &aProfileName, bool aScheduled);
323 
329  bool startSyncNow(SyncSession *aSession);
330 
337  bool startNextSync();
338 
344  void cleanupSession(SyncSession *aSession, Sync::SyncStatus aStatus);
345 
350  void startServers( bool resume = false );
351 
356  void stopServers( bool suspend = false );
357 
361  void backupRestoreStarts ();
362 
366  void backupRestoreFinished();
367 
371  void initializeScheduler();
372 
373  bool isBackupRestoreInProgress ();
374 
380  bool cleanupProfile(const QString &profileId);
381 
382  bool clientProfileActive(const QString &clientProfileName);
383 
389  void removeExternalSyncStatus(const SyncProfile *aProfile);
390 
395  bool acceptScheduledSync(bool aConnected, Sync::InternetConnectionType aType) const;
396 
397  QMap<QString, SyncSession*> iActiveSessions;
398 
399  QMap<QString, bool> iExternalSyncProfileStatus;
400 
401  QList<QString> iProfilesToRemove;
402 
404 
405  QList<QString> iWaitingOnlineSyncs;
406 
407  NetworkManager *iNetworkManager;
408 
409  QMap<QString, int> iCountersStorage;
410 
411  PluginManager iPluginManager;
412 
413  ProfileManager iProfileManager;
414 
415  SyncQueue iSyncQueue;
416 
417  StorageBooker iStorageBooker;
418 
419  SyncScheduler *iSyncScheduler;
420 
421  SyncBackup *iSyncBackup;
422 
423  TransportTracker *iTransportTracker;
424 
425  ServerActivator *iServerActivator;
426 
427  AccountsHelper *iAccounts;
428 
429  bool iClosing;
430 
431  SyncOnChange iSyncOnChange;
432 
433  SyncOnChangeScheduler iSyncOnChangeScheduler;
434 
439  void saveProfileCounter(const SyncProfile* aProfile);
440 
445  void restoreProfileCounter(SyncProfile* aProfile);
446 
447  bool iSOCEnabled;
448 
449  QString iUUID;
450 
451  QString iRemoteName;
452 
453 #ifdef SYNCFW_UNIT_TESTS
454  friend class SynchronizerTest;
455 #endif
456 
457  QDBusInterface *iSyncUIInterface;
458  _GSettings *iSettings;
459 };
460 
461 }
462 
463 #endif // SYNCHRONIZER_H
virtual QStringList runningSyncs()
Definition: synchronizer.cpp:1026
virtual Profile * getSyncProfileByRemoteAddress(const QString &aAddress)
Definition: synchronizer.cpp:1974
void restoreFinished()
Called when backup is restored.
Definition: synchronizer.cpp:1700
This class represents a single profile, a collection of settings or data releated to some entity...
Definition: Profile.h:52
virtual bool startSync(QString aProfileName)
Definition: synchronizer.cpp:283
Definition: SyncOnChangeScheduler.h:15
Manages plugins.
Definition: PluginManager.h:91
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:2129
virtual void releaseStorages(QStringList aStorageNames)
Definition: synchronizer.cpp:1018
void close()
stops the daemon and unregisters the dbus object
Definition: synchronizer.cpp:235
this class initiates a sync if there are changes in storage(s) it's asked to monitor ...
Definition: SyncOnChange.h:19
virtual bool requestStorages(QStringList aStorageNames)
Definition: synchronizer.cpp:1011
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:1737
QList< unsigned int > syncingAccounts()
Returns the list of account IDs for which sync is ongoing.
Definition: synchronizer.cpp:1797
virtual QStringList allVisibleSyncProfiles()
Gets all visible sync profiles.
Definition: synchronizer.cpp:1858
Definition: AccountsHelper.h:31
Synchronizer(QCoreApplication *aApplication)
The contructor.
Definition: synchronizer.cpp:65
void storageReleased()
emitted by releaseStorages call
Definition: moc_synchronizer.cpp:413
Class for queuing sync sessions.
Definition: SyncQueue.h:37
void stop(unsigned int aAccountId)
Stops sync for all profiles matching the given account ID.
Definition: synchronizer.cpp:1725
virtual StoragePlugin * createStorage(const QString &aPluginName)
Definition: synchronizer.cpp:1110
virtual QString createSyncProfileForAccount(uint aAccountId)
Definition: synchronizer.cpp:343
Keeps track of which server plug-ins should be enabled.
Definition: ServerActivator.h:47
virtual bool setSyncSchedule(QString aProfileId, QString aScheduleAsXml)
Definition: synchronizer.cpp:319
virtual bool isConnectivityAvailable(Sync::ConnectivityType aType)
Definition: synchronizer.cpp:1156
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:419
virtual bool requestStorage(const QString &aStorageName, const SyncPluginBase *aCaller)
Definition: synchronizer.cpp:1092
The main entry point to the synchronization framework.
Definition: synchronizer.h:64
Defines a D-Bus interface for the sync daemon.
Definition: msyncd/SyncDBusInterface.h:41
virtual ~Synchronizer()
Destructor.
Definition: synchronizer.cpp:81
Helper Class towards Accounts::Manager and various SSO related operations.
Definition: AccountsHelper.h:43
ProfileManager is responsible for storing and retrieving the profiles.
Definition: ProfileManager.h:45
virtual void releaseStorage(const QString &aStorageName, const SyncPluginBase *aCaller)
Definition: synchronizer.cpp:1101
virtual QString getLastSyncResult(const QString &aProfileId)
To get lastSyncResult.
Definition: synchronizer.cpp:1832
Class representing a single sync session.
Definition: SyncSession.h:43
virtual bool saveSyncResults(QString aProfileId, QString aSyncResults)
Definition: synchronizer.cpp:329
SyncScheduler Object to be used to set Schedule via the framework.
Definition: SyncScheduler.h:52
Interface which client and server plugins can use to communicate with synchronization daemon...
Definition: PluginCbInterface.h:38
virtual bool getBackUpRestoreState()
Called to get the current backup/restore state.
Definition: synchronizer.cpp:1707
Handles Sync requirements towards Backup.
Definition: SyncBackup.h:37
virtual QString syncProfile(const QString &aProfileId)
Gets a sync profile.
Definition: synchronizer.cpp:1879
virtual bool updateProfile(QString aProfileAsXml)
Definition: synchronizer.cpp:959
virtual void destroyStorage(StoragePlugin *aStorage)
Definition: synchronizer.cpp:1149
void backupFinished()
Called when backup is completed.
Definition: synchronizer.cpp:1686
Class for managing network sessions.
Definition: NetworkManager.h:43
void restoreStarts()
Called when starting to restore a backup.
Definition: synchronizer.cpp:1693
Base class for client and server plugins.
Definition: SyncPluginBase.h:45
A top level synchronization profile.
Definition: SyncProfile.h:47
bool initialize()
registers the dbus service and creates handlers for various tasks of the synchronizer ...
Definition: synchronizer.cpp:92
Class for tracking transport states.
Definition: TransportTracker.h:47
A helper class for managing storage reservations.
Definition: StorageBooker.h:36
Base class for storage plugins.
Definition: StoragePlugin.h:38
virtual bool removeProfile(QString aProfileAsXml)
Definition: synchronizer.cpp:938
bool startScheduledSync(QString aProfileName)
Called starts a schedule sync.
Definition: synchronizer.cpp:291
virtual void abortSync(QString aProfileName)
Definition: synchronizer.cpp:840
Definition: SyncBackupAdaptor.h:41
void backupStarts()
Called when backup starts.
Definition: synchronizer.cpp:1679
Definition: SyncBackupAdaptor.h:40
virtual QString getValue(const QString &aAddress, const QString &aKey)
Definition: synchronizer.cpp:2010