kprocess.h00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __kprocess_h__
00021 #define __kprocess_h__
00022
00023 #include <sys/types.h>
00024 #include <sys/wait.h>
00025 #include <signal.h>
00026 #include <unistd.h>
00027 #include <qvaluelist.h>
00028 #include <qcstring.h>
00029 #include <qobject.h>
00030 #include "kdelibs_export.h"
00031
00032 class QSocketNotifier;
00033 class KProcessPrivate;
00034 class KPty;
00035
00124 class KDECORE_EXPORT KProcess : public QObject
00125 {
00126 Q_OBJECT
00127
00128 public:
00129
00151 enum Communication {
00152 NoCommunication = 0,
00153 Stdin = 1, Stdout = 2, Stderr = 4,
00154 AllOutput = 6, All = 7,
00155 NoRead = 8,
00156 CTtyOnly = NoRead,
00157 MergedStderr = 16
00158 };
00159
00163 enum RunMode {
00168 DontCare,
00172 NotifyOnExit,
00176 Block,
00181 OwnGroup
00182 };
00183
00188 KProcess( QObject* parent, const char *name = 0 );
00189
00193 KProcess();
00194
00203 virtual ~KProcess();
00204
00216 bool setExecutable(const QString& proc) KDE_DEPRECATED;
00217
00218
00232 KProcess &operator<<(const QString& arg);
00236 KProcess &operator<<(const char * arg);
00242 KProcess &operator<<(const QCString & arg);
00243
00250 KProcess &operator<<(const QStringList& args);
00251
00256 void clearArguments();
00257
00284 virtual bool start(RunMode runmode = NotifyOnExit,
00285 Communication comm = NoCommunication);
00286
00293 virtual bool kill(int signo = SIGTERM);
00294
00299 bool isRunning() const;
00300
00311 pid_t pid() const;
00312
00317 KDE_DEPRECATED pid_t getPid() const { return pid(); }
00318
00322 void suspend();
00323
00327 void resume();
00328
00337 bool wait(int timeout = -1);
00338
00345 bool normalExit() const;
00346
00355 bool signalled() const;
00356
00366 bool coreDumped() const;
00367
00374 int exitStatus() const;
00375
00384 int exitSignal() const;
00385
00414 bool writeStdin(const char *buffer, int buflen);
00415
00422 bool closeStdin();
00423
00431 bool closeStdout();
00432
00440 bool closeStderr();
00441
00450 bool closePty();
00451
00458 void closeAll();
00459
00464 const QValueList<QCString> &args() { return arguments; }
00465
00475 void setRunPrivileged(bool keepPrivileges);
00476
00482 bool runPrivileged() const;
00483
00490 void setEnvironment(const QString &name, const QString &value);
00491
00498 void setWorkingDirectory(const QString &dir);
00499
00516 void setUseShell(bool useShell, const char *shell = 0);
00517
00527 static QString quote(const QString &arg);
00528
00536 void detach();
00537
00538 #ifdef Q_OS_UNIX
00539
00550 void setUsePty(Communication comm, bool addUtmp);
00551
00559 KPty *pty() const;
00560 #endif
00561
00565 enum { PrioLowest = 20, PrioLow = 10, PrioLower = 5, PrioNormal = 0,
00566 PrioHigher = -5, PrioHigh = -10, PrioHighest = -19 };
00567
00574 bool setPriority(int prio);
00575
00576 signals:
00583 void processExited(KProcess *proc);
00584
00585
00604 void receivedStdout(KProcess *proc, char *buffer, int buflen);
00605
00624 void receivedStdout(int fd, int &len);
00625
00626
00641 void receivedStderr(KProcess *proc, char *buffer, int buflen);
00642
00649 void wroteStdin(KProcess *proc);
00650
00651
00652 protected slots:
00653
00659 void slotChildOutput(int fdno);
00660
00666 void slotChildError(int fdno);
00667
00674 void slotSendData(int dummy);
00675
00676 protected:
00677
00682 void setupEnvironment();
00683
00688 QValueList<QCString> arguments;
00693 RunMode run_mode;
00700 bool runs;
00701
00709 pid_t pid_;
00710
00718 int status;
00719
00720
00726 bool keepPrivs;
00727
00740 virtual int setupCommunication(Communication comm);
00741
00754 virtual int commSetupDoneP();
00755
00761 virtual int commSetupDoneC();
00762
00763
00770 virtual void processHasExited(int state);
00771
00797 virtual void commClose();
00798
00799
00800
00801
00802
00803
00804
00805
00806
00812 void setBinaryExecutable(const char *filename);
00813
00817 int out[2];
00821 int in[2];
00825 int err[2];
00826
00830 QSocketNotifier *innot;
00834 QSocketNotifier *outnot;
00838 QSocketNotifier *errnot;
00839
00844 Communication communication;
00845
00851 int childOutput(int fdno);
00852
00858 int childError(int fdno);
00859
00863 const char *input_data;
00867 int input_sent;
00871 int input_total;
00872
00877 friend class KProcessController;
00878
00879 protected:
00880 virtual void virtual_hook( int id, void* data );
00881 private:
00882 KProcessPrivate *d;
00883 };
00884
00885 class KShellProcessPrivate;
00886
00896 class KDECORE_EXPORT KShellProcess: public KProcess
00897 {
00898 Q_OBJECT
00899
00900 public:
00901
00907 KShellProcess(const char *shellname=0);
00908
00912 ~KShellProcess();
00913
00914 virtual bool start(RunMode runmode = NotifyOnExit,
00915 Communication comm = NoCommunication);
00916
00917 static QString quote(const QString &arg);
00918
00919 private:
00920 QCString shell;
00921
00922 protected:
00923 virtual void virtual_hook( int id, void* data );
00924 private:
00925 KShellProcessPrivate *d;
00926 };
00927
00928
00929
00930 #endif
00931
|