Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[buteo-syncfw] Use SyncResults::MajorCode and MinorCode instead of int.
  • Loading branch information
dcaliste committed Apr 9, 2021
1 parent fd1beef commit e1b3376
Show file tree
Hide file tree
Showing 27 changed files with 72 additions and 86 deletions.
7 changes: 2 additions & 5 deletions libbuteosyncfw/clientfw/SyncClientInterfacePrivate.cpp
Expand Up @@ -202,10 +202,6 @@ bool SyncClientInterfacePrivate::isValid()
Buteo::SyncResults SyncClientInterfacePrivate::getLastSyncResult(const QString &aProfileId)
{
FUNCTION_CALL_TRACE;
// Default construct with invalid values
// Using default constructor for QDateTime() creates "null" date.
Buteo::SyncResults syncResult(QDateTime(),
SyncResults::SYNC_RESULT_INVALID, Buteo::SyncResults::SYNC_RESULT_INVALID);

if (iSyncDaemon) {
QString resultASXmlString = iSyncDaemon->getLastSyncResult(aProfileId);
Expand All @@ -218,7 +214,8 @@ Buteo::SyncResults SyncClientInterfacePrivate::getLastSyncResult(const QString &
LOG_CRITICAL("Invalid Profile Xml Received from msyncd");
}
}
return syncResult;
return SyncResults(QDateTime(),
SyncResults::SYNC_RESULT_INVALID, SyncResults::NO_ERROR);
}

QList<QString /*profilesAsXml*/> SyncClientInterfacePrivate::allVisibleSyncProfiles()
Expand Down
11 changes: 5 additions & 6 deletions libbuteosyncfw/pluginmgr/OOPClientPlugin.cpp
Expand Up @@ -156,14 +156,12 @@ SyncResults OOPClientPlugin::getSyncResults() const
{
FUNCTION_CALL_TRACE;

SyncResults errorSyncResult(QDateTime::currentDateTime(),
SyncResults::SYNC_RESULT_INVALID,
SyncResults::SYNC_RESULT_INVALID);
QDBusPendingReply<QString> reply = iOopPluginIface->getSyncResults();
reply.waitForFinished();
if (!reply.isValid()) {
LOG_WARNING( "Invalid reply for getSyncResults from plugin" );
return errorSyncResult;
return SyncResults(QDateTime::currentDateTime(),
SyncResults::SYNC_RESULT_INVALID, SyncResults::PLUGIN_ERROR);
}

QString resultAsXml = reply.value();
Expand All @@ -173,7 +171,8 @@ SyncResults OOPClientPlugin::getSyncResults() const
return syncResult;
} else {
LOG_CRITICAL( "Invalid sync results returned from plugin" );
return errorSyncResult;
return SyncResults(QDateTime::currentDateTime(),
SyncResults::SYNC_RESULT_INVALID, SyncResults::NO_ERROR);
}
}

