-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDapMonitorCmdProgram.cpp
More file actions
69 lines (58 loc) · 1.85 KB
/
DapMonitorCmdProgram.cpp
File metadata and controls
69 lines (58 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
#include "DapMonitorCmdProgram.h"
DapMonitorCmdProgram::DapMonitorCmdProgram(const QString& name,
const QStringList& args,
QObject *parent)
: QObject(parent), m_name(name), m_args(args)
{
}
void DapMonitorCmdProgram::sltProcessFinished()
{
qDebug() << "sltProcessFinished";
m_isRunning = false;
m_process->deleteLater();
emit sigFinished();
}
void DapMonitorCmdProgram::sltReadProgramOutput()
{
while (!m_process->atEnd()) {
qint64 count_bytes = m_process->readLine(m_outputBuffer, MAX_LINE_LENGTH);
if(count_bytes == 0) {
qWarning() << "Read 0 bytes";
continue;
}
if(count_bytes == -1) {
qWarning() << "Error read line";
break;
}
// qDebug() << "monitoring proces out:" << m_outputBuffer;
sigProgramOutput(m_outputBuffer);
}
}
void DapMonitorCmdProgram::start()
{
if(m_isRunning) {
qWarning() << "Can't start monitoring. He is already started";
return;
}
m_process = new QProcess(this);
connect(m_process, &QProcess::finished,
this, &DapMonitorCmdProgram::sltProcessFinished);
connect(m_process, &QProcess::errorOccurred, [=](QProcess::ProcessError error) {
qCritical() << "Monitoring process: " << error;
if(error == QProcess::ProcessError::FailedToStart) {
emit sigStartError();
sltProcessFinished();
}
});
connect(m_process, &QProcess::readyRead, this, &DapMonitorCmdProgram::sltReadProgramOutput);
connect(m_process, &QProcess::started, [=] {
qInfo() << "Started process network monitor";
emit sigStarted();
m_isRunning = true;
});
m_process->start(m_name, m_args);
}
void DapMonitorCmdProgram::stop()
{
m_process->kill();
}