Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages | Examples

pprocess.h

Go to the documentation of this file.
00001 /*
00002  *   P::Classes - Portable C++ Application Framework
00003  *   Copyright (C) 2000-2003 Christian Prochnow <cproch@seculogix.de>
00004  *
00005  *   This library is free software; you can redistribute it and/or
00006  *   modify it under the terms of the GNU Lesser General Public
00007  *   License as published by the Free Software Foundation; either
00008  *   version 2 of the License, or (at your option) any later version.
00009  *
00010  *   This library is distributed in the hope that it will be useful,
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  *   Lesser General Public License for more details.
00014  *
00015  *   You should have received a copy of the GNU Lesser General Public
00016  *   License along with this library; if not, write to the Free Software
00017  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  */
00019 
00020 #ifndef _pprocess_h_
00021 #define _pprocess_h_
00022 
00023 #include <pclasses/pexport.h>
00024 #include <pclasses/pexception.h>
00025 #include <pclasses/piodevice.h>
00026 #include <string>
00027 #include <list>
00028 
00029 namespace P {
00030 
00032 
00037 class PCORE_EXPORT ProcessIO: public IODevice {
00038   friend class Process;
00039   public:
00040 
00042     void close() throw(IOError);
00043 
00045     size_t write(const char* buffer, size_t count) throw(IOError);
00046 
00048     size_t read(char* buffer, size_t count) throw(IOError);
00049 
00051     size_t readErr(char* buffer, size_t count) throw(IOError);
00052 
00053   protected:
00054     ProcessIO(io_handle_t in, io_handle_t out, io_handle_t err) throw();
00055     ~ProcessIO() throw();
00056 
00057   private:
00058     io_handle_t m_in;
00059     io_handle_t m_out;
00060     io_handle_t m_err;
00061 
00062 };
00063 
00064 
00066 
00070 class PCORE_EXPORT ProcessEnv {
00071   public:
00072 
00074     static void set(const char* name, const char* value);
00075 
00077     static void unset(const char* name);
00078 
00080     static const char* get(const char* name);
00081 
00082   private:
00083     ProcessEnv();
00084     ~ProcessEnv();
00085 };
00086 
00087 
00089 
00095 class PCORE_EXPORT Process {
00096   public:
00098     enum state_t {
00099       Stopped,
00100       Running,
00101       Stopping
00102     };
00103 
00105     enum commMode_t {
00106       NoCommunication = 0,  
00107       StdIn     = 1,        
00108       StdOut    = 2,        
00109       StdErr    = 4,        
00110       AllOutput = 6,        
00111       All       = 7         
00112     };
00113 
00115     typedef std::list<std::string> arg_list;
00116 
00118     Process(const char* path, const arg_list& args = arg_list())
00119       throw(IOError);
00120 
00121     ~Process() throw();
00122 
00124     inline state_t state() const
00125     { return m_state; }
00126 
00128     void addArg(const char* arg);
00129 
00131     void clearArgs();
00132 
00134     void setWorkDir(const char* dir);
00135 
00136     inline const std::string& workDir() const
00137     { return m_dir; }
00138 
00140     void start(commMode_t mode = NoCommunication)
00141       throw(SystemError,IOError,LogicError);
00142 
00144     void stop() throw(SystemError);
00145 
00147     void kill() throw(SystemError);
00148 
00150     bool tryWait(int& exitCode) throw(SystemError);
00151 
00153     int wait() throw(SystemError);
00154 
00156     static Process* tryWaitAny(int& exitCode) throw(SystemError);
00157 
00159     static Process* waitAny(int& exitCode) throw(SystemError);
00160 
00162 
00169     inline ProcessIO* processIO() const throw()
00170     { return m_procIO; }
00171 
00172   private:
00173     struct process_handle_t;
00174     process_handle_t* m_handle;
00175 
00176     ProcessIO*    m_procIO;
00177     state_t       m_state;
00178     std::string   m_dir;
00179     std::string   m_program;
00180     arg_list      m_args;
00181 };
00182 
00183 }
00184 
00185 #endif

Generated on Fri Mar 12 21:08:31 2004 for P::Classes by doxygen 1.3.3