~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/qt3support/other/q3process.h

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

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