File indexing completed on 2024-04-28 05:50:46
0001 /* 0002 SPDX-FileCopyrightText: 2019 Vitaly Petrov <v31337@gmail.com> 0003 SPDX-License-Identifier: MIT 0004 */ 0005 #ifndef IPTYPROCESS_H 0006 #define IPTYPROCESS_H 0007 0008 #include <QDebug> 0009 #include <QIODevice> 0010 #include <QObject> 0011 #include <QString> 0012 #include <QStringList> 0013 #include <QTimer> 0014 0015 #define CONPTY_MINIMAL_WINDOWS_VERSION 18309 0016 0017 class IPtyProcess : public QObject 0018 { 0019 Q_OBJECT 0020 public: 0021 enum PtyType { UnixPty = 0, WinPty = 1, ConPty = 2, AutoPty = 3 }; 0022 0023 IPtyProcess() 0024 : m_pid(0) 0025 , m_trace(false) 0026 { 0027 } 0028 virtual ~IPtyProcess(); 0029 0030 virtual bool startProcess(const QString &shellPath, 0031 const QStringList &arguments, 0032 const QString &workingDirectory, 0033 QStringList environment, 0034 qint16 cols, 0035 qint16 rows) = 0; 0036 virtual bool resize(qint16 cols, qint16 rows) = 0; 0037 virtual bool kill() = 0; 0038 virtual PtyType type() = 0; 0039 virtual QString dumpDebugInfo() = 0; 0040 virtual QIODevice *notifier() = 0; 0041 virtual QByteArray readAll() = 0; 0042 virtual qint64 write(const char *data, int size) = 0; 0043 virtual bool isAvailable() = 0; 0044 virtual void moveToThread(QThread *targetThread) = 0; 0045 virtual int processList() const = 0; // 0 - unsupported, 1 - no process , 2 - run process 0046 qint64 pid() 0047 { 0048 return m_pid; 0049 } 0050 QPair<qint16, qint16> size() 0051 { 0052 return m_size; 0053 } 0054 const QString lastError() 0055 { 0056 return m_lastError; 0057 } 0058 bool toggleTrace() 0059 { 0060 m_trace = !m_trace; 0061 return m_trace; 0062 } 0063 int exitCode() const 0064 { 0065 return m_exitCode; 0066 } 0067 Q_SIGNALS: 0068 void started(); 0069 void exited(); 0070 0071 protected: 0072 QString m_shellPath; 0073 QString m_lastError; 0074 qint64 m_pid; 0075 QPair<qint16, qint16> m_size; // cols / rows 0076 bool m_trace; 0077 int m_exitCode = -1; 0078 }; 0079 0080 #endif // IPTYPROCESS_H