File indexing completed on 2024-04-28 04:38:36

0001 /*
0002     SPDX-FileCopyrightText: 1999 John Birch <jbb@kdevelop.org>
0003 
0004     This code was copied originally from the KDEStudio project:
0005     SPDX-FileCopyrightText: Judin Maxim
0006 
0007     It was then updated with later code from konsole (KDE).
0008 
0009     It has also been enhanced with an idea from the code in kdbg:
0010     SPDX-FileCopyrightText: Johannes Sixt<Johannes.Sixt@telecom.at>
0011 
0012     SPDX-License-Identifier: GPL-2.0-or-later
0013 */
0014 
0015 #ifndef _STTY_H_
0016 #define _STTY_H_
0017 
0018 class QSocketNotifier;
0019 class QProcess;
0020 
0021 #include <QObject>
0022 #include <QString>
0023 #include <QScopedPointer>
0024 
0025 namespace KDevMI {
0026 
0027 class STTY : public QObject
0028 {
0029     Q_OBJECT
0030 
0031 public:
0032     explicit STTY(bool ext=false, const QString &termAppName=QString());
0033     ~STTY() override;
0034 
0035     ///Call it if getSlave returns an empty string.
0036     QString lastError(){return m_lastError;}
0037     QString getSlave()    { return ttySlave; };
0038     void readRemaining();
0039 
0040 private Q_SLOTS:
0041     void OutReceived(int);
0042 
0043 Q_SIGNALS:
0044     void OutOutput(const QByteArray&);
0045     void ErrOutput(const QByteArray&);
0046 
0047 private:
0048     int findTTY();
0049     bool findExternalTTY(const QString &termApp);
0050 
0051 private:
0052     int fout;
0053     QSocketNotifier *out = nullptr;
0054     QString ttySlave;
0055     QString m_lastError;
0056     QScopedPointer<QProcess> m_externalTerminal;
0057     bool external_;
0058 
0059     char pty_master[50];  // "/dev/ptyxx" | "/dev/ptmx"
0060     char tty_slave[50];   // "/dev/ttyxx" | "/dev/pts/########..."
0061 };
0062 
0063 } // end of namespace KDevMI
0064 
0065 #endif