kdecore Library: kprocess.h Source File (kdecore Library)

| # kdecore Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# 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 "kdelibs_export.h"
    00031
    00032 class QSocketNotifier;
    00033 class KProcessPrivate;
    00034 class KPty;
    00035
    00124 class KDECORE_EXPORT 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
    00524 #ifdef Q_OS_UNIX
    00525
    00536   void setUsePty(Communication comm, bool addUtmp);
    00537
    00546   KPty *pty() const;
    00547 #endif
    00548
    00552   enum { PrioLowest = 20, PrioLow = 10, PrioLower = 5, PrioNormal = 0,
    00553     PrioHigher = -5, PrioHigh = -10, PrioHighest = -19 };
    00554
    00561   bool setPriority(int prio);
    00562
    00563 signals:
    00570   void processExited(KProcess *proc);
    00571
    00572
    00591   void receivedStdout(KProcess *proc, char *buffer, int buflen);
    00592
    00611   void receivedStdout(int fd, int &len); // KDE4: change, broken API
    00612
    00613
    00628   void receivedStderr(KProcess *proc, char *buffer, int buflen);
    00629
    00636   void wroteStdin(KProcess *proc);
    00637
    00638
    00639 protected slots:
    00640
    00646   void slotChildOutput(int fdno);
    00647
    00653   void slotChildError(int fdno);
    00654
    00661   void slotSendData(int dummy); // KDE 4: remove dummy
    00662
    00663 protected:
    00664
    00669   void setupEnvironment();
    00670
    00675   QValueList<QCString> arguments;
    00680   RunMode run_mode;
    00687   bool runs;
    00688
    00696   pid_t pid_;
    00697
    00705   int status;
    00706
    00707
    00713   bool keepPrivs;
    00714
    00727   virtual int setupCommunication(Communication comm);
    00728
    00741   virtual int commSetupDoneP();
    00742
    00748   virtual int commSetupDoneC();
    00749
    00750
    00757   virtual void processHasExited(int state);
    00758
    00784   virtual void commClose();
    00785
    00786   /* KDE 4 - commClose will be changed to perform cleanup only in all cases *
    00787    * If @p notfd is -1, all data immediately available from the
    00788    *  communication links should be processed.
    00789    * If @p notfd is not -1, the communication links should be monitored
    00790    *  for data until the file handle @p notfd becomes ready for reading.
    00791    */
    00792 //  virtual void commDrain(int notfd);
    00793
    00799   void setBinaryExecutable(const char *filename);
    00800
    00804   int out[2];
    00808   int in[2];
    00812   int err[2];
    00813
    00817   QSocketNotifier *innot;
    00821   QSocketNotifier *outnot;
    00825   QSocketNotifier *errnot;
    00826
    00831   Communication communication;
    00832
    00838   int childOutput(int fdno);
    00839
    00845   int childError(int fdno);
    00846
    00850   const char *input_data;
    00854   int input_sent;
    00858   int input_total;
    00859
    00864   friend class KProcessController;
    00865
    00866 protected:
    00867   virtual void virtual_hook( int id, void* data );
    00868 private:
    00869   KProcessPrivate *d;
    00870 };
    00871
    00872 class KShellProcessPrivate;
    00873
    00883 class KDECORE_EXPORT KShellProcess: public KProcess
    00884 {
    00885   Q_OBJECT
    00886
    00887 public:
    00888
    00894   KShellProcess(const char *shellname=0);
    00895
    00899   ~KShellProcess();
    00900
    00901   virtual bool start(RunMode  runmode = NotifyOnExit,
    00902           Communication comm = NoCommunication);
    00903
    00904   static QString quote(const QString &arg);
    00905
    00906 private:
    00907   QCString shell;
    00908
    00909 protected:
    00910   virtual void virtual_hook( int id, void* data );
    00911 private:
    00912   KShellProcessPrivate *d;
    00913 };
    00914
    00915
    00916
    00917 #endif
    00918

This file is part of the documentation for kdecore Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:18:09 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003