From: Christian P. <cp...@us...> - 2004-12-31 03:23:09
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22434/include/pclasses/System Added Files: Process.h ProcessIO.h Log Message: Added ProcessIO and Process class (compiles but untested). --- NEW FILE: Process.h --- /*************************************************************************** * Copyright (C) 2004 by Christian Prochnow * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef P_System_Process_h #define P_System_Process_h #include <pclasses/Unicode/String.h> #include <pclasses/IO/IOError.h> #include <pclasses/System/SystemError.h> #include <pclasses/System/ProcessIO.h> #include <list> namespace P { namespace System { //! Child process class /*! This class is used to concurrently execute child processes. \author Christian Prochnow <cp...@se...> */ class Process { public: //! Child process state enum State { Stopped, Running, Stopping }; //! Communication mode flags enum CommFlags { NoComm = 0x00, /*!< Close StdIn, StdOut, StdErr */ InheritStdIn = 0x01, /*!< Inherit StdIn from parent */ RedirectStdIn = 0x02, /*!< Redirect StdIn to ProcessIO object */ InheritStdOut = 0x04, /*!< Inherit StdOut from parent */ RedirectStdOut = 0x08, /*!< Redirect StdOut to ProcessIO object */ InheritStdErr = 0x10, /*!< Inherit StdErr from parent */ RedirectStdErr = 0x20, /*!< Redirect StdErr to ProcessIO object */ InheritAll = InheritStdIn|InheritStdOut|InheritStdErr, RedirectAll = RedirectStdIn|RedirectStdOut|RedirectStdErr }; //! Argument list type typedef std::list<Unicode::String> ArgList; //! Process constructor Process(const Unicode::String& program, const ArgList& args = ArgList()); ~Process() throw(); //! Returns the process state State state() const; void setArgs(const ArgList& args); //! Add argument void addArg(const Unicode::String& arg); //! Clear arguments void clearArgs(); //! Set working directory void setWorkDir(const Unicode::String& dir); //! Returns the programs working directory const Unicode::String& workDir() const; //! Run program void start(int mode = NoComm) throw(IO::IOError,SystemError,LogicError); //! Terminate process void stop() throw(SystemError); //! Kill process void kill() throw(SystemError); //! Try wait for program to finish bool tryWait(int& exitCode) throw(SystemError); //! Wait for program to finish int wait() throw(SystemError); //! Return the process i/o object ProcessIO& processIO() const throw(LogicError); private: unsigned long _handle; ProcessIO* _procIO; State _state; Unicode::String _workDir; Unicode::String _program; ArgList _args; }; } // !namespace System } // !namespace P #endif --- NEW FILE: ProcessIO.h --- /*************************************************************************** * Copyright (C) 2004 by Christian Prochnow * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef P_System_ProcessIO_h #define P_System_ProcessIO_h #include <pclasses/IO/IODevice.h> #include <pclasses/System/Pipe.h> namespace P { namespace System { //! Child process I/O device /*! \author Christian Prochnow <cp...@se...> */ class ProcessIO: public IO::IODevice { public: ProcessIO(const Pipe& in, const Pipe& out, const Pipe& err) throw(IO::IOError); ~ProcessIO() throw(); //! Close pipe's to child process void close() throw(IO::IOError); void closeWrite() throw(IO::IOError); void closeRead() throw(IO::IOError); void closeErr() throw(IO::IOError); //! Write to process stdin size_t write(const char* buffer, size_t count) throw(IO::IOError); //! Read from process stdout size_t read(char* buffer, size_t count) throw(IO::IOError); //! Read from process stderr size_t readErr(char* buffer, size_t count) throw(IO::IOError); private: Pipe _in, _out, _err; }; } // !namespace System } // !namespace P #endif |