00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00018 #ifndef BOOST_PROCESS_POSIX_CHILD_HPP
00019 #define BOOST_PROCESS_POSIX_CHILD_HPP
00020
00021 #include <boost/process/child.hpp>
00022 #include <boost/process/pistream.hpp>
00023 #include <boost/process/postream.hpp>
00024 #include <boost/process/detail/pipe.hpp>
00025 #include <boost/process/detail/posix_ops.hpp>
00026 #include <boost/process/detail/stream_info.hpp>
00027 #include <boost/shared_ptr.hpp>
00028 #include <boost/assert.hpp>
00029 #include <map>
00030 #include <unistd.h>
00031
00032 namespace boost {
00033 namespace process {
00034
00054 class posix_child : public child
00055 {
00056 public:
00070 postream &get_input(int desc) const
00071 {
00072 if (desc == STDIN_FILENO)
00073 return posix_child::get_stdin();
00074 else
00075 {
00076 input_map_t::const_iterator it = input_map_.find(desc);
00077 BOOST_ASSERT(it != input_map_.end());
00078 return *it->second;
00079 }
00080 }
00081
00095 pistream &get_output(int desc) const
00096 {
00097 if (desc == STDOUT_FILENO)
00098 return posix_child::get_stdout();
00099 else if (desc == STDERR_FILENO)
00100 return posix_child::get_stderr();
00101 else
00102 {
00103 output_map_t::const_iterator it = output_map_.find(desc);
00104 BOOST_ASSERT(it != output_map_.end());
00105 return *it->second;
00106 }
00107 }
00108
00122 posix_child(id_type id, detail::info_map &infoin, detail::info_map &infoout)
00123 : child(id,
00124 detail::posix_info_locate_pipe(infoin, STDIN_FILENO, false),
00125 detail::posix_info_locate_pipe(infoout, STDOUT_FILENO, true),
00126 detail::posix_info_locate_pipe(infoout, STDERR_FILENO, true))
00127 {
00128 for (detail::info_map::iterator it = infoin.begin(); it != infoin.end(); ++it)
00129 {
00130 detail::stream_info &si = it->second;
00131 if (si.type_ == detail::stream_info::use_pipe)
00132 {
00133 BOOST_ASSERT(si.pipe_->wend().valid());
00134 boost::shared_ptr<postream> st(new postream(si.pipe_->wend()));
00135 input_map_.insert(input_map_t::value_type(it->first, st));
00136 }
00137 }
00138
00139 for (detail::info_map::iterator it = infoout.begin(); it != infoout.end(); ++it)
00140 {
00141 detail::stream_info &si = it->second;
00142 if (si.type_ == detail::stream_info::use_pipe)
00143 {
00144 BOOST_ASSERT(si.pipe_->rend().valid());
00145 boost::shared_ptr<pistream> st(new pistream(si.pipe_->rend()));
00146 output_map_.insert(output_map_t::value_type(it->first, st));
00147 }
00148 }
00149 }
00150
00151 private:
00155 typedef std::map<int, boost::shared_ptr<postream> > input_map_t;
00156
00161 input_map_t input_map_;
00162
00166 typedef std::map<int, boost::shared_ptr<pistream> > output_map_t;
00167
00172 output_map_t output_map_;
00173 };
00174
00175 }
00176 }
00177
00178 #endif