source: ogBrowser-Git/qtermwidget/lib/kptyprocess.h @ c0cec9d

jenkinsmain
Last change on this file since c0cec9d was fedf2a2, checked in by Vadim Troshchinskiy Shmelev <vtroshchinskiy@…>, 18 months ago

Update Qtermwidget to Qt6 version
Remove build files

  • Property mode set to 100644
File size: 4.5 KB
Line 
1/*
2 * This file is a part of QTerminal - http://gitorious.org/qterminal
3 *
4 * This file was un-linked from KDE and modified
5 * by Maxim Bourmistrov <maxim@unixconn.com>
6 *
7 */
8
9/*
10    This file is part of the KDE libraries
11
12    Copyright (C) 2007 Oswald Buddenhagen <ossi@kde.org>
13
14    This library is free software; you can redistribute it and/or
15    modify it under the terms of the GNU Library General Public
16    License as published by the Free Software Foundation; either
17    version 2 of the License, or (at your option) any later version.
18
19    This library is distributed in the hope that it will be useful,
20    but WITHOUT ANY WARRANTY; without even the implied warranty of
21    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
22    Library General Public License for more details.
23
24    You should have received a copy of the GNU Library General Public License
25    along with this library; see the file COPYING.LIB.  If not, write to
26    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
27    Boston, MA 02110-1301, USA.
28*/
29
30#ifndef KPTYPROCESS_H
31#define KPTYPROCESS_H
32
33#include "kprocess.h"
34#include "kptydevice.h"
35
36#include <csignal>
37#include <memory>
38
39class KPtyDevice;
40
41class KPtyProcessPrivate;
42
43/**
44 * This class extends KProcess by support for PTYs (pseudo TTYs).
45 *
46 * The PTY is opened as soon as the class is instantiated. Verify that
47 * it was opened successfully by checking that pty()->masterFd() is not -1.
48 *
49 * The PTY is always made the process' controlling TTY.
50 * Utmp registration and connecting the stdio handles to the PTY are optional.
51 *
52 * No attempt to integrate with QProcess' waitFor*() functions was made,
53 * for it is impossible. Note that execute() does not work with the PTY, too.
54 * Use the PTY device's waitFor*() functions or use it asynchronously.
55 *
56 * @author Oswald Buddenhagen <ossi@kde.org>
57 */
58class KPtyProcess : public KProcess
59{
60    Q_OBJECT
61    Q_DECLARE_PRIVATE(KPtyProcess)
62
63public:
64    enum PtyChannelFlag {
65        NoChannels = 0, /**< The PTY is not connected to any channel. */
66        StdinChannel = 1, /**< Connect PTY to stdin. */
67        StdoutChannel = 2, /**< Connect PTY to stdout. */
68        StderrChannel = 4, /**< Connect PTY to stderr. */
69        AllOutputChannels = 6, /**< Connect PTY to all output channels. */
70        AllChannels = 7 /**< Connect PTY to all channels. */
71    };
72
73    Q_DECLARE_FLAGS(PtyChannels, PtyChannelFlag)
74
75    /**
76     * Constructor
77     */
78    explicit KPtyProcess(QObject *parent = nullptr);
79
80    /**
81     * Construct a process using an open pty master.
82     *
83     * @param ptyMasterFd an open pty master file descriptor.
84     *   The process does not take ownership of the descriptor;
85     *   it will not be automatically closed at any point.
86     */
87    KPtyProcess(int ptyMasterFd, QObject *parent = nullptr);
88
89    /**
90     * Destructor
91     */
92    ~KPtyProcess() override;
93
94    /**
95     * Set to which channels the PTY should be assigned.
96     *
97     * This function must be called before starting the process.
98     *
99     * @param channels the output channel handling mode
100     */
101    void setPtyChannels(PtyChannels channels);
102
103    bool isRunning() const
104    {
105        bool rval;
106        (processId() > 0) ? rval= true : rval= false;
107        return rval;
108
109    }
110    /**
111     * Query to which channels the PTY is assigned.
112     *
113     * @return the output channel handling mode
114     */
115    PtyChannels ptyChannels() const;
116
117    /**
118     * Set whether to register the process as a TTY login in utmp.
119     *
120     * Utmp is disabled by default.
121     * It should enabled for interactively fed processes, like terminal
122     * emulations.
123     *
124     * This function must be called before starting the process.
125     *
126     * @param value whether to register in utmp.
127     */
128    void setUseUtmp(bool value);
129
130    /**
131     * Get whether to register the process as a TTY login in utmp.
132     *
133     * @return whether to register in utmp
134     */
135    bool isUseUtmp() const;
136
137    /**
138     * Get the PTY device of this process.
139     *
140     * @return the PTY device
141     */
142    KPtyDevice *pty() const;
143
144protected:
145    /**
146     * @reimp
147     */
148#if QT_VERSION < 0x060000
149    void setupChildProcess() override;
150#endif
151private:
152    std::unique_ptr<KPtyProcessPrivate> const d_ptr;
153};
154
155
156//////////////////
157// private data //
158//////////////////
159
160class KPtyProcessPrivate {
161public:
162    KPtyProcessPrivate()
163    {
164    }
165
166    std::unique_ptr<KPtyDevice> pty;
167    KPtyProcess::PtyChannels ptyChannels = KPtyProcess::NoChannels;
168    bool addUtmp = false;
169};
170
171Q_DECLARE_OPERATORS_FOR_FLAGS(KPtyProcess::PtyChannels)
172
173#endif
Note: See TracBrowser for help on using the repository browser.