src/qt3support/other/q3process.h
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the Qt3Support module of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #ifndef Q3PROCESS_H
       
    43 #define Q3PROCESS_H
       
    44 
       
    45 #include <QtCore/qobject.h>
       
    46 #include <QtCore/qstringlist.h>
       
    47 #include <QtCore/qdir.h>
       
    48 
       
    49 QT_BEGIN_HEADER
       
    50 
       
    51 QT_BEGIN_NAMESPACE
       
    52 
       
    53 QT_MODULE(Qt3SupportLight)
       
    54 
       
    55 #ifndef QT_NO_PROCESS
       
    56 
       
    57 class Q3ProcessPrivate;
       
    58 class Q3Membuf;
       
    59 
       
    60 class Q_COMPAT_EXPORT Q3Process : public QObject
       
    61 {
       
    62     Q_OBJECT
       
    63 public:
       
    64     Q3Process( QObject *parent=0, const char *name=0 );
       
    65     Q3Process( const QString& arg0, QObject *parent=0, const char *name=0 );
       
    66     Q3Process( const QStringList& args, QObject *parent=0, const char *name=0 );
       
    67     ~Q3Process();
       
    68 
       
    69     // set and get the arguments and working directory
       
    70     QStringList arguments() const;
       
    71     void clearArguments();
       
    72     virtual void setArguments( const QStringList& args );
       
    73     virtual void addArgument( const QString& arg );
       
    74 #ifndef QT_NO_DIR
       
    75     QDir workingDirectory() const;
       
    76     virtual void setWorkingDirectory( const QDir& dir );
       
    77 #endif
       
    78 
       
    79     // set and get the comms wanted
       
    80     enum Communication { Stdin=0x01, Stdout=0x02, Stderr=0x04, DupStderr=0x08 };
       
    81     void setCommunication( int c );
       
    82     int communication() const;
       
    83 
       
    84     // start the execution
       
    85     virtual bool start( QStringList *env=0 );
       
    86     virtual bool launch( const QString& buf, QStringList *env=0  );
       
    87     virtual bool launch( const QByteArray& buf, QStringList *env=0  );
       
    88 
       
    89     // inquire the status
       
    90     bool isRunning() const;
       
    91     bool normalExit() const;
       
    92     int exitStatus() const;
       
    93 
       
    94     // reading
       
    95     virtual QByteArray readStdout();
       
    96     virtual QByteArray readStderr();
       
    97     bool canReadLineStdout() const;
       
    98     bool canReadLineStderr() const;
       
    99     virtual QString readLineStdout();
       
   100     virtual QString readLineStderr();
       
   101 
       
   102     // get platform dependent process information
       
   103 #if defined(Q_OS_WIN32) || defined(Q_OS_WINCE)
       
   104     typedef void* PID;
       
   105 #else
       
   106     typedef Q_LONG PID;
       
   107 #endif
       
   108     PID processIdentifier();
       
   109 
       
   110     void flushStdin();
       
   111 
       
   112 Q_SIGNALS:
       
   113     void readyReadStdout();
       
   114     void readyReadStderr();
       
   115     void processExited();
       
   116     void wroteToStdin();
       
   117     void launchFinished();
       
   118 
       
   119 public Q_SLOTS:
       
   120     // end the execution
       
   121     void tryTerminate() const;
       
   122     void kill() const;
       
   123 
       
   124     // input
       
   125     virtual void writeToStdin( const QByteArray& buf );
       
   126     virtual void writeToStdin( const QString& buf );
       
   127     virtual void closeStdin();
       
   128 
       
   129 protected: // ### or private?
       
   130     void connectNotify( const char * signal );
       
   131     void disconnectNotify( const char * signal );
       
   132 private:
       
   133     void setIoRedirection( bool value );
       
   134     void setNotifyOnExit( bool value );
       
   135     void setWroteStdinConnected( bool value );
       
   136 
       
   137     void init();
       
   138     void reset();
       
   139 #if defined(Q_OS_WIN32) || defined(Q_OS_WINCE)
       
   140     uint readStddev( Qt::HANDLE dev, char *buf, uint bytes );
       
   141 #endif
       
   142     Q3Membuf* membufStdout();
       
   143     Q3Membuf* membufStderr();
       
   144 
       
   145 private Q_SLOTS:
       
   146     void socketRead( int fd );
       
   147     void socketWrite( int fd );
       
   148     void timeout();
       
   149     void closeStdinLaunch();
       
   150 
       
   151 private:
       
   152     Q3ProcessPrivate *d;
       
   153 #ifndef QT_NO_DIR
       
   154     QDir        workingDir;
       
   155 #endif
       
   156     QStringList _arguments;
       
   157 
       
   158     int  exitStat; // exit status
       
   159     bool exitNormal; // normal exit?
       
   160     bool ioRedirection; // automatically set be (dis)connectNotify
       
   161     bool notifyOnExit; // automatically set be (dis)connectNotify
       
   162     bool wroteToStdinConnected; // automatically set be (dis)connectNotify
       
   163 
       
   164     bool readStdoutCalled;
       
   165     bool readStderrCalled;
       
   166     int comms;
       
   167 
       
   168     friend class Q3ProcessPrivate;
       
   169 #if defined(Q_OS_UNIX)
       
   170     friend class Q3ProcessManager;
       
   171     friend class QProc;
       
   172 #endif
       
   173 
       
   174 #if defined(Q_DISABLE_COPY) // Disabled copy constructor and operator=
       
   175     Q3Process( const Q3Process & );
       
   176     Q3Process &operator=( const Q3Process & );
       
   177 #endif
       
   178 };
       
   179 
       
   180 #endif // QT_NO_PROCESS
       
   181 
       
   182 QT_END_NAMESPACE
       
   183 
       
   184 QT_END_HEADER
       
   185 
       
   186 #endif // Q3PROCESS_H