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
00228 KProcess &operator<<(const QString& arg);
00232 KProcess &operator<<(const char * arg);
00236 KProcess &operator<<(const QCString & arg);
00237
00242 KProcess &operator<<(const QStringList& args);
00243
00248 void clearArguments();
00249
00272 virtual bool start(RunMode runmode = NotifyOnExit,
00273 Communication comm = NoCommunication);
00274
00281 virtual bool kill(int signo = SIGTERM);
00282
00286 bool isRunning() const;
00287
00297 pid_t pid() const;
00298
00303 pid_t getPid() const { return pid(); }
00304
00308 void suspend();
00309
00313 void resume();
00314
00322 bool normalExit() const;
00323
00333 int exitStatus() const;
00334
00335
00360 bool writeStdin(const char *buffer, int buflen);
00361
00369 bool closeStdin();
00370
00378 bool closeStdout();
00379
00387 bool closeStderr();
00388
00393 const QValueList<QCString> &args() { return arguments; }
00394
00401 void setRunPrivileged(bool keepPrivileges);
00402
00407 bool runPrivileged() const;
00408
00413 void setEnvironment(const QString &name, const QString &value);
00414
00420 void setWorkingDirectory(const QString &dir);
00421
00429 void detach();
00430
00431 signals:
00432
00438 void processExited(KProcess *proc);
00439
00440
00455 void receivedStdout(KProcess *proc, char *buffer, int buflen);
00456
00472 void receivedStdout(int fd, int &len);
00473
00474
00488 void receivedStderr(KProcess *proc, char *buffer, int buflen);
00489
00495 void wroteStdin(KProcess *proc);
00496
00497
00498 protected slots:
00499
00504 void slotChildOutput(int fdno);
00505
00510 void slotChildError(int fdno);
00511
00512
00513
00514
00520 void slotSendData(int dummy);
00521
00522 protected:
00523
00528 void setupEnvironment();
00529
00534 QValueList<QCString> arguments;
00539 RunMode run_mode;
00547 bool runs;
00548
00556 pid_t pid_;
00557
00565 int status;
00566
00567
00571 bool keepPrivs;
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00599 virtual int setupCommunication(Communication comm);
00600
00612 virtual int commSetupDoneP();
00613
00620 virtual int commSetupDoneC();
00621
00622
00629 virtual void processHasExited(int state);
00630
00635 virtual void commClose();
00636
00637
00641 int out[2];
00642 int in[2];
00643 int err[2];
00644
00648 QSocketNotifier *innot;
00649 QSocketNotifier *outnot;
00650 QSocketNotifier *errnot;
00651
00656 Communication communication;
00657
00663 int childOutput(int fdno);
00664
00670 int childError(int fdno);
00671
00672
00673
00674 const char *input_data;
00675 int input_sent;
00676 int input_total;
00677
00682 friend class KProcessController;
00683
00684
00685 private:
00686
00687 KProcess( const KProcess& );
00688 KProcess& operator= ( const KProcess& );
00689
00690 protected:
00691 virtual void virtual_hook( int id, void* data );
00692 private:
00693 KProcessPrivate *d;
00694 };
00695
00696 class KShellProcessPrivate;
00697
00727 class KShellProcess: public KProcess
00728 {
00729 Q_OBJECT
00730
00731 public:
00732
00740 KShellProcess(const char *shellname=0);
00741
00745 ~KShellProcess();
00746
00752 virtual bool start(RunMode runmode = NotifyOnExit,
00753 Communication comm = NoCommunication);
00754
00761 static QString quote(const QString &arg);
00762
00763 private:
00764
00769 QCString searchShell();
00770
00775 bool isExecutable(const QCString &filename);
00776
00777 QCString shell;
00778
00779
00780 KShellProcess( const KShellProcess& );
00781 KShellProcess& operator= ( const KShellProcess& );
00782
00783 protected:
00784 virtual void virtual_hook( int id, void* data );
00785 private:
00786 KShellProcessPrivate *d;
00787 };
00788
00789
00790
00791 #endif
00792