GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
kpty.h
Go to the documentation of this file.
1 /* This file is part of the KDE libraries
2 
3  Copyright (C) 2003, 2007, 2013 Oswald Buddenhagen <ossi@kde.org>
4 
5  Rewritten for QT4 by e_k <e_k at users.sourceforge.net>, Copyright (C)2008
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public License
18  along with this library; see the file COPYING.LIB. If not, write to
19  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  Boston, MA 02110-1301, USA.
21 */
22 
23 #ifndef kpty_h
24 #define kpty_h
25 
26 #include <QtCore>
27 
28 struct KPtyPrivate;
29 struct termios;
30 
31 /**
32  * Provides primitives for opening & closing a pseudo TTY pair, assigning the
33  * controlling TTY, utmp registration and setting various terminal attributes.
34  */
35 class KPty {
36  Q_DECLARE_PRIVATE(KPty)
37 
38 public:
39 
40  /**
41  * Constructor
42  */
43  KPty();
44  KPty(int masterFd, int slaveFd);
45 
46  /**
47  * Destructor:
48  *
49  * If the pty is still open, it will be closed. Note, however, that
50  * an utmp registration is @em not undone.
51  */
52  ~KPty();
53 
54  /**
55  * Create a pty master/slave pair.
56  *
57  * @return true if a pty pair was successfully opened
58  */
59  bool open();
60 
61  /**
62  * Close the pty master/slave pair.
63  */
64  void close();
65 
66  /**
67  * Close the pty slave descriptor.
68  *
69  * When creating the pty, KPty also opens the slave and keeps it open.
70  * Consequently the master will never receive an EOF notification.
71  * Usually this is the desired behavior, as a closed pty slave can be
72  * reopened any time - unlike a pipe or socket. However, in some cases
73  * pipe-alike behavior might be desired.
74  *
75  * After this function was called, slaveFd() and setCTty() cannot be
76  * used.
77  */
78  void closeSlave();
79 
80  /**
81  * Wrapper around tcgetattr(3).
82  *
83  * This function can be used only while the PTY is open.
84  * You will need an #include &lt;termios.h&gt; to do anything useful
85  * with it.
86  *
87  * @param ttmode a pointer to a termios structure.
88  * Note: when declaring ttmode, @c struct @c ::termios must be used -
89  * without the '::' some version of HP-UX thinks, this declares
90  * the struct in your class, in your method.
91  * @return @c true on success, false otherwise
92  */
93  bool tcGetAttr(struct ::termios *ttmode) const;
94 
95  /**
96  * Wrapper around tcsetattr(3) with mode TCSANOW.
97  *
98  * This function can be used only while the PTY is open.
99  *
100  * @param ttmode a pointer to a termios structure.
101  * @return @c true on success, false otherwise. Note that success means
102  * that @em at @em least @em one attribute could be set.
103  */
104  bool tcSetAttr(struct ::termios *ttmode);
105 
106  /**
107  * Change the logical (screen) size of the pty.
108  * The default is 24 lines by 80 columns.
109  *
110  * This function can be used only while the PTY is open.
111  *
112  * @param lines the number of rows
113  * @param columns the number of columns
114  * @return @c true on success, false otherwise
115  */
116  bool setWinSize(int lines, int columns);
117 
118  /**
119  * Set whether the pty should echo input.
120  *
121  * Echo is on by default.
122  * If the output of automatically fed (non-interactive) PTY clients
123  * needs to be parsed, disabling echo often makes it much simpler.
124  *
125  * This function can be used only while the PTY is open.
126  *
127  * @param echo true if input should be echoed.
128  * @return @c true on success, false otherwise
129  */
130  bool setEcho(bool echo);
131 
132  /**
133  * @return the name of the slave pty device.
134  *
135  * This function should be called only while the pty is open.
136  */
137  const char *ttyName() const;
138 
139  /**
140  * @return the file descriptor of the master pty
141  *
142  * This function should be called only while the pty is open.
143  */
144  int masterFd() const;
145 
146  /**
147  * @return the file descriptor of the slave pty
148  *
149  * This function should be called only while the pty slave is open.
150  */
151  int slaveFd() const;
152 
153 protected:
154  /**
155  * @internal
156  */
157  KPty(KPtyPrivate *d);
158 
159  /**
160  * @internal
161  */
163 };
164 
165 #endif
166 
int masterFd() const
Definition: kpty.cpp:479
const char * ttyName() const
Definition: kpty.cpp:472
bool tcGetAttr(struct::termios *ttmode) const
Wrapper around tcgetattr(3).
Definition: kpty.cpp:435
void closeSlave()
Close the pty slave descriptor.
Definition: kpty.cpp:393
bool open()
Create a pty master/slave pair.
Definition: kpty.cpp:212
~KPty()
Destructor:
Definition: kpty.cpp:206
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
int slaveFd() const
Definition: kpty.cpp:486
bool setWinSize(int lines, int columns)
Change the logical (screen) size of the pty.
Definition: kpty.cpp:449
KPty()
Constructor.
Definition: kpty.cpp:190
void close()
Close the pty master/slave pair.
Definition: kpty.cpp:403
bool tcSetAttr(struct::termios *ttmode)
Wrapper around tcsetattr(3) with mode TCSANOW.
Definition: kpty.cpp:442
KPtyPrivate *const d_ptr
Definition: kpty.h:162
bool setEcho(bool echo)
Set whether the pty should echo input.
Definition: kpty.cpp:460
Provides primitives for opening & closing a pseudo TTY pair, assigning the controlling TTY...
Definition: kpty.h:35