UX: Report more drone startup errors

* Changed drone exit code from -1 to 1 'coz typically exit codes are
between 0 and 255
* Detect and report drone TCP port bind failure
* In all the following drone errors are reported (including previous
  commits) -
  * Drone already running (TCP port bind failure)
  * Drone executable not found
  * Packet.dll not found (Win32 only)
* The following conditions should NOT be reported
  * Start/Stop Ostinato
    * Stop before 5sec
    * Stop after 5sec
This commit is contained in:
Srivats P 2017-09-26 19:59:49 +05:30
parent a2b349e5b7
commit 57e8fe7236
3 changed files with 32 additions and 8 deletions

View File

@ -76,11 +76,13 @@ MainWindow::MainWindow(QWidget *parent)
qDebug("staring local server - %s", qPrintable(serverApp)); qDebug("staring local server - %s", qPrintable(serverApp));
localServer_ = new QProcess(this); localServer_ = new QProcess(this);
connect(localServer_, SIGNAL(finished(int, QProcess::ExitStatus)),
SLOT(onLocalServerFinished(int, QProcess::ExitStatus)));
connect(localServer_, SIGNAL(error(QProcess::ProcessError)), connect(localServer_, SIGNAL(error(QProcess::ProcessError)),
SLOT(onLocalServerError(QProcess::ProcessError))); SLOT(onLocalServerError(QProcess::ProcessError)));
localServer_->setProcessChannelMode(QProcess::ForwardedChannels); localServer_->setProcessChannelMode(QProcess::ForwardedChannels);
localServer_->start(serverApp, QStringList()); localServer_->start(serverApp, QStringList());
QTimer::singleShot(5000, this, SLOT(onLocalServerStarted())); QTimer::singleShot(5000, this, SLOT(stopLocalServerMonitor()));
} }
else else
localServer_ = NULL; localServer_ = NULL;
@ -151,6 +153,7 @@ MainWindow::MainWindow(QWidget *parent)
MainWindow::~MainWindow() MainWindow::~MainWindow()
{ {
stopLocalServerMonitor();
if (localServer_) { if (localServer_) {
#ifdef Q_OS_WIN32 #ifdef Q_OS_WIN32
//! \todo - find a way to terminate cleanly //! \todo - find a way to terminate cleanly
@ -328,28 +331,47 @@ void MainWindow::on_actionHelpAbout_triggered()
delete aboutDialog; delete aboutDialog;
} }
void MainWindow::onLocalServerStarted() void MainWindow::stopLocalServerMonitor()
{ {
// We are only interested in startup errors // We are only interested in startup errors
disconnect(localServer_, SIGNAL(error(QProcess::ProcessError)), disconnect(localServer_, SIGNAL(error(QProcess::ProcessError)),
this, SLOT(onLocalServerError(QProcess::ProcessError))); this, SLOT(onLocalServerError(QProcess::ProcessError)));
disconnect(localServer_, SIGNAL(finished(int, QProcess::ExitStatus)),
this, SLOT(onLocalServerFinished(int, QProcess::ExitStatus)));
} }
void MainWindow::onLocalServerError(QProcess::ProcessError error) void MainWindow::onLocalServerFinished(int exitCode,
QProcess::ExitStatus /*exitStatus*/)
{
if (exitCode)
reportLocalServerError();
}
void MainWindow::onLocalServerError(QProcess::ProcessError /*error*/)
{
reportLocalServerError();
}
void MainWindow::reportLocalServerError()
{ {
QMessageBox msgBox(this); QMessageBox msgBox(this);
msgBox.setIcon(QMessageBox::Warning); msgBox.setIcon(QMessageBox::Warning);
msgBox.setTextFormat(Qt::RichText); msgBox.setTextFormat(Qt::RichText);
msgBox.setStyleSheet("messagebox-text-interaction-flags: 5"); // mouse copy msgBox.setStyleSheet("messagebox-text-interaction-flags: 5"); // mouse copy
QString errorStr = tr("<p>Failed to start the local drone agent - " QString errorStr = tr("<p>Failed to start the local drone agent - "
"error 0x%1, exit code 0x%2.</p>") "error 0x%1, exit status 0x%2 exit code 0x%3.</p>")
.arg(error, 0, 16) .arg(localServer_->error(), 0, 16)
.arg(localServer_->exitStatus(), 0, 16)
.arg(localServer_->exitCode(), 0, 16); .arg(localServer_->exitCode(), 0, 16);
if (error == QProcess::FailedToStart) if (localServer_->error() == QProcess::FailedToStart)
errorStr.append(tr("<p>The drone program does not exist at %1 or you " errorStr.append(tr("<p>The drone program does not exist at %1 or you "
"don't have sufficient permissions to execute it." "don't have sufficient permissions to execute it."
"</p>") "</p>")
.arg(QCoreApplication::applicationDirPath())); .arg(QCoreApplication::applicationDirPath()));
if (localServer_->exitCode() == 1)
errorStr.append(tr("<p>The drone program was not able to bind to "
"TCP port 7878 - maybe a drone process is already "
"running?</p>"));
#ifdef Q_OS_WIN32 #ifdef Q_OS_WIN32
if (localServer_->exitCode() == STATUS_DLL_NOT_FOUND) if (localServer_->exitCode() == STATUS_DLL_NOT_FOUND)
errorStr.append(tr("<p>This is most likely because Packet.dll " errorStr.append(tr("<p>This is most likely because Packet.dll "

View File

@ -60,8 +60,10 @@ public slots:
void on_actionHelpAbout_triggered(); void on_actionHelpAbout_triggered();
private slots: private slots:
void onLocalServerStarted(); void stopLocalServerMonitor();
void onLocalServerFinished(int exitCode, QProcess::ExitStatus exitStatus);
void onLocalServerError(QProcess::ProcessError error); void onLocalServerError(QProcess::ProcessError error);
void reportLocalServerError();
void onNewVersion(QString version); void onNewVersion(QString version);
}; };

View File

@ -77,7 +77,7 @@ int main(int argc, char *argv[])
if (!drone->init()) if (!drone->init())
{ {
exitCode = -1; exitCode = 1;
goto _exit; goto _exit;
} }