summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorBai Jing <jing.t.bai@nokia.com>2012-06-07 14:26:39 +0200
committerQt by Nokia <qt-info@nokia.com>2012-06-08 13:14:18 +0200
commit6c523c6894b321415809c8f9c324d89864e8a581 (patch)
treec1787a08142dc73e51d171ea0216be4b08d42041 /tools
parent72eb7cda976c05c67616e93403750442175af430 (diff)
cleanup popRequest
We should pop the request only if it is pushed to the stack and the request is finished or error occurrs. Change-Id: I124f15e0f246a1099992c4f89a5d7b5f35724753 Reviewed-by: Denis Dzyubenko <denis.dzyubenko@nokia.com> Reviewed-by: Ali Akhtarzada <ali.akhtarzada@nokia.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/jsondb-client/client.cpp32
-rw-r--r--tools/jsondb-client/client.h2
2 files changed, 22 insertions, 12 deletions
diff --git a/tools/jsondb-client/client.cpp b/tools/jsondb-client/client.cpp
index dcdf939..a876ba2 100644
--- a/tools/jsondb-client/client.cpp
+++ b/tools/jsondb-client/client.cpp
@@ -327,6 +327,12 @@ void Client::error(QtJsonDb::QJsonDbConnection::ErrorCode error, const QString &
}
}
+void Client::onPushedRequestFinished()
+{
+ popRequest();
+ onRequestFinished();
+}
+
void Client::onRequestFinished()
{
quint32 stateNumber;
@@ -355,7 +361,6 @@ void Client::onRequestFinished()
void Client::aboutToRemove(void)
{
-
QtJsonDb::QJsonDbRequest *queryRequest = qobject_cast<QtJsonDb::QJsonDbRequest *>(sender());
Q_ASSERT(queryRequest != 0);
if (!queryRequest)
@@ -379,14 +384,19 @@ void Client::aboutToRemove(void)
QtJsonDb::QJsonDbRemoveRequest* request = new QtJsonDb::QJsonDbRemoveRequest(objects);
request->setPartition(queryRequest->partition());
- connect(request, SIGNAL(finished()), this, SLOT(onRequestFinished()));
- connect(request, SIGNAL(finished()), this, SLOT(popRequest()));
+ connect(request, SIGNAL(finished()), this, SLOT(onPushedRequestFinished()));
connect(request, SIGNAL(error(QtJsonDb::QJsonDbRequest::ErrorCode,QString)),
- this, SLOT(onRequestError(QtJsonDb::QJsonDbRequest::ErrorCode,QString)));
+ this, SLOT(onPushedRequestError(QtJsonDb::QJsonDbRequest::ErrorCode,QString)));
pushRequest(request);
mConnection->send(request);
}
+void Client::onPushedRequestError(QtJsonDb::QJsonDbRequest::ErrorCode code, const QString &message)
+{
+ Q_UNUSED(code);
+ popRequest();
+ onRequestError(code,message);
+}
void Client::onRequestError(QtJsonDb::QJsonDbRequest::ErrorCode code, const QString &message)
{
Q_UNUSED(code);
@@ -400,6 +410,8 @@ void Client::pushRequest(QtJsonDb::QJsonDbRequest *request)
void Client::popRequest()
{
+ if (mDebug)
+ qDebug() << "popRequest:" << mRequests[0];
mRequests.takeFirst()->deleteLater();
if (mRequests.isEmpty() && mTerminate)
emit terminate();
@@ -489,13 +501,10 @@ bool Client::processCommand(const QString &command)
connect(request, SIGNAL(finished()), this, SLOT(aboutToRemove()));
}
else {
- connect(request, SIGNAL(finished()), this, SLOT(onRequestFinished()));
- connect(request, SIGNAL(finished()), this, SLOT(popRequest()));
+ connect(request, SIGNAL(finished()), this, SLOT(onPushedRequestFinished()));
}
connect(request, SIGNAL(error(QtJsonDb::QJsonDbRequest::ErrorCode,QString)),
- this, SLOT(popRequest()));
- connect(request, SIGNAL(error(QtJsonDb::QJsonDbRequest::ErrorCode,QString)),
- this, SLOT(onRequestError(QtJsonDb::QJsonDbRequest::ErrorCode,QString)));
+ this, SLOT(onPushedRequestError(QtJsonDb::QJsonDbRequest::ErrorCode,QString)));
pushRequest(request);
mConnection->send(request);
} else if (cmd == "notify") {
@@ -577,10 +586,9 @@ bool Client::processCommand(const QString &command)
else
Q_ASSERT(false);
request->setPartition(partition);
- connect(request, SIGNAL(finished()), this, SLOT(onRequestFinished()));
- connect(request, SIGNAL(finished()), this, SLOT(popRequest()));
+ connect(request, SIGNAL(finished()), this, SLOT(onPushedRequestFinished()));
connect(request, SIGNAL(error(QtJsonDb::QJsonDbRequest::ErrorCode,QString)),
- this, SLOT(onRequestError(QtJsonDb::QJsonDbRequest::ErrorCode,QString)));
+ this, SLOT(onPushedRequestError(QtJsonDb::QJsonDbRequest::ErrorCode,QString)));
pushRequest(request);
mConnection->send(request);
} else if (cmd == "load") {
diff --git a/tools/jsondb-client/client.h b/tools/jsondb-client/client.h
index 5d1735d..23c71f7 100644
--- a/tools/jsondb-client/client.h
+++ b/tools/jsondb-client/client.h
@@ -100,7 +100,9 @@ protected slots:
void onNotificationError(QtJsonDb::QJsonDbWatcher::ErrorCode, const QString &);
void onRequestFinished();
+ void onPushedRequestFinished();
void onRequestError(QtJsonDb::QJsonDbRequest::ErrorCode code, const QString &message);
+ void onPushedRequestError(QtJsonDb::QJsonDbRequest::ErrorCode code, const QString &message);
void aboutToRemove();
void pushRequest(QtJsonDb::QJsonDbRequest *);