Skip to content

Commit

Permalink
Use more modern cpp and memory management
Browse files Browse the repository at this point in the history
 * Cleanup TailRunner
  • Loading branch information
SneWs committed Jul 15, 2024
1 parent 46eb2b9 commit 3b92f92
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
15 changes: 4 additions & 11 deletions TailRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,9 @@
TailRunner::TailRunner(const TailSettings& s, QObject* parent)
: QObject(parent)
, settings(s)
, pProcess(nullptr)
, eCommand(Command::Status)
{ }

TailRunner::~TailRunner() {
delete pProcess;
}

void TailRunner::checkStatus() {
eCommand = Command::Status;
runCommand("status", QStringList(), true);
Expand Down Expand Up @@ -113,12 +108,10 @@ void TailRunner::runCommand(QString cmd, QStringList args, bool jsonResult, bool
});
return;
}

delete pProcess;
}

pProcess = new QProcess(this);
connect(pProcess, &QProcess::finished, this, [this](int exitCode, QProcess::ExitStatus status) {
pProcess = std::make_unique<QProcess>(this);
connect(pProcess.get(), &QProcess::finished, this, [this](int exitCode, QProcess::ExitStatus status) {
qDebug() << "Process exit code " << exitCode << " - " << status;

if (exitCode != 0) {
Expand Down Expand Up @@ -153,11 +146,11 @@ void TailRunner::runCommand(QString cmd, QStringList args, bool jsonResult, bool
}
});

connect(pProcess, &QProcess::readyReadStandardOutput,
connect(pProcess.get(), &QProcess::readyReadStandardOutput,
this, &TailRunner::onProcessCanReadStdOut);

// TODO: @grenis This needs some refactoring
connect(pProcess, &QProcess::readyReadStandardError,
connect(pProcess.get(), &QProcess::readyReadStandardError,
this, [this]() {
// NOTE! For whatever reason, the login command output is not captured by the readyReadStandardOutput signal
// and arrives as a error output, so we need to check for that here.
Expand Down
5 changes: 3 additions & 2 deletions TailRunner.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef TAILRUNNER_H
#define TAILRUNNER_H

#include <memory>

#include <QObject>
#include <QString>
#include <QList>
Expand All @@ -14,7 +16,6 @@ class TailRunner : public QObject
Q_OBJECT
public:
explicit TailRunner(const TailSettings& s, QObject* parent = nullptr);
virtual ~TailRunner();

void checkStatus();
void getAccounts();
Expand All @@ -28,7 +29,7 @@ class TailRunner : public QObject

private:
const TailSettings& settings;
QProcess* pProcess;
std::unique_ptr<QProcess> pProcess;
enum class Command {
ListAccounts,
SwitchAccount,
Expand Down

0 comments on commit 3b92f92

Please sign in to comment.