SyncSession.h
/*
* This file is part of buteo-syncfw package
*
* Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
*
* Contact: Sateesh Kavuri <sateesh.kavuri@nokia.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2.1 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
#ifndef SYNCSESSION_H
#define SYNCSESSION_H
#include "SyncCommonDefs.h"
#include "SyncResults.h"
#include <QObject>
#include <QMap>
namespace Buteo {
class SyncProfile;
class PluginRunner;
class StorageBooker;
class NetworkManager;
class SyncSession : public QObject
{
Q_OBJECT
public:
explicit SyncSession(SyncProfile *aProfile, QObject *aParent = 0);
virtual ~SyncSession();
void setPluginRunner(PluginRunner *aPluginRunner, bool aTransferOwnership);
PluginRunner *pluginRunner();
bool isFinished();
bool isAborted();
bool start();
void abort(Sync::SyncStatus aStatus = Sync::SYNC_ABORTED);
void stop();
SyncProfile *profile() const;
QString profileName() const;
SyncResults results() const;
void setScheduled(bool aScheduled);
bool isScheduled() const;
void updateResults(const SyncResults &aResults);
void setFailureResult(SyncResults::MajorCode aMajorCode, SyncResults::MinorCode aMinorCode);
bool reserveStorages(StorageBooker *aStorageBooker);
void releaseStorages();
QMap<QString, bool> getStorageMap();
void setStorageMap(QMap<QString, bool> &aStorageMap);
bool isProfileCreated();
void setProfileCreated(bool aProfileCreated);
Sync::SyncStatus mapToSyncStatusError(int aErrorCode);
signals:
void transferProgress(const QString &aProfileName,
Sync::TransferDatabase aDatabase, Sync::TransferType aType,
const QString &aMimeType, int aCommittedItems);
void storageAccquired(const QString &aProfileName, const QString &aMimeType);
void finished(const QString &aProfileName, Sync::SyncStatus aStatus,
const QString &aMessage, SyncResults::MinorCode aErrorCode);
void syncProgressDetail(const QString &aProfileName, int aProgressDetail);
private:
bool tryStart();
private slots:
// Slots for catching plug-in runner signals.
void onSuccess(const QString &aProfileName, const QString &aMessage);
void onError(const QString &aProfileName, const QString &aMessage, SyncResults::MinorCode aErrorCode);
void onTransferProgress(const QString &aProfileName,
Sync::TransferDatabase aDatabase, Sync::TransferType aType,
const QString &aMimeType, int aCommittedItems);
void onStorageAccquired (const QString &aMimeType);
void onSyncProgressDetail(const QString &aProfileName, int aProgressDetail);
void onDone();
void onDestroyed(QObject *aPluginRunner);
void onNetworkSessionOpened();
void onNetworkSessionError();
private:
SyncProfile *iProfile;
PluginRunner *iPluginRunner;
SyncResults iResults;
Sync::SyncStatus iStatus;
SyncResults::MinorCode iErrorCode;
bool iPluginRunnerOwned;
bool iScheduled;
bool iAborted;
bool iStarted;
bool iFinished;
bool iCreateProfile;
QString iMessage;
QString iRemoteId;
StorageBooker *iStorageBooker;
QMap<QString, bool> iStorageMap;
NetworkManager *iNetworkManager;
#ifdef SYNCFW_UNIT_TESTS
friend class SyncSessionTest;
#endif
};
}
#endif // SYNCSESSION_H
Buteo::NetworkManager
Class for managing network sessions.
Definition NetworkManager.h:44
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:67
Buteo::SyncResults::MajorCode
MajorCode
enum value
Definition SyncResults.h:81
Buteo::SyncResults::MinorCode
MinorCode
enum value
Definition SyncResults.h:93
Buteo::SyncSession::finished
void finished(const QString &aProfileName, Sync::SyncStatus aStatus, const QString &aMessage, SyncResults::MinorCode aErrorCode)
Signal sent when the session has finished.
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)
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.
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.
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
Definition SyncBackupAdaptor.h:41