edelib 1.0

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List

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
30 EDELIB_NS_BEGIN
31
32 class PTY;
33
42 class EDELIB_API PtyProcess {
43 private:
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
53 E_DISABLE_CLASS_COPY(PtyProcess)
54 protected:
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
63 public:
67 PtyProcess();
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
114 int wait_for_child();
115
121 int wait_slave();
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
157 void terminate_child();
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
194 EDELIB_NS_END
195 #endif