#include "applicationcontrol.h"
ApplicationControl
::ApplicationControl(QObject *parent
) :{
for(int i = 0; i < 2; i++)
{
m_pProcess
[i
]->setProcessChannelMode
(QProcess::MergedChannels);
connect(m_pProcess
[i
],
SIGNAL(finished
(int,
QProcess::ExitStatus)),
this,
SLOT(processFinished
(int,
QProcess::ExitStatus)));
connect(m_pProcess
[i
],
SIGNAL(error
(QProcess::ProcessError)),
this,
SLOT(processError
(QProcess::ProcessError)));
}
m_pProcess[0]->setObjectName("Server");
m_pProcess[1]->setObjectName("Client");
QTimer::singleShot(5,
this,
SLOT(StartJob
()));
m_nServerStarted = false;
m_nClientStarted = false;
}
void ApplicationControl::StartJob()
{
m_pProcess[0]->start("/root/CCU/Server");
m_pProcess[1]->start("/root/CCU/Client");
}
void ApplicationControl
::processError(QProcess::ProcessError error
) {
QProcess *pProcess
= qobject_cast<QProcess
*>
(sender
());
qDebug() << "Application Name " << pProcess->objectName();
{
qDebug(("Unable to Start Job ..."));
return ;
}
{
qDebug
() <<
"Program Crashed error " << error <<
QDateTime::currentDateTime().
toString();
}
{
qDebug
() <<
"Program Timedout error " << error <<
QDateTime::currentDateTime().
toString();
}
{
qDebug
() <<
"Program WriteError error " << error <<
QDateTime::currentDateTime().
toString();
}
{
qDebug
() <<
"Program ReadError error " << error <<
QDateTime::currentDateTime().
toString();
}
else
{
qDebug
() <<
"Program Unknow error " << error <<
QDateTime::currentDateTime().
toString();
}
}
void ApplicationControl
::processFinished(int exitCode,
QProcess::ExitStatus exitStatus
) {
/* If crashed Restart Application */
QProcess *pProcess
= qobject_cast<QProcess
*>
(sender
());
qDebug() << "Application Name " << pProcess->objectName();
if(exitStatus == 0)
{
qDebug() << "exit Success Restarting " << pProcess->objectName();
return ;
}
{
qDebug
() <<
"Program Crashed " <<
QDateTime::currentDateTime().
toString();
// return ;
}
else if (exitCode != 0)
{
qDebug
() <<
"Failed to Start" <<
QDateTime::currentDateTime().
toString();
}
if(pProcess->objectName() == "Server")
{
m_pProcess[0]->start("/root/CCU/Server");
}
else if(pProcess->objectName() == "Client")
{
m_pProcess[1]->start("/root/CCU/Client");
}
}
#include "applicationcontrol.h"
ApplicationControl::ApplicationControl(QObject *parent) :
QObject(parent)
{
m_pProcess = new QProcess*[2];
for(int i = 0; i < 2; i++)
{
m_pProcess[i] = new QProcess();
m_pProcess[i]->setProcessChannelMode(QProcess::MergedChannels);
connect(m_pProcess[i], SIGNAL(finished(int, QProcess::ExitStatus)),this, SLOT(processFinished(int, QProcess::ExitStatus)));
connect(m_pProcess[i], SIGNAL(error(QProcess::ProcessError)),this, SLOT(processError(QProcess::ProcessError)));
}
m_pProcess[0]->setObjectName("Server");
m_pProcess[1]->setObjectName("Client");
QTimer::singleShot(5,this,SLOT(StartJob()));
m_nServerStarted = false;
m_nClientStarted = false;
}
void ApplicationControl::StartJob()
{
m_pProcess[0]->start("/root/CCU/Server");
m_pProcess[1]->start("/root/CCU/Client");
}
void ApplicationControl::processError(QProcess::ProcessError error)
{
QProcess *pProcess = qobject_cast<QProcess*>(sender());
qDebug() << "Application Name " << pProcess->objectName();
if (error == QProcess::FailedToStart)
{
qDebug(("Unable to Start Job ..."));
return ;
}
else if (error == QProcess::Crashed)
{
qDebug() << "Program Crashed error " << error << QDateTime::currentDateTime().toString();
}
else if (error == QProcess::Timedout)
{
qDebug() << "Program Timedout error " << error << QDateTime::currentDateTime().toString();
}
else if (error == QProcess::WriteError)
{
qDebug() << "Program WriteError error " << error << QDateTime::currentDateTime().toString();
}
else if (error == QProcess::ReadError)
{
qDebug() << "Program ReadError error " << error << QDateTime::currentDateTime().toString();
}
else
{
qDebug() << "Program Unknow error " << error << QDateTime::currentDateTime().toString();
}
}
void ApplicationControl::processFinished(int exitCode, QProcess::ExitStatus exitStatus)
{
/* If crashed Restart Application */
QProcess *pProcess = qobject_cast<QProcess*>(sender());
qDebug() << "Application Name " << pProcess->objectName();
if(exitStatus == 0)
{
qDebug() << "exit Success Restarting " << pProcess->objectName();
return ;
}
if (exitStatus == QProcess::CrashExit)
{
qDebug() << "Program Crashed " << QDateTime::currentDateTime().toString();
// return ;
}
else if (exitCode != 0)
{
qDebug() << "Failed to Start" << QDateTime::currentDateTime().toString();
}
if(pProcess->objectName() == "Server")
{
m_pProcess[0]->start("/root/CCU/Server");
}
else if(pProcess->objectName() == "Client")
{
m_pProcess[1]->start("/root/CCU/Client");
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks