KDE3Support
k3process.h
Go to the documentation of this file.
00001 /* This file is part of the KDE libraries 00002 Copyright (C) 1997 Christian Czezakte (e9025461@student.tuwien.ac.at) 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to 00016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00017 Boston, MA 02110-1301, USA. 00018 */ 00019 00020 #ifndef K3PROCESS_H 00021 #define K3PROCESS_H 00022 00023 #include <kde3support_export.h> 00024 00025 #include <QtCore/QObject> 00026 00027 #include <sys/types.h> // for pid_t 00028 #include <sys/wait.h> 00029 #include <signal.h> 00030 #include <unistd.h> 00031 00032 class QSocketNotifier; 00033 class K3ProcessPrivate; 00034 class KPty; 00035 00127 class KDE3SUPPORT_EXPORT_DEPRECATED K3Process : public QObject 00128 { 00129 Q_OBJECT 00130 00131 public: 00132 00142 enum CommunicationFlag { 00143 NoCommunication = 0, 00144 Stdin = 1, 00145 Stdout = 2, 00146 Stderr = 4, 00147 AllOutput = 6, 00148 All = 7, 00149 NoRead = 8, 00151 CTtyOnly = NoRead, 00154 MergedStderr = 16 00158 }; 00159 00160 Q_DECLARE_FLAGS(Communication, CommunicationFlag) 00161 00162 00165 enum RunMode { 00170 DontCare, 00174 NotifyOnExit, 00178 Block, 00183 OwnGroup 00184 }; 00185 00189 explicit K3Process( QObject* parent=0L ); 00190 00199 virtual ~K3Process(); 00200 00214 K3Process &operator<<(const QString& arg); 00218 K3Process &operator<<(const char * arg); 00224 K3Process &operator<<(const QByteArray & arg); 00225 00232 K3Process &operator<<(const QStringList& args); 00233 00238 void clearArguments(); 00239 00266 virtual bool start(RunMode runmode = NotifyOnExit, 00267 Communication comm = NoCommunication); 00268 00275 virtual bool kill(int signo = SIGTERM); 00276 00281 bool isRunning() const; 00282 00293 pid_t pid() const; 00294 00298 void suspend(); 00299 00303 void resume(); 00304 00312 bool wait(int timeout = -1); 00313 00320 bool normalExit() const; 00321 00328 bool signalled() const; 00329 00337 bool coreDumped() const; 00338 00345 int exitStatus() const; 00346 00353 int exitSignal() const; 00354 00385 bool writeStdin(const char *buffer, int buflen); 00386 00393 bool closeStdin(); 00394 00402 bool closeStdout(); 00403 00411 bool closeStderr(); 00412 00421 bool closePty(); 00422 00429 void closeAll(); 00430 00435 const QList<QByteArray> &args() /* const */ { return arguments; } 00436 00446 void setRunPrivileged(bool keepPrivileges); 00447 00453 bool runPrivileged() const; 00454 00461 void setEnvironment(const QString &name, const QString &value); 00462 00469 void setWorkingDirectory(const QString &dir); 00470 00486 void setUseShell(bool useShell, const char *shell = 0); 00487 00496 static QString quote(const QString &arg); 00497 00505 void detach(); 00506 00517 void setUsePty(Communication comm, bool addUtmp); 00518 00525 KPty *pty() const; 00526 00530 enum { PrioLowest = 20, PrioLow = 10, PrioLower = 5, PrioNormal = 0, 00531 PrioHigher = -5, PrioHigh = -10, PrioHighest = -19 }; 00532 00538 bool setPriority(int prio); 00539 00540 Q_SIGNALS: 00547 void processExited(K3Process *proc); 00548 00549 00568 void receivedStdout(K3Process *proc, char *buffer, int buflen); 00569 00588 void receivedStdout(int fd, int &len); // KDE4: change, broken API 00589 00590 00605 void receivedStderr(K3Process *proc, char *buffer, int buflen); 00606 00613 void wroteStdin(K3Process *proc); 00614 00615 00616 protected Q_SLOTS: 00617 00623 void slotChildOutput(int fdno); 00624 00630 void slotChildError(int fdno); 00631 00638 void slotSendData(int dummy); // KDE 4: remove dummy 00639 00640 protected: 00641 00646 void setupEnvironment(); 00647 00652 QList<QByteArray> arguments; 00657 RunMode run_mode; 00664 bool runs; 00665 00673 pid_t pid_; 00674 00682 int status; 00683 00684 00690 bool keepPrivs; 00691 00704 virtual int setupCommunication(Communication comm); 00705 00718 virtual int commSetupDoneP(); 00719 00725 virtual int commSetupDoneC(); 00726 00727 00734 virtual void processHasExited(int state); 00735 00761 virtual void commClose(); 00762 00763 /* KDE 4 - commClose will be changed to perform cleanup only in all cases * 00764 * If @p notfd is -1, all data immediately available from the 00765 * communication links should be processed. 00766 * If @p notfd is not -1, the communication links should be monitored 00767 * for data until the file handle @p notfd becomes ready for reading. 00768 */ 00769 // virtual void commDrain(int notfd); 00770 00776 void setBinaryExecutable(const char *filename); 00777 00781 int out[2]; 00785 int in[2]; 00789 int err[2]; 00790 00794 QSocketNotifier *innot; 00798 QSocketNotifier *outnot; 00802 QSocketNotifier *errnot; 00803 00808 Communication communication; 00809 00815 int childOutput(int fdno); 00816 00822 int childError(int fdno); 00823 00827 const char *input_data; 00831 int input_sent; 00835 int input_total; 00836 00841 friend class K3ProcessController; 00842 00843 private: 00844 K3ProcessPrivate* const d; 00845 }; 00846 00847 Q_DECLARE_OPERATORS_FOR_FLAGS(K3Process::Communication) 00848 00849 class K3ShellProcessPrivate; 00850 00860 class KDE3SUPPORT_EXPORT_DEPRECATED K3ShellProcess : public K3Process 00861 { 00862 Q_OBJECT 00863 00864 public: 00865 00871 explicit K3ShellProcess(const char *shellname=0); 00872 00876 ~K3ShellProcess(); 00877 00878 virtual bool start(RunMode runmode = NotifyOnExit, 00879 Communication comm = NoCommunication); 00880 00881 static QString quote(const QString &arg); 00882 00883 private: 00884 K3ShellProcessPrivate* const d; 00885 }; 00886 00887 00888 00889 #endif 00890
KDE 4.6 API Reference