2021-07-07 11:36:03 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2021 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
|
**
|
|
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "launcherpackets.h"
|
|
|
|
|
|
2021-08-19 16:39:21 +02:00
|
|
|
#include <QByteArray>
|
2021-07-07 11:36:03 +02:00
|
|
|
|
|
|
|
|
namespace Utils {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
LauncherPacket::~LauncherPacket() = default;
|
|
|
|
|
|
|
|
|
|
QByteArray LauncherPacket::serialize() const
|
|
|
|
|
{
|
|
|
|
|
QByteArray data;
|
|
|
|
|
QDataStream stream(&data, QIODevice::WriteOnly);
|
|
|
|
|
stream << static_cast<int>(0) << static_cast<quint8>(type) << token;
|
|
|
|
|
doSerialize(stream);
|
|
|
|
|
stream.device()->reset();
|
|
|
|
|
stream << static_cast<int>(data.size() - sizeof(int));
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LauncherPacket::deserialize(const QByteArray &data)
|
|
|
|
|
{
|
|
|
|
|
QDataStream stream(data);
|
|
|
|
|
doDeserialize(stream);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
StartProcessPacket::StartProcessPacket(quintptr token)
|
|
|
|
|
: LauncherPacket(LauncherPacketType::StartProcess, token)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StartProcessPacket::doSerialize(QDataStream &stream) const
|
|
|
|
|
{
|
2022-03-31 14:56:09 +02:00
|
|
|
stream << command
|
|
|
|
|
<< arguments
|
|
|
|
|
<< workingDir
|
|
|
|
|
<< env
|
|
|
|
|
<< int(processMode)
|
|
|
|
|
<< writeData
|
2022-04-19 02:28:30 -07:00
|
|
|
<< int(processChannelMode)
|
2022-03-31 14:56:09 +02:00
|
|
|
<< standardInputFile
|
|
|
|
|
<< belowNormalPriority
|
|
|
|
|
<< nativeArguments
|
|
|
|
|
<< lowPriority
|
|
|
|
|
<< unixTerminalDisabled
|
|
|
|
|
<< useCtrlCStub;
|
2021-07-07 11:36:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StartProcessPacket::doDeserialize(QDataStream &stream)
|
|
|
|
|
{
|
2022-04-11 11:28:39 +02:00
|
|
|
int processModeInt;
|
2022-04-19 02:28:30 -07:00
|
|
|
int processChannelModeInt;
|
2022-03-31 14:56:09 +02:00
|
|
|
stream >> command
|
|
|
|
|
>> arguments
|
|
|
|
|
>> workingDir
|
|
|
|
|
>> env
|
2022-04-11 11:28:39 +02:00
|
|
|
>> processModeInt
|
2022-03-31 14:56:09 +02:00
|
|
|
>> writeData
|
2022-04-19 02:28:30 -07:00
|
|
|
>> processChannelModeInt
|
2022-03-31 14:56:09 +02:00
|
|
|
>> standardInputFile
|
|
|
|
|
>> belowNormalPriority
|
|
|
|
|
>> nativeArguments
|
|
|
|
|
>> lowPriority
|
|
|
|
|
>> unixTerminalDisabled
|
|
|
|
|
>> useCtrlCStub;
|
2022-04-11 11:28:39 +02:00
|
|
|
processMode = Utils::ProcessMode(processModeInt);
|
2022-04-19 02:28:30 -07:00
|
|
|
processChannelMode = QProcess::ProcessChannelMode(processChannelModeInt);
|
2021-07-07 11:36:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-07-12 15:49:20 +02:00
|
|
|
ProcessStartedPacket::ProcessStartedPacket(quintptr token)
|
|
|
|
|
: LauncherPacket(LauncherPacketType::ProcessStarted, token)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProcessStartedPacket::doSerialize(QDataStream &stream) const
|
|
|
|
|
{
|
|
|
|
|
stream << processId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProcessStartedPacket::doDeserialize(QDataStream &stream)
|
|
|
|
|
{
|
|
|
|
|
stream >> processId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-07-07 11:36:03 +02:00
|
|
|
StopProcessPacket::StopProcessPacket(quintptr token)
|
|
|
|
|
: LauncherPacket(LauncherPacketType::StopProcess, token)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StopProcessPacket::doSerialize(QDataStream &stream) const
|
|
|
|
|
{
|
2022-04-01 15:14:05 +02:00
|
|
|
stream << int(signalType);
|
2021-07-07 11:36:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StopProcessPacket::doDeserialize(QDataStream &stream)
|
|
|
|
|
{
|
2022-04-11 11:28:39 +02:00
|
|
|
int signalTypeInt;
|
|
|
|
|
stream >> signalTypeInt;
|
|
|
|
|
signalType = SignalType(signalTypeInt);
|
2021-07-07 11:36:03 +02:00
|
|
|
}
|
|
|
|
|
|
2021-08-06 14:43:03 +02:00
|
|
|
void WritePacket::doSerialize(QDataStream &stream) const
|
|
|
|
|
{
|
|
|
|
|
stream << inputData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WritePacket::doDeserialize(QDataStream &stream)
|
|
|
|
|
{
|
|
|
|
|
stream >> inputData;
|
|
|
|
|
}
|
2021-07-07 11:36:03 +02:00
|
|
|
|
2021-08-02 13:26:33 +02:00
|
|
|
void ReadyReadPacket::doSerialize(QDataStream &stream) const
|
|
|
|
|
{
|
|
|
|
|
stream << standardChannel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ReadyReadPacket::doDeserialize(QDataStream &stream)
|
|
|
|
|
{
|
|
|
|
|
stream >> standardChannel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2022-04-11 11:28:39 +02:00
|
|
|
ProcessDonePacket::ProcessDonePacket(quintptr token)
|
|
|
|
|
: LauncherPacket(LauncherPacketType::ProcessDone, token)
|
2021-07-07 11:36:03 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-11 11:28:39 +02:00
|
|
|
void ProcessDonePacket::doSerialize(QDataStream &stream) const
|
2021-07-07 11:36:03 +02:00
|
|
|
{
|
2022-04-11 11:28:39 +02:00
|
|
|
stream << exitCode
|
|
|
|
|
<< int(exitStatus)
|
|
|
|
|
<< int(error)
|
|
|
|
|
<< errorString
|
|
|
|
|
<< stdOut
|
|
|
|
|
<< stdErr;
|
2021-07-07 11:36:03 +02:00
|
|
|
}
|
|
|
|
|
|
2022-04-11 11:28:39 +02:00
|
|
|
void ProcessDonePacket::doDeserialize(QDataStream &stream)
|
2021-07-07 11:36:03 +02:00
|
|
|
{
|
2022-04-11 11:28:39 +02:00
|
|
|
int exitStatusInt, errorInt;
|
|
|
|
|
stream >> exitCode
|
|
|
|
|
>> exitStatusInt
|
|
|
|
|
>> errorInt
|
|
|
|
|
>> errorString
|
|
|
|
|
>> stdOut
|
|
|
|
|
>> stdErr;
|
|
|
|
|
exitStatus = QProcess::ExitStatus(exitStatusInt);
|
|
|
|
|
error = QProcess::ProcessError(errorInt);
|
2021-07-07 11:36:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ShutdownPacket::ShutdownPacket() : LauncherPacket(LauncherPacketType::Shutdown, 0) { }
|
|
|
|
|
void ShutdownPacket::doSerialize(QDataStream &stream) const { Q_UNUSED(stream); }
|
|
|
|
|
void ShutdownPacket::doDeserialize(QDataStream &stream) { Q_UNUSED(stream); }
|
|
|
|
|
|
|
|
|
|
void PacketParser::setDevice(QIODevice *device)
|
|
|
|
|
{
|
|
|
|
|
m_stream.setDevice(device);
|
|
|
|
|
m_sizeOfNextPacket = -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PacketParser::parse()
|
|
|
|
|
{
|
|
|
|
|
static const int commonPayloadSize = static_cast<int>(1 + sizeof(quintptr));
|
|
|
|
|
if (m_sizeOfNextPacket == -1) {
|
|
|
|
|
if (m_stream.device()->bytesAvailable() < static_cast<int>(sizeof m_sizeOfNextPacket))
|
|
|
|
|
return false;
|
|
|
|
|
m_stream >> m_sizeOfNextPacket;
|
|
|
|
|
if (m_sizeOfNextPacket < commonPayloadSize)
|
|
|
|
|
throw InvalidPacketSizeException(m_sizeOfNextPacket);
|
|
|
|
|
}
|
|
|
|
|
if (m_stream.device()->bytesAvailable() < m_sizeOfNextPacket)
|
|
|
|
|
return false;
|
|
|
|
|
quint8 type;
|
|
|
|
|
m_stream >> type;
|
|
|
|
|
m_type = static_cast<LauncherPacketType>(type);
|
|
|
|
|
m_stream >> m_token;
|
|
|
|
|
m_packetData = m_stream.device()->read(m_sizeOfNextPacket - commonPayloadSize);
|
|
|
|
|
m_sizeOfNextPacket = -1;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Utils
|