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
32namespace Buteo {
33
34class SyncProfile;
35class PluginRunner;
36class StorageBooker;
37class NetworkManager;
38
43class SyncSession : public QObject
44{
45 Q_OBJECT
46
47public:
55 explicit SyncSession(SyncProfile *aProfile, QObject *aParent = 0);
56
58 virtual ~SyncSession();
59
67 void setPluginRunner(PluginRunner *aPluginRunner, bool aTransferOwnership);
68
74
79 bool isFinished();
80
85 bool isAborted();
86
91 bool start();
92
96 void abort(Sync::SyncStatus aStatus = Sync::SYNC_ABORTED);
97
100 void stop();
101
106 SyncProfile *profile() const;
107
112 QString profileName() const;
113
120 SyncResults results() const;
121
126 void setScheduled(bool aScheduled);
127
132 bool isScheduled() const;
133
140 void updateResults(const SyncResults &aResults);
141
151
163 bool reserveStorages(StorageBooker *aStorageBooker);
164
166 void releaseStorages();
167
170
175 void setStorageMap(QMap<QString, bool> &aStorageMap);
176
178 bool isProfileCreated();
179
181 void setProfileCreated(bool aProfileCreated);
182
184 Sync::SyncStatus mapToSyncStatusError(int aErrorCode);
185
186signals:
188 void transferProgress(const QString &aProfileName,
189 Sync::TransferDatabase aDatabase, Sync::TransferType aType,
190 const QString &aMimeType, int aCommittedItems);
191
197 void storageAccquired(const QString &aProfileName, const QString &aMimeType);
198
206 void finished(const QString &aProfileName, Sync::SyncStatus aStatus,
207 const QString &aMessage, SyncResults::MinorCode aErrorCode);
208
214 void syncProgressDetail(const QString &aProfileName, int aProgressDetail);
215
216private:
217 bool tryStart();
218
219private slots:
220 // Slots for catching plug-in runner signals.
221 void onSuccess(const QString &aProfileName, const QString &aMessage);
222 void onError(const QString &aProfileName, const QString &aMessage, SyncResults::MinorCode aErrorCode);
223 void onTransferProgress(const QString &aProfileName,
224 Sync::TransferDatabase aDatabase, Sync::TransferType aType,
225 const QString &aMimeType, int aCommittedItems);
226 void onStorageAccquired (const QString &aMimeType);
227 void onSyncProgressDetail(const QString &aProfileName, int aProgressDetail);
228 void onDone();
229 void onDestroyed(QObject *aPluginRunner);
230 void onNetworkSessionOpened();
231 void onNetworkSessionError();
232
233private:
234 SyncProfile *iProfile;
235 PluginRunner *iPluginRunner;
236 SyncResults iResults;
237 Sync::SyncStatus iStatus;
238 SyncResults::MinorCode iErrorCode;
239 bool iPluginRunnerOwned;
240 bool iScheduled;
241 bool iAborted;
242 bool iStarted;
243 bool iFinished;
244 bool iCreateProfile;
245 QString iMessage;
246 QString iRemoteId;
247 StorageBooker *iStorageBooker;
248 QMap<QString, bool> iStorageMap;
249 NetworkManager *iNetworkManager;
250
251#ifdef SYNCFW_UNIT_TESTS
252 friend class SyncSessionTest;
253#endif
254};
255
256}
257
258#endif // SYNCSESSION_H
Class for managing network sessions.
Definition NetworkManager.h:43
Base class for running sync plug-ins.
Definition PluginRunner.h:45
A helper class for managing storage reservations.
Definition StorageBooker.h:37
A top level synchronization profile.
Definition SyncProfile.h:49
Contains information about a completed synchronization session.
Definition SyncResults.h:62
MajorCode
enum value
Definition SyncResults.h:77
MinorCode
enum value
Definition SyncResults.h:89
Class representing a single sync session.
Definition SyncSession.h:44
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
bool isScheduled() const
Checks if the session was started by the scheduler.
Definition SyncSession.cpp:261
void setPluginRunner(PluginRunner *aPluginRunner, bool aTransferOwnership)
Associates a plug-in runner with this session.
Definition SyncSession.cpp:76
bool isAborted()
Returns if the sync session was aborted.
Definition SyncSession.cpp:167
QMap< QString, bool > getStorageMap()
returns the StorageMap used for this session
Definition SyncSession.cpp:192
PluginRunner * pluginRunner()
Gets the plug-in runner associated with this session.
Definition SyncSession.cpp:112
SyncResults results() const
Gets the results of the finished session.
Definition SyncSession.cpp:246
void transferProgress(const QString &aProfileName, Sync::TransferDatabase aDatabase, Sync::TransferType aType, const QString &aMimeType, int aCommittedItems)
Definition moc_SyncSession.cpp:255
void setProfileCreated(bool aProfileCreated)
sets Profile Created flag to true
Definition SyncSession.cpp:210
void storageAccquired(const QString &aProfileName, const QString &aMimeType)
Signal sent when a storage is accquired.
Definition moc_SyncSession.cpp:262
void updateResults(const SyncResults &aResults)
Sets the results for this session.
Definition SyncSession.cpp:372
void stop()
Stops the session. Returns when the session is stopped.
Definition SyncSession.cpp:216
void abort(Sync::SyncStatus aStatus=Sync::SYNC_ABORTED)
Aborts the session. Returns when the abort request is sent.
Definition SyncSession.cpp:172
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
bool start()
Starts the session using the associated plug-in runner.
Definition SyncSession.cpp:119
void setStorageMap(QMap< QString, bool > &aStorageMap)
sets the storage map for this session
Definition SyncSession.cpp:198
bool isFinished()
Returns if the sync session is finished or in process.
Definition SyncSession.cpp:162
bool isProfileCreated()
returns the returns the status of the profile creation for this session
Definition SyncSession.cpp:204
void releaseStorages()
Releases storages that were reserved earlier with reserveStorages.
Definition SyncSession.cpp:403
void setFailureResult(SyncResults::MajorCode aMajorCode, SyncResults::MinorCode aMinorCode)
Sets the results for this session using the provided error code.
Definition SyncSession.cpp:380
bool reserveStorages(StorageBooker *aStorageBooker)
Tries to reserve storages needed by the session.
Definition SyncSession.cpp:388
virtual ~SyncSession()
Destructor.
Definition SyncSession.cpp:51
QString profileName() const
Gets the name of the profile used by this session.
Definition SyncSession.cpp:234
SyncProfile * profile() const
Gets the sync profile used by this session.
Definition SyncSession.cpp:227
void setScheduled(bool aScheduled)
Sets if the session was started by the scheduler.
Definition SyncSession.cpp:253
Sync::SyncStatus mapToSyncStatusError(int aErrorCode)
Maps sync failure error code from stack to SyncStatus.
Definition SyncSession.cpp:308
Definition SyncBackupAdaptor.h:41