1
/* This file is part of the KDE libraries
3
Copyright (C) 2003,2007 Oswald Buddenhagen <ossi@kde.org>
5
Rewritten for QT4 by e_k <e_k at users.sourceforge.net>, Copyright (C)2008
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.
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.
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.
32
* Provides primitives for opening & closing a pseudo TTY pair, assigning the
33
* controlling TTY, utmp registration and setting various terminal attributes.
37
Q_DECLARE_PRIVATE( KPty )
49
* If the pty is still open, it will be closed. Note, however, that
50
* an utmp registration is @em not undone.
55
* Create a pty master/slave pair.
57
* @return true if a pty pair was successfully opened
62
* Close the pty master/slave pair.
67
* Close the pty slave descriptor.
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.
75
* After this function was called, slaveFd() and setCTty() cannot be
81
* Creates a new session and process group and makes this pty the
88
* Creates an utmp entry for the tty.
89
* This function must be called after calling setCTty and
90
* making this pty the stdin.
91
* @param user the user to be logged on
92
* @param remotehost the host from which the login is coming. This is
93
* @em not the local host. For remote logins it should be the hostname
94
* of the client. For local logins from inside an X session it should
95
* be the name of the X display. Otherwise it should be empty.
97
void login( const char *user = 0, const char *remotehost = 0 );
100
* Removes the utmp entry for this tty.
106
* Wrapper around tcgetattr(3).
108
* This function can be used only while the PTY is open.
109
* You will need an #include <termios.h> to do anything useful
112
* @param ttmode a pointer to a termios structure.
113
* Note: when declaring ttmode, @c struct @c ::termios must be used -
114
* without the '::' some version of HP-UX thinks, this declares
115
* the struct in your class, in your method.
116
* @return @c true on success, false otherwise
118
bool tcGetAttr( struct ::termios *ttmode ) const;
121
* Wrapper around tcsetattr(3) with mode TCSANOW.
123
* This function can be used only while the PTY is open.
125
* @param ttmode a pointer to a termios structure.
126
* @return @c true on success, false otherwise. Note that success means
127
* that @em at @em least @em one attribute could be set.
129
bool tcSetAttr( struct ::termios *ttmode );
132
* Change the logical (screen) size of the pty.
133
* The default is 24 lines by 80 columns.
135
* This function can be used only while the PTY is open.
137
* @param lines the number of rows
138
* @param columns the number of columns
139
* @return @c true on success, false otherwise
141
bool setWinSize( int lines, int columns );
144
* Set whether the pty should echo input.
146
* Echo is on by default.
147
* If the output of automatically fed (non-interactive) PTY clients
148
* needs to be parsed, disabling echo often makes it much simpler.
150
* This function can be used only while the PTY is open.
152
* @param echo true if input should be echoed.
153
* @return @c true on success, false otherwise
155
bool setEcho( bool echo );
158
* @return the name of the slave pty device.
160
* This function should be called only while the pty is open.
162
const char *ttyName() const;
165
* @return the file descriptor of the master pty
167
* This function should be called only while the pty is open.
169
int masterFd() const;
172
* @return the file descriptor of the slave pty
174
* This function should be called only while the pty slave is open.
182
KPty( KPtyPrivate *d );
187
KPtyPrivate * const d_ptr;