Expand Down Expand Up @@ -217,7 +216,7 @@ void OOPClientPlugin::onError(QString aProfileName, QString aMessage, int aError
{
if (!iDone) {
iDone = true;
emit error(aProfileName, aMessage, aErrorCode);
emit error(aProfileName, aMessage, static_cast<SyncResults::MinorCode>(aErrorCode));
}
}

Expand Down
2 changes: 1 addition & 1 deletion libbuteosyncfw/pluginmgr/OOPServerPlugin.cpp
Expand Up @@ -211,7 +211,7 @@ void OOPServerPlugin::onError(QString aProfileName, QString aMessage, int aError
{
if (!iDone) {
iDone = true;
emit error(aProfileName, aMessage, aErrorCode);
emit error(aProfileName, aMessage, static_cast<SyncResults::MinorCode>(aErrorCode));
}
}

Expand Down
2 changes: 1 addition & 1 deletion libbuteosyncfw/pluginmgr/SyncPluginBase.h
Expand Up @@ -136,7 +136,7 @@ class SyncPluginBase : public QObject
* @param aMessage Message data related to error event
* @param aErrorCode Error code
*/
void error(const QString &aProfileName, const QString &aMessage, int aErrorCode);
void error(const QString &aProfileName, const QString &aMessage, SyncResults::MinorCode aErrorCode);

/*! \brief Emitted when synchronization has been finished successfully.
*
Expand Down
25 changes: 11 additions & 14 deletions libbuteosyncfw/profile/SyncResults.cpp
Expand Up @@ -45,11 +45,8 @@ class SyncResultsPrivate
//! Sync time.
QDateTime iTime;

//! Sync major code.
int iMajorCode;

//! Sync minor reason.
int iMinorCode;
SyncResults::MajorCode iMajorCode;
SyncResults::MinorCode iMinorCode;

//! Sync target id
QString iTargetId;
Expand All @@ -61,8 +58,8 @@ class SyncResultsPrivate

SyncResultsPrivate::SyncResultsPrivate()
: iTime(QDateTime::currentDateTime()),
iMajorCode(0),
iMinorCode(0),
iMajorCode(SyncResults::SYNC_RESULT_SUCCESS),
iMinorCode(SyncResults::NO_ERROR),
iScheduled(false)
{
}
Expand Down Expand Up @@ -92,7 +89,7 @@ SyncResults::SyncResults(const SyncResults &aSource)
{
}

SyncResults::SyncResults(QDateTime aTime, int aMajorCode, int aMinorCode)
SyncResults::SyncResults(QDateTime aTime, SyncResults::MajorCode aMajorCode, SyncResults::MinorCode aMinorCode)
: d_ptr(new SyncResultsPrivate())
{
d_ptr->iTime = aTime;
Expand All @@ -104,8 +101,8 @@ SyncResults::SyncResults(const QDomElement &aRoot)
: d_ptr(new SyncResultsPrivate())
{
d_ptr->iTime = QDateTime::fromString(aRoot.attribute(ATTR_TIME), Qt::ISODate);
d_ptr->iMajorCode = aRoot.attribute(ATTR_MAJOR_CODE).toInt();
d_ptr->iMinorCode = aRoot.attribute(ATTR_MINOR_CODE).toInt();
d_ptr->iMajorCode = static_cast<SyncResults::MajorCode>(aRoot.attribute(ATTR_MAJOR_CODE).toInt());
d_ptr->iMinorCode = static_cast<SyncResults::MinorCode>(aRoot.attribute(ATTR_MINOR_CODE).toInt());
d_ptr->iScheduled = (aRoot.attribute(KEY_SYNC_SCHEDULED) == BOOLEAN_TRUE);

QDomElement target = aRoot.firstChildElement(TAG_TARGET_RESULTS);
Expand Down Expand Up @@ -176,23 +173,23 @@ QDateTime SyncResults::syncTime() const
return d_ptr->iTime;
}

int SyncResults::majorCode() const
SyncResults::MajorCode SyncResults::majorCode() const
{
return d_ptr->iMajorCode;
}

void SyncResults::setMajorCode(int aMajorCode)
void SyncResults::setMajorCode(SyncResults::MajorCode aMajorCode)
{
FUNCTION_CALL_TRACE;
d_ptr->iMajorCode = aMajorCode;
}

int SyncResults::minorCode() const
SyncResults::MinorCode SyncResults::minorCode() const
{
return d_ptr->iMinorCode;
}

void SyncResults::setMinorCode(int aMinorCode)
void SyncResults::setMinorCode(SyncResults::MinorCode aMinorCode)
{
FUNCTION_CALL_TRACE;
d_ptr->iMinorCode = aMinorCode;
Expand Down
10 changes: 5 additions & 5 deletions libbuteosyncfw/profile/SyncResults.h
Expand Up @@ -126,7 +126,7 @@ class SyncResults
* \param aMajorCode Sync result code.
* \param aMinorCode Sync Failed Reason.
*/
SyncResults(QDateTime aTime, int aMajorCode, int aMinorCode);
SyncResults(QDateTime aTime, MajorCode aMajorCode, MinorCode aMinorCode);

/*! \brief Constructs sync results from XML.
*
Expand Down Expand Up @@ -181,25 +181,25 @@ class SyncResults
*
* \return major code.
*/
int majorCode() const;
MajorCode majorCode() const;

/*! \brief Sets the result code.
*
* \param aMajorCode The result code.
*/
void setMajorCode(int aMajorCode);
void setMajorCode(MajorCode aMajorCode);

/*! \brief Gets the failed reason.
*
* \return failed Reason.
*/
int minorCode() const;
MinorCode minorCode() const;

/*! \brief Sets the failed Reason.
*
* \param aMinorCode - minor code or the reason
*/
void setMinorCode(int aMinorCode);
void setMinorCode(MinorCode aMinorCode);


/*! \brief Sets the remote target Id.
Expand Down
8 changes: 3 additions & 5 deletions msyncd/ClientPluginRunner.cpp
Expand Up @@ -89,8 +89,7 @@ bool ClientPluginRunner::init()
int)),
this, SLOT(onTransferProgress(const QString &, Sync::TransferDatabase, Sync::TransferType, const QString &, int)));

connect(iPlugin, SIGNAL(error(const QString &, const QString &, int)),
this, SLOT(onError(const QString &, const QString &, int)));
connect(iPlugin, &ClientPlugin::error, this, &ClientPluginRunner::onError);

connect(iPlugin, SIGNAL(success(const QString &, const QString &)),
this, SLOT(onSuccess(const QString &, const QString &)));
Expand All @@ -102,8 +101,7 @@ bool ClientPluginRunner::init()
this, SLOT(onSyncProgressDetail(const QString &, int)));

// Connect signals from the thread.
connect(iThread, SIGNAL(initError(const QString &, const QString &, int)),
this, SLOT(onError(const QString &, const QString &, int)));
connect(iThread, &ClientThread::initError, this, &ClientPluginRunner::onError);

connect(iThread, SIGNAL(finished()), this, SLOT(onThreadExit()));

Expand Down Expand Up @@ -185,7 +183,7 @@ void ClientPluginRunner::onTransferProgress(const QString &aProfileName,
}

void ClientPluginRunner::onError(const QString &aProfileName,
const QString &aMessage, int aErrorCode)
const QString &aMessage, SyncResults::MinorCode aErrorCode)
{
FUNCTION_CALL_TRACE;

Expand Down
2 changes: 1 addition & 1 deletion msyncd/ClientPluginRunner.h
Expand Up @@ -87,7 +87,7 @@ private slots:
Sync::TransferDatabase aDatabase, Sync::TransferType aType,
const QString &aMimeType, int aCommittedItems);

void onError(const QString &aProfileName, const QString &aMessage, int aErrorCode);
void onError(const QString &aProfileName, const QString &aMessage, SyncResults::MinorCode aErrorCode);

void onSuccess(const QString &aProfileName, const QString &aMessage);

Expand Down
8 changes: 4 additions & 4 deletions msyncd/ClientThread.cpp
Expand Up @@ -122,13 +122,13 @@ void ClientThread::run()

if (!iClientPlugin->init()) {
LOG_WARNING( "Could not initialize client plugin:" << iClientPlugin->getPluginName() );
emit initError(getProfileName(), "", 0);
emit initError(getProfileName(), "", SyncResults::PLUGIN_ERROR);
return;
}

if (!iClientPlugin->startSync()) {
LOG_WARNING( "Could not start client plugin:" << iClientPlugin->getPluginName() );
emit initError(getProfileName(), "", 0);
emit initError(getProfileName(), "", SyncResults::PLUGIN_ERROR);
return;
}

Expand Down Expand Up @@ -176,7 +176,7 @@ void ClientThread::identities(const QList<SignOn::IdentityInfo> &identityList)
return;
}
}
emit initError(getProfileName(), "credentials not found in SSO", 0);
emit initError(getProfileName(), "credentials not found in SSO", SyncResults::AUTHENTICATION_FAILURE);
}

void ClientThread::identityResponse(const SignOn::SessionData &sessionData)
Expand All @@ -198,6 +198,6 @@ void ClientThread::identityError(SignOn::Error err)
{
FUNCTION_CALL_TRACE;

emit initError(getProfileName(), err.message(), 0);
emit initError(getProfileName(), err.message(), SyncResults::AUTHENTICATION_FAILURE);
}

3 changes: 2 additions & 1 deletion msyncd/ClientThread.h
Expand Up @@ -91,7 +91,8 @@ class ClientThread : public QThread
* @param aMessage Message data related to error event
* @param aErrorCode Error code
*/
void initError(const QString &aProfileName, const QString &aMessage, int aErrorCode);
void initError(const QString &aProfileName, const QString &aMessage,
SyncResults::MinorCode aErrorCode);

protected:
/*! \brief overriding method for QThread::run
Expand Down
2 changes: 1 addition & 1 deletion msyncd/PluginRunner.h
Expand Up @@ -134,7 +134,7 @@ class PluginRunner : public QObject
const QString &aMimeType, int aCommittedItems);

//! @see SyncPluginBase::error
void error(const QString &aProfileName, const QString &aMessage, int aErrorCode);
void error(const QString &aProfileName, const QString &aMessage, SyncResults::MinorCode aErrorCode);

//! @see SyncPluginBase::success
void success(const QString &aProfileName, const QString &aMessage);
Expand Down
8 changes: 3 additions & 5 deletions msyncd/ServerPluginRunner.cpp
Expand Up @@ -94,8 +94,7 @@ bool ServerPluginRunner::init()
int)),
this, SLOT(onTransferProgress(const QString &, Sync::TransferDatabase, Sync::TransferType, const QString &, int)));

connect(iPlugin, SIGNAL(error(const QString &, const QString &, int)),
this, SLOT(onError(const QString &, const QString &, int)));
connect(iPlugin, &ServerPlugin::error, this, &ServerPluginRunner::onError);

connect(iPlugin, SIGNAL(success(const QString &, const QString &)),
this, SLOT(onSuccess(const QString &, const QString &)));
Expand All @@ -108,8 +107,7 @@ bool ServerPluginRunner::init()

// Connect signals from the thread.

connect(iThread, SIGNAL(initError(const QString &, const QString &, int)),
this, SLOT(onError(const QString &, const QString &, int)));
connect(iThread, &ServerThread::initError, this, &ServerPluginRunner::onError);

connect(iThread, SIGNAL(finished()), this, SLOT(onThreadExit()));

Expand Down Expand Up @@ -221,7 +219,7 @@ void ServerPluginRunner::onTransferProgress(const QString &aProfileName,
}

void ServerPluginRunner::onError(const QString &aProfileName,
const QString &aMessage, int aErrorCode)
const QString &aMessage, SyncResults::MinorCode aErrorCode)
{
FUNCTION_CALL_TRACE;

Expand Down
2 changes: 1 addition & 1 deletion msyncd/ServerPluginRunner.h
Expand Up @@ -98,7 +98,7 @@ private slots:
const QString &aMimeType, int aCommittedItems);

void onStorageAccquired(const QString &aMimeType );
void onError(const QString &aProfileName, const QString &aMessage, int aErrorCode);
void onError(const QString &aProfileName, const QString &aMessage, SyncResults::MinorCode aErrorCode);

void onSuccess(const QString &aProfileName, const QString &aMessage);

Expand Down
4 changes: 2 additions & 2 deletions msyncd/ServerThread.cpp
Expand Up @@ -104,13 +104,13 @@ void ServerThread::run()

if (!iServerPlugin->init()) {
LOG_WARNING( "Could not initialize server plugin:" << iServerPlugin->getPluginName() );
emit initError(iServerPlugin->getProfileName(), "", 0);
emit initError(iServerPlugin->getProfileName(), "", SyncResults::PLUGIN_ERROR);
return;
}

if (!iServerPlugin->startListen()) {
LOG_WARNING( "Could not start server plugin:" << iServerPlugin->getPluginName() );
emit initError(iServerPlugin->getProfileName(), "", 0);
emit initError(iServerPlugin->getProfileName(), "", SyncResults::PLUGIN_ERROR);
return;
}

Expand Down
3 changes: 2 additions & 1 deletion msyncd/ServerThread.h
Expand Up @@ -25,6 +25,7 @@

#include <QThread>
#include <QMutex>
#include <SyncResults.h>

namespace Buteo {

Expand Down Expand Up @@ -83,7 +84,7 @@ class ServerThread : public QThread
* @param aErrorCode Error code
*/
void initError(const QString &aProfileName, const QString &aMessage,
int aErrorCode);
SyncResults::MinorCode aErrorCode);

protected:

Expand Down

0 comments on commit e1b3376

Please sign in to comment.