kdecore Library API Documentation

kprocess.h

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., 59 Temple Place - Suite 330,
00017     Boston, MA 02111-1307, USA.
00018 */
00019 
00020 #ifndef __kprocess_h__
00021 #define __kprocess_h__
00022 
00023 #include <sys/types.h> // for pid_t
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 "kdemacros.h"
00031 
00032 class QSocketNotifier;
00033 class KProcessPrivate;
00034 class KPty;
00035 
00124 class 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  // KDE4 merge with the above
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 
00444   void closeAll();
00445 
00450   const QValueList<QCString> &args() /* const */ { return arguments; }
00451 
00461   void setRunPrivileged(bool keepPrivileges);
00462 
00468   bool runPrivileged() const;
00469 
00476   void setEnvironment(const QString &name, const QString &value);
00477 
00484   void setWorkingDirectory(const QString &dir);
00485 
00502   void setUseShell(bool useShell, const char *shell = 0);
00503 
00513   static QString quote(const QString &arg);
00514 
00522   void detach();
00523 
00535   void setUsePty(Communication comm, bool addUtmp);
00536 
00545   KPty *pty() const;
00546 
00550   enum { PrioLowest = 20, PrioLow = 10, PrioLower = 5, PrioNormal = 0,
00551     PrioHigher = -5, PrioHigh = -10, PrioHighest = -19 };
00552 
00559   bool setPriority(int prio);
00560 
00561 signals:
00568   void processExited(KProcess *proc);
00569 
00570 
00589   void receivedStdout(KProcess *proc, char *buffer, int buflen);
00590 
00609   void receivedStdout(int fd, int &len); // KDE4: change, broken API
00610 
00611 
00626   void receivedStderr(KProcess *proc, char *buffer, int buflen);
00627 
00634   void wroteStdin(KProcess *proc);
00635 
00636 
00637 protected slots:
00638 
00644   void slotChildOutput(int fdno);
00645 
00651   void slotChildError(int fdno);
00652 
00659   void slotSendData(int dummy); // KDE 4: remove dummy
00660 
00661 protected:
00662 
00667   void setupEnvironment();
00668 
00673   QValueList<QCString> arguments;
00678   RunMode run_mode;
00685   bool runs;
00686 
00694   pid_t pid_;
00695 
00703   int status;
00704 
00705 
00711   bool keepPrivs;
00712 
00725   virtual int setupCommunication(Communication comm);
00726 
00739   virtual int commSetupDoneP();
00740 
00746   virtual int commSetupDoneC();
00747 
00748 
00755   virtual void processHasExited(int state);
00756 
00782   virtual void commClose();
00783 
00784   /* KDE 4 - commClose will be changed to perform cleanup only in all cases *
00785    * If @p notfd is -1, all data immediately available from the
00786    *  communication links should be processed.
00787    * If @p notfd is not -1, the communication links should be monitored
00788    *  for data until the file handle @p notfd becomes ready for reading.
00789    */
00790 //  virtual void commDrain(int notfd);
00791 
00797   void setBinaryExecutable(const char *filename);
00798 
00802   int out[2];
00806   int in[2];
00810   int err[2];
00811 
00815   QSocketNotifier *innot;
00819   QSocketNotifier *outnot;
00823   QSocketNotifier *errnot;
00824 
00829   Communication communication;
00830 
00836   int childOutput(int fdno);
00837 
00843   int childError(int fdno);
00844 
00848   const char *input_data;
00852   int input_sent;
00856   int input_total;
00857 
00862   friend class KProcessController;
00863 
00864 protected:
00865   virtual void virtual_hook( int id, void* data );
00866 private:
00867   KProcessPrivate *d;
00868 };
00869 
00870 class KShellProcessPrivate;
00871 
00882 class KShellProcess: public KProcess
00883 {
00884   Q_OBJECT
00885 
00886 public:
00887 
00893   KShellProcess(const char *shellname=0);
00894 
00898   ~KShellProcess();
00899 
00900   virtual bool start(RunMode  runmode = NotifyOnExit,
00901           Communication comm = NoCommunication);
00902 
00903   static QString quote(const QString &arg);
00904 
00905 private:
00906   QCString shell;
00907 
00908 protected:
00909   virtual void virtual_hook( int id, void* data );
00910 private:
00911   KShellProcessPrivate *d;
00912 };
00913 
00914 
00915 
00916 #endif
00917 
KDE Logo
This file is part of the documentation for kdecore Library Version 3.3.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jan 22 16:43:44 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003