home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / qt3_emx.zip / include / qprocess.h < prev    next >
C/C++ Source or Header  |  2001-10-11  |  5KB  |  174 lines

  1. /****************************************************************************
  2. ** $Id:  qt/qprocess.h   3.0.0   edited Oct 2 13:57 $
  3. **
  4. ** Implementation of QProcess class
  5. **
  6. ** Created : 20000905
  7. **
  8. ** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
  9. **
  10. ** This file is part of the kernel module of the Qt GUI Toolkit.
  11. **
  12. ** This file may be distributed under the terms of the Q Public License
  13. ** as defined by Trolltech AS of Norway and appearing in the file
  14. ** LICENSE.QPL included in the packaging of this file.
  15. **
  16. ** This file may be distributed and/or modified under the terms of the
  17. ** GNU General Public License version 2 as published by the Free Software
  18. ** Foundation and appearing in the file LICENSE.GPL included in the
  19. ** packaging of this file.
  20. **
  21. ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
  22. ** licenses may use this file in accordance with the Qt Commercial License
  23. ** Agreement provided with the Software.
  24. **
  25. ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  26. ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  27. **
  28. ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
  29. **   information about Qt Commercial License Agreements.
  30. ** See http://www.trolltech.com/qpl/ for QPL licensing information.
  31. ** See http://www.trolltech.com/gpl/ for GPL licensing information.
  32. **
  33. ** Contact info@trolltech.com if any conditions of this licensing are
  34. ** not clear to you.
  35. **
  36. **********************************************************************/
  37.  
  38. #ifndef QPROCESS_H
  39. #define QPROCESS_H
  40.  
  41. #ifndef QT_H
  42. #include "qobject.h"
  43. #include "qstringlist.h"
  44. #include "qdir.h"
  45. #endif // QT_H
  46.  
  47. #ifndef QT_NO_PROCESS
  48.  
  49. class QProcessPrivate;
  50.  
  51.  
  52. class Q_EXPORT QProcess : public QObject
  53. {
  54.     Q_OBJECT
  55. public:
  56.     QProcess( QObject *parent=0, const char *name=0 );
  57.     QProcess( const QString& arg0, QObject *parent=0, const char *name=0 );
  58.     QProcess( const QStringList& args, QObject *parent=0, const char *name=0 );
  59.     ~QProcess();
  60.  
  61.     // set and get the arguments and working directory
  62.     QStringList arguments() const;
  63.     void clearArguments();
  64.     virtual void setArguments( const QStringList& args );
  65.     virtual void addArgument( const QString& arg );
  66. #ifndef QT_NO_DIR
  67.     QDir workingDirectory() const;
  68.     virtual void setWorkingDirectory( const QDir& dir );
  69. #endif
  70.  
  71.     // set and get the comms wanted
  72.     enum Communication { Stdin=0x01, Stdout=0x02, Stderr=0x04, DupStderr=0x08 };
  73.     void setCommunication( int c );
  74.     int communication() const;
  75.  
  76.     // start the execution
  77.     virtual bool start( QStringList *env=0 );
  78.     virtual bool launch( const QString& buf, QStringList *env=0  );
  79.     virtual bool launch( const QByteArray& buf, QStringList *env=0  );
  80.  
  81.     // inquire the status
  82.     bool isRunning() const;
  83.     bool normalExit() const;
  84.     int exitStatus() const;
  85.  
  86.     // reading
  87.     virtual QByteArray readStdout();
  88.     virtual QByteArray readStderr();
  89.     bool canReadLineStdout() const;
  90.     bool canReadLineStderr() const;
  91.     virtual QString readLineStdout();
  92.     virtual QString readLineStderr();
  93.  
  94.     // get platform dependent process information
  95. #if defined(Q_OS_WIN32)
  96.     typedef void* PID;
  97. #else
  98.     typedef Q_LONG PID;
  99. #endif
  100.     PID processIdentifier();
  101.  
  102.     void flushStdin();
  103.  
  104. signals:
  105.     void readyReadStdout();
  106.     void readyReadStderr();
  107.     void processExited();
  108.     void wroteToStdin();
  109.     void launchFinished();
  110.  
  111. public slots:
  112.     // end the execution
  113.     void tryTerminate() const;
  114.     void kill() const;
  115.  
  116.     // input
  117.     virtual void writeToStdin( const QByteArray& buf );
  118.     virtual void writeToStdin( const QString& buf );
  119.     virtual void closeStdin();
  120.  
  121. protected: // ### or private?
  122.     void connectNotify( const char * signal );
  123.     void disconnectNotify( const char * signal );
  124. private:
  125.     void setIoRedirection( bool value );
  126.     void setNotifyOnExit( bool value );
  127.     void setWroteStdinConnected( bool value );
  128.  
  129.     void init();
  130.     void reset();
  131. #if defined(Q_OS_WIN32)
  132.     uint readStddev( HANDLE dev, char *buf, uint bytes );
  133. #endif
  134.     bool scanNewline( bool stdOut, QByteArray *store );
  135.  
  136.     QByteArray* bufStdout();
  137.     QByteArray* bufStderr();
  138.     void consumeBufStdout( int consume );
  139.     void consumeBufStderr( int consume );
  140.  
  141. private slots:
  142.     void socketRead( int fd );
  143.     void socketWrite( int fd );
  144.     void timeout();
  145.     void closeStdinLaunch();
  146.  
  147. private:
  148.     QProcessPrivate *d;
  149. #ifndef QT_NO_DIR
  150.     QDir        workingDir;
  151. #endif
  152.     QStringList _arguments;
  153.  
  154.     int  exitStat; // exit status
  155.     bool exitNormal; // normal exit?
  156.     bool ioRedirection; // automatically set be (dis)connectNotify
  157.     bool notifyOnExit; // automatically set be (dis)connectNotify
  158.     bool wroteToStdinConnected; // automatically set be (dis)connectNotify
  159.  
  160.     bool readStdoutCalled;
  161.     bool readStderrCalled;
  162.     int comms;
  163.  
  164.     friend class QProcessPrivate;
  165. #if defined(Q_OS_UNIX)
  166.     friend class QProcessManager;
  167.     friend class QProc;
  168. #endif
  169. };
  170.  
  171. #endif // QT_NO_PROCESS
  172.  
  173. #endif // QPROCESS_H
  174.