parent
71bce5a281
commit
de6b60734e
@ -137,7 +137,8 @@ JsonReply::JsonReply(Type type, JsonHandler *handler, const QString &method, con
|
||||
m_type(type),
|
||||
m_data(data),
|
||||
m_handler(handler),
|
||||
m_method(method)
|
||||
m_method(method),
|
||||
m_timedOut(false)
|
||||
{
|
||||
connect(&m_timeout, &QTimer::timeout, this, &JsonReply::timeout);
|
||||
}
|
||||
@ -204,7 +205,11 @@ void JsonReply::startWait()
|
||||
|
||||
void JsonReply::timeout()
|
||||
{
|
||||
m_data.insert("success", false);
|
||||
m_data.insert("errorMessage", "Command timed out.");
|
||||
finished();
|
||||
m_timedOut = true;
|
||||
emit finished();
|
||||
}
|
||||
|
||||
bool JsonReply::timedOut() const
|
||||
{
|
||||
return m_timedOut;
|
||||
}
|
||||
|
||||
@ -53,6 +53,8 @@ public:
|
||||
int commandId() const;
|
||||
void setCommandId(int commandId);
|
||||
|
||||
bool timedOut() const;
|
||||
|
||||
public slots:
|
||||
void startWait();
|
||||
|
||||
@ -71,6 +73,7 @@ private:
|
||||
QString m_method;
|
||||
QUuid m_clientId;
|
||||
int m_commandId;
|
||||
bool m_timedOut;
|
||||
|
||||
QTimer m_timeout;
|
||||
|
||||
|
||||
@ -235,8 +235,13 @@ void JsonRPCServer::sendNotification(const QVariantMap ¶ms)
|
||||
void JsonRPCServer::asyncReplyFinished()
|
||||
{
|
||||
JsonReply *reply = qobject_cast<JsonReply*>(sender());
|
||||
Q_ASSERT(reply->handler()->validateReturns(reply->method(), reply->data()).first);
|
||||
sendResponse(reply->clientId(), reply->commandId(), reply->data());
|
||||
if (!reply->timedOut()) {
|
||||
Q_ASSERT_X(reply->handler()->validateReturns(reply->method(), reply->data()).first
|
||||
,"validating return value", formatAssertion(reply->handler()->name(), reply->method(), reply->handler(), reply->data()).toLatin1().data());
|
||||
sendResponse(reply->clientId(), reply->commandId(), reply->data());
|
||||
} else {
|
||||
sendErrorResponse(reply->clientId(), reply->commandId(), "Command timed out");
|
||||
}
|
||||
reply->deleteLater();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user