2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2022 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2022-05-05 15:08:25 +02:00
|
|
|
|
2022-09-15 12:25:39 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
2022-05-05 15:08:25 +02:00
|
|
|
#include "utils_global.h"
|
|
|
|
|
|
2022-10-07 16:54:27 +02:00
|
|
|
#include "fileutils.h"
|
|
|
|
|
|
2022-05-13 15:13:35 +02:00
|
|
|
#include <QMap>
|
|
|
|
|
#include <QMutex>
|
2022-05-05 15:08:25 +02:00
|
|
|
#include <QProcess>
|
|
|
|
|
#include <QThread>
|
2022-05-13 15:13:35 +02:00
|
|
|
#include <QWaitCondition>
|
2022-05-05 15:08:25 +02:00
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
|
|
namespace Utils {
|
|
|
|
|
|
|
|
|
|
class CommandLine;
|
2022-06-17 13:11:08 +02:00
|
|
|
class ProcessResultData;
|
2022-05-05 15:08:25 +02:00
|
|
|
class QtcProcess;
|
|
|
|
|
|
|
|
|
|
class DeviceShellImpl;
|
|
|
|
|
|
|
|
|
|
class QTCREATOR_UTILS_EXPORT DeviceShell : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
2022-08-10 14:38:06 +02:00
|
|
|
enum class State { FailedToStart = -1, Unknown = 0, Succeeded = 1, NoScript = 2 };
|
2022-05-13 15:13:35 +02:00
|
|
|
|
|
|
|
|
enum class ParseType {
|
|
|
|
|
StdOut,
|
|
|
|
|
StdErr,
|
|
|
|
|
ExitCode,
|
2022-05-05 15:08:25 +02:00
|
|
|
};
|
|
|
|
|
|
2022-09-20 10:23:18 +02:00
|
|
|
DeviceShell(bool forceFailScriptInstallation = false);
|
2022-05-05 15:08:25 +02:00
|
|
|
virtual ~DeviceShell();
|
|
|
|
|
|
2022-05-17 10:07:27 +02:00
|
|
|
bool start();
|
|
|
|
|
|
2022-10-07 16:54:27 +02:00
|
|
|
RunResult runInShell(const CommandLine &cmd, const QByteArray &stdInData = {});
|
2022-05-05 15:08:25 +02:00
|
|
|
|
2022-05-13 15:13:35 +02:00
|
|
|
State state() const;
|
2022-05-05 15:08:25 +02:00
|
|
|
|
2022-08-10 14:38:06 +02:00
|
|
|
QStringList missingFeatures() const;
|
|
|
|
|
|
2022-05-05 15:08:25 +02:00
|
|
|
signals:
|
2022-06-17 13:11:08 +02:00
|
|
|
void done(const ProcessResultData &resultData);
|
2022-05-05 15:08:25 +02:00
|
|
|
|
|
|
|
|
protected:
|
2022-05-13 15:13:35 +02:00
|
|
|
virtual void startupFailed(const CommandLine &cmdLine);
|
|
|
|
|
RunResult run(const CommandLine &cmd, const QByteArray &stdInData = {});
|
2022-05-05 15:08:25 +02:00
|
|
|
|
|
|
|
|
void close();
|
|
|
|
|
|
|
|
|
|
private:
|
2022-05-05 15:08:46 +02:00
|
|
|
virtual void setupShellProcess(QtcProcess *shellProcess);
|
2022-08-10 14:38:06 +02:00
|
|
|
virtual CommandLine createFallbackCommand(const CommandLine &cmdLine);
|
2022-05-05 15:08:25 +02:00
|
|
|
|
2022-05-13 15:13:35 +02:00
|
|
|
bool installShellScript();
|
2022-05-05 15:08:25 +02:00
|
|
|
void closeShellProcess();
|
|
|
|
|
|
2022-05-13 15:13:35 +02:00
|
|
|
void onReadyRead();
|
|
|
|
|
|
2022-08-10 14:38:06 +02:00
|
|
|
bool checkCommand(const QByteArray &command);
|
|
|
|
|
|
2022-05-05 15:08:25 +02:00
|
|
|
private:
|
2022-05-13 15:13:35 +02:00
|
|
|
struct CommandRun : public RunResult
|
|
|
|
|
{
|
|
|
|
|
QWaitCondition *waiter;
|
|
|
|
|
};
|
|
|
|
|
|
2022-09-14 09:52:09 +02:00
|
|
|
std::unique_ptr<QtcProcess> m_shellProcess;
|
2022-05-05 15:08:25 +02:00
|
|
|
QThread m_thread;
|
2022-05-13 15:13:35 +02:00
|
|
|
int m_currentId{0};
|
|
|
|
|
|
|
|
|
|
QMutex m_commandMutex;
|
|
|
|
|
// QMap is used here to preserve iterators
|
|
|
|
|
QMap<quint64, CommandRun> m_commandOutput;
|
|
|
|
|
QByteArray m_commandBuffer;
|
|
|
|
|
|
|
|
|
|
State m_shellScriptState = State::Unknown;
|
2022-08-10 14:38:06 +02:00
|
|
|
QStringList m_missingFeatures;
|
2022-09-20 10:23:18 +02:00
|
|
|
|
|
|
|
|
// Only used for tests
|
|
|
|
|
bool m_forceFailScriptInstallation = false;
|
2022-05-05 15:08:25 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace Utils
|