00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef __EDELIB_PTYPROCESS_H__
00025 #define __EDELIB_PTYPROCESS_H__
00026
00027 #include "edelib-global.h"
00028 #include <sys/types.h>
00029
00030 EDELIB_NS_BEGIN
00031
00032 class PTY;
00033
00042 class EDELIB_API PtyProcess {
00043 private:
00044 int init();
00045 int setup_tty(int fd);
00046
00047 PTY *m_pPTY;
00048 char *m_Inbuf, *m_TTY;
00049
00050 class PtyProcessPrivate;
00051 PtyProcessPrivate *d;
00052
00053 E_DISABLE_CLASS_COPY(PtyProcess)
00054 protected:
00055 #ifndef SKIP_DOCS
00056 char **environment() const;
00057
00058 bool m_bErase, m_bTerminal;
00059 int m_Pid, m_Fd;
00060 char *m_Command, *m_Exit;
00061 #endif
00062
00063 public:
00067 PtyProcess();
00068
00072 virtual ~PtyProcess();
00073
00081 int exec(const char *command, const char **args);
00082
00089 char *read_line(bool block=true);
00090
00096 void write_line(const char *line, bool addNewline=true);
00097
00103 void unread_line(const char *line, bool addNewline=true);
00104
00109 void set_exit_string(char *exit) { m_Exit = exit; }
00110
00114 int wait_for_child();
00115
00121 int wait_slave();
00122
00126 int enable_local_echo(bool enable=true);
00127
00131 void set_terminal(bool terminal) { m_bTerminal = terminal; }
00132
00137 void set_erase(bool erase) { m_bErase = erase; }
00138
00142 void set_environment( const char **env );
00143
00147 inline int fd() const { return m_Fd; }
00148
00152 inline int pid() const { return m_Pid; }
00153
00157 void terminate_child();
00158
00168 static int wait_ms(int fd,int ms);
00169
00174 static bool check_pid(pid_t pid);
00175
00182 enum CheckPidStatus { Error=-1, NotExited=-2, Killed=-3, Crashed=-4 } ;
00183
00191 static int check_pid_exited(pid_t pid);
00192
00193 };
00194
00195 EDELIB_NS_END
00196 #endif