99 lines
2.9 KiB
C++
Executable File
99 lines
2.9 KiB
C++
Executable File
/**
|
|
* The ServiceProcess class represents a service which was startet as a process
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* Created by Hannes Baeuerle, SLSE, 2016-02-15
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <QtCore/QProcess>
|
|
#include <QtCore/QDateTime>
|
|
|
|
#include <DDS/Core/core.hpp>
|
|
#include <ServiceManagement/scm.hpp>
|
|
#include "logger.h"
|
|
|
|
namespace ServiceManagement
|
|
{
|
|
class Service;
|
|
class ServiceInformation;
|
|
|
|
class ServiceProcess : public QProcess
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
explicit ServiceProcess(const GroupRequest &groupData, Service *parentService);
|
|
~ServiceProcess();
|
|
|
|
Core::RunningState runningState() const;
|
|
int serviceProcessId() const;
|
|
qint64 lastHeartbeatMSec() const;
|
|
void setLastHeartbeatMSec(qint64 lastHeartbeatMSec);
|
|
int32_t domainId() const { return m_groupData.domainId(); }
|
|
int32_t prio() const { return m_prio; }
|
|
int32_t exercisePartitionId() const { return m_groupData.exercisePartitionId(); }
|
|
int32_t replayPartitionId() const { return m_groupData.replayPartitionId(); }
|
|
QString serviceName() const;
|
|
QString abbreviation() const;
|
|
dds::core::optional<std::vector<Core::PortInformation>> ports() const;
|
|
bool devMode() const;
|
|
bool stoppedFromRequest() const;
|
|
|
|
void setNewStateFromChangeRequest(const Core::RunningState &newState);
|
|
void setNewStateFromHeartbeat(const Core::CurrentRunningState &data);
|
|
void killallRemote();
|
|
qint64 usablePid() const
|
|
{
|
|
#ifdef WIN32
|
|
auto myPid = pid();
|
|
if (!myPid)
|
|
return 0;
|
|
return myPid->dwProcessId;
|
|
#else
|
|
return pid();
|
|
#endif
|
|
}
|
|
|
|
void restart();
|
|
void stopFromRequest();
|
|
int remotePid() {return m_remotePid;};
|
|
unsigned short failedStartingAttempts() const;
|
|
|
|
void addStartAttempt();
|
|
QString debugInfo() const;
|
|
Q_SIGNALS:
|
|
void newServiceInformation(const ServiceInformation &info);
|
|
|
|
public Q_SLOTS:
|
|
virtual bool start(OpenMode mode = ReadWrite);
|
|
|
|
private Q_SLOTS:
|
|
void onNewInfoFromProc(QProcess::ProcessState state);
|
|
void doRestart();
|
|
void onDataFromPidProc();
|
|
|
|
private:
|
|
const int m_serviceId;
|
|
const int m_serviceProcessId;
|
|
const QString m_abbreviation;
|
|
const QString m_name;
|
|
const int m_prio;
|
|
const GroupRequest m_groupData;
|
|
int m_remotePid;
|
|
Core::RunningState m_runningState;
|
|
dds::core::optional<std::vector<Core::PortInformation>> m_ports;
|
|
qint64 m_lastHeartbeatMSec;
|
|
Service *m_parentService;
|
|
bool m_hasLicence;
|
|
bool m_isInDevMode;
|
|
unsigned short m_failedStartAttemptCounter;
|
|
bool m_stoppedFromRequest;
|
|
QProcess *m_pidProc;
|
|
LOGGER_T m_logger;
|
|
|
|
static int s_serviceProcessIdCounter;
|
|
};
|
|
} // namespace ServiceManagement
|