ButeoSynchronizationFramework
SyncSession.h
1 /*
2  * This file is part of buteo-syncfw package
3  *
4  * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
5  *
6  * Contact: Sateesh Kavuri <sateesh.kavuri@nokia.com>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public License
10  * version 2.1 as published by the Free Software Foundation.
11  *
12  * This library is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA
21  *
22  */
23 
24 #ifndef SYNCSESSION_H
25 #define SYNCSESSION_H
26 
27 #include "SyncCommonDefs.h"
28 #include "SyncResults.h"
29 #include <QObject>
30 #include <QMap>
31 
32 namespace Buteo {
33 
34 class SyncProfile;
35 class PluginRunner;
36 class StorageBooker;
37 class NetworkManager;
38 
43 class SyncSession : public QObject
44 {
45  Q_OBJECT
46 
47 public:
48 
56  explicit SyncSession(SyncProfile *aProfile, QObject *aParent = 0);
57 
59  virtual ~SyncSession();
60 
68  void setPluginRunner(PluginRunner *aPluginRunner, bool aTransferOwnership);
69 
75 
80  bool isFinished();
81 
86  bool isAborted();
87 
92  bool start();
93 
97  void abort(Sync::SyncStatus aStatus = Sync::SYNC_ABORTED);
98 
101  void stop();
102 
107  SyncProfile *profile() const;
108 
113  QString profileName() const;
114 
121  SyncResults results() const;
122 
127  void setScheduled(bool aScheduled);
128 
133  bool isScheduled() const;
134 
141  void updateResults(const SyncResults &aResults);
142 
151  void setFailureResult(int aMajorCode, int aMinorCode);
152 
164  bool reserveStorages(StorageBooker *aStorageBooker);
165 
167  void releaseStorages();
168 
171 
176  void setStorageMap(QMap<QString,bool> &aStorageMap);
177 
179  bool isProfileCreated();
180 
182  void setProfileCreated(bool aProfileCreated);
183 
185  Sync::SyncStatus mapToSyncStatusError(int aErrorCode);
186 
187 signals:
188 
190  void transferProgress(const QString &aProfileName,
191  Sync::TransferDatabase aDatabase, Sync::TransferType aType,
192  const QString &aMimeType, int aCommittedItems);
193 
199  void storageAccquired (const QString &aProfileName , const QString &aMimeType) ;
200 
208  void finished(const QString &aProfileName, Sync::SyncStatus aStatus,
209  const QString &aMessage, int aErrorCode);
210 
216  void syncProgressDetail(const QString &aProfileName,int aProgressDetail);
217 private:
218 
219  bool tryStart();
220 
221 private slots:
222 
223  // Slots for catching plug-in runner signals.
224 
225  void onSuccess(const QString &aProfileName, const QString &aMessage);
226 
227  void onError(const QString &aProfileName, const QString &aMessage, int aErrorCode);
228 
229  void onTransferProgress(const QString &aProfileName,
230  Sync::TransferDatabase aDatabase, Sync::TransferType aType,
231  const QString &aMimeType, int aCommittedItems);
232 
233  void onStorageAccquired (const QString &aMimeType);
234 
235  void onSyncProgressDetail(const QString &aProfileName,int aProgressDetail);
236 
237  void onDone();
238 
239  void onDestroyed(QObject *aPluginRunner);
240 
241  void onNetworkSessionOpened();
242 
243  void onNetworkSessionError();
244 
245  private:
246 
247  SyncProfile *iProfile;
248 
249  PluginRunner *iPluginRunner;
250 
251  SyncResults iResults;
252 
253  Sync::SyncStatus iStatus;
254 
255  int iErrorCode;
256 
257  bool iPluginRunnerOwned;
258 
259  bool iScheduled;
260 
261  bool iAborted;
262 
263  bool iStarted;
264 
265  bool iFinished;
266 
267  bool iCreateProfile;
268 
269  QString iMessage;
270 
271  QString iRemoteId ;
272 
273  StorageBooker *iStorageBooker;
274 
275  QMap<QString , bool> iStorageMap;
276 
277  NetworkManager *iNetworkManager;
278 
279  #ifdef SYNCFW_UNIT_TESTS
280  friend class SyncSessionTest;
281  #endif
282 
283 };
284 
285 }
286 
287 #endif // SYNCSESSION_H
Sync::SyncStatus mapToSyncStatusError(int aErrorCode)
Maps sync failure error code from stack to SyncStatus.
Definition: SyncSession.cpp:333
void releaseStorages()
Releases storages that were reserved earlier with reserveStorages.
Definition: SyncSession.cpp:435
void transferProgress(const QString &aProfileName, Sync::TransferDatabase aDatabase, Sync::TransferType aType, const QString &aMimeType, int aCommittedItems)
Definition: moc_SyncSession.cpp:247
virtual ~SyncSession()
Destructor.
Definition: SyncSession.cpp:51
void storageAccquired(const QString &aProfileName, const QString &aMimeType)
Signal sent when a storage is accquired.
Definition: moc_SyncSession.cpp:254
bool isScheduled() const
Checks if the session was started by the scheduler.
Definition: SyncSession.cpp:281
QString profileName() const
Gets the name of the profile used by this session.
Definition: SyncSession.cpp:253
Contains information about a completed synchronization session.
Definition: SyncResults.h:58
void finished(const QString &aProfileName, Sync::SyncStatus aStatus, const QString &aMessage, int aErrorCode)
Signal sent when the session has finished.
Definition: moc_SyncSession.cpp:261
bool isProfileCreated()
returns the returns the status of the profile creation for this session
Definition: SyncSession.cpp:220
void setFailureResult(int aMajorCode, int aMinorCode)
Sets the results for this session using the provided error code.
Definition: SyncSession.cpp:411
Definition: AccountsHelper.h:31
QMap< QString, bool > getStorageMap()
returns the StorageMap used for this session
Definition: SyncSession.cpp:208
bool isAborted()
Returns if the sync session was aborted.
Definition: SyncSession.cpp:179
bool isFinished()
Returns if the sync session is finished or in process.
Definition: SyncSession.cpp:174
void abort(Sync::SyncStatus aStatus=Sync::SYNC_ABORTED)
Aborts the session. Returns when the abort request is sent.
Definition: SyncSession.cpp:184
void updateResults(const SyncResults &aResults)
Sets the results for this session.
Definition: SyncSession.cpp:403
void setStorageMap(QMap< QString, bool > &aStorageMap)
sets the storage map for this session
Definition: SyncSession.cpp:214
void setPluginRunner(PluginRunner *aPluginRunner, bool aTransferOwnership)
Associates a plug-in runner with this session.
Definition: SyncSession.cpp:78
void setScheduled(bool aScheduled)
Sets if the session was started by the scheduler.
Definition: SyncSession.cpp:274
SyncResults results() const
Gets the results of the finished session.
Definition: SyncSession.cpp:266
Class representing a single sync session.
Definition: SyncSession.h:43
bool start()
Starts the session using the associated plug-in runner.
Definition: SyncSession.cpp:124
bool reserveStorages(StorageBooker *aStorageBooker)
Tries to reserve storages needed by the session.
Definition: SyncSession.cpp:419
SyncProfile * profile() const
Gets the sync profile used by this session.
Definition: SyncSession.cpp:246
PluginRunner * pluginRunner()
Gets the plug-in runner associated with this session.
Definition: SyncSession.cpp:117
Class for managing network sessions.
Definition: NetworkManager.h:43
void setProfileCreated(bool aProfileCreated)
sets Profile Created flag to true
Definition: SyncSession.cpp:226
Base class for running sync plug-ins.
Definition: PluginRunner.h:44
A top level synchronization profile.
Definition: SyncProfile.h:47
void syncProgressDetail(const QString &aProfileName, int aProgressDetail)
Signal sent when the sync is in progress to indicate the detail of the progress.
Definition: moc_SyncSession.cpp:268
SyncSession(SyncProfile *aProfile, QObject *aParent=0)
Constructor.
Definition: SyncSession.cpp:33
A helper class for managing storage reservations.
Definition: StorageBooker.h:36
void stop()
Stops the session. Returns when the session is stopped.
Definition: SyncSession.cpp:232