oprocess.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
00030 #ifndef __kprocess_h__
00031 #define __kprocess_h__
00032
00033 #include <sys/types.h>
00034 #include <sys/wait.h>
00035 #include <signal.h>
00036 #include <unistd.h>
00037 #include <qvaluelist.h>
00038 #include <qcstring.h>
00039 #include <qobject.h>
00040
00041 class QSocketNotifier;
00042 class OProcessPrivate;
00043
00147 class OProcess : public QObject
00148 {
00149 Q_OBJECT
00150
00151 public:
00152
00165 enum Communication { NoCommunication = 0, Stdin = 1, Stdout = 2, Stderr = 4,
00166 AllOutput = 6, All = 7,
00167 NoRead };
00168
00172 enum RunMode {
00177 DontCare,
00181 NotifyOnExit,
00185 Block };
00186
00190 OProcess(QObject *parent = 0, const char *name = 0);
00194 OProcess(const QString &arg0, QObject *parent = 0, const char *name = 0);
00198 OProcess(const QStringList &args, QObject *parent = 0, const char *name = 0);
00199
00208 virtual ~OProcess();
00209
00223 bool setExecutable(const QString& proc);
00224
00225
00237 OProcess &operator<<(const QString& arg);
00241 OProcess &operator<<(const char * arg);
00245 OProcess &operator<<(const QCString & arg);
00246
00251 OProcess &operator<<(const QStringList& args);
00252
00257 void clearArguments();
00258
00281 virtual bool start(RunMode runmode = NotifyOnExit,
00282 Communication comm = NoCommunication);
00283
00290 virtual bool kill(int signo = SIGTERM);
00291
00295 bool isRunning() const;
00296
00306 pid_t pid() const;
00307
00311 void suspend();
00312
00316 void resume();
00317
00325 bool normalExit() const;
00326
00336 int exitStatus() const;
00337
00338
00363 bool writeStdin(const char *buffer, int buflen);
00364
00365 void flushStdin();
00366
00374 bool closeStdin();
00375
00383 bool closeStdout();
00384
00392 bool closeStderr();
00393
00398 const QValueList<QCString> &args() { return arguments; }
00399
00406 void setRunPrivileged(bool keepPrivileges);
00407
00412 bool runPrivileged() const;
00413
00418 void setEnvironment(const QString &name, const QString &value);
00419
00425 void setWorkingDirectory(const QString &dir);
00426
00438 void setUseShell(bool useShell, const char *shell = 0);
00439
00446 static QString quote(const QString &arg);
00447
00455 void detach();
00456
00457
00458
00459 signals:
00460
00466 void processExited(OProcess *proc);
00467
00468
00483 void receivedStdout(OProcess *proc, char *buffer, int buflen);
00484
00500 void receivedStdout(int fd, int &len);
00501
00502
00516 void receivedStderr(OProcess *proc, char *buffer, int buflen);
00517
00523 void wroteStdin(OProcess *proc);
00524
00525
00526 protected slots:
00527
00532 void slotChildOutput(int fdno);
00533
00538 void slotChildError(int fdno);
00539
00540
00541
00542
00548 void slotSendData(int dummy);
00549
00550 protected:
00551
00556 void setupEnvironment();
00557
00562 QValueList<QCString> arguments;
00567 RunMode run_mode;
00575 bool runs;
00576
00584 pid_t pid_;
00585
00593 int status;
00594
00595
00599 bool keepPrivs;
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613
00627 virtual int setupCommunication(Communication comm);
00628
00640 virtual int commSetupDoneP();
00641
00648 virtual int commSetupDoneC();
00649
00650
00657 virtual void processHasExited(int state);
00658
00663 virtual void commClose();
00664
00665
00669 int out[2];
00670 int in[2];
00671 int err[2];
00672
00676 QSocketNotifier *innot;
00677 QSocketNotifier *outnot;
00678 QSocketNotifier *errnot;
00679
00684 Communication communication;
00685
00691 int childOutput(int fdno);
00692
00698 int childError(int fdno);
00699
00700
00701
00702 const char *input_data;
00703 int input_sent;
00704 int input_total;
00705
00710 friend class OProcessController;
00711
00712
00713 private:
00726 QCString searchShell();
00727
00732 bool isExecutable(const QCString &filename);
00733
00734
00735 OProcess( const OProcess& );
00736 OProcess& operator= ( const OProcess& );
00737
00738 private:
00739 void init ( );
00740
00741 OProcessPrivate *d;
00742 };
00743
00744
00745
00746 #endif
00747
This file is part of the documentation for OPIE Version 1.1.