Buteo Synchronization Framework: SyncSession.h Source File

Buteo Synchronization Framework

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
74 PluginRunner *pluginRunner();
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(SyncResults::MajorCode aMajorCode, SyncResults::MinorCode aMinorCode);
152
164 bool reserveStorages(StorageBooker *aStorageBooker);
165
167 void releaseStorages();
168
170 QMap<QString, bool> getStorageMap();
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, SyncResults::MinorCode 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, SyncResults::MinorCode 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 SyncProfile *iProfile;
247 PluginRunner *iPluginRunner;
248 SyncResults iResults;
249 Sync::SyncStatus iStatus;
250 SyncResults::MinorCode iErrorCode;
251 bool iPluginRunnerOwned;
252 bool iScheduled;
253 bool iAborted;
254 bool iStarted;
255 bool iFinished;
256 bool iCreateProfile;
257 QString iMessage;
258 QString iRemoteId;
259 StorageBooker *iStorageBooker;
260 QMap<QString, bool> iStorageMap;
261 NetworkManager *iNetworkManager;
262
263 #ifdef SYNCFW_UNIT_TESTS
264 friend class SyncSessionTest;
265 #endif
266 };
267
268 }
269
270 #endif // SYNCSESSION_H
Buteo::NetworkManager
Class for managing network sessions.
Definition: NetworkManager.h:43
Buteo::PluginRunner
Base class for running sync plug-ins.
Definition: PluginRunner.h:45
Buteo::StorageBooker
A helper class for managing storage reservations.
Definition: StorageBooker.h:37
Buteo::SyncProfile
A top level synchronization profile.
Definition: SyncProfile.h:49
Buteo::SyncResults
Contains information about a completed synchronization session.
Definition: SyncResults.h:59
Buteo::SyncResults::MajorCode
MajorCode
enum value
Definition: SyncResults.h:66
Buteo::SyncResults::MinorCode
MinorCode
enum value
Definition: SyncResults.h:77
Buteo::SyncSession
Class representing a single sync session.
Definition: SyncSession.h:44
Buteo::SyncSession::finished
void finished(const QString &aProfileName, Sync::SyncStatus aStatus, const QString &aMessage, SyncResults::MinorCode aErrorCode)
Signal sent when the session has finished.
Definition: moc_SyncSession.cpp:269
Buteo::SyncSession::isScheduled
bool isScheduled() const
Checks if the session was started by the scheduler.
Definition: SyncSession.cpp:261
Buteo::SyncSession::setPluginRunner
void setPluginRunner(PluginRunner *aPluginRunner, bool aTransferOwnership)
Associates a plug-in runner with this session.
Definition: SyncSession.cpp:76
Buteo::SyncSession::isAborted
bool isAborted()
Returns if the sync session was aborted.
Definition: SyncSession.cpp:167
Buteo::SyncSession::getStorageMap
QMap< QString, bool > getStorageMap()
returns the StorageMap used for this session
Definition: SyncSession.cpp:192
Buteo::SyncSession::pluginRunner
PluginRunner * pluginRunner()
Gets the plug-in runner associated with this session.
Definition: SyncSession.cpp:112
Buteo::SyncSession::results
SyncResults results() const
Gets the results of the finished session.
Definition: SyncSession.cpp:246
Buteo::SyncSession::transferProgress
void transferProgress(const QString &aProfileName, Sync::TransferDatabase aDatabase, Sync::TransferType aType, const QString &aMimeType, int aCommittedItems)
Definition: moc_SyncSession.cpp:255
Buteo::SyncSession::setProfileCreated
void setProfileCreated(bool aProfileCreated)
sets Profile Created flag to true
Definition: SyncSession.cpp:210
Buteo::SyncSession::storageAccquired
void storageAccquired(const QString &aProfileName, const QString &aMimeType)
Signal sent when a storage is accquired.
Definition: moc_SyncSession.cpp:262
Buteo::SyncSession::updateResults
void updateResults(const SyncResults &aResults)
Sets the results for this session.
Definition: SyncSession.cpp:372
Buteo::SyncSession::stop
void stop()
Stops the session. Returns when the session is stopped.
Definition: SyncSession.cpp:216
Buteo::SyncSession::abort
void abort(Sync::SyncStatus aStatus=Sync::SYNC_ABORTED)
Aborts the session. Returns when the abort request is sent.
Definition: SyncSession.cpp:172
Buteo::SyncSession::syncProgressDetail
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:276
Buteo::SyncSession::start
bool start()
Starts the session using the associated plug-in runner.
Definition: SyncSession.cpp:119
Buteo::SyncSession::setStorageMap
void setStorageMap(QMap< QString, bool > &aStorageMap)
sets the storage map for this session
Definition: SyncSession.cpp:198
Buteo::SyncSession::isFinished
bool isFinished()
Returns if the sync session is finished or in process.
Definition: SyncSession.cpp:162
Buteo::SyncSession::isProfileCreated
bool isProfileCreated()
returns the returns the status of the profile creation for this session
Definition: SyncSession.cpp:204
Buteo::SyncSession::releaseStorages
void releaseStorages()
Releases storages that were reserved earlier with reserveStorages.
Definition: SyncSession.cpp:403
Buteo::SyncSession::setFailureResult
void setFailureResult(SyncResults::MajorCode aMajorCode, SyncResults::MinorCode aMinorCode)
Sets the results for this session using the provided error code.
Definition: SyncSession.cpp:380
Buteo::SyncSession::reserveStorages
bool reserveStorages(StorageBooker *aStorageBooker)
Tries to reserve storages needed by the session.
Definition: SyncSession.cpp:388
Buteo::SyncSession::~SyncSession
virtual ~SyncSession()
Destructor.
Definition: SyncSession.cpp:51
Buteo::SyncSession::profileName
QString profileName() const
Gets the name of the profile used by this session.
Definition: SyncSession.cpp:234
Buteo::SyncSession::profile
SyncProfile * profile() const
Gets the sync profile used by this session.
Definition: SyncSession.cpp:227
Buteo::SyncSession::setScheduled
void setScheduled(bool aScheduled)
Sets if the session was started by the scheduler.
Definition: SyncSession.cpp:253
Buteo::SyncSession::SyncSession
SyncSession(SyncProfile *aProfile, QObject *aParent=0)
Constructor.
Definition: SyncSession.cpp:33
Buteo::SyncSession::mapToSyncStatusError
Sync::SyncStatus mapToSyncStatusError(int aErrorCode)
Maps sync failure error code from stack to SyncStatus.
Definition: SyncSession.cpp:308
QMap< QString, bool >