00001 // 00002 // Boost.Process 00003 // ~~~~~~~~~~~~~ 00004 // 00005 // Copyright (c) 2006, 2007 Julio M. Merino Vidal 00006 // Copyright (c) 2008 Boris Schaeling 00007 // 00008 // Distributed under the Boost Software License, Version 1.0. (See accompanying 00009 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 00010 // 00011 00018 #ifndef BOOST_PROCESS_DETAIL_STREAM_INFO_HPP 00019 #define BOOST_PROCESS_DETAIL_STREAM_INFO_HPP 00020 00021 #include <boost/process/config.hpp> 00022 00023 #if defined(BOOST_POSIX_API) 00024 # include <unistd.h> 00025 #elif defined(BOOST_WINDOWS_API) 00026 #else 00027 # error "Unsupported platform." 00028 #endif 00029 00030 #include <boost/process/stream_behavior.hpp> 00031 #include <boost/process/detail/file_handle.hpp> 00032 #include <boost/process/detail/pipe.hpp> 00033 #include <boost/optional.hpp> 00034 #include <boost/assert.hpp> 00035 #include <string> 00036 00037 namespace boost { 00038 namespace process { 00039 namespace detail { 00040 00049 struct stream_info 00050 { 00054 enum type 00055 { 00059 close, 00060 00064 inherit, 00065 00070 redirect, 00071 00075 use_file, 00076 00080 use_handle, 00081 00085 use_pipe 00086 }; 00087 00091 type type_; 00092 00096 int desc_to_; 00097 00101 std::string file_; 00102 00106 file_handle handle_; 00107 00111 boost::optional<pipe> pipe_; 00112 00116 stream_info(const stream_behavior &sb, bool out) 00117 { 00118 switch (sb.type_) 00119 { 00120 case stream_behavior::close: 00121 { 00122 type_ = close; 00123 break; 00124 } 00125 case stream_behavior::inherit: 00126 { 00127 type_ = inherit; 00128 break; 00129 } 00130 case stream_behavior::redirect_to_stdout: 00131 { 00132 type_ = redirect; 00133 #if defined(BOOST_POSIX_API) 00134 desc_to_ = STDOUT_FILENO; 00135 #elif defined(BOOST_WINDOWS_API) 00136 desc_to_ = 1; 00137 #endif 00138 break; 00139 } 00140 #if defined(BOOST_POSIX_API) 00141 case stream_behavior::posix_redirect: 00142 { 00143 type_ = redirect; 00144 desc_to_ = sb.desc_to_; 00145 break; 00146 } 00147 #endif 00148 case stream_behavior::silence: 00149 { 00150 type_ = use_file; 00151 #if defined(BOOST_POSIX_API) 00152 file_ = out ? "/dev/null" : "/dev/zero"; 00153 #elif defined(BOOST_WINDOWS_API) 00154 file_ = "NUL"; 00155 #endif 00156 break; 00157 } 00158 case stream_behavior::capture: 00159 { 00160 type_ = use_pipe; 00161 pipe_ = pipe(); 00162 break; 00163 } 00164 default: 00165 { 00166 BOOST_ASSERT(false); 00167 } 00168 } 00169 } 00170 }; 00171 00172 } 00173 } 00174 } 00175 00176 #endif