00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00019 #ifndef BOOST_PROCESS_CONTEXT_HPP
00020 #define BOOST_PROCESS_CONTEXT_HPP
00021
00022 #include <boost/process/config.hpp>
00023
00024 #if defined(BOOST_POSIX_API)
00025 # include <boost/scoped_array.hpp>
00026 # include <cerrno>
00027 # include <unistd.h>
00028 #elif defined(BOOST_WINDOWS_API)
00029 # include <windows.h>
00030 #else
00031 # error "Unsupported platform."
00032 #endif
00033
00034 #include <boost/process/environment.hpp>
00035 #include <boost/process/stream_behavior.hpp>
00036 #include <boost/system/system_error.hpp>
00037 #include <boost/throw_exception.hpp>
00038 #include <boost/assert.hpp>
00039 #include <string>
00040 #include <vector>
00041
00042 namespace boost {
00043 namespace process {
00044
00053 template <class Path>
00054 class basic_work_directory_context
00055 {
00056 public:
00064 basic_work_directory_context()
00065 {
00066 #if defined(BOOST_POSIX_API)
00067 errno = 0;
00068 long size = ::pathconf(".", _PC_PATH_MAX);
00069 if (size == -1 && errno)
00070 boost::throw_exception(boost::system::system_error(boost::system::error_code(errno, boost::system::get_system_category()), "boost::process::basic_work_directory_context::basic_work_directory_context: pathconf(2) failed"));
00071 else if (size == -1)
00072 size = BOOST_PROCESS_POSIX_PATH_MAX;
00073 boost::scoped_array<char> cwd(new char[size]);
00074 if (!::getcwd(cwd.get(), size))
00075 boost::throw_exception(boost::system::system_error(boost::system::error_code(errno, boost::system::get_system_category()), "boost::process::basic_work_directory_context::basic_work_directory_context: getcwd(2) failed"));
00076 work_directory = cwd.get();
00077 #elif defined(BOOST_WINDOWS_API)
00078 char cwd[MAX_PATH];
00079 if (!::GetCurrentDirectoryA(sizeof(cwd), cwd))
00080 boost::throw_exception(boost::system::system_error(boost::system::error_code(::GetLastError(), boost::system::get_system_category()), "boost::process::basic_work_directory_context::basic_work_directory_context: GetCurrentDirectory failed"));
00081 work_directory = cwd;
00082 #endif
00083 BOOST_ASSERT(!work_directory.empty());
00084 }
00085
00092 Path work_directory;
00093 };
00094
00103 class environment_context
00104 {
00105 public:
00112 boost::process::environment environment;
00113 };
00114
00121 template <class Path>
00122 class basic_context : public basic_work_directory_context<Path>, public environment_context
00123 {
00124 public:
00128 stream_behavior stdin_behavior;
00129
00133 stream_behavior stdout_behavior;
00134
00138 stream_behavior stderr_behavior;
00139 };
00140
00141 typedef basic_context<std::string> context;
00142
00149 template <class Executable, class Arguments, class Context>
00150 class basic_pipeline_entry
00151 {
00152 public:
00156 Executable executable;
00157
00161 Arguments arguments;
00162
00166 Context context;
00167
00172 typedef Executable executable_type;
00173
00178 typedef Arguments arguments_type;
00179
00184 typedef Context context_type;
00185
00193 basic_pipeline_entry(const Executable &exe, const Arguments &args, const Context &ctx)
00194 : executable(exe),
00195 arguments(args),
00196 context(ctx)
00197 {
00198 }
00199 };
00200
00204 typedef basic_pipeline_entry<std::string, std::vector<std::string>, context> pipeline_entry;
00205
00206 }
00207 }
00208
00209 #endif