kprocess.h
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 #ifndef __kprocess_h__
00030 #define __kprocess_h__
00031
00032 #include <sys/types.h>
00033 #include <sys/wait.h>
00034 #include <signal.h>
00035 #include <unistd.h>
00036 #include <qvaluelist.h>
00037 #include <qcstring.h>
00038 #include <qobject.h>
00039
00040 class QSocketNotifier;
00041 class KProcessPrivate;
00042
00146 class KProcess : public QObject
00147 {
00148 Q_OBJECT
00149
00150 public:
00151
00164 enum Communication { NoCommunication = 0, Stdin = 1, Stdout = 2, Stderr = 4,
00165 AllOutput = 6, All = 7,
00166 NoRead };
00167
00171 enum RunMode {
00176 DontCare,
00180 NotifyOnExit,
00184 Block };
00185
00189 KProcess();
00190
00199 virtual ~KProcess();
00200
00214 bool setExecutable(const QString& proc);
00215
00216
00230 KProcess &operator<<(const QString& arg);
00234 KProcess &operator<<(const char * arg);
00240 KProcess &operator<<(const QCString & arg);
00241
00248 KProcess &operator<<(const QStringList& args);
00249
00254 void clearArguments();
00255
00279 virtual bool start(RunMode runmode = NotifyOnExit,
00280 Communication comm = NoCommunication);
00281
00288 virtual bool kill(int signo = SIGTERM);
00289
00294 bool isRunning() const;
00295
00306 pid_t pid() const;
00307
00312 pid_t getPid() const { return pid(); }
00313
00317 void suspend();
00318
00322 void resume();
00323
00331 bool normalExit() const;
00332
00343 int exitStatus() const;
00344
00345
00373 bool writeStdin(const char *buffer, int buflen);
00374
00382 bool closeStdin();
00383
00391 bool closeStdout();
00392
00400 bool closeStderr();
00401
00406 const QValueList<QCString> &args() { return arguments; }
00407
00415 void setRunPrivileged(bool keepPrivileges);
00416
00422 bool runPrivileged() const;
00423
00430 void setEnvironment(const QString &name, const QString &value);
00431
00438 void setWorkingDirectory(const QString &dir);
00439
00455 void setUseShell(bool useShell, const char *shell = 0);
00456
00466 static QString quote(const QString &arg);
00467
00475 void detach();
00476
00477
00478
00479 signals:
00480
00487 void processExited(KProcess *proc);
00488
00489
00507 void receivedStdout(KProcess *proc, char *buffer, int buflen);
00508
00526 void receivedStdout(int fd, int &len);
00527
00528
00543 void receivedStderr(KProcess *proc, char *buffer, int buflen);
00544
00551 void wroteStdin(KProcess *proc);
00552
00553
00554 protected slots:
00555
00561 void slotChildOutput(int fdno);
00562
00568 void slotChildError(int fdno);
00569
00570
00571
00572
00579 void slotSendData(int dummy);
00580
00581 protected:
00582
00587 void setupEnvironment();
00588
00593 QValueList<QCString> arguments;
00598 RunMode run_mode;
00606 bool runs;
00607
00615 pid_t pid_;
00616
00624 int status;
00625
00626
00630 bool keepPrivs;
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644
00658 virtual int setupCommunication(Communication comm);
00659
00671 virtual int commSetupDoneP();
00672
00679 virtual int commSetupDoneC();
00680
00681
00688 virtual void processHasExited(int state);
00689
00694 virtual void commClose();
00695
00696
00700 int out[2];
00701 int in[2];
00702 int err[2];
00703
00707 QSocketNotifier *innot;
00708 QSocketNotifier *outnot;
00709 QSocketNotifier *errnot;
00710
00715 Communication communication;
00716
00722 int childOutput(int fdno);
00723
00729 int childError(int fdno);
00730
00731
00732
00733 const char *input_data;
00734 int input_sent;
00735 int input_total;
00736
00741 friend class KProcessController;
00742
00743
00744 private:
00758 QCString searchShell();
00759
00765 bool isExecutable(const QCString &filename);
00766
00767
00768 KProcess( const KProcess& );
00769 KProcess& operator= ( const KProcess& );
00770
00771 protected:
00772 virtual void virtual_hook( int id, void* data );
00773 private:
00774 KProcessPrivate *d;
00775 };
00776
00777 class KShellProcessPrivate;
00778
00790 class KShellProcess: public KProcess
00791 {
00792 Q_OBJECT
00793
00794 public:
00795
00802 KShellProcess(const char *shellname=0);
00803
00807 ~KShellProcess();
00808
00814 virtual bool start(RunMode runmode = NotifyOnExit,
00815 Communication comm = NoCommunication);
00816
00823 static QString quote(const QString &arg);
00824
00825 private:
00826
00827 QCString shell;
00828
00829
00830 KShellProcess( const KShellProcess& );
00831 KShellProcess& operator= ( const KShellProcess& );
00832
00833 protected:
00834 virtual void virtual_hook( int id, void* data );
00835 private:
00836 KShellProcessPrivate *d;
00837 };
00838
00839
00840
00841 #endif
00842
This file is part of the documentation for kdelibs Version 3.1.5.