00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef QPROCESS_H
00022 #define QPROCESS_H
00023
00024 #include <qtopia/global.h>
00025
00026 #ifndef QT_H
00027 #include "qobject.h"
00028 #include "qstringlist.h"
00029 #include "qdir.h"
00030 #endif // QT_H
00031
00032 #ifndef QT_NO_PROCESS
00033
00034 class QProcessPrivate;
00035
00036
00037 class Q_EXPORT QProcess : public QObject
00038 {
00039 Q_OBJECT
00040 public:
00041 QProcess( QObject *parent=0, const char *name=0 );
00042 QProcess( const QString& arg0, QObject *parent=0, const char *name=0 );
00043 QProcess( const QStringList& args, QObject *parent=0, const char *name=0 );
00044 ~QProcess();
00045
00046
00047 QStringList arguments() const;
00048 void clearArguments();
00049 virtual void setArguments( const QStringList& args );
00050 virtual void addArgument( const QString& arg );
00051 #ifndef QT_NO_DIR
00052 QDir workingDirectory() const;
00053 virtual void setWorkingDirectory( const QDir& dir );
00054 #endif
00055
00056
00057 int priority() const;
00058 void setPriority(int);
00059
00060
00061 enum Communication { Stdin=0x01, Stdout=0x02, Stderr=0x04, DupStderr=0x08 };
00062 void setCommunication( int c );
00063 int communication() const;
00064
00065
00066 virtual bool start( QStringList *env=0 );
00067 virtual bool launch( const QString& buf, QStringList *env=0 );
00068 virtual bool launch( const QByteArray& buf, QStringList *env=0 );
00069
00070
00071 bool isRunning() const;
00072 bool normalExit() const;
00073 int exitStatus() const;
00074
00075
00076 virtual QByteArray readStdout();
00077 virtual QByteArray readStderr();
00078 bool canReadLineStdout() const;
00079 bool canReadLineStderr() const;
00080 virtual QString readLineStdout();
00081 virtual QString readLineStderr();
00082
00083
00084 #if defined(Q_OS_WIN32)
00085 typedef void* PID;
00086 #else
00087 typedef long Q_LONG;
00088 typedef Q_LONG PID;
00089 #endif
00090 PID processIdentifier();
00091
00092 void flushStdin();
00093
00094 signals:
00095 void readyReadStdout();
00096 void readyReadStderr();
00097 void processExited();
00098 void wroteToStdin();
00099 void launchFinished();
00100
00101 public slots:
00102
00103 void tryTerminate() const;
00104 void kill() const;
00105
00106
00107 virtual void writeToStdin( const QByteArray& buf );
00108 virtual void writeToStdin( const QString& buf );
00109 virtual void closeStdin();
00110
00111 protected:
00112 void connectNotify( const char * signal );
00113 void disconnectNotify( const char * signal );
00114 private:
00115 void setIoRedirection( bool value );
00116 void setNotifyOnExit( bool value );
00117 void setWroteStdinConnected( bool value );
00118
00119 void init();
00120 void reset();
00121 #if defined(Q_OS_WIN32)
00122 uint readStddev( HANDLE dev, char *buf, uint bytes );
00123 #endif
00124 bool scanNewline( bool stdOut, QByteArray *store );
00125
00126 QByteArray* bufStdout();
00127 QByteArray* bufStderr();
00128 void consumeBufStdout( int consume );
00129 void consumeBufStderr( int consume );
00130
00131 private slots:
00132 void socketRead( int fd );
00133 void socketWrite( int fd );
00134 void timeout();
00135 void closeStdinLaunch();
00136
00137 private:
00138 QProcessPrivate *d;
00139 #ifndef QT_NO_DIR
00140 QDir workingDir;
00141 #endif
00142 QStringList _arguments;
00143
00144 int exitStat;
00145 bool exitNormal;
00146 bool ioRedirection;
00147 bool notifyOnExit;
00148 bool wroteToStdinConnected;
00149
00150 bool readStdoutCalled;
00151 bool readStderrCalled;
00152 int comms;
00153
00154 friend class QProcessPrivate;
00155 #if defined(Q_OS_UNIX) || defined(_OS_UNIX) || defined(UNIX)
00156 friend class QProcessManager;
00157 friend class QProc;
00158 #endif
00159 };
00160
00161 #endif // QT_NO_PROCESS
00162
00163 #endif // QPROCESS_H