Skip to content

Commit

Permalink
[QMS-623] remove use of QTimer in brouter startup error detection
Browse files Browse the repository at this point in the history
  • Loading branch information
ntruchsess authored and kiozen committed Aug 14, 2023
1 parent 034faee commit 6301026
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[QMS-622] Update BRouter setup (install from github)
[QMS-623] remove use of QTimer in brouter startup error detection
[QMS-630] BRouter on-the-fly routing cannot be canceled

V1.17.0
Expand Down
12 changes: 3 additions & 9 deletions src/qmapshack/gis/rte/router/brouter/CRouterBRouterToolShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,23 @@ CRouterBRouterToolShell::CRouterBRouterToolShell(QTextBrowser* textBrowser, QWid
setTextBrowser(textBrowser);
connect(&cmd, &QProcess::stateChanged, this, &CRouterBRouterToolShell::slotStateChanged);
connect(&cmd, &QProcess::errorOccurred, this, &CRouterBRouterToolShell::slotError);
startupTimer = new QTimer(this);
startupTimer->setSingleShot(true);
connect(startupTimer, &QTimer::timeout, this, &CRouterBRouterToolShell::slotStartupTimer);
}

CRouterBRouterToolShell::~CRouterBRouterToolShell() {}

void CRouterBRouterToolShell::start(const QString& dir, const QString& command, const QStringList& args) {
isBeingKilled = false;
isStarting = true;
isBeingStopped = false;
stdOut("cd " + dir);
stdOut(command + " " + args.join(" ") + "\n");
cmd.setWorkingDirectory(dir);
startupTimer->start(200);
cmd.start(command, args);
cmd.waitForStarted();
}

void CRouterBRouterToolShell::stop() {
if (cmd.state() != QProcess::NotRunning) {
isBeingStopped = true;
#ifdef USE_KILL_FOR_SHUTDOWN
isBeingKilled = true;
cmd.kill();
Expand All @@ -55,10 +52,9 @@ void CRouterBRouterToolShell::stop() {
}

void CRouterBRouterToolShell::slotStateChanged(const QProcess::ProcessState newState) {
if (newState == QProcess::NotRunning && isStarting) {
if (newState == QProcess::NotRunning && !isBeingStopped) {
emit sigProcessError(QProcess::FailedToStart, text->toPlainText());
}

emit sigProcessStateChanged(newState);
}

Expand All @@ -69,8 +65,6 @@ void CRouterBRouterToolShell::slotError(const QProcess::ProcessError error) {
emit sigProcessError(error, cmd.errorString());
}

void CRouterBRouterToolShell::slotStartupTimer() { isStarting = false; }

void CRouterBRouterToolShell::finished(const int exitCode, const QProcess::ExitStatus status) {
if (status == QProcess::ExitStatus::NormalExit) {
text->setTextColor(Qt::darkGreen);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,12 @@ class CRouterBRouterToolShell : public IToolShell {
private slots:
void slotStateChanged(const QProcess::ProcessState newState);
void slotError(const QProcess::ProcessError error);
void slotStartupTimer();

private:
void finished(int exitCode, QProcess::ExitStatus status) override;

bool isBeingKilled{false};
bool isStarting{false};
QTimer* startupTimer{nullptr};
bool isBeingStopped{false};
};

#endif // CROUTERBROUTERTOOLSHELL_H

0 comments on commit 6301026

Please sign in to comment.