00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef OPROCESS_H
00032 #define OPROCESS_H
00033
00034
00035 #include <qcstring.h>
00036 #include <qobject.h>
00037 #include <qvaluelist.h>
00038
00039
00040 #include <sys/types.h>
00041 #include <sys/wait.h>
00042 #include <signal.h>
00043 #include <unistd.h>
00044
00045 class QSocketNotifier;
00046
00047 namespace Opie {
00048 namespace Core {
00049 namespace Internal {
00050 class OProcessController;
00051 class OProcessPrivate;
00052 }
00053
00157 class OProcess : public QObject
00158 {
00159 Q_OBJECT
00160
00161 public:
00162
00175 enum Communication { NoCommunication = 0, Stdin = 1, Stdout = 2, Stderr = 4,
00176 AllOutput = 6, All = 7,
00177 NoRead };
00178
00182 enum RunMode {
00187 DontCare,
00191 NotifyOnExit,
00195 Block };
00196
00200 OProcess( QObject *parent = 0, const char *name = 0 );
00204 OProcess( const QString &arg0, QObject *parent = 0, const char *name = 0 );
00208 OProcess( const QStringList &args, QObject *parent = 0, const char *name = 0 );
00209
00218 virtual ~OProcess();
00219
00233 bool setExecutable( const QString& proc );
00234
00235
00247 OProcess &operator<<( const QString& arg );
00251 OProcess &operator<<( const char * arg );
00255 OProcess &operator<<( const QCString & arg );
00256
00261 OProcess &operator<<( const QStringList& args );
00262
00267 void clearArguments();
00268
00291 virtual bool start( RunMode runmode = NotifyOnExit,
00292 Communication comm = NoCommunication );
00293
00300 virtual bool kill( int signo = SIGTERM );
00301
00305 bool isRunning() const;
00306
00316 pid_t pid() const;
00317
00321 void suspend();
00322
00326 void resume();
00327
00335 bool normalExit() const;
00336
00346 int exitStatus() const;
00347
00348
00373 bool writeStdin( const char *buffer, int buflen );
00374
00375 void flushStdin();
00376
00384 bool closeStdin();
00385
00393 bool closeStdout();
00394
00402 bool closeStderr();
00403
00409 const QValueList<QCString> &args()
00410 {
00411 return arguments;
00412 }
00413
00420 void setRunPrivileged( bool keepPrivileges );
00421
00426 bool runPrivileged() const;
00427
00432 void setEnvironment( const QString &name, const QString &value );
00433
00439 void setWorkingDirectory( const QString &dir );
00440
00452 void setUseShell( bool useShell, const char *shell = 0 );
00453
00460 static QString quote( const QString &arg );
00461
00469 void detach();
00470
00474 static int processPID( const QString& process );
00475
00476 signals:
00477
00483 void processExited( Opie::Core::OProcess *proc );
00484
00485
00501 void receivedStdout( Opie::Core::OProcess *proc, char *buffer, int buflen );
00502
00518 void receivedStdout( int fd, int &len );
00519
00520
00535 void receivedStderr( Opie::Core::OProcess *proc, char *buffer, int buflen );
00536
00542 void wroteStdin( Opie::Core::OProcess *proc );
00543
00544 protected slots:
00545
00550 void slotChildOutput( int fdno );
00551
00556 void slotChildError( int fdno );
00557
00558
00559
00560
00566 void slotSendData( int dummy );
00567
00568 protected:
00569
00574 void setupEnvironment();
00575
00580 QValueList<QCString> arguments;
00585 RunMode run_mode;
00593 bool runs;
00594
00602 pid_t pid_;
00603
00611 int status;
00612
00613
00617 bool keepPrivs;
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00645 virtual int setupCommunication( Communication comm );
00646
00658 virtual int commSetupDoneP();
00659
00666 virtual int commSetupDoneC();
00667
00668
00675 virtual void processHasExited( int state );
00676
00681 virtual void commClose();
00682
00683
00687 int out[ 2 ];
00688 int in[ 2 ];
00689 int err[ 2 ];
00690
00694 QSocketNotifier *innot;
00695 QSocketNotifier *outnot;
00696 QSocketNotifier *errnot;
00697
00702 Communication communication;
00703
00709 int childOutput( int fdno );
00710
00716 int childError( int fdno );
00717
00718
00719
00720 const char *input_data;
00721 int input_sent;
00722 int input_total;
00723
00728 friend class Internal::OProcessController;
00729
00730 private:
00743 QCString searchShell();
00744
00749 bool isExecutable( const QCString &filename );
00750
00751
00752 OProcess( const OProcess& );
00753 OProcess& operator= ( const OProcess& );
00754
00755 private:
00756 void init ( );
00757 Internal::OProcessPrivate *d;
00758 };
00759 }
00760 }
00761
00762 #endif
00763