else
{
// If we got the first command sent, we update the replyTimeoutTimer to count the remaining time untill timeout.
- // This should be less than Client::UDP_API_COMMAND_TIMEOUT, but never negative.
- int newTimeout = qBound(0, Client::UDP_API_COMMAND_TIMEOUT - sentCommands[commandId]->timeSent().secsTo(QDateTime::currentDateTime()), Client::UDP_API_COMMAND_TIMEOUT);
- newTimeout *= 1000;
- replyTimeoutTimer->start(newTimeout);
+ resetReplyTimeoutTimer(sentCommands[sentCommandOrder.head()]);
#ifdef ANIDBUDPCLIENT_CLIENT_MISC_DEBUG
qDebug() << "Starting replyTimeoutTimer" << newTimeout;
#endif
void Client::cancel(AbstractReply *reply)
{
commandQueue.removeAll(reply);
- if (reply)
- sentCommands.remove(reply->id());
+ if (!reply)
+ return;
+
+ int index = 0;
+ if (sentCommandOrder.head() == reply->id())
+ {
+ resetReplyTimeoutTimer(sentCommands[sentCommandOrder.head()]);
+ emit model_sentCommandRemoved(0);
+ }
+ else
+ {
+ index = sentCommandOrder.indexOf(reply->id());
+ emit model_sentCommandRemoved(index);
+ }
+ sentCommandOrder.removeAt(index);
+ sentCommands.remove(reply->id());
}
void Client::clearErrors()
return false;
}
+void Client::resetReplyTimeoutTimer(AbstractReply *cmd)
+{
+ Q_ASSERT(cmd);
+ int newTimeout = qBound(0, Client::UDP_API_COMMAND_TIMEOUT - cmd->timeSent().secsTo(QDateTime::currentDateTime()), Client::UDP_API_COMMAND_TIMEOUT);
+ newTimeout *= 1000;
+ replyTimeoutTimer->start(newTimeout);
+}
+
void Client::init()
{
static bool done = false;
#endif
if (!sentCommandOrder.isEmpty())
{
- int newTimeout = qBound(0, Client::UDP_API_COMMAND_TIMEOUT - sentCommands[commandId]->timeSent().secsTo(QDateTime::currentDateTime()), Client::UDP_API_COMMAND_TIMEOUT);
- newTimeout *= 1000;
- replyTimeoutTimer->start(newTimeout);
+ resetReplyTimeoutTimer(sentCommands[sentCommandOrder.head()]);
#ifdef ANIDBUDPCLIENT_CLIENT_MISC_DEBUG
qDebug() << "Starting replyTimeoutTimer" << newTimeout;
#endif