mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 10:22:48 +00:00
kpty: format and indent
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
8bce018375
commit
25bc102ae0
6 changed files with 156 additions and 157 deletions
|
@ -446,7 +446,7 @@ bool KPty::setEcho(bool echo)
|
||||||
const char *KPty::ttyName() const
|
const char *KPty::ttyName() const
|
||||||
{
|
{
|
||||||
Q_D(const KPty);
|
Q_D(const KPty);
|
||||||
return d->ttyName.data();
|
return d->ttyName.constData();
|
||||||
}
|
}
|
||||||
|
|
||||||
int KPty::masterFd() const
|
int KPty::masterFd() const
|
||||||
|
|
295
kpty/kpty.h
295
kpty/kpty.h
|
@ -32,175 +32,174 @@ struct termios;
|
||||||
* Provides primitives for opening & closing a pseudo TTY pair, assigning the
|
* Provides primitives for opening & closing a pseudo TTY pair, assigning the
|
||||||
* controlling TTY, utmp registration and setting various terminal attributes.
|
* controlling TTY, utmp registration and setting various terminal attributes.
|
||||||
*/
|
*/
|
||||||
class KPTY_EXPORT KPty {
|
class KPTY_EXPORT KPty
|
||||||
|
{
|
||||||
Q_DECLARE_PRIVATE(KPty)
|
Q_DECLARE_PRIVATE(KPty)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*/
|
||||||
|
KPty();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Destructor:
|
||||||
*/
|
*
|
||||||
KPty();
|
* If the pty is still open, it will be closed. Note, however, that
|
||||||
|
* an utmp registration is @em not undone.
|
||||||
|
*/
|
||||||
|
~KPty();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destructor:
|
* Create a pty master/slave pair.
|
||||||
*
|
*
|
||||||
* If the pty is still open, it will be closed. Note, however, that
|
* @return true if a pty pair was successfully opened
|
||||||
* an utmp registration is @em not undone.
|
*/
|
||||||
*/
|
bool open();
|
||||||
~KPty();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a pty master/slave pair.
|
* Open using an existing pty master.
|
||||||
*
|
*
|
||||||
* @return true if a pty pair was successfully opened
|
* @param fd an open pty master file descriptor.
|
||||||
*/
|
* The ownership of the fd remains with the caller;
|
||||||
bool open();
|
* it will not be automatically closed at any point.
|
||||||
|
* @return true if a pty pair was successfully opened
|
||||||
|
*/
|
||||||
|
bool open(int fd);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open using an existing pty master.
|
* Close the pty master/slave pair.
|
||||||
*
|
*/
|
||||||
* @param fd an open pty master file descriptor.
|
void close();
|
||||||
* The ownership of the fd remains with the caller;
|
|
||||||
* it will not be automatically closed at any point.
|
|
||||||
* @return true if a pty pair was successfully opened
|
|
||||||
*/
|
|
||||||
bool open(int fd);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Close the pty master/slave pair.
|
* Close the pty slave descriptor.
|
||||||
*/
|
*
|
||||||
void close();
|
* When creating the pty, KPty also opens the slave and keeps it open.
|
||||||
|
* Consequently the master will never receive an EOF notification.
|
||||||
|
* Usually this is the desired behavior, as a closed pty slave can be
|
||||||
|
* reopened any time - unlike a pipe or socket. However, in some cases
|
||||||
|
* pipe-alike behavior might be desired.
|
||||||
|
*
|
||||||
|
* After this function was called, slaveFd() and setCTty() cannot be
|
||||||
|
* used.
|
||||||
|
*/
|
||||||
|
void closeSlave();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Close the pty slave descriptor.
|
* Open the pty slave descriptor.
|
||||||
*
|
*
|
||||||
* When creating the pty, KPty also opens the slave and keeps it open.
|
* This undoes the effect of closeSlave().
|
||||||
* Consequently the master will never receive an EOF notification.
|
*
|
||||||
* Usually this is the desired behavior, as a closed pty slave can be
|
* @return true if the pty slave was successfully opened
|
||||||
* reopened any time - unlike a pipe or socket. However, in some cases
|
*/
|
||||||
* pipe-alike behavior might be desired.
|
bool openSlave();
|
||||||
*
|
|
||||||
* After this function was called, slaveFd() and setCTty() cannot be
|
|
||||||
* used.
|
|
||||||
*/
|
|
||||||
void closeSlave();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open the pty slave descriptor.
|
* Creates a new session and process group and makes this pty the
|
||||||
*
|
* controlling tty.
|
||||||
* This undoes the effect of closeSlave().
|
*/
|
||||||
*
|
void setCTty();
|
||||||
* @return true if the pty slave was successfully opened
|
|
||||||
*/
|
|
||||||
bool openSlave();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new session and process group and makes this pty the
|
* Creates an utmp entry for the tty.
|
||||||
* controlling tty.
|
* This function must be called after calling setCTty and
|
||||||
*/
|
* making this pty the stdin.
|
||||||
void setCTty();
|
* @param user the user to be logged on
|
||||||
|
* @param remotehost the host from which the login is coming. This is
|
||||||
|
* @em not the local host. For remote logins it should be the hostname
|
||||||
|
* of the client. For local logins from inside an X session it should
|
||||||
|
* be the name of the X display. Otherwise it should be empty.
|
||||||
|
*/
|
||||||
|
void login(const char *user = 0, const char *remotehost = 0);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an utmp entry for the tty.
|
* Removes the utmp entry for this tty.
|
||||||
* This function must be called after calling setCTty and
|
*/
|
||||||
* making this pty the stdin.
|
void logout();
|
||||||
* @param user the user to be logged on
|
|
||||||
* @param remotehost the host from which the login is coming. This is
|
|
||||||
* @em not the local host. For remote logins it should be the hostname
|
|
||||||
* of the client. For local logins from inside an X session it should
|
|
||||||
* be the name of the X display. Otherwise it should be empty.
|
|
||||||
*/
|
|
||||||
void login(const char *user = 0, const char *remotehost = 0);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the utmp entry for this tty.
|
* Wrapper around tcgetattr(3).
|
||||||
*/
|
*
|
||||||
void logout();
|
* This function can be used only while the PTY is open.
|
||||||
|
* You will need an #include <termios.h> to do anything useful
|
||||||
|
* with it.
|
||||||
|
*
|
||||||
|
* @param ttmode a pointer to a termios structure.
|
||||||
|
* Note: when declaring ttmode, @c struct @c ::termios must be used -
|
||||||
|
* without the '::' some version of HP-UX thinks, this declares
|
||||||
|
* the struct in your class, in your method.
|
||||||
|
* @return @c true on success, false otherwise
|
||||||
|
*/
|
||||||
|
bool tcGetAttr(struct ::termios *ttmode) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper around tcgetattr(3).
|
* Wrapper around tcsetattr(3) with mode TCSANOW.
|
||||||
*
|
*
|
||||||
* This function can be used only while the PTY is open.
|
* This function can be used only while the PTY is open.
|
||||||
* You will need an #include <termios.h> to do anything useful
|
*
|
||||||
* with it.
|
* @param ttmode a pointer to a termios structure.
|
||||||
*
|
* @return @c true on success, false otherwise. Note that success means
|
||||||
* @param ttmode a pointer to a termios structure.
|
* that @em at @em least @em one attribute could be set.
|
||||||
* Note: when declaring ttmode, @c struct @c ::termios must be used -
|
*/
|
||||||
* without the '::' some version of HP-UX thinks, this declares
|
bool tcSetAttr(struct ::termios *ttmode);
|
||||||
* the struct in your class, in your method.
|
|
||||||
* @return @c true on success, false otherwise
|
|
||||||
*/
|
|
||||||
bool tcGetAttr(struct ::termios *ttmode) const;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper around tcsetattr(3) with mode TCSANOW.
|
* Change the logical (screen) size of the pty.
|
||||||
*
|
* The default is 24 lines by 80 columns.
|
||||||
* This function can be used only while the PTY is open.
|
*
|
||||||
*
|
* This function can be used only while the PTY is open.
|
||||||
* @param ttmode a pointer to a termios structure.
|
*
|
||||||
* @return @c true on success, false otherwise. Note that success means
|
* @param lines the number of rows
|
||||||
* that @em at @em least @em one attribute could be set.
|
* @param columns the number of columns
|
||||||
*/
|
* @return @c true on success, false otherwise
|
||||||
bool tcSetAttr(struct ::termios *ttmode);
|
*/
|
||||||
|
bool setWinSize(int lines, int columns);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Change the logical (screen) size of the pty.
|
* Set whether the pty should echo input.
|
||||||
* The default is 24 lines by 80 columns.
|
*
|
||||||
*
|
* Echo is on by default.
|
||||||
* This function can be used only while the PTY is open.
|
* If the output of automatically fed (non-interactive) PTY clients
|
||||||
*
|
* needs to be parsed, disabling echo often makes it much simpler.
|
||||||
* @param lines the number of rows
|
*
|
||||||
* @param columns the number of columns
|
* This function can be used only while the PTY is open.
|
||||||
* @return @c true on success, false otherwise
|
*
|
||||||
*/
|
* @param echo true if input should be echoed.
|
||||||
bool setWinSize(int lines, int columns);
|
* @return @c true on success, false otherwise
|
||||||
|
*/
|
||||||
|
bool setEcho(bool echo);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set whether the pty should echo input.
|
* @return the name of the slave pty device.
|
||||||
*
|
*
|
||||||
* Echo is on by default.
|
* This function should be called only while the pty is open.
|
||||||
* If the output of automatically fed (non-interactive) PTY clients
|
*/
|
||||||
* needs to be parsed, disabling echo often makes it much simpler.
|
const char *ttyName() const;
|
||||||
*
|
|
||||||
* This function can be used only while the PTY is open.
|
|
||||||
*
|
|
||||||
* @param echo true if input should be echoed.
|
|
||||||
* @return @c true on success, false otherwise
|
|
||||||
*/
|
|
||||||
bool setEcho(bool echo);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the name of the slave pty device.
|
* @return the file descriptor of the master pty
|
||||||
*
|
*
|
||||||
* This function should be called only while the pty is open.
|
* This function should be called only while the pty is open.
|
||||||
*/
|
*/
|
||||||
const char *ttyName() const;
|
int masterFd() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the file descriptor of the master pty
|
* @return the file descriptor of the slave pty
|
||||||
*
|
*
|
||||||
* This function should be called only while the pty is open.
|
* This function should be called only while the pty slave is open.
|
||||||
*/
|
*/
|
||||||
int masterFd() const;
|
int slaveFd() const;
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the file descriptor of the slave pty
|
|
||||||
*
|
|
||||||
* This function should be called only while the pty slave is open.
|
|
||||||
*/
|
|
||||||
int slaveFd() const;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
KPty(KPtyPrivate *d);
|
KPty(KPtyPrivate *d);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
KPtyPrivate * const d_ptr;
|
KPtyPrivate * const d_ptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -35,7 +35,8 @@ class KPtyDevicePrivate;
|
||||||
/**
|
/**
|
||||||
* Encapsulates KPty into a QIODevice, so it can be used with Q*Stream, etc.
|
* Encapsulates KPty into a QIODevice, so it can be used with Q*Stream, etc.
|
||||||
*/
|
*/
|
||||||
class KPTY_EXPORT KPtyDevice : public QIODevice, public KPty { //krazy:exclude=dpointer (via macro)
|
class KPTY_EXPORT KPtyDevice : public QIODevice, public KPty
|
||||||
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_DECLARE_PRIVATE_MI(KPtyDevice, KPty)
|
Q_DECLARE_PRIVATE_MI(KPtyDevice, KPty)
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,8 @@ class KPtyProcessPrivate : public KProcessPrivate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
KPtyProcessPrivate()
|
KPtyProcessPrivate()
|
||||||
: ptyChannels(KPtyProcess::NoChannels),
|
: pty(nullptr),
|
||||||
|
ptyChannels(KPtyProcess::NoChannels),
|
||||||
addUtmp(false)
|
addUtmp(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,6 @@ class KPTY_EXPORT KPtyProcess : public KProcess
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_DECLARE_PRIVATE(KPtyProcess)
|
Q_DECLARE_PRIVATE(KPtyProcess)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum PtyChannelFlag {
|
enum PtyChannelFlag {
|
||||||
NoChannels = 0, /**< The PTY is not connected to any channel. */
|
NoChannels = 0, /**< The PTY is not connected to any channel. */
|
||||||
|
@ -58,7 +57,6 @@ public:
|
||||||
AllOutputChannels = 6, /**< Connect PTY to all output channels. */
|
AllOutputChannels = 6, /**< Connect PTY to all output channels. */
|
||||||
AllChannels = 7 /**< Connect PTY to all channels. */
|
AllChannels = 7 /**< Connect PTY to all channels. */
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_FLAGS(PtyChannels, PtyChannelFlag)
|
Q_DECLARE_FLAGS(PtyChannels, PtyChannelFlag)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -93,7 +93,7 @@ void KPtyProcessTest::test_shared_pty()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// This test (or KPtyProcess) is fragile, sometimes the \r\n is missing. Disabled.
|
// This test (or KPtyProcess) is fragile, sometimes the \r\n is missing. Disabled.
|
||||||
//QCOMPARE(p.pty()->readAll(), QByteArray("hello from process 2\r\n"));
|
// QCOMPARE(p.pty()->readAll(), QByteArray("hello from process 2\r\n"));
|
||||||
|
|
||||||
// write to the first process' pty
|
// write to the first process' pty
|
||||||
p.pty()->write("hi from process 1\n");
|
p.pty()->write("hi from process 1\n");
|
||||||
|
@ -138,8 +138,9 @@ void KPtyProcessTest::slotReadyRead()
|
||||||
|
|
||||||
void KPtyProcessTest::slotDoRead()
|
void KPtyProcessTest::slotDoRead()
|
||||||
{
|
{
|
||||||
while (sp.pty()->canReadLine())
|
while (sp.pty()->canReadLine()) {
|
||||||
log.append('>').append(sp.pty()->readLine()).append("$\n");
|
log.append('>').append(sp.pty()->readLine()).append("$\n");
|
||||||
|
}
|
||||||
log.append("!\n");
|
log.append("!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,7 +197,6 @@ void KPtyProcessTest::test_pty_signals()
|
||||||
QCOMPARE(QLatin1String(log), QLatin1String(want));
|
QCOMPARE(QLatin1String(log), QLatin1String(want));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void KPtyProcessTest::test_ctty()
|
void KPtyProcessTest::test_ctty()
|
||||||
{
|
{
|
||||||
KPtyProcess p;
|
KPtyProcess p;
|
||||||
|
@ -207,6 +207,6 @@ void KPtyProcessTest::test_ctty()
|
||||||
QCOMPARE(output, QLatin1String("this is a test\r\n"));
|
QCOMPARE(output, QLatin1String("this is a test\r\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
QTEST_KDEMAIN_CORE( KPtyProcessTest )
|
QTEST_KDEMAIN_CORE(KPtyProcessTest)
|
||||||
|
|
||||||
#include "moc_kptyprocesstest.cpp"
|
#include "moc_kptyprocesstest.cpp"
|
||||||
|
|
Loading…
Add table
Reference in a new issue