Newer
Older
#include "DapServiceClientNativeLinux.h"
#include <QtDebug>
#include <QMessageBox>
DapServiceClientNativeLinux::DapServiceClientNativeLinux()
{
QString dapServiceNameToLower = QString(DAP_SERVICE_NAME).toLower();
QString cmd = QString("ps -C %1 > /dev/null").arg(DAP_SERVICE_NAME);
m_checkIsServiceRunningCommand = strdup(cmd.toLatin1().data());
m_cmdTemplate = QString("service " + dapServiceNameToLower) + " %1";
qDebug() << "command for check is service running: " << m_checkIsServiceRunningCommand;
}
DapServiceClientNativeLinux::~DapServiceClientNativeLinux()
{
delete m_checkIsServiceRunningCommand;
}
bool DapServiceClientNativeLinux::isServiceRunning()
{
m_isServiceRunning =true;// (::system(m_checkIsServiceRunningCommand) == 0);
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
return m_isServiceRunning;
}
DapServiceError DapServiceClientNativeLinux::serviceRestart()
{
qDebug() << "Restart service name" << m_cmdTemplate.arg("restart").toLatin1().data();
int retCode = ::system(m_cmdTemplate.arg("restart").toLatin1().data());
qDebug() << "Restart result code:" << retCode;
if(retCode != 0) {
return DapServiceError::USER_COMMAND_ABORT;
}
return DapServiceError::NO_ERRORS;
}
/**
* @brief SapNetworkClientNativeLinux::serviceStart
*/
DapServiceError DapServiceClientNativeLinux::serviceStart()
{
// yes better use restart
int ret = ::system(m_cmdTemplate.arg("restart").toLatin1().data());
qDebug() << "serviceStart Result: " << ret;
if(ret != 0) {
return DapServiceError::USER_COMMAND_ABORT;
}
return DapServiceError::NO_ERRORS;
}
/**
* @brief SapServiceClientNativeLinux::serviceStop
*/
DapServiceError DapServiceClientNativeLinux::serviceStop()
{
int ret = ::system(m_cmdTemplate.arg("stop").toLatin1().data());
qDebug() << "serviceStop result:" << ret;
if(ret != 0) {
return DapServiceError::USER_COMMAND_ABORT;
}
return DapServiceError::NO_ERRORS;
}
/**
* @brief SapServiceClientNativeLinux::serviceInstallAndRun
*/
DapServiceError DapServiceClientNativeLinux::serviceInstallAndRun()
{
return serviceStart();
}