DaemonManager: add stateChanged()

This commit is contained in:
Jaquee 2016-11-26 11:54:06 +01:00
parent 760e01b50c
commit 8d19a03b68
No known key found for this signature in database
GPG key ID: 384E52B09F45DC39
2 changed files with 16 additions and 6 deletions

View file

@ -61,6 +61,9 @@ bool DaemonManager::start()
m_daemon->start(process,arguments); m_daemon->start(process,arguments);
bool started = m_daemon->waitForStarted(); bool started = m_daemon->waitForStarted();
// add state changed listener
connect(m_daemon,SIGNAL(stateChanged(QProcess::ProcessState)),this,SLOT(stateChanged(QProcess::ProcessState)));
if(!started){ if(!started){
qDebug() << "Daemon start error: " + m_daemon->errorString(); qDebug() << "Daemon start error: " + m_daemon->errorString();
} else { } else {
@ -74,16 +77,22 @@ bool DaemonManager::stop()
{ {
if(initialized){ if(initialized){
qDebug() << "stopping daemon"; qDebug() << "stopping daemon";
m_daemon->terminate(); // we can't use QProcess::terminate() on windows console process
// Wait until stopped. Max 10 seconds // write exit command to stdin
bool stopped = m_daemon->waitForFinished(10000); m_daemon->write("exit\n");
if(stopped) emit daemonStopped();
return stopped;
} }
return true; return true;
} }
void DaemonManager::stateChanged(QProcess::ProcessState state)
{
qDebug() << "STATE CHANGED: " << state;
if(state == QProcess::NotRunning) {
emit daemonStopped();
}
}
void DaemonManager::printOutput() void DaemonManager::printOutput()
{ {
QByteArray byteArray = m_daemon->readAllStandardOutput(); QByteArray byteArray = m_daemon->readAllStandardOutput();
@ -111,7 +120,7 @@ bool DaemonManager::running() const
if(initialized){ if(initialized){
qDebug() << m_daemon->state(); qDebug() << m_daemon->state();
qDebug() << QProcess::NotRunning; qDebug() << QProcess::NotRunning;
// m_daemon->write("status\n");
return m_daemon->state() > QProcess::NotRunning; return m_daemon->state() > QProcess::NotRunning;
} }
return false; return false;

View file

@ -28,6 +28,7 @@ public slots:
void printOutput(); void printOutput();
void printError(); void printError();
void closing(); void closing();
void stateChanged(QProcess::ProcessState state);
private: private: