kprocess.h Source File (kdecore Library)

| # kdecore Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | 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 //  KPROCESS -- A class for handling child processes in KDE without
    00021 //  having to take care of Un*x specific implementation details
    00022 //
    00023 //  version 0.3.1, Jan 8th 1998
    00024 //
    00025 //  (C) Christian Czezatke
    00026 //  e9025461@student.tuwien.ac.at
    00027 //
    00028
    00029 #ifndef __kprocess_h__
    00030 #define __kprocess_h__
    00031
    00032 #include <sys/types.h> // for pid_t
    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
    00230   KProcess &operator<<(const QString& arg);
    00234   KProcess &operator<<(const char * arg);
    00240   KProcess &operator<<(const QCString & arg);
    00241
    00248   KProcess &operator<<(const QStringList& args);
    00249
    00254   void clearArguments();
    00255
    00279   virtual bool start(RunMode  runmode = NotifyOnExit,
    00280         Communication comm = NoCommunication);
    00281
    00288   virtual bool kill(int signo = SIGTERM);
    00289
    00294   bool isRunning() const;
    00295
    00306   pid_t pid() const;
    00307
    00312   pid_t getPid() const { return pid(); }
    00313
    00317   void suspend();
    00318
    00322   void resume();
    00323
    00331   bool normalExit() const;
    00332
    00343   int  exitStatus() const;
    00344
    00345
    00373   bool writeStdin(const char *buffer, int buflen);
    00374
    00382   bool closeStdin();
    00383
    00391   bool closeStdout();
    00392
    00400   bool closeStderr();
    00401
    00406   const QValueList<QCString> &args() { return arguments; }
    00407
    00415   void setRunPrivileged(bool keepPrivileges);
    00416
    00422   bool runPrivileged() const;
    00423
    00430   void setEnvironment(const QString &name, const QString &value);
    00431
    00438   void setWorkingDirectory(const QString &dir);
    00439
    00455   void setUseShell(bool useShell, const char *shell = 0);
    00456
    00466   static QString quote(const QString &arg);
    00467
    00475   void detach();
    00476
    00477
    00478
    00479 signals:
    00480
    00487   void processExited(KProcess *proc);
    00488
    00489
    00507   void receivedStdout(KProcess *proc, char *buffer, int buflen);
    00508
    00526   void receivedStdout(int fd, int &len);
    00527
    00528
    00543   void receivedStderr(KProcess *proc, char *buffer, int buflen);
    00544
    00551   void wroteStdin(KProcess *proc);
    00552
    00553
    00554 protected slots:
    00555
    00561   void slotChildOutput(int fdno);
    00562
    00568   void slotChildError(int fdno);
    00569   /*
    00570         Slot functions for capturing stdout and stderr of the child
    00571   */
    00572
    00579   void slotSendData(int dummy);
    00580
    00581 protected:
    00582
    00587   void setupEnvironment();
    00588
    00593   QValueList<QCString> arguments;
    00598   RunMode run_mode;
    00606   bool runs;
    00607
    00615   pid_t pid_;
    00616
    00624   int status;
    00625
    00626
    00630   bool keepPrivs;
    00631
    00632   /*
    00633         Functions for setting up the sockets for communication.
    00634         setupCommunication
    00635         -- is called from "start" before "fork"ing.
    00636         commSetupDoneP
    00637         -- completes communication socket setup in the parent
    00638         commSetupDoneC
    00639         -- completes communication setup in the child process
    00640         commClose
    00641         -- frees all allocated communication resources in the parent
    00642         after the process has exited
    00643   */
    00644
    00658   virtual int setupCommunication(Communication comm);
    00659
    00671   virtual int commSetupDoneP();
    00672
    00679   virtual int commSetupDoneC();
    00680
    00681
    00688   virtual void processHasExited(int state);
    00689
    00694   virtual void commClose();
    00695
    00696
    00700   int out[2];
    00701   int in[2];
    00702   int err[2];
    00703
    00707   QSocketNotifier *innot;
    00708   QSocketNotifier *outnot;
    00709   QSocketNotifier *errnot;
    00710
    00715   Communication communication;
    00716
    00722   int childOutput(int fdno);
    00723
    00729   int childError(int fdno);
    00730
    00731   // information about the data that has to be sent to the child:
    00732
    00733   const char *input_data;  // the buffer holding the data
    00734   int input_sent;    // # of bytes already transmitted
    00735   int input_total;   // total length of input_data
    00736
    00741   friend class KProcessController;
    00742
    00743
    00744 private:
    00758   QCString searchShell();
    00759
    00765   bool isExecutable(const QCString &filename);
    00766
    00767   // Disallow assignment and copy-construction
    00768   KProcess( const KProcess& );
    00769   KProcess& operator= ( const KProcess& );
    00770
    00771 protected:
    00772   virtual void virtual_hook( int id, void* data );
    00773 private:
    00774   KProcessPrivate *d;
    00775 };
    00776
    00777 class KShellProcessPrivate;
    00778
    00790 class KShellProcess: public KProcess
    00791 {
    00792   Q_OBJECT
    00793
    00794 public:
    00795
    00802   KShellProcess(const char *shellname=0);
    00803
    00807   ~KShellProcess();
    00808
    00814   virtual bool start(RunMode  runmode = NotifyOnExit,
    00815                   Communication comm = NoCommunication);
    00816
    00823   static QString quote(const QString &arg);
    00824
    00825 private:
    00826
    00827   QCString shell;
    00828
    00829   // Disallow assignment and copy-construction
    00830   KShellProcess( const KShellProcess& );
    00831   KShellProcess& operator= ( const KShellProcess& );
    00832
    00833 protected:
    00834   virtual void virtual_hook( int id, void* data );
    00835 private:
    00836   KShellProcessPrivate *d;
    00837 };
    00838
    00839
    00840
    00841 #endif
    00842

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 12:46:47 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001