Qtopia library API Documentation

qprocess.h

00001 /****************************************************************************
00002 ** $Id: qprocess.h,v 1.1.1.1 2002/01/25 22:14:56 kergoth Exp $
00003 **
00004 ** Implementation of QProcess class
00005 **
00006 ** Created : 20000905
00007 **
00008 ** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
00009 **
00010 ** This file is part of the kernel module of the Qt GUI Toolkit.
00011 **
00012 ** This file may be distributed under the terms of the Q Public License
00013 ** as defined by Trolltech AS of Norway and appearing in the file
00014 ** LICENSE.QPL included in the packaging of this file.
00015 **
00016 ** This file may be distributed and/or modified under the terms of the
00017 ** GNU General Public License version 2 as published by the Free Software
00018 ** Foundation and appearing in the file LICENSE.GPL included in the
00019 ** packaging of this file.
00020 **
00021 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
00022 ** licenses may use this file in accordance with the Qt Commercial License
00023 ** Agreement provided with the Software.
00024 **
00025 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00026 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00027 **
00028 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
00029 **   information about Qt Commercial License Agreements.
00030 ** See http://www.trolltech.com/qpl/ for QPL licensing information.
00031 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00032 **
00033 ** Contact info@trolltech.com if any conditions of this licensing are
00034 ** not clear to you.
00035 **
00036 **********************************************************************/
00037 
00038 #ifndef QPROCESS_H
00039 #define QPROCESS_H
00040 
00041 #ifndef QT_H
00042 #include "qobject.h"
00043 #include "qstringlist.h"
00044 #include "qdir.h"
00045 #endif // QT_H
00046 
00047 #ifndef QT_NO_PROCESS
00048 
00049 class QProcessPrivate;
00050 
00051 
00052 class Q_EXPORT QProcess : public QObject
00053 {
00054     Q_OBJECT
00055 public:
00056     QProcess( QObject *parent=0, const char *name=0 );
00057     QProcess( const QString& arg0, QObject *parent=0, const char *name=0 );
00058     QProcess( const QStringList& args, QObject *parent=0, const char *name=0 );
00059     ~QProcess();
00060 
00061     // set and get the arguments and working directory
00062     QStringList arguments() const;
00063     void clearArguments();
00064     virtual void setArguments( const QStringList& args );
00065     virtual void addArgument( const QString& arg );
00066 #ifndef QT_NO_DIR
00067     QDir workingDirectory() const;
00068     virtual void setWorkingDirectory( const QDir& dir );
00069 #endif
00070 
00071     // set and get the comms wanted
00072     enum Communication { Stdin=0x01, Stdout=0x02, Stderr=0x04, DupStderr=0x08 };
00073     void setCommunication( int c );
00074     int communication() const;
00075 
00076     // start the execution
00077     virtual bool start( QStringList *env=0 );
00078     virtual bool launch( const QString& buf, QStringList *env=0  );
00079     virtual bool launch( const QByteArray& buf, QStringList *env=0  );
00080 
00081     // inquire the status
00082     bool isRunning() const;
00083     bool normalExit() const;
00084     int exitStatus() const;
00085 
00086     // reading
00087     virtual QByteArray readStdout();
00088     virtual QByteArray readStderr();
00089     bool canReadLineStdout() const;
00090     bool canReadLineStderr() const;
00091     virtual QString readLineStdout();
00092     virtual QString readLineStderr();
00093 
00094     // get platform dependent process information
00095 #if defined(Q_OS_WIN32)
00096     typedef void* PID;
00097 #else
00098     typedef long Q_LONG;
00099     typedef Q_LONG PID;
00100 #endif
00101     PID processIdentifier();
00102 
00103     void flushStdin();
00104 
00105 signals:
00106     void readyReadStdout();
00107     void readyReadStderr();
00108     void processExited();
00109     void wroteToStdin();
00110     void launchFinished();
00111 
00112 public slots:
00113     // end the execution
00114     void tryTerminate() const;
00115     void kill() const;
00116 
00117     // input
00118     virtual void writeToStdin( const QByteArray& buf );
00119     virtual void writeToStdin( const QString& buf );
00120     virtual void closeStdin();
00121 
00122 protected: // ### or private?
00123     void connectNotify( const char * signal );
00124     void disconnectNotify( const char * signal );
00125 private:
00126     void setIoRedirection( bool value );
00127     void setNotifyOnExit( bool value );
00128     void setWroteStdinConnected( bool value );
00129 
00130     void init();
00131     void reset();
00132 #if defined(Q_OS_WIN32)
00133     uint readStddev( HANDLE dev, char *buf, uint bytes );
00134 #endif
00135     bool scanNewline( bool stdOut, QByteArray *store );
00136 
00137     QByteArray* bufStdout();
00138     QByteArray* bufStderr();
00139     void consumeBufStdout( int consume );
00140     void consumeBufStderr( int consume );
00141 
00142 private slots:
00143     void socketRead( int fd );
00144     void socketWrite( int fd );
00145     void timeout();
00146     void closeStdinLaunch();
00147 
00148 private:
00149     QProcessPrivate *d;
00150 #ifndef QT_NO_DIR
00151     QDir        workingDir;
00152 #endif
00153     QStringList _arguments;
00154 
00155     int  exitStat; // exit status
00156     bool exitNormal; // normal exit?
00157     bool ioRedirection; // automatically set be (dis)connectNotify
00158     bool notifyOnExit; // automatically set be (dis)connectNotify
00159     bool wroteToStdinConnected; // automatically set be (dis)connectNotify
00160 
00161     bool readStdoutCalled;
00162     bool readStderrCalled;
00163     int comms;
00164 
00165     friend class QProcessPrivate;
00166 #if defined(Q_OS_UNIX) || defined(_OS_UNIX) || defined(UNIX)
00167     friend class QProcessManager;
00168     friend class QProc;
00169 #endif
00170 };
00171 
00172 #endif // QT_NO_PROCESS
00173 
00174 #endif // QPROCESS_H
KDE Logo
This file is part of the documentation for OPIE Version 1.5.5.
Documentation copyright © 1997-2003 the KDE developers. 2003 OPIE developers
Generated on Tue Feb 10 20:24:08 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001