LauncherSocketHandler: Disambiguate Process name

Rename Process -> ProcessWithToken.

Change-Id: I75920488107f45198590e0b17fa5c9e7679c6192
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2023-05-03 16:05:33 +02:00
parent c99d848e53
commit 1c37aab5bd
2 changed files with 22 additions and 22 deletions

View File

@@ -14,11 +14,11 @@
namespace Utils { namespace Utils {
namespace Internal { namespace Internal {
class Process : public ProcessHelper class ProcessWithToken : public ProcessHelper
{ {
Q_OBJECT Q_OBJECT
public: public:
Process(quintptr token, QObject *parent = nullptr) : ProcessWithToken(quintptr token, QObject *parent = nullptr) :
ProcessHelper(parent), m_token(token) { } ProcessHelper(parent), m_token(token) { }
quintptr token() const { return m_token; } quintptr token() const { return m_token; }
@@ -41,7 +41,7 @@ LauncherSocketHandler::LauncherSocketHandler(QString serverPath, QObject *parent
LauncherSocketHandler::~LauncherSocketHandler() LauncherSocketHandler::~LauncherSocketHandler()
{ {
for (auto it = m_processes.cbegin(); it != m_processes.cend(); ++it) { for (auto it = m_processes.cbegin(); it != m_processes.cend(); ++it) {
Process *p = it.value(); ProcessWithToken *p = it.value();
if (p->state() != QProcess::NotRunning) if (p->state() != QProcess::NotRunning)
logWarn(QStringLiteral("Shutting down while process %1 is running").arg(p->program())); logWarn(QStringLiteral("Shutting down while process %1 is running").arg(p->program()));
ProcessReaper::reap(p); ProcessReaper::reap(p);
@@ -114,7 +114,7 @@ void LauncherSocketHandler::handleSocketClosed()
qApp->quit(); qApp->quit();
} }
void LauncherSocketHandler::handleProcessError(Process *process) void LauncherSocketHandler::handleProcessError(ProcessWithToken *process)
{ {
// In case of FailedToStart we won't receive finished signal, so we send the error // In case of FailedToStart we won't receive finished signal, so we send the error
// packet and remove the process here and now. For all other errors we should expect // packet and remove the process here and now. For all other errors we should expect
@@ -124,7 +124,7 @@ void LauncherSocketHandler::handleProcessError(Process *process)
handleProcessFinished(process); handleProcessFinished(process);
} }
void LauncherSocketHandler::handleProcessStarted(Process *process) void LauncherSocketHandler::handleProcessStarted(ProcessWithToken *process)
{ {
ProcessStartedPacket packet(process->token()); ProcessStartedPacket packet(process->token());
packet.processId = process->processId(); packet.processId = process->processId();
@@ -132,21 +132,21 @@ void LauncherSocketHandler::handleProcessStarted(Process *process)
sendPacket(packet); sendPacket(packet);
} }
void LauncherSocketHandler::handleReadyReadStandardOutput(Process *process) void LauncherSocketHandler::handleReadyReadStandardOutput(ProcessWithToken *process)
{ {
ReadyReadStandardOutputPacket packet(process->token()); ReadyReadStandardOutputPacket packet(process->token());
packet.standardChannel = process->readAllStandardOutput(); packet.standardChannel = process->readAllStandardOutput();
sendPacket(packet); sendPacket(packet);
} }
void LauncherSocketHandler::handleReadyReadStandardError(Process *process) void LauncherSocketHandler::handleReadyReadStandardError(ProcessWithToken *process)
{ {
ReadyReadStandardErrorPacket packet(process->token()); ReadyReadStandardErrorPacket packet(process->token());
packet.standardChannel = process->readAllStandardError(); packet.standardChannel = process->readAllStandardError();
sendPacket(packet); sendPacket(packet);
} }
void LauncherSocketHandler::handleProcessFinished(Process *process) void LauncherSocketHandler::handleProcessFinished(ProcessWithToken *process)
{ {
ProcessDonePacket packet(process->token()); ProcessDonePacket packet(process->token());
packet.exitCode = process->exitCode(); packet.exitCode = process->exitCode();
@@ -162,7 +162,7 @@ void LauncherSocketHandler::handleProcessFinished(Process *process)
void LauncherSocketHandler::handleStartPacket() void LauncherSocketHandler::handleStartPacket()
{ {
Process *& process = m_processes[m_packetParser.token()]; ProcessWithToken *& process = m_processes[m_packetParser.token()];
if (!process) if (!process)
process = setupProcess(m_packetParser.token()); process = setupProcess(m_packetParser.token());
if (process->state() != QProcess::NotRunning) { if (process->state() != QProcess::NotRunning) {
@@ -197,7 +197,7 @@ void LauncherSocketHandler::handleStartPacket()
void LauncherSocketHandler::handleWritePacket() void LauncherSocketHandler::handleWritePacket()
{ {
Process * const process = m_processes.value(m_packetParser.token()); ProcessWithToken * const process = m_processes.value(m_packetParser.token());
if (!process) { if (!process) {
logWarn("Got write request for unknown process"); logWarn("Got write request for unknown process");
return; return;
@@ -214,7 +214,7 @@ void LauncherSocketHandler::handleWritePacket()
void LauncherSocketHandler::handleControlPacket() void LauncherSocketHandler::handleControlPacket()
{ {
Process * const process = m_processes.value(m_packetParser.token()); ProcessWithToken * const process = m_processes.value(m_packetParser.token());
if (!process) { if (!process) {
// This can happen when the process finishes on its own at about the same time the client // This can happen when the process finishes on its own at about the same time the client
// sends the request. In this case the process was already deleted. // sends the request. In this case the process was already deleted.
@@ -253,9 +253,9 @@ void LauncherSocketHandler::sendPacket(const LauncherPacket &packet)
m_socket->write(packet.serialize()); m_socket->write(packet.serialize());
} }
Process *LauncherSocketHandler::setupProcess(quintptr token) ProcessWithToken *LauncherSocketHandler::setupProcess(quintptr token)
{ {
const auto p = new Process(token, this); const auto p = new ProcessWithToken(token, this);
connect(p, &QProcess::started, this, [this, p] { handleProcessStarted(p); }); connect(p, &QProcess::started, this, [this, p] { handleProcessStarted(p); });
connect(p, &QProcess::errorOccurred, this, [this, p] { handleProcessError(p); }); connect(p, &QProcess::errorOccurred, this, [this, p] { handleProcessError(p); });
connect(p, &QProcess::finished, this, [this, p] { handleProcessFinished(p); }); connect(p, &QProcess::finished, this, [this, p] { handleProcessFinished(p); });
@@ -272,7 +272,7 @@ void LauncherSocketHandler::removeProcess(quintptr token)
if (it == m_processes.constEnd()) if (it == m_processes.constEnd())
return; return;
Process *process = it.value(); ProcessWithToken *process = it.value();
m_processes.erase(it); m_processes.erase(it);
ProcessReaper::reap(process, process->reaperTimeout()); ProcessReaper::reap(process, process->reaperTimeout());
} }

View File

@@ -15,7 +15,7 @@ QT_END_NAMESPACE
namespace Utils { namespace Utils {
namespace Internal { namespace Internal {
class Process; class ProcessWithToken;
class LauncherSocketHandler : public QObject class LauncherSocketHandler : public QObject
{ {
@@ -31,11 +31,11 @@ private:
void handleSocketError(); void handleSocketError();
void handleSocketClosed(); void handleSocketClosed();
void handleProcessStarted(Process *process); void handleProcessStarted(ProcessWithToken *process);
void handleProcessError(Process *process); void handleProcessError(ProcessWithToken *process);
void handleProcessFinished(Process *process); void handleProcessFinished(ProcessWithToken *process);
void handleReadyReadStandardOutput(Process *process); void handleReadyReadStandardOutput(ProcessWithToken *process);
void handleReadyReadStandardError(Process *process); void handleReadyReadStandardError(ProcessWithToken *process);
void handleStartPacket(); void handleStartPacket();
void handleWritePacket(); void handleWritePacket();
@@ -44,13 +44,13 @@ private:
void sendPacket(const LauncherPacket &packet); void sendPacket(const LauncherPacket &packet);
Process *setupProcess(quintptr token); ProcessWithToken *setupProcess(quintptr token);
void removeProcess(quintptr token); void removeProcess(quintptr token);
const QString m_serverPath; const QString m_serverPath;
QLocalSocket * const m_socket; QLocalSocket * const m_socket;
PacketParser m_packetParser; PacketParser m_packetParser;
QHash<quintptr, Process *> m_processes; QHash<quintptr, ProcessWithToken *> m_processes;
}; };
} // namespace Internal } // namespace Internal