Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

oprocess.h

Go to the documentation of this file.
00001 /*
00002                             This file is part of the Opie Project
00003                             Copyright (C) 2003-2004 Holger Freyther <zecke@handhelds.org>
00004                             Copyright (C) The Opie Team <opie-devel@handhelds.org>
00005              =.             Based on KProcess (C) 1997 Christian Czezatke (e9025461@student.tuwien.ac.at)
00006            .=l.
00007           .>+-=
00008 _;:,     .>    :=|.         This program is free software; you can
00009 .> <`_,   >  .   <=         redistribute it and/or  modify it under
00010 :`=1 )Y*s>-.--   :          the terms of the GNU Library General Public
00011 .="- .-=="i,     .._        License as published by the Free Software
00012 - .   .-<_>     .<>         Foundation; either version 2 of the License,
00013     ._= =}       :          or (at your option) any later version.
00014    .%`+i>       _;_.
00015    .i_,=:_.      -<s.       This program is distributed in the hope that
00016     +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
00017    : ..    .:,     . . .    without even the implied warranty of
00018    =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
00019  _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
00020 ..}^=.=       =       ;     Library General Public License for more
00021 ++=   -.     .`     .:      details.
00022 :     =  ...= . :.=-
00023 -.   .:....=;==+<;          You should have received a copy of the GNU
00024  -_. . .   )=.  =           Library General Public License along with
00025    --        :-=`           this library; see the file COPYING.LIB.
00026                             If not, write to the Free Software Foundation,
00027                             Inc., 59 Temple Place - Suite 330,
00028                             Boston, MA 02111-1307, USA.
00029 */
00030 
00031 #ifndef OPROCESS_H
00032 #define OPROCESS_H
00033 
00034 /* QT */
00035 #include <qcstring.h>
00036 #include <qobject.h>
00037 #include <qvaluelist.h>
00038 
00039 /* STD */
00040 #include <sys/types.h> // for pid_t
00041 #include <sys/wait.h>
00042 #include <signal.h>
00043 #include <unistd.h>
00044 
00045 class QSocketNotifier;
00046 
00047 namespace Opie {
00048 namespace Core {
00049 namespace Internal {
00050 class OProcessController;
00051 class OProcessPrivate;
00052 }
00053 
00157 class OProcess : public QObject
00158 {
00159     Q_OBJECT
00160 
00161 public:
00162 
00175     enum Communication { NoCommunication = 0, Stdin = 1, Stdout = 2, Stderr = 4,
00176                          AllOutput = 6, All = 7,
00177                          NoRead };
00178 
00182     enum RunMode {
00187         DontCare,
00191         NotifyOnExit,
00195         Block };
00196 
00200     OProcess( QObject *parent = 0, const char *name = 0 );
00204     OProcess( const QString &arg0, QObject *parent = 0, const char *name = 0 );
00208     OProcess( const QStringList &args, QObject *parent = 0, const char *name = 0 );
00209 
00218     virtual ~OProcess();
00219 
00233     bool setExecutable( const QString& proc );
00234 
00235 
00247     OProcess &operator<<( const QString& arg );
00251     OProcess &operator<<( const char * arg );
00255     OProcess &operator<<( const QCString & arg );
00256 
00261     OProcess &operator<<( const QStringList& args );
00262 
00267     void clearArguments();
00268 
00291     virtual bool start( RunMode runmode = NotifyOnExit,
00292                         Communication comm = NoCommunication );
00293 
00300     virtual bool kill( int signo = SIGTERM );
00301 
00305     bool isRunning() const;
00306 
00316     pid_t pid() const;
00317 
00321     void suspend();
00322 
00326     void resume();
00327 
00335     bool normalExit() const;
00336 
00346     int exitStatus() const;
00347 
00348 
00373     bool writeStdin( const char *buffer, int buflen );
00374 
00375     void flushStdin();
00376 
00384     bool closeStdin();
00385 
00393     bool closeStdout();
00394 
00402     bool closeStderr();
00403 
00409     const QValueList<QCString> &args()
00410     {
00411         return arguments;
00412     }
00413 
00420     void setRunPrivileged( bool keepPrivileges );
00421 
00426     bool runPrivileged() const;
00427 
00432     void setEnvironment( const QString &name, const QString &value );
00433 
00439     void setWorkingDirectory( const QString &dir );
00440 
00452     void setUseShell( bool useShell, const char *shell = 0 );
00453 
00460     static QString quote( const QString &arg );
00461 
00469     void detach();
00470 
00474     static int processPID( const QString& process );
00475 
00476 signals:
00477 
00483     void processExited( Opie::Core::OProcess *proc );
00484 
00485 
00501     void receivedStdout( Opie::Core::OProcess *proc, char *buffer, int buflen );
00502 
00518     void receivedStdout( int fd, int &len );
00519 
00520 
00535     void receivedStderr( Opie::Core::OProcess *proc, char *buffer, int buflen );
00536 
00542     void wroteStdin( Opie::Core::OProcess *proc );
00543 
00544 protected slots:
00545 
00550     void slotChildOutput( int fdno );
00551 
00556     void slotChildError( int fdno );
00557     /*
00558     Slot functions for capturing stdout and stderr of the child
00559     */
00560 
00566     void slotSendData( int dummy );
00567 
00568 protected:
00569 
00574     void setupEnvironment();
00575 
00580     QValueList<QCString> arguments;
00585     RunMode run_mode;
00593     bool runs;
00594 
00602     pid_t pid_;
00603 
00611     int status;
00612 
00613 
00617     bool keepPrivs;
00618 
00619     /*
00620     Functions for setting up the sockets for communication.
00621     setupCommunication
00622     -- is called from "start" before "fork"ing.
00623     commSetupDoneP
00624     -- completes communication socket setup in the parent
00625     commSetupDoneC
00626     -- completes communication setup in the child process
00627     commClose
00628     -- frees all allocated communication resources in the parent
00629     after the process has exited
00630     */
00631 
00645     virtual int setupCommunication( Communication comm );
00646 
00658     virtual int commSetupDoneP();
00659 
00666     virtual int commSetupDoneC();
00667 
00668 
00675     virtual void processHasExited( int state );
00676 
00681     virtual void commClose();
00682 
00683 
00687     int out[ 2 ];
00688     int in[ 2 ];
00689     int err[ 2 ];
00690 
00694     QSocketNotifier *innot;
00695     QSocketNotifier *outnot;
00696     QSocketNotifier *errnot;
00697 
00702     Communication communication;
00703 
00709     int childOutput( int fdno );
00710 
00716     int childError( int fdno );
00717 
00718     // information about the data that has to be sent to the child:
00719 
00720     const char *input_data;  // the buffer holding the data
00721     int input_sent;    // # of bytes already transmitted
00722     int input_total;   // total length of input_data
00723 
00728     friend class Internal::OProcessController;
00729 
00730 private:
00743     QCString searchShell();
00744 
00749     bool isExecutable( const QCString &filename );
00750 
00751     // Disallow assignment and copy-construction
00752     OProcess( const OProcess& );
00753     OProcess& operator= ( const OProcess& );
00754 
00755 private:
00756     void init ( );
00757     Internal::OProcessPrivate *d;
00758 };
00759 }
00760 }
00761 
00762 #endif
00763 

Generated on Sat Nov 5 16:16:10 2005 for OPIE by  doxygen 1.4.2