Commit 4992f93d authored by Lorenz Meier's avatar Lorenz Meier

Merge pull request #748 from DonLakeFlyer/FTPTimeout

FTP: Better timeout handling
parents 973b9c0c d9bc4cb2
......@@ -471,15 +471,19 @@ void QGCUASFileManager::_clearAckTimeout(void)
/// @brief Called when ack timeout timer fires
void QGCUASFileManager::_ackTimeout(void)
{
_emitErrorMessage(tr("Timeout waiting for ack"));
// Make sure to set _currentOperation state before emitting error message. Code may respond
// to error message signal by sending another command, which will fail if state is not back
// to idle. FileView UI works this way with the List command.
switch (_currentOperation) {
case kCORead:
_currentOperation = kCOAck;
_emitErrorMessage(tr("Timeout waiting for ack: Sending Terminate command"));
_sendTerminateCommand();
break;
default:
_currentOperation = kCOIdle;
_emitErrorMessage(tr("Timeout waiting for ack"));
break;
}
}
......
......@@ -40,7 +40,9 @@ QGCUASFileView::QGCUASFileView(QWidget *parent, QGCUASFileManager *manager) :
Q_ASSERT(success);
success = connect(_ui.treeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), this, SLOT(_currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)));
Q_ASSERT(success);
Q_UNUSED(success);
success = connect(&_listCompleteTimer, SIGNAL(timeout()), this, SLOT(_listCompleteTimeout()));
Q_ASSERT(success);
Q_UNUSED(success); // Silence retail unused variable error
}
void QGCUASFileView::_downloadFiles(void)
......@@ -88,8 +90,7 @@ void QGCUASFileView::_refreshTree(void)
// Don't queue up more than once
_ui.listFilesButton->setEnabled(false);
qDebug() << "List: /";
_manager->listDirectory("/");
_requestDirectoryList("/");
}
void QGCUASFileView::_treeStatusMessage(const QString& msg)
......@@ -128,6 +129,8 @@ void QGCUASFileView::_treeErrorMessage(const QString& msg)
void QGCUASFileView::_listComplete(void)
{
_clearListCompleteTimeout();
// Walk the current items, traversing down into directories
Again:
......@@ -159,8 +162,7 @@ Again:
QTreeWidgetItem* item = _walkItemStack[i];
dir.append("/" + item->text(0));
}
qDebug() << "List:" << dir;
_manager->listDirectory(dir);
_requestDirectoryList(dir);
} else {
// We have run out of items at the this level, pop the stack and keep going at that level
_walkIndexStack.removeLast();
......@@ -192,3 +194,30 @@ void QGCUASFileView::_currentItemChanged(QTreeWidgetItem* current, QTreeWidgetIt
Q_UNUSED(previous);
_ui.downloadButton->setEnabled(current ? (current->type() == _typeFile) : false);
}
void QGCUASFileView::_setupListCompleteTimeout(void)
{
Q_ASSERT(!_listCompleteTimer.isActive());
_listCompleteTimer.setSingleShot(true);
_listCompleteTimer.start(_listCompleteTimerTimeoutMsecs);
}
void QGCUASFileView::_clearListCompleteTimeout(void)
{
Q_ASSERT(_listCompleteTimer.isActive());
_listCompleteTimer.stop();
}
void QGCUASFileView::_listCompleteTimeout(void)
{
_treeErrorMessage(tr("Timeout waiting for listComplete signal"));
}
void QGCUASFileView::_requestDirectoryList(const QString& dir)
{
qDebug() << "List:" << dir;
_setupListCompleteTimeout();
_manager->listDirectory(dir);
}
......@@ -48,12 +48,20 @@ private slots:
void _listComplete(void);
void _downloadStatusMessage(const QString& msg);
void _currentItemChanged(QTreeWidgetItem* current, QTreeWidgetItem* previous);
void _listCompleteTimeout(void);
private:
void _setupListCompleteTimeout(void);
void _clearListCompleteTimeout(void);
void _requestDirectoryList(const QString& dir);
static const int _typeFile = QTreeWidgetItem::UserType + 1;
static const int _typeDir = QTreeWidgetItem::UserType + 2;
static const int _typeError = QTreeWidgetItem::UserType + 3;
QTimer _listCompleteTimer; ///> Used to signal a timeout waiting for a listComplete signal
static const int _listCompleteTimerTimeoutMsecs = 5000; ///> Timeout in msecs for listComplete timer
QList<int> _walkIndexStack;
QList<QTreeWidgetItem*> _walkItemStack;
Ui::QGCUASFileView _ui;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment