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
00142 enum Communication {
00143 NoCommunication = 0,
00144 Stdin = 1, Stdout = 2, Stderr = 4,
00145 AllOutput = 6, All = 7,
00146 NoRead
00147 };
00148
00152 enum RunMode {
00157 DontCare,
00161 NotifyOnExit,
00165 Block,
00170 OwnGroup
00171 };
00172
00177 KProcess( QObject* parent, const char *name = 0 );
00178
00182 KProcess();
00183
00192 virtual ~KProcess();
00193
00205 bool setExecutable(const QString& proc) KDE_DEPRECATED;
00206
00207
00221 KProcess &operator<<(const QString& arg);
00225 KProcess &operator<<(const char * arg);
00231 KProcess &operator<<(const QCString & arg);
00232
00239 KProcess &operator<<(const QStringList& args);
00240
00245 void clearArguments();
00246
00273 virtual bool start(RunMode runmode = NotifyOnExit,
00274 Communication comm = NoCommunication);
00275
00282 virtual bool kill(int signo = SIGTERM);
00283
00288 bool isRunning() const;
00289
00300 pid_t pid() const;
00301
00306 KDE_DEPRECATED pid_t getPid() const { return pid(); }
00307
00311 void suspend();
00312
00316 void resume();
00317
00326 bool wait(int timeout = -1);
00327
00334 bool normalExit() const;
00335
00344 bool signalled() const;
00345
00355 bool coreDumped() const;
00356
00363 int exitStatus() const;
00364
00373 int exitSignal() const;
00374
00403 bool writeStdin(const char *buffer, int buflen);
00404
00411 bool closeStdin();
00412
00420 bool closeStdout();
00421
00429 bool closeStderr();
00430
00439 bool closePty();
00440
00447 void closeAll();
00448
00453 const QValueList<QCString> &args() { return arguments; }
00454
00464 void setRunPrivileged(bool keepPrivileges);
00465
00471 bool runPrivileged() const;
00472
00479 void setEnvironment(const QString &name, const QString &value);
00480
00487 void setWorkingDirectory(const QString &dir);
00488
00505 void setUseShell(bool useShell, const char *shell = 0);
00506
00516 static QString quote(const QString &arg);
00517
00525 void detach();
00526
00527 #ifdef Q_OS_UNIX
00528
00539 void setUsePty(Communication comm, bool addUtmp);
00540
00549 KPty *pty() const;
00550 #endif
00551
00555 enum { PrioLowest = 20, PrioLow = 10, PrioLower = 5, PrioNormal = 0,
00556 PrioHigher = -5, PrioHigh = -10, PrioHighest = -19 };
00557
00564 bool setPriority(int prio);
00565
00566 signals:
00573 void processExited(KProcess *proc);
00574
00575
00594 void receivedStdout(KProcess *proc, char *buffer, int buflen);
00595
00614 void receivedStdout(int fd, int &len);
00615
00616
00631 void receivedStderr(KProcess *proc, char *buffer, int buflen);
00632
00639 void wroteStdin(KProcess *proc);
00640
00641
00642 protected slots:
00643
00649 void slotChildOutput(int fdno);
00650
00656 void slotChildError(int fdno);
00657
00664 void slotSendData(int dummy);
00665
00666 protected:
00667
00672 void setupEnvironment();
00673
00678 QValueList<QCString> arguments;
00683 RunMode run_mode;
00690 bool runs;
00691
00699 pid_t pid_;
00700
00708 int status;
00709
00710
00716 bool keepPrivs;
00717
00730 virtual int setupCommunication(Communication comm);
00731
00744 virtual int commSetupDoneP();
00745
00751 virtual int commSetupDoneC();
00752
00753
00760 virtual void processHasExited(int state);
00761
00787 virtual void commClose();
00788
00789
00790
00791
00792
00793
00794
00795
00796
00802 void setBinaryExecutable(const char *filename);
00803
00807 int out[2];
00811 int in[2];
00815 int err[2];
00816
00820 QSocketNotifier *innot;
00824 QSocketNotifier *outnot;
00828 QSocketNotifier *errnot;
00829
00834 Communication communication;
00835
00841 int childOutput(int fdno);
00842
00848 int childError(int fdno);
00849
00853 const char *input_data;
00857 int input_sent;
00861 int input_total;
00862
00867 friend class KProcessController;
00868
00869 protected:
00870 virtual void virtual_hook( int id, void* data );
00871 private:
00872 KProcessPrivate *d;
00873 };
00874
00875 class KShellProcessPrivate;
00876
00886 class KDECORE_EXPORT KShellProcess: public KProcess
00887 {
00888 Q_OBJECT
00889
00890 public:
00891
00897 KShellProcess(const char *shellname=0);
00898
00902 ~KShellProcess();
00903
00904 virtual bool start(RunMode runmode = NotifyOnExit,
00905 Communication comm = NoCommunication);
00906
00907 static QString quote(const QString &arg);
00908
00909 private:
00910 QCString shell;
00911
00912 protected:
00913 virtual void virtual_hook( int id, void* data );
00914 private:
00915 KShellProcessPrivate *d;
00916 };
00917
00918
00919
00920 #endif
00921
|