X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2Fstlplus%2Fportability%2Fsubprocesses.hpp;h=c60aa5ee5c702f84a43e9585482400bea52b09e7;hp=0369daad40b6b5c645c52e4533968ab5a54772bd;hb=4f6e4488a55f7e3ba3f7485d78177f793c0eab9a;hpb=6b0a0d0efafe34d48ab344fca3b479553bd4e62c diff --git a/src/stlplus/portability/subprocesses.hpp b/src/stlplus/portability/subprocesses.hpp index 0369daa..c60aa5e 100644 --- a/src/stlplus/portability/subprocesses.hpp +++ b/src/stlplus/portability/subprocesses.hpp @@ -4,9 +4,9 @@ // Author: Andy Rushton // Copyright: (c) Southampton University 1999-2004 -// (c) Andy Rushton 2004-2009 +// (c) Andy Rushton 2004 onwards // License: BSD License, see ../docs/license.html - + // Platform-independent wrapper around the very platform-specific handling of // subprocesses. Uses the C++ convention that all resources must be contained in // an object so that when a subprocess object goes out of scope the subprocess @@ -102,11 +102,17 @@ namespace stlplus #else #define ENVIRON_TYPE char** #endif + class subprocess; + class async_subprocess; class env_vector { private: ENVIRON_TYPE m_env; + friend class subprocess; + friend class async_subprocess; + // access the env_vector as an envp type - used for passing to subprocesses + ENVIRON_TYPE envp (void) const; public: // create an env_vector vector from the current process @@ -116,16 +122,16 @@ namespace stlplus env_vector& operator = (const env_vector&); - void clear (void); - // manipulate the env_vector by adding or removing variables // adding a name that already exists replaces its value void add (const std::string& name, const std::string& value); bool remove (const std::string& name); + void clear (void); // get the value associated with a name // the first uses an indexed notation (e.g. env["PATH"] ) // the second is a function based form (e.g. env.get("PATH")) + bool present(const std::string& name) const; std::string operator [] (const std::string& name) const; std::string get (const std::string& name) const; @@ -135,9 +141,6 @@ namespace stlplus // get the name=value pairs by index (in the range 0 to size()-1) std::pair operator [] (unsigned index) const throw(std::out_of_range); std::pair get (unsigned index) const throw(std::out_of_range); - - // access the env_vector as an envp type - used for passing to subprocesses - ENVIRON_TYPE envp (void) const; }; //////////////////////////////////////////////////////////////////////////////// @@ -155,7 +158,7 @@ namespace stlplus class subprocess { - private: + protected: PID_TYPE m_pid; #ifdef MSWINDOWS @@ -167,6 +170,7 @@ namespace stlplus env_vector m_env; int m_err; int m_status; + void set_error(int); public: subprocess(void); @@ -174,6 +178,7 @@ namespace stlplus void add_variable(const std::string& name, const std::string& value); bool remove_variable(const std::string& name); + const env_vector& get_variables(void) const; bool spawn(const std::string& path, const arg_vector& argv, bool connect_stdin = false, bool connect_stdout = false, bool connect_stderr = false); @@ -208,7 +213,7 @@ namespace stlplus class backtick_subprocess : public subprocess { - private: + protected: std::string m_text; public: backtick_subprocess(void); @@ -226,7 +231,7 @@ namespace stlplus class async_subprocess { - private: + protected: PID_TYPE m_pid; #ifdef MSWINDOWS HANDLE m_job; @@ -245,6 +250,7 @@ namespace stlplus void add_variable(const std::string& name, const std::string& value); bool remove_variable(const std::string& name); + const env_vector& get_variables(void) const; bool spawn(const std::string& path, const arg_vector& argv, bool connect_stdin = false, bool connect_stdout = false, bool connect_stderr = false);