2
* This file is part of buteo-syncfw package
4
* Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
6
* Contact: Sateesh Kavuri <sateesh.kavuri@nokia.com>
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.
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.
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
25
#include "ClientPluginRunner.h"
26
#include "ClientThread.h"
27
#include "ClientPlugin.h"
28
#include "LogMacros.h"
29
#include "PluginManager.h"
31
using namespace Buteo;
33
// Maximum time in milliseconds to wait for a thread to stop
34
static const unsigned long long MAX_THREAD_STOP_WAIT_TIME = 5000;
36
ClientPluginRunner::ClientPluginRunner(const QString &aPluginName,
37
SyncProfile *aProfile, PluginManager *aPluginMgr,
38
PluginCbInterface *aPluginCbIf, QObject *aParent)
39
: PluginRunner(PLUGIN_CLIENT, aPluginName, aPluginMgr, aPluginCbIf, aParent),
47
ClientPluginRunner::~ClientPluginRunner()
53
if (iPlugin != 0 && iPluginMgr != 0)
55
iPluginMgr->destroyClient(iPlugin);
66
bool ClientPluginRunner::init()
73
if (iPluginMgr == 0 || iPluginCbIf == 0 || iProfile == 0)
75
LOG_WARNING("Invalid members, failed to initialize");
79
iPlugin = iPluginMgr->createClient(iPluginName, *iProfile, iPluginCbIf);
82
LOG_WARNING("Failed to create client plug-in:" << iPluginName);
86
iThread = new ClientThread();
89
LOG_WARNING("Failed to create client thread");
93
// Pass connectivity state change signal to the plug-in.
94
connect(this, SIGNAL(connectivityStateChanged(Sync::ConnectivityType, bool)),
95
iPlugin, SLOT(connectivityStateChanged(Sync::ConnectivityType, bool)));
97
// Connect signals from the plug-in.
99
connect(iPlugin, SIGNAL(transferProgress(const QString &, Sync::TransferDatabase, Sync::TransferType, const QString &)),
100
this, SLOT(onTransferProgress(const QString &, Sync::TransferDatabase, Sync::TransferType, const QString &)));
102
connect(iPlugin, SIGNAL(error(const QString &, const QString &, int)),
103
this, SLOT(onError(const QString &, const QString &, int)));
105
connect(iPlugin, SIGNAL(success(const QString &, const QString &)),
106
this, SLOT(onSuccess(const QString &, const QString &)));
108
connect(iPlugin, SIGNAL(accquiredStorage(const QString &)),
109
this, SLOT(onStorageAccquired(const QString &)));
110
// Connect signals from the thread.
112
connect(iThread, SIGNAL(initError(const QString &, const QString &, int)),
113
this, SLOT(onError(const QString &, const QString &, int)));
115
connect(iThread, SIGNAL(terminated()), this, SLOT(onThreadExit()));
117
connect(iThread, SIGNAL(finished()), this, SLOT(onThreadExit()));
124
bool ClientPluginRunner::start()
129
if (iInitialized && iThread != 0)
131
rv = iThread->startThread(iPlugin);
137
void ClientPluginRunner::stop()
143
iThread->stopThread();
148
void ClientPluginRunner::abort()
154
iPlugin->abortSync();
158
SyncPluginBase *ClientPluginRunner::plugin()
165
SyncResults ClientPluginRunner::syncResults()
171
return iPlugin->getSyncResults();
175
return SyncResults();
179
bool ClientPluginRunner::cleanUp()
186
retval = iPlugin->cleanUp();
191
void ClientPluginRunner::onTransferProgress(const QString &aProfileName,
192
Sync::TransferDatabase aDatabase, Sync::TransferType aType,
193
const QString &aMimeType)
197
emit transferProgress(aProfileName, aDatabase, aType, aMimeType);
200
void ClientPluginRunner::onError(const QString &aProfileName,
201
const QString &aMessage, int aErrorCode)
205
emit error(aProfileName, aMessage, aErrorCode);
209
void ClientPluginRunner::onSuccess(const QString &aProfileName,
210
const QString &aMessage)
214
emit success(aProfileName, aMessage);
219
void ClientPluginRunner::onStorageAccquired(const QString &aMimeType )
223
emit storageAccquired(aMimeType);
226
void ClientPluginRunner::onThreadExit()