process.h
00001 /* vi: ts=8 sts=4 sw=4 00002 * 00003 * $Id$ 00004 * 00005 * This file is part of the KDE project, module kdesu. 00006 * Copyright (C) 1999,2000 Geert Jansen <jansen@kde.org> 00007 * 00008 * This is free software; you can use this library under the GNU Library 00009 * General Public License, version 2. See the file "COPYING.LIB" for the 00010 * exact licensing terms. 00011 */ 00012 00013 #ifndef __Process_h_Included__ 00014 #define __Process_h_Included__ 00015 00016 #include <sys/types.h> 00017 00018 #include <tqcstring.h> 00019 #include <tqstring.h> 00020 #include <tqstringlist.h> 00021 #include <tqvaluelist.h> 00022 00023 #include <kdelibs_export.h> 00024 00025 class PTY; 00026 typedef TQValueList<TQCString> QCStringList; 00027 00036 class KDESU_EXPORT PtyProcess 00037 { 00038 public: 00039 PtyProcess(); 00040 virtual ~PtyProcess(); 00041 00049 int exec(const TQCString &command, const QCStringList &args); 00050 00057 TQCString readLine(bool block=true); 00063 TQCString readAll(bool block=true); 00064 00070 void writeLine(const TQCString &line, bool addNewline=true); 00071 00077 void unreadLine(const TQCString &line, bool addNewline=true); 00078 00083 void setExitString(const TQCString &exit) { m_Exit = exit; } 00084 00088 int waitForChild(); 00089 00095 int WaitSlave(); 00096 00100 int enableLocalEcho(bool enable=true); 00101 00105 void setTerminal(bool terminal) { m_bTerminal = terminal; } 00106 00111 void setErase(bool erase) { m_bErase = erase; } 00112 00116 void setEnvironment( const QCStringList &env ); 00117 00121 int fd() {return m_Fd;} 00122 00126 int pid() {return m_Pid;} 00127 00128 public: /* static */ 00129 /* 00130 ** This is a collection of static functions that can be 00131 ** used for process control inside kdesu. I'd suggest 00132 ** against using this publicly. There are probably 00133 ** nicer Qt based ways to do what you want. 00134 */ 00135 00145 static int waitMS(int fd,int ms); 00146 00147 00153 static bool checkPid(pid_t pid); 00154 00162 enum checkPidStatus { Error=-1, NotExited=-2, Killed=-3 } ; 00163 static int checkPidExited(pid_t pid); 00164 00165 00166 protected: 00167 const QCStringList& environment() const; 00168 00169 bool m_bErase, m_bTerminal; 00170 int m_Pid, m_Fd; 00171 TQCString m_Command, m_Exit; 00172 00173 private: 00174 int init(); 00175 int SetupTTY(int fd); 00176 00177 PTY *m_pPTY; 00178 TQCString m_Inbuf, m_TTY; 00179 00180 protected: 00181 virtual void virtual_hook( int id, void* data ); 00182 private: 00183 class PtyProcessPrivate; 00184 PtyProcessPrivate *d; 00185 }; 00186 00187 00188 #endif