edelib 2.1.0
PtyProcess.h
1/*
2 * $Id: PtyProcess.h 3362 2012-08-08 14:41:11Z karijes $
3 *
4 * This class enables to "chat" with terminal programs synchronously
5 * Copyright (c) 2006-2009 edelib authors
6 *
7 * This file was a part of the KDE project, module kdesu.
8 * Copyright (C) 1999,2000 Geert Jansen <jansen@kde.org>
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this library. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24#ifndef __EDELIB_PTYPROCESS_H__
25#define __EDELIB_PTYPROCESS_H__
26
27#include "edelib-global.h"
28#include <sys/types.h>
29
30EDELIB_NS_BEGIN
31
32class PTY;
33
42class EDELIB_API PtyProcess {
43private:
44 int init();
45 int setup_tty(int fd);
46
47 PTY *m_pPTY;
48 char *m_Inbuf, *m_TTY;
49
50 class PtyProcessPrivate;
51 PtyProcessPrivate *d;
52
54protected:
55#ifndef SKIP_DOCS
56 char **environment() const;
57
58 bool m_bErase, m_bTerminal;
59 int m_Pid, m_Fd;
60 char *m_Command, *m_Exit;
61#endif
62
63public:
68
72 virtual ~PtyProcess();
73
81 int exec(const char *command, const char **args);
82
89 char *read_line(bool block=true);
90
96 void write_line(const char *line, bool addNewline=true);
97
103 void unread_line(const char *line, bool addNewline=true);
104
109 void set_exit_string(char *exit) { m_Exit = exit; }
110
115
122
126 int enable_local_echo(bool enable=true);
127
131 void set_terminal(bool terminal) { m_bTerminal = terminal; }
132
137 void set_erase(bool erase) { m_bErase = erase; }
138
142 void set_environment( const char **env );
143
147 inline int fd() const { return m_Fd; }
148
152 inline int pid() const { return m_Pid; }
153
158
168 static int wait_ms(int fd,int ms);
169
174 static bool check_pid(pid_t pid);
175
182 enum CheckPidStatus { Error=-1, NotExited=-2, Killed=-3, Crashed=-4 } ;
183
191 static int check_pid_exited(pid_t pid);
192};
193
194EDELIB_NS_END
195#endif
emulate pty api
Definition: Pty.h:38
Synchronous communication with tty programs.
Definition: PtyProcess.h:42
void set_exit_string(char *exit)
Definition: PtyProcess.h:109
virtual ~PtyProcess()
static int wait_ms(int fd, int ms)
void set_terminal(bool terminal)
Definition: PtyProcess.h:131
void set_environment(const char **env)
int pid() const
Definition: PtyProcess.h:152
int exec(const char *command, const char **args)
void unread_line(const char *line, bool addNewline=true)
static bool check_pid(pid_t pid)
CheckPidStatus
Definition: PtyProcess.h:182
char * read_line(bool block=true)
void write_line(const char *line, bool addNewline=true)
void set_erase(bool erase)
Definition: PtyProcess.h:137
int enable_local_echo(bool enable=true)
int fd() const
Definition: PtyProcess.h:147
static int check_pid_exited(pid_t pid)
#define E_DISABLE_CLASS_COPY(klass)
Definition: edelib-global.h:161