process.h

00001 /* vi: ts=8 sts=4 sw=4
00002  *
00003  * $Id: process.h 363176 2004-11-15 14:38:23Z mueller $
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 <qcstring.h>
00019 #include <qstring.h>
00020 #include <qstringlist.h>
00021 #include <qvaluelist.h>
00022 
00023 #include <kdelibs_export.h>
00024 
00025 class PTY;
00026 typedef QValueList<QCString> QCStringList;
00027 
00036 class KDESU_EXPORT PtyProcess
00037 {
00038 public:
00039     PtyProcess();
00040     virtual ~PtyProcess();
00041 
00049     int exec(const QCString &command, const QCStringList &args);
00050 
00057     QCString readLine(bool block=true);
00058 
00064     void writeLine(const QCString &line, bool addNewline=true);
00065 
00071     void unreadLine(const QCString &line, bool addNewline=true);
00072 
00077     void setExitString(const QCString &exit) { m_Exit = exit; }
00078 
00082     int waitForChild();
00083 
00089     int WaitSlave();
00090 
00094     int enableLocalEcho(bool enable=true);
00095 
00099     void setTerminal(bool terminal) { m_bTerminal = terminal; }
00100 
00105     void setErase(bool erase) { m_bErase = erase; }
00106 
00110     void setEnvironment( const QCStringList &env );
00111 
00115     int fd() {return m_Fd;};
00116 
00120     int pid() {return m_Pid;};
00121 
00122 public /* static */:
00123     /*
00124     ** This is a collection of static functions that can be
00125     ** used for process control inside kdesu. I'd suggest 
00126     ** against using this publicly. There are probably 
00127     ** nicer Qt based ways to do what you want.
00128     */
00129 
00130     /*
00131     ** Wait @p ms miliseconds (ie. 1/10th of a second is 100ms),
00132     ** using @p fd as a filedescriptor to wait on. Returns
00133     ** select(2)'s result, which is -1 on error, 0 on timeout,
00134     ** or positive if there is data on one of the selected fd's.
00135     **
00136     ** @p ms must be in the range 0..999 (ie. the maximum wait
00137     ** duration is 999ms, almost one second).
00138     */
00139     static int waitMS(int fd,int ms);
00140 
00141 
00142     /*
00143     ** Basic check for the existence of @p pid.
00144     ** Returns true iff @p pid is an extant process,
00145     ** (one you could kill - see man kill(2) for signal 0).
00146     */
00147     static bool checkPid(pid_t pid);
00148 
00149     /*
00150     ** Check process exit status for process @p pid.
00151     ** On error (no child, no exit), return -1.
00152     ** If child @p pid has exited, return its exit status,
00153     ** (which may be zero).
00154     ** If child @p has not exited, return -2.
00155     */
00156     enum checkPidStatus { Error=-1, NotExited=-2, Killed=-3 } ;
00157     static int checkPidExited(pid_t pid);
00158 
00159 
00160 protected:
00161     const QCStringList& environment() const;
00162 
00163     bool m_bErase, m_bTerminal;
00164     int m_Pid, m_Fd;
00165     QCString m_Command, m_Exit;
00166 
00167 private:
00168     int init();
00169     int SetupTTY(int fd);
00170 
00171     PTY *m_pPTY;
00172     QCString m_Inbuf, m_TTY;
00173 
00174 protected:
00175     virtual void virtual_hook( int id, void* data );
00176 private:
00177     class PtyProcessPrivate;
00178     PtyProcessPrivate *d;
00179 };
00180 
00181 
00182 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys