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