libopie API Documentation

oprocess.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 //  Ported by Holger Freyther to the Open Palmtop Integrated Environment
00028 //
00029 
00030 #ifndef __kprocess_h__
00031 #define __kprocess_h__
00032 
00033 #include <sys/types.h> // for pid_t
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     Slot functions for capturing stdout and stderr of the child
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     Functions for setting up the sockets for communication.
00603     setupCommunication
00604     -- is called from "start" before "fork"ing.
00605     commSetupDoneP
00606     -- completes communication socket setup in the parent
00607     commSetupDoneC
00608     -- completes communication setup in the child process
00609     commClose
00610     -- frees all allocated communication resources in the parent
00611     after the process has exited
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   // information about the data that has to be sent to the child:
00701 
00702   const char *input_data;  // the buffer holding the data
00703   int input_sent;    // # of bytes already transmitted
00704   int input_total;   // total length of input_data
00705 
00710   friend class OProcessController;
00711 
00712 
00713 private:
00726   QCString searchShell();
00727 
00732   bool isExecutable(const QCString &filename);
00733 
00734   // Disallow assignment and copy-construction
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 
KDE Logo
This file is part of the documentation for OPIE Version 1.1.
Documentation copyright © 1997-2003 the KDE developers. 2003 OPIE developers
Generated on Tue Feb 10 20:24:44 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001