1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2025-07-26 02:32:25 -04:00

Commands: fixed error and exit signals handling

This commit is contained in:
f4exb 2018-01-04 23:10:05 +01:00
parent 069d9a7d07
commit 098ae3be74
6 changed files with 65 additions and 55 deletions

View File

@ -25,7 +25,7 @@ Command::Command() :
m_currentProcessState(QProcess::NotRunning), m_currentProcessState(QProcess::NotRunning),
m_isInError(false), m_isInError(false),
m_currentProcessError(QProcess::UnknownError), m_currentProcessError(QProcess::UnknownError),
m_isFinished(true), m_hasExited(false),
m_currentProcessExitCode(0), m_currentProcessExitCode(0),
m_currentProcessExitStatus(QProcess::NormalExit), m_currentProcessExitStatus(QProcess::NormalExit),
m_currentProcessPid(0) m_currentProcessPid(0)
@ -52,7 +52,7 @@ Command::Command(const Command& command) :
m_currentProcessState(QProcess::NotRunning), m_currentProcessState(QProcess::NotRunning),
m_isInError(false), m_isInError(false),
m_currentProcessError(QProcess::UnknownError), m_currentProcessError(QProcess::UnknownError),
m_isFinished(true), m_hasExited(false),
m_currentProcessExitCode(0), m_currentProcessExitCode(0),
m_currentProcessExitStatus(QProcess::NormalExit), m_currentProcessExitStatus(QProcess::NormalExit),
m_currentProcessPid(0) m_currentProcessPid(0)
@ -179,7 +179,7 @@ void Command::run(const QString& apiAddress, int apiPort, int deviceSetIndex)
m_currentProcess = new QProcess(this); m_currentProcess = new QProcess(this);
m_isInError = false; m_isInError = false;
m_isFinished = false; m_hasExited = false;
#if QT_VERSION < 0x051000 #if QT_VERSION < 0x051000
connect(m_currentProcess, SIGNAL(error(QProcess::ProcessError)), this, SLOT(processError(QProcess::ProcessError))); connect(m_currentProcess, SIGNAL(error(QProcess::ProcessError)), this, SLOT(processError(QProcess::ProcessError)));
@ -200,17 +200,6 @@ void Command::kill()
{ {
qDebug("Command::kill: %lld", m_currentProcessPid); qDebug("Command::kill: %lld", m_currentProcessPid);
m_currentProcess->kill(); m_currentProcess->kill();
#if QT_VERSION < 0x051000
disconnect(m_currentProcess, SIGNAL(error(QProcess::ProcessError)), this, SLOT(processError(QProcess::ProcessError)));
#else
disconnect(m_currentProcess, SIGNAL(errorOccurred(QProcess::ProcessError)), this, SLOT(processError(QProcess::ProcessError)));
#endif
disconnect(m_currentProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(processFinished(int, QProcess::ExitStatus)));
disconnect(m_currentProcess, SIGNAL(stateChanged(QProcess::ProcessState)), this, SLOT(processStateChanged(QProcess::ProcessState)));
delete m_currentProcess;
m_currentProcess = 0;
} }
} }
@ -228,15 +217,15 @@ bool Command::getLastProcessError(QProcess::ProcessError& error) const
return m_isInError; return m_isInError;
} }
bool Command::getLastProcessTermination(int& exitCode, QProcess::ExitStatus& exitStatus) const bool Command::getLastProcessExit(int& exitCode, QProcess::ExitStatus& exitStatus) const
{ {
if (m_isFinished) if (m_hasExited)
{ {
exitCode = m_currentProcessExitCode; exitCode = m_currentProcessExitCode;
exitStatus = m_currentProcessExitStatus; exitStatus = m_currentProcessExitStatus;
} }
return m_isFinished; return m_hasExited;
} }
const QString& Command::getLastProcessLog() const const QString& Command::getLastProcessLog() const
@ -255,37 +244,41 @@ void Command::processStateChanged(QProcess::ProcessState newState)
void Command::processError(QProcess::ProcessError error) void Command::processError(QProcess::ProcessError error)
{ {
//qDebug("Command::processError: %d state: %d", error, m_currentProcessState);
gettimeofday(&m_currentProcessFinishTimeStamp, 0); gettimeofday(&m_currentProcessFinishTimeStamp, 0);
m_currentProcessError = error; m_currentProcessError = error;
m_isInError = true; m_isInError = true;
m_isFinished = true;
m_log = m_currentProcess->readAllStandardOutput(); if (m_currentProcessState == QProcess::NotRunning)
{
m_log = m_currentProcess->readAllStandardOutput();
#if QT_VERSION < 0x051000 #if QT_VERSION < 0x051000
disconnect(m_currentProcess, SIGNAL(error(QProcess::ProcessError)), this, SLOT(processError(QProcess::ProcessError))); disconnect(m_currentProcess, SIGNAL(error(QProcess::ProcessError)), this, SLOT(processError(QProcess::ProcessError)));
#else #else
disconnect(m_currentProcess, SIGNAL(errorOccurred(QProcess::ProcessError)), this, SLOT(processError(QProcess::ProcessError))); disconnect(m_currentProcess, SIGNAL(errorOccurred(QProcess::ProcessError)), this, SLOT(processError(QProcess::ProcessError)));
#endif #endif
disconnect(m_currentProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(processFinished(int, QProcess::ExitStatus))); disconnect(m_currentProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(processFinished(int, QProcess::ExitStatus)));
disconnect(m_currentProcess, SIGNAL(stateChanged(QProcess::ProcessState)), this, SLOT(processStateChanged(QProcess::ProcessState))); disconnect(m_currentProcess, SIGNAL(stateChanged(QProcess::ProcessState)), this, SLOT(processStateChanged(QProcess::ProcessState)));
delete m_currentProcess; delete m_currentProcess;
m_currentProcess = 0; m_currentProcess = 0;
}
} }
void Command::processFinished(int exitCode, QProcess::ExitStatus exitStatus) void Command::processFinished(int exitCode, QProcess::ExitStatus exitStatus)
{ {
//qDebug("Command::processFinished: (%d) %d", exitCode, exitStatus);
gettimeofday(&m_currentProcessFinishTimeStamp, 0); gettimeofday(&m_currentProcessFinishTimeStamp, 0);
m_currentProcessExitCode = exitCode; m_currentProcessExitCode = exitCode;
m_currentProcessExitStatus = exitStatus; m_currentProcessExitStatus = exitStatus;
m_isInError = false; m_hasExited = true;
m_isFinished = true;
m_log = m_currentProcess->readAllStandardOutput(); m_log = m_currentProcess->readAllStandardOutput();
#if QT_VERSION < 0x051000 #if QT_VERSION < 0x051000
disconnect(m_currentProcess, SIGNAL(error(QProcess::ProcessError)), this, SLOT(processError(QProcess::ProcessError))); disconnect(m_currentProcess, SIGNAL(error(QProcess::ProcessError)), this, SLOT(processError(QProcess::ProcessError)));
#else #else
disconnect(m_currentProcess, SIGNAL(errorOccurred(QProcess::ProcessError)), this, SLOT(processError(QProcess::ProcessError))); disconnect(m_currentProcess, SIGNAL(errorOccurred(QProcess::ProcessError)), this, SLOT(processError(QProcess::ProcessError)));
#endif #endif
disconnect(m_currentProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(processFinished(int, QProcess::ExitStatus))); disconnect(m_currentProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(processFinished(int, QProcess::ExitStatus)));
disconnect(m_currentProcess, SIGNAL(stateChanged(QProcess::ProcessState)), this, SLOT(processStateChanged(QProcess::ProcessState))); disconnect(m_currentProcess, SIGNAL(stateChanged(QProcess::ProcessState)), this, SLOT(processStateChanged(QProcess::ProcessState)));

View File

@ -59,7 +59,7 @@ public:
void kill(); void kill();
QProcess::ProcessState getLastProcessState() const; QProcess::ProcessState getLastProcessState() const;
bool getLastProcessError(QProcess::ProcessError& error) const; bool getLastProcessError(QProcess::ProcessError& error) const;
bool getLastProcessTermination(int& exitCode, QProcess::ExitStatus& exitStatus) const; bool getLastProcessExit(int& exitCode, QProcess::ExitStatus& exitStatus) const;
const QString& getLastProcessLog() const; const QString& getLastProcessLog() const;
struct timeval getLastProcessStartTimestamp() const { return m_currentProcessStartTimeStamp; } struct timeval getLastProcessStartTimestamp() const { return m_currentProcessStartTimeStamp; }
struct timeval getLastProcessFinishTimestamp() const { return m_currentProcessFinishTimeStamp; } struct timeval getLastProcessFinishTimestamp() const { return m_currentProcessFinishTimeStamp; }
@ -101,7 +101,7 @@ private:
QProcess::ProcessState m_currentProcessState; QProcess::ProcessState m_currentProcessState;
bool m_isInError; bool m_isInError;
QProcess::ProcessError m_currentProcessError; QProcess::ProcessError m_currentProcessError;
bool m_isFinished; bool m_hasExited;
int m_currentProcessExitCode; int m_currentProcessExitCode;
QProcess::ExitStatus m_currentProcessExitStatus; QProcess::ExitStatus m_currentProcessExitStatus;
QString m_log; QString m_log;

View File

@ -64,34 +64,35 @@ void CommandOutputDialog::refresh()
ui->runningState->setChecked(m_command.getLastProcessState() == QProcess::Running); ui->runningState->setChecked(m_command.getLastProcessState() == QProcess::Running);
QProcess::ProcessError processError; QProcess::ProcessError processError;
if (m_command.getLastProcessStartTimestamp().tv_sec == 0) if (m_command.getLastProcessStartTimestamp().tv_sec == 0) // not started
{ {
ui->errorText->setText("..."); ui->errorText->setText("...");
ui->exitCode->setText("-"); ui->exitCode->setText("-");
ui->exitText->setText("..."); ui->exitText->setText("...");
ui->runningState->setStyleSheet("QToolButton { background:rgb(79,79,79); }"); ui->runningState->setStyleSheet("QToolButton { background:rgb(79,79,79); }");
} }
else if (m_command.getLastProcessState() != QProcess::NotRunning) else if (m_command.getLastProcessState() != QProcess::NotRunning) // running
{ {
ui->errorText->setText("..."); ui->errorText->setText("...");
ui->runningState->setStyleSheet("QToolButton { background-color : blue; }"); ui->runningState->setStyleSheet("QToolButton { background-color : orange; }");
} }
else if (m_command.getLastProcessError(processError)) else // finished
{ {
ui->runningState->setStyleSheet("QToolButton { background-color : red; }"); if (m_command.getLastProcessError(processError)) // finished
setErrorText(processError); {
ui->exitCode->setText("-"); ui->runningState->setStyleSheet("QToolButton { background-color : red; }");
ui->exitText->setText("..."); setErrorText(processError);
} }
else else
{ {
ui->runningState->setStyleSheet("QToolButton { background-color : green; }"); ui->runningState->setStyleSheet("QToolButton { background-color : green; }");
ui->errorText->setText("No error"); ui->errorText->setText("No error");
}
int processExitCode; int processExitCode;
QProcess::ExitStatus processExitStatus; QProcess::ExitStatus processExitStatus;
if (m_command.getLastProcessTermination(processExitCode, processExitStatus)) if (m_command.getLastProcessExit(processExitCode, processExitStatus))
{ {
ui->exitCode->setText(QString("%1").arg(processExitCode)); ui->exitCode->setText(QString("%1").arg(processExitCode));
setExitText(processExitStatus); setExitText(processExitStatus);
@ -148,13 +149,21 @@ void CommandOutputDialog::setExitText(const QProcess::ExitStatus& processExit)
} }
} }
void CommandOutputDialog::on_processRefresh_toggled(bool checked __attribute__((unused))) void CommandOutputDialog::on_processRefresh_toggled(bool checked)
{ {
refresh(); if (checked)
{
refresh();
ui->processRefresh->setChecked(false);
}
} }
void CommandOutputDialog::on_processKill_toggled(bool checked __attribute__((unused))) void CommandOutputDialog::on_processKill_toggled(bool checked)
{ {
m_command.kill(); if (checked)
{
m_command.kill();
ui->processKill->setChecked(false);
}
} }

View File

@ -55,6 +55,9 @@
<iconset resource="../resources/res.qrc"> <iconset resource="../resources/res.qrc">
<normaloff>:/recycle.png</normaloff>:/recycle.png</iconset> <normaloff>:/recycle.png</normaloff>:/recycle.png</iconset>
</property> </property>
<property name="checkable">
<bool>true</bool>
</property>
</widget> </widget>
</item> </item>
<item> <item>
@ -158,6 +161,9 @@
<iconset resource="../resources/res.qrc"> <iconset resource="../resources/res.qrc">
<normaloff>:/kill.png</normaloff>:/kill.png</iconset> <normaloff>:/kill.png</normaloff>:/kill.png</iconset>
</property> </property>
<property name="checkable">
<bool>true</bool>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>

View File

@ -682,14 +682,14 @@ QTreeWidgetItem* MainWindow::addCommandToTree(const Command* command)
QStringList sl; QStringList sl;
sl.append(QString("%1").arg(command->getDescription())); // Descriptions column sl.append(QString("%1").arg(command->getDescription())); // Descriptions column
sl.append(QString("%1").arg(command->getKeyLabel())); // key column
sl.append(QString("%1").arg(command->getAssociateKey() ? command->getRelease() ? "R" : "P" : "")); // key press/release column sl.append(QString("%1").arg(command->getAssociateKey() ? command->getRelease() ? "R" : "P" : "")); // key press/release column
sl.append(QString("%1").arg(command->getKeyLabel())); // key column
CommandItem* item = new CommandItem(group, sl, command->getDescription(), PItem); CommandItem* item = new CommandItem(group, sl, command->getDescription(), PItem);
item->setData(0, Qt::UserRole, qVariantFromValue(command)); item->setData(0, Qt::UserRole, qVariantFromValue(command));
item->setTextAlignment(0, Qt::AlignLeft); item->setTextAlignment(0, Qt::AlignLeft);
ui->presetTree->resizeColumnToContents(0); // Resize description column to minimum ui->commandTree->resizeColumnToContents(0); // Resize description column to minimum
ui->presetTree->resizeColumnToContents(1); // Resize key column to minimum ui->commandTree->resizeColumnToContents(1); // Resize key column to minimum
ui->presetTree->resizeColumnToContents(2); // Resize key press/release column to minimum ui->commandTree->resizeColumnToContents(2); // Resize key press/release column to minimum
//updatePresetControls(); //updatePresetControls();
return item; return item;
@ -816,9 +816,11 @@ void MainWindow::handleMessages()
void MainWindow::on_action_View_Fullscreen_toggled(bool checked) void MainWindow::on_action_View_Fullscreen_toggled(bool checked)
{ {
if(checked) if(checked) {
showFullScreen(); showFullScreen();
else showNormal(); } else {
showNormal();
}
} }
void MainWindow::on_commandNew_clicked() void MainWindow::on_commandNew_clicked()

View File

@ -591,12 +591,12 @@
</column> </column>
<column> <column>
<property name="text"> <property name="text">
<string>Key</string> <string>P/R</string>
</property> </property>
</column> </column>
<column> <column>
<property name="text"> <property name="text">
<string>P/R</string> <string>Key</string>
</property> </property>
</column> </column>
</widget> </widget>