Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

qprocess.h

Go to the documentation of this file.
00001 /**********************************************************************
00002 ** Copyright (C) 2000-2002 Trolltech AS.  All rights reserved.
00003 **
00004 ** This file is part of the Qtopia Environment.
00005 **
00006 ** This file may be distributed and/or modified under the terms of the
00007 ** GNU General Public License version 2 as published by the Free Software
00008 ** Foundation and appearing in the file LICENSE.GPL included in the
00009 ** packaging of this file.
00010 **
00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 **
00014 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00015 **
00016 ** Contact info@trolltech.com if any conditions of this licensing are
00017 ** not clear to you.
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     // set and get the arguments and working directory
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     // priority
00057     int priority() const;
00058     void setPriority(int);
00059 
00060     // set and get the comms wanted
00061     enum Communication { Stdin=0x01, Stdout=0x02, Stderr=0x04, DupStderr=0x08 };
00062     void setCommunication( int c );
00063     int communication() const;
00064 
00065     // start the execution
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     // inquire the status
00071     bool isRunning() const;
00072     bool normalExit() const;
00073     int exitStatus() const;
00074 
00075     // reading
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     // get platform dependent process information
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     // end the execution
00103     void tryTerminate() const;
00104     void kill() const;
00105 
00106     // input
00107     virtual void writeToStdin( const QByteArray& buf );
00108     virtual void writeToStdin( const QString& buf );
00109     virtual void closeStdin();
00110 
00111 protected: // ### or private?
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; // exit status
00145     bool exitNormal; // normal exit?
00146     bool ioRedirection; // automatically set be (dis)connectNotify
00147     bool notifyOnExit; // automatically set be (dis)connectNotify
00148     bool wroteToStdinConnected; // automatically set be (dis)connectNotify
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

Generated on Sat Nov 5 16:15:31 2005 for OPIE by  doxygen 1.4.